annotate uniqprimer-0.5.0/primertools/primersearchutils.py @ 6:8218425fda1d draft default tip

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