Package Bio :: Package Emboss :: Module PrimerSearch
[hide private]
[frames] | no frames]

Source Code for Module Bio.Emboss.PrimerSearch

 1  # This code is part of the Biopython distribution and governed by its 
 2  # license.  Please see the LICENSE file that should have been included 
 3  # as part of this package. 
 4  # 
 5   
 6  """Code to interact with the primersearch program from EMBOSS. 
 7  """ 
 8   
 9   
10 -class InputRecord(object):
11 """Represent the input file into the primersearch program. 12 13 This makes it easy to add primer information and write it out to the 14 simple primer file format. 15 """
16 - def __init__(self):
17 self.primer_info = []
18
19 - def __str__(self):
20 output = "" 21 for name, primer1, primer2 in self.primer_info: 22 output += "%s %s %s\n" % (name, primer1, primer2) 23 return output
24
25 - def add_primer_set(self, primer_name, first_primer_seq, 26 second_primer_seq):
27 """Add primer information to the record. 28 """ 29 self.primer_info.append((primer_name, first_primer_seq, 30 second_primer_seq))
31 32
33 -class OutputRecord(object):
34 """Represent the information from a primersearch job. 35 36 amplifiers is a dictionary where the keys are the primer names and 37 the values are a list of PrimerSearchAmplifier objects. 38 """
39 - def __init__(self):
40 self.amplifiers = {}
41 42
43 -class Amplifier(object):
44 """Represent a single amplification from a primer. 45 """
46 - def __init__(self):
47 self.hit_info = "" 48 self.length = 0
49 50
51 -def read(handle):
52 """Get output from primersearch into a PrimerSearchOutputRecord 53 """ 54 record = OutputRecord() 55 56 for line in handle: 57 if not line.strip(): 58 continue 59 elif line.startswith("Primer name"): 60 name = line.split()[-1] 61 record.amplifiers[name] = [] 62 elif line.startswith("Amplimer"): 63 amplifier = Amplifier() 64 record.amplifiers[name].append(amplifier) 65 elif line.startswith("\tSequence: "): 66 amplifier.hit_info = line.replace("\tSequence: ", "") 67 elif line.startswith("\tAmplimer length: "): 68 length = line.split()[-2] 69 amplifier.length = int(length) 70 else: 71 amplifier.hit_info += line 72 73 for name in record.amplifiers: 74 for amplifier in record.amplifiers[name]: 75 amplifier.hit_info = amplifier.hit_info.rstrip() 76 77 return record
78