annotate uniqprimer-0.5.0/primertools/eprimerparser.py @ 3:3249d78ecfc2 draft

Uploaded
author dereeper
date Mon, 03 Jan 2022 09:56:55 +0000
parents
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 os
3249d78ecfc2 Uploaded
dereeper
parents:
diff changeset
11 import utils
3249d78ecfc2 Uploaded
dereeper
parents:
diff changeset
12 import re
3249d78ecfc2 Uploaded
dereeper
parents:
diff changeset
13
3249d78ecfc2 Uploaded
dereeper
parents:
diff changeset
14 def parsePrimerSequences( eprimerFile ):
3249d78ecfc2 Uploaded
dereeper
parents:
diff changeset
15 '''
3249d78ecfc2 Uploaded
dereeper
parents:
diff changeset
16 parse an eprimer3 output file for all primers
3249d78ecfc2 Uploaded
dereeper
parents:
diff changeset
17 '''
3249d78ecfc2 Uploaded
dereeper
parents:
diff changeset
18
3249d78ecfc2 Uploaded
dereeper
parents:
diff changeset
19 utils.logMessage( "eprimerparser::parsePrimerSequences( )", "parsing for primer sequences" )
3249d78ecfc2 Uploaded
dereeper
parents:
diff changeset
20 if os.path.exists( eprimerFile ) == False:
3249d78ecfc2 Uploaded
dereeper
parents:
diff changeset
21 utils.logMessage( "eprimerparser::parsePrimerSequences( )", "ERROR - eprimer file was not found" )
3249d78ecfc2 Uploaded
dereeper
parents:
diff changeset
22 raise utils.NoFileFoundException( eprimerFile )
3249d78ecfc2 Uploaded
dereeper
parents:
diff changeset
23
3249d78ecfc2 Uploaded
dereeper
parents:
diff changeset
24
3249d78ecfc2 Uploaded
dereeper
parents:
diff changeset
25 primers = [ ]
3249d78ecfc2 Uploaded
dereeper
parents:
diff changeset
26 primerFile = open( eprimerFile )
3249d78ecfc2 Uploaded
dereeper
parents:
diff changeset
27
3249d78ecfc2 Uploaded
dereeper
parents:
diff changeset
28 currentPrimer = None
3249d78ecfc2 Uploaded
dereeper
parents:
diff changeset
29
3249d78ecfc2 Uploaded
dereeper
parents:
diff changeset
30 nextPrimerId = 0
3249d78ecfc2 Uploaded
dereeper
parents:
diff changeset
31 for line in primerFile.readlines( ):
3249d78ecfc2 Uploaded
dereeper
parents:
diff changeset
32
3249d78ecfc2 Uploaded
dereeper
parents:
diff changeset
33 if line[ 0 ] == '# ':
3249d78ecfc2 Uploaded
dereeper
parents:
diff changeset
34 continue
3249d78ecfc2 Uploaded
dereeper
parents:
diff changeset
35
3249d78ecfc2 Uploaded
dereeper
parents:
diff changeset
36 if line.find( "PRODUCT SIZE" ) != -1:
3249d78ecfc2 Uploaded
dereeper
parents:
diff changeset
37 if currentPrimer is not None:
3249d78ecfc2 Uploaded
dereeper
parents:
diff changeset
38 primers.append( currentPrimer )
3249d78ecfc2 Uploaded
dereeper
parents:
diff changeset
39 currentPrimer = utils.PrimerSet( str( nextPrimerId ) )
3249d78ecfc2 Uploaded
dereeper
parents:
diff changeset
40 nextPrimerId += 1
3249d78ecfc2 Uploaded
dereeper
parents:
diff changeset
41 productSize = int( line.split( ':' )[ 1 ].strip( ) )
3249d78ecfc2 Uploaded
dereeper
parents:
diff changeset
42 currentPrimer.setProductSize( productSize )
3249d78ecfc2 Uploaded
dereeper
parents:
diff changeset
43 else:
3249d78ecfc2 Uploaded
dereeper
parents:
diff changeset
44 tokens = re.split( ' *', line.strip( ) )
3249d78ecfc2 Uploaded
dereeper
parents:
diff changeset
45 if len( tokens ) == 7:
3249d78ecfc2 Uploaded
dereeper
parents:
diff changeset
46
3249d78ecfc2 Uploaded
dereeper
parents:
diff changeset
47 sequence = tokens[ 6 ]
3249d78ecfc2 Uploaded
dereeper
parents:
diff changeset
48 temp = tokens[ 4 ]
3249d78ecfc2 Uploaded
dereeper
parents:
diff changeset
49
3249d78ecfc2 Uploaded
dereeper
parents:
diff changeset
50 if tokens[ 0 ] == "FORWARD":
3249d78ecfc2 Uploaded
dereeper
parents:
diff changeset
51 currentPrimer.setForwardPrimerData( sequence, temp )
3249d78ecfc2 Uploaded
dereeper
parents:
diff changeset
52 elif tokens[ 0 ] == "REVERSE":
3249d78ecfc2 Uploaded
dereeper
parents:
diff changeset
53 currentPrimer.setReversePrimerData( sequence, temp )
3249d78ecfc2 Uploaded
dereeper
parents:
diff changeset
54
3249d78ecfc2 Uploaded
dereeper
parents:
diff changeset
55 if currentPrimer is not None:
3249d78ecfc2 Uploaded
dereeper
parents:
diff changeset
56 primers.append( currentPrimer )
3249d78ecfc2 Uploaded
dereeper
parents:
diff changeset
57
3249d78ecfc2 Uploaded
dereeper
parents:
diff changeset
58 utils.logMessage( "eprimerparser::parsePrimerSequences( )", "finished parsing. found {0} primers".format( len( primers ) ) )
3249d78ecfc2 Uploaded
dereeper
parents:
diff changeset
59 return primers
3249d78ecfc2 Uploaded
dereeper
parents:
diff changeset
60
3249d78ecfc2 Uploaded
dereeper
parents:
diff changeset
61
3249d78ecfc2 Uploaded
dereeper
parents:
diff changeset
62
3249d78ecfc2 Uploaded
dereeper
parents:
diff changeset
63
3249d78ecfc2 Uploaded
dereeper
parents:
diff changeset
64
3249d78ecfc2 Uploaded
dereeper
parents:
diff changeset
65
3249d78ecfc2 Uploaded
dereeper
parents:
diff changeset
66
3249d78ecfc2 Uploaded
dereeper
parents:
diff changeset
67
3249d78ecfc2 Uploaded
dereeper
parents:
diff changeset
68
3249d78ecfc2 Uploaded
dereeper
parents:
diff changeset
69
3249d78ecfc2 Uploaded
dereeper
parents:
diff changeset
70
3249d78ecfc2 Uploaded
dereeper
parents:
diff changeset
71
3249d78ecfc2 Uploaded
dereeper
parents:
diff changeset
72
3249d78ecfc2 Uploaded
dereeper
parents:
diff changeset
73
3249d78ecfc2 Uploaded
dereeper
parents:
diff changeset
74
3249d78ecfc2 Uploaded
dereeper
parents:
diff changeset
75