annotate uniqprimer-0.5.0/build/lib/primertools/programs.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
3249d78ecfc2 Uploaded
dereeper
parents:
diff changeset
11 import utils
3249d78ecfc2 Uploaded
dereeper
parents:
diff changeset
12 import os
3249d78ecfc2 Uploaded
dereeper
parents:
diff changeset
13 import subprocess
3249d78ecfc2 Uploaded
dereeper
parents:
diff changeset
14
3249d78ecfc2 Uploaded
dereeper
parents:
diff changeset
15
3249d78ecfc2 Uploaded
dereeper
parents:
diff changeset
16 class ProgramBase( object ):
3249d78ecfc2 Uploaded
dereeper
parents:
diff changeset
17
3249d78ecfc2 Uploaded
dereeper
parents:
diff changeset
18 def __init__( self ):
3249d78ecfc2 Uploaded
dereeper
parents:
diff changeset
19
3249d78ecfc2 Uploaded
dereeper
parents:
diff changeset
20 self.programName = None
3249d78ecfc2 Uploaded
dereeper
parents:
diff changeset
21 self.proc = None
3249d78ecfc2 Uploaded
dereeper
parents:
diff changeset
22
3249d78ecfc2 Uploaded
dereeper
parents:
diff changeset
23 def getProcessArgs( self, args ):
3249d78ecfc2 Uploaded
dereeper
parents:
diff changeset
24 crash #abstract
3249d78ecfc2 Uploaded
dereeper
parents:
diff changeset
25
3249d78ecfc2 Uploaded
dereeper
parents:
diff changeset
26 def execute( self, args, async = False ):
3249d78ecfc2 Uploaded
dereeper
parents:
diff changeset
27 '''
3249d78ecfc2 Uploaded
dereeper
parents:
diff changeset
28 run the nucmer program with a given compare file and an exclude file
3249d78ecfc2 Uploaded
dereeper
parents:
diff changeset
29 '''
3249d78ecfc2 Uploaded
dereeper
parents:
diff changeset
30
3249d78ecfc2 Uploaded
dereeper
parents:
diff changeset
31 utils.logMessage( "ProgramBase::Execute( )", "Running the {0} program.".format( self.programName ) )
3249d78ecfc2 Uploaded
dereeper
parents:
diff changeset
32
3249d78ecfc2 Uploaded
dereeper
parents:
diff changeset
33 args, outputFile = self.getProcessArgs( args )
3249d78ecfc2 Uploaded
dereeper
parents:
diff changeset
34
3249d78ecfc2 Uploaded
dereeper
parents:
diff changeset
35 print "*** Running {0} ***".format( self.programName )
3249d78ecfc2 Uploaded
dereeper
parents:
diff changeset
36
3249d78ecfc2 Uploaded
dereeper
parents:
diff changeset
37 utils.logList( "ProgramBase::Execute( )", args )
3249d78ecfc2 Uploaded
dereeper
parents:
diff changeset
38
3249d78ecfc2 Uploaded
dereeper
parents:
diff changeset
39 proc = subprocess.Popen( args )
3249d78ecfc2 Uploaded
dereeper
parents:
diff changeset
40
3249d78ecfc2 Uploaded
dereeper
parents:
diff changeset
41 if async == False:
3249d78ecfc2 Uploaded
dereeper
parents:
diff changeset
42 #wait for the nucmer instance to finish
3249d78ecfc2 Uploaded
dereeper
parents:
diff changeset
43 proc.wait( )
3249d78ecfc2 Uploaded
dereeper
parents:
diff changeset
44 print "*** Running {0} Complete ***".format( self.programName )
3249d78ecfc2 Uploaded
dereeper
parents:
diff changeset
45
3249d78ecfc2 Uploaded
dereeper
parents:
diff changeset
46 #return the name of the coords file
3249d78ecfc2 Uploaded
dereeper
parents:
diff changeset
47 return outputFile
3249d78ecfc2 Uploaded
dereeper
parents:
diff changeset
48
3249d78ecfc2 Uploaded
dereeper
parents:
diff changeset
49 def isFinished( self ):
3249d78ecfc2 Uploaded
dereeper
parents:
diff changeset
50 ifIsFinished
3249d78ecfc2 Uploaded
dereeper
parents:
diff changeset
51
3249d78ecfc2 Uploaded
dereeper
parents:
diff changeset
52 class Nucmer( ProgramBase ):
3249d78ecfc2 Uploaded
dereeper
parents:
diff changeset
53
3249d78ecfc2 Uploaded
dereeper
parents:
diff changeset
54 def __init__( self ):
3249d78ecfc2 Uploaded
dereeper
parents:
diff changeset
55 #if we can't find the nucemer binary, throw
3249d78ecfc2 Uploaded
dereeper
parents:
diff changeset
56 nucmerPath = utils.search_file( 'nucmer' )
3249d78ecfc2 Uploaded
dereeper
parents:
diff changeset
57 ProgramBase.__init__( self )
3249d78ecfc2 Uploaded
dereeper
parents:
diff changeset
58 if nucmerPath is None:
3249d78ecfc2 Uploaded
dereeper
parents:
diff changeset
59 raise utils.ProgramNotFoundException( 'nucmer', "Please ensure that the MUMmer package is installed and configured on your system." )
3249d78ecfc2 Uploaded
dereeper
parents:
diff changeset
60
3249d78ecfc2 Uploaded
dereeper
parents:
diff changeset
61 self.nucmer = nucmerPath
3249d78ecfc2 Uploaded
dereeper
parents:
diff changeset
62
3249d78ecfc2 Uploaded
dereeper
parents:
diff changeset
63 self.programName = "nucmer"
3249d78ecfc2 Uploaded
dereeper
parents:
diff changeset
64 self.outputExtension = ".coords"
3249d78ecfc2 Uploaded
dereeper
parents:
diff changeset
65
3249d78ecfc2 Uploaded
dereeper
parents:
diff changeset
66
3249d78ecfc2 Uploaded
dereeper
parents:
diff changeset
67 def getProcessArgs( self, inputArgs ):
3249d78ecfc2 Uploaded
dereeper
parents:
diff changeset
68
3249d78ecfc2 Uploaded
dereeper
parents:
diff changeset
69
3249d78ecfc2 Uploaded
dereeper
parents:
diff changeset
70 time = utils.getTimeStamp( )
3249d78ecfc2 Uploaded
dereeper
parents:
diff changeset
71
3249d78ecfc2 Uploaded
dereeper
parents:
diff changeset
72 identifier = "nucmer_alignments"
3249d78ecfc2 Uploaded
dereeper
parents:
diff changeset
73 args = [ self.nucmer, '-p', identifier, '-o', '--minmatch', '300', '--maxgap', '1' ]
3249d78ecfc2 Uploaded
dereeper
parents:
diff changeset
74
3249d78ecfc2 Uploaded
dereeper
parents:
diff changeset
75 args.extend( inputArgs )
3249d78ecfc2 Uploaded
dereeper
parents:
diff changeset
76
3249d78ecfc2 Uploaded
dereeper
parents:
diff changeset
77 outputFile = "{0}.coords".format( identifier )
3249d78ecfc2 Uploaded
dereeper
parents:
diff changeset
78
3249d78ecfc2 Uploaded
dereeper
parents:
diff changeset
79 return args, outputFile
3249d78ecfc2 Uploaded
dereeper
parents:
diff changeset
80
3249d78ecfc2 Uploaded
dereeper
parents:
diff changeset
81 class Eprimer( ProgramBase ):
3249d78ecfc2 Uploaded
dereeper
parents:
diff changeset
82
3249d78ecfc2 Uploaded
dereeper
parents:
diff changeset
83 def __init__( self, eprimerOptions ):
3249d78ecfc2 Uploaded
dereeper
parents:
diff changeset
84
3249d78ecfc2 Uploaded
dereeper
parents:
diff changeset
85 self.programName = "EPrimer3"
3249d78ecfc2 Uploaded
dereeper
parents:
diff changeset
86 self.options = eprimerOptions
3249d78ecfc2 Uploaded
dereeper
parents:
diff changeset
87
3249d78ecfc2 Uploaded
dereeper
parents:
diff changeset
88 primer3corePath = utils.search_file( "primer3_core" )
3249d78ecfc2 Uploaded
dereeper
parents:
diff changeset
89 if primer3corePath is None:
3249d78ecfc2 Uploaded
dereeper
parents:
diff changeset
90 raise utils.ProgramNotFoundException( "primer3_core", "Please ensure that the primer3 package is installed on your system. It can be obtained from http://primer3.sourceforge.net/" )
3249d78ecfc2 Uploaded
dereeper
parents:
diff changeset
91
3249d78ecfc2 Uploaded
dereeper
parents:
diff changeset
92 eprimerPath = utils.search_file( "eprimer3" )
3249d78ecfc2 Uploaded
dereeper
parents:
diff changeset
93 if eprimerPath is None:
3249d78ecfc2 Uploaded
dereeper
parents:
diff changeset
94 raise utils.ProgramNotFoundException( 'eprimer3', "Please ensure that the EMBOSS package is installed and configured on your system." )
3249d78ecfc2 Uploaded
dereeper
parents:
diff changeset
95
3249d78ecfc2 Uploaded
dereeper
parents:
diff changeset
96 self.primer3core = primer3corePath
3249d78ecfc2 Uploaded
dereeper
parents:
diff changeset
97 self.eprimer3 = eprimerPath
3249d78ecfc2 Uploaded
dereeper
parents:
diff changeset
98
3249d78ecfc2 Uploaded
dereeper
parents:
diff changeset
99 def getProcessArgs( self, inputArgs ):
3249d78ecfc2 Uploaded
dereeper
parents:
diff changeset
100
3249d78ecfc2 Uploaded
dereeper
parents:
diff changeset
101 #todo - allow user to determine output file location/name
3249d78ecfc2 Uploaded
dereeper
parents:
diff changeset
102
3249d78ecfc2 Uploaded
dereeper
parents:
diff changeset
103 inputFasta = inputArgs[ 0 ]
3249d78ecfc2 Uploaded
dereeper
parents:
diff changeset
104 outputFile = inputArgs[ 1 ]
3249d78ecfc2 Uploaded
dereeper
parents:
diff changeset
105 args = [ self.eprimer3, inputFasta, outputFile, '-numreturn', '2', '-prange', self.options.getProductRange( ), '-osize', str( self.options.getPrimerSize( ) ),
3249d78ecfc2 Uploaded
dereeper
parents:
diff changeset
106 '-minsize', str( self.options.getMinPrimerSize( ) ), '-maxsize', str( self.options.getMaxPrimerSize( ) )]
3249d78ecfc2 Uploaded
dereeper
parents:
diff changeset
107
3249d78ecfc2 Uploaded
dereeper
parents:
diff changeset
108 return args, outputFile
3249d78ecfc2 Uploaded
dereeper
parents:
diff changeset
109
3249d78ecfc2 Uploaded
dereeper
parents:
diff changeset
110 class PrimerSearch( ProgramBase ):
3249d78ecfc2 Uploaded
dereeper
parents:
diff changeset
111 def __init__( self ):
3249d78ecfc2 Uploaded
dereeper
parents:
diff changeset
112
3249d78ecfc2 Uploaded
dereeper
parents:
diff changeset
113 self.programName = "PrimerSearch"
3249d78ecfc2 Uploaded
dereeper
parents:
diff changeset
114 primerSearchPath = utils.search_file( "primersearch" )
3249d78ecfc2 Uploaded
dereeper
parents:
diff changeset
115 if primerSearchPath is None:
3249d78ecfc2 Uploaded
dereeper
parents:
diff changeset
116 raise utils.ProgramNotFoundException( "primersearch", "Please ensure that the EMBOSS package is installed on your system." )
3249d78ecfc2 Uploaded
dereeper
parents:
diff changeset
117
3249d78ecfc2 Uploaded
dereeper
parents:
diff changeset
118 self.primerSearch = primerSearchPath
3249d78ecfc2 Uploaded
dereeper
parents:
diff changeset
119
3249d78ecfc2 Uploaded
dereeper
parents:
diff changeset
120 def getProcessArgs( self, inputArgs ):
3249d78ecfc2 Uploaded
dereeper
parents:
diff changeset
121 '''
3249d78ecfc2 Uploaded
dereeper
parents:
diff changeset
122 usage for this program: inputArgs is an array length 4
3249d78ecfc2 Uploaded
dereeper
parents:
diff changeset
123 inputArgs[0] = sequence file
3249d78ecfc2 Uploaded
dereeper
parents:
diff changeset
124 inputArgs[1] = primer pairs file
3249d78ecfc2 Uploaded
dereeper
parents:
diff changeset
125 inputArgs[2] = output file name
3249d78ecfc2 Uploaded
dereeper
parents:
diff changeset
126 inputArgs[3] = percent mismatch
3249d78ecfc2 Uploaded
dereeper
parents:
diff changeset
127 '''
3249d78ecfc2 Uploaded
dereeper
parents:
diff changeset
128
3249d78ecfc2 Uploaded
dereeper
parents:
diff changeset
129 args = [ self.primerSearch ]
3249d78ecfc2 Uploaded
dereeper
parents:
diff changeset
130 args.extend( [ '-seqall', inputArgs[ 0 ] ] )
3249d78ecfc2 Uploaded
dereeper
parents:
diff changeset
131 args.extend( [ '-infile', inputArgs[ 1 ] ] )
3249d78ecfc2 Uploaded
dereeper
parents:
diff changeset
132 args.extend( [ '-mismatchpercent', inputArgs[ 3 ] ] )
3249d78ecfc2 Uploaded
dereeper
parents:
diff changeset
133 args.extend( [ '-outfile', inputArgs[ 2 ] ] )
3249d78ecfc2 Uploaded
dereeper
parents:
diff changeset
134
3249d78ecfc2 Uploaded
dereeper
parents:
diff changeset
135
3249d78ecfc2 Uploaded
dereeper
parents:
diff changeset
136 return args, inputArgs[ 2 ]
3249d78ecfc2 Uploaded
dereeper
parents:
diff changeset
137
3249d78ecfc2 Uploaded
dereeper
parents:
diff changeset
138
3249d78ecfc2 Uploaded
dereeper
parents:
diff changeset
139
3249d78ecfc2 Uploaded
dereeper
parents:
diff changeset
140
3249d78ecfc2 Uploaded
dereeper
parents:
diff changeset
141