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