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(object):
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
28 -class OutputRecord(object):
29 """Represent the information from a primersearch job. 30 31 amplifiers is a dictionary where the keys are the primer names and 32 the values are a list of PrimerSearchAmplifier objects. 33 """
34 - def __init__(self):
35 self.amplifiers = {}
36 37
38 -class Amplifier(object):
39 """Represent a single amplification from a primer. 40 """
41 - def __init__(self):
42 self.hit_info = "" 43 self.length = 0
44 45
46 -def read(handle):
47 """Get output from primersearch into a PrimerSearchOutputRecord 48 """ 49 record = OutputRecord() 50 51 for line in handle: 52 if not line.strip(): 53 continue 54 elif line.startswith("Primer name"): 55 name = line.split()[-1] 56 record.amplifiers[name] = [] 57 elif line.startswith("Amplimer"): 58 amplifier = Amplifier() 59 record.amplifiers[name].append(amplifier) 60 elif line.startswith("\tSequence: "): 61 amplifier.hit_info = line.replace("\tSequence: ", "") 62 elif line.startswith("\tAmplimer length: "): 63 length = line.split()[-2] 64 amplifier.length = int(length) 65 else: 66 amplifier.hit_info += line 67 68 for name in record.amplifiers: 69 for amplifier in record.amplifiers[name]: 70 amplifier.hit_info = amplifier.hit_info.rstrip() 71 72 return record
73