comparison commons/launcher/YassProgramLauncher.py @ 18:94ab73e8a190

Uploaded
author m-zytnicki
date Mon, 29 Apr 2013 03:20:15 -0400
parents
children
comparison
equal deleted inserted replaced
17:b0e8584489e6 18:94ab73e8a190
1 #!/usr/bin/env python
2
3 ##@file
4 # Launch Yass (pairwise alignment).
5 #
6 # options:
7 # -h: this help
8 # -i: name of the input file (queries, format='fasta')
9 # -s: name of the subject file (format='fasta')
10 # -p: parameters for 'yass' (default='-d 2')
11 # -o: name of the output file (format='align', default=inFile+'.align')
12 # -c: clean
13 # -v: verbosity level (default=0/1)
14
15
16 import os
17 import sys
18
19 from pyRepet.launcher.AbstractProgramLauncher import AbstractProgramLauncher
20
21
22 class YassProgramLauncher( AbstractProgramLauncher ):
23 """
24 Launch Yass (pairwise alignment).
25 """
26
27 def __init__( self ):
28 """
29 Constructor.
30 """
31 AbstractProgramLauncher.__init__( self )
32 self._prgName = "yass"
33 self._formatInFile = "fasta"
34 self._sbjFile = ""
35 self._prgParam = ""
36 self._allByAll = False
37 self._cmdLineSpecificOptions = "s:p:Ao:"
38
39
40 def getSpecificHelpAsString( self ):
41 """
42 Return the specific help as a string.
43 """
44 string = ""
45 string += "\nspecific options:"
46 string += "\n -s: name of the subject file (format='fasta')"
47 string += "\n -p: parameters for '%s'" % ( self.getProgramName() )
48 string += "\n -A: same sequences (all-by-all)"
49 string += "\n -o: name of the output file (format='align', default=inFile+'.align')"
50 return string
51
52
53 def setASpecificAttributeFromCmdLine( self, o, a="" ):
54 """
55 Set a specific attribute from the command-line arguments.
56 """
57 if o =="-s":
58 self.setSubjectFile( a )
59 elif o == "-p":
60 self.setProgramParameters( a )
61 elif o == "-A":
62 self.setAllByAll()
63 elif o == "-o":
64 self.setOutputFile( a )
65
66
67 def setSubjectFile( self, arg ):
68 self._sbjFile = arg
69
70
71 def getSubjectFile( self ):
72 return self._sbjFile
73
74
75 def setAllByAll( self ):
76 self._allByAll = True
77
78
79 def getAllByAll( self ):
80 return self._allByAll
81
82
83 def checkSpecificAttributes( self ):
84 """
85 Check the specific attributes before running the program.
86 """
87 if self._sbjFile == "":
88 string = "ERROR: missing subject file (-s)"
89 print string
90 print self.getHelpAsString()
91 sys.exit(1)
92 if self.getOutputFile() == "":
93 self.setOutputFile( "%s.align" % ( self.getInputFile() ) )
94
95
96 def setWrapperCommandLine( self ):
97 """
98 Set the command-line of the wrapper.
99 Required for YassClusterLauncher.
100 """
101 self._wrpCmdLine = self.getWrapperName()
102 self._wrpCmdLine += " -i %s" % ( self.getInputFile() )
103 self._wrpCmdLine += " -s %s" % ( self.getSubjectFile() )
104 if self.getProgramParameters() != "":
105 self._wrpCmdLine += " -p '%s'" % ( self.getProgramParameters() )
106 if self.getAllByAll():
107 self._wrpCmdLine += " -A"
108 if self.getOutputFile() == "":
109 self.setOutputFile( "%s.align" % ( self.getInputFile() ) )
110 self._wrpCmdLine += " -o %s" % ( self.getOutputFile() )
111 if self.getClean():
112 self._wrpCmdLine += " -c"
113 self._wrpCmdLine += " -v %i" % ( self.getVerbosityLevel() )
114
115
116 def setProgramCommandLine( self ):
117 """
118 Set the command-line of the program.
119 """
120 self._prgCmdLine = self.getProgramName()
121 self._prgCmdLine += " -d 2"
122 if self.getProgramParameters() != "":
123 self._prgCmdLine += " %s" % ( self.getProgramParameters() )
124 self._prgCmdLine += " -o %s.blast" % ( self.getInputFile() )
125 self._prgCmdLine += " %s" % ( self.getInputFile() )
126 self._prgCmdLine += " %s" % ( self.getSubjectFile() )
127
128
129 def setListFilesToKeep( self ):
130 """
131 Set the list of files to keep.
132 """
133 if self.getOutputFile() == "":
134 self.setOutputFile( "%s.align" % ( self.getInputFile() ) )
135 self.appendFileToKeep( self.getOutputFile() )
136
137
138 def setListFilesToRemove( self ):
139 """
140 Set the list of files to remove.
141 """
142 pass
143
144
145 def convertBlastIntoAlign( self ):
146 """
147 Convert a 'blast' file into the 'align' format.
148 """
149 cmd = os.environ["REPET_PATH"] + "/bin/blast2align.py"
150 cmd += " -i %s.blast" % ( self.getInputFile() )
151 cmd += " -o %s" % ( self.getOutputFile() )
152 exitStatus = os.system( cmd )
153 if exitStatus != 0:
154 string = "ERROR while converting 'blast' file into 'align' format"
155 print string
156 sys.exit(1)
157
158
159 def setSummary( self ):
160 self._summary = "input file: %s" % ( self.getInputFile() )
161 self._summary += "\nsubject file: %s" % ( self.getSubjectFile() )
162 self._summary += "\nparameters: %s" % ( self.getProgramParameters() )
163 if self.getAllByAll():
164 self._summary += "\nall-by-all"
165 if self.getOutputFile() == "":
166 self.setOutputFile( "%s.align" % ( self.getInputFile() ) )
167 self._summary += "\noutput file: %s" % ( self.getOutputFile() )
168
169
170 def run( self ):
171 """
172 Run the program.
173 """
174 self.start()
175
176 self.setProgramCommandLine()
177 cmd = self.getProgramCommandLine()
178 if self.getVerbosityLevel() > 0:
179 print "LAUNCH: %s" % ( cmd )
180 sys.stdout.flush()
181 exitStatus = os.system( cmd )
182 if exitStatus != 0:
183 string = "ERROR: program '%s' returned exit status '%i'" % ( self.getProgramName(), exitStatus )
184 print string
185 sys.exit(1)
186
187 self.convertBlastIntoAlign()
188
189 self.end()
190
191
192 if __name__ == "__main__":
193 i = YassProgramLauncher()
194 i.setAttributesFromCmdLine()
195 i.run()