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

Source Code for Module Bio.Emboss.PrimerSearch

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