comparison uniqprimer-0.5.0/primertools/primersearchutils.py @ 3:3249d78ecfc2 draft

Uploaded
author dereeper
date Mon, 03 Jan 2022 09:56:55 +0000
parents
children
comparison
equal deleted inserted replaced
2:7e0438dad4e9 3:3249d78ecfc2
1 '''
2 Created on Jan 1, 2011
3
4 @author: John L. Herndon
5 @contact: herndon@cs.colostate.edu
6 @organization: Colorado State University
7 @group: Computer Science Department, Asa Ben-Hur's laboratory
8 '''
9
10 import utils
11
12 def writePrimerSearchInputFile( primerSets, outputFile ):
13 '''
14 A function to write primer pairs to a file formatted as primer search input.
15 primerPairs - a list of utils.PrimerSet objects
16 outputFile - a string containing the path to the output file
17 '''
18
19 file = open( outputFile, 'w' )
20 i = 0
21 for primerSet in primerSets:
22 i += 1
23 if primerSet.reversePrimer == "":
24 print "Error - primer {0} has no reverse primer. {1} primers total".format( i, len( primerSets ) )
25 continue
26 file.write( primerSet.id + "\t" + primerSet.forwardPrimer + "\t" + primerSet.reversePrimer + "\n" )
27
28 file.close( )
29
30 def parsePrimerSearchFile( primerSearchFileName ):
31 '''
32 return a list of primer ids that are associated with at least one amplimer in the primer search output file.
33 '''
34 found = [ ]
35
36 amplimerFound = False
37 currentId = -1;
38 for line in open( primerSearchFileName ).readlines( ):
39
40 if "Primer name" in line:
41 #the id of the primer is found after the string "Primer name" in the file
42 currentId = line.split( ' ' )[ 2: ][ 0 ].strip( )
43 elif "Amplimer" in line and currentId not in found:
44 found.append( currentId )
45
46 if amplimerFound == True:
47 found.append( currentId )
48
49 return found
50
51
52
53
54
55