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