annotate commons/launcher/LaunchRepeatMasker.py @ 18:94ab73e8a190

Uploaded
author m-zytnicki
date Mon, 29 Apr 2013 03:20:15 -0400
parents
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
18
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
1 #! /usr/bin/env python
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
2
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
3 # Copyright INRA (Institut National de la Recherche Agronomique)
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
4 # http://www.inra.fr
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
5 # http://urgi.versailles.inra.fr
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
6 #
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
7 # This software is governed by the CeCILL license under French law and
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
8 # abiding by the rules of distribution of free software. You can use,
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
9 # modify and/ or redistribute the software under the terms of the CeCILL
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
10 # license as circulated by CEA, CNRS and INRIA at the following URL
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
11 # "http://www.cecill.info".
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
12 #
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
13 # As a counterpart to the access to the source code and rights to copy,
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
14 # modify and redistribute granted by the license, users are provided only
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
15 # with a limited warranty and the software's author, the holder of the
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
16 # economic rights, and the successive licensors have only limited
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
17 # liability.
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
18 #
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
19 # In this respect, the user's attention is drawn to the risks associated
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
20 # with loading, using, modifying and/or developing or reproducing the
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
21 # software by the user in light of its specific status of free software,
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
22 # that may mean that it is complicated to manipulate, and that also
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
23 # therefore means that it is reserved for developers and experienced
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
24 # professionals having in-depth computer knowledge. Users are therefore
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
25 # encouraged to load and test the software's suitability as regards their
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
26 # requirements in conditions enabling the security of their systems and/or
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
27 # data to be ensured and, more generally, to use and operate it in the
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
28 # same conditions as regards security.
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
29 #
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
30 # The fact that you are presently reading this means that you have had
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
31 # knowledge of the CeCILL license and that you accept its terms.
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
32
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
33 from commons.core.checker.CheckerUtils import CheckerUtils
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
34 from commons.core.utils.FileUtils import FileUtils
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
35 from commons.core.utils.RepetOptionParser import RepetOptionParser
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
36 import subprocess
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
37
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
38 class LaunchRepeatMasker(object):
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
39
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
40 def __init__(self,queryFileName="", libFileName ="",sensitivity="", engine="wu", cutOff=225, outputDir = ".",verbosity=0):
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
41 self._queryFileName = queryFileName
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
42 self._libFileName = libFileName
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
43 self._engine = engine
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
44 self._sensitivity = sensitivity
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
45 self._cutOff = cutOff
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
46 self._outputDir = outputDir
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
47 self._verbosity = verbosity
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
48
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
49 def setAttributesFromCmdLine(self):
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
50 description = "LaunchRepeatMasker runs the RepeatMasker program ."
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
51 parser = RepetOptionParser(description = description)
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
52 parser.add_option("-q", "--query", dest="queryFileName", default = None, action="store", type="string", help="input query file [compulsory] [format: fasta]")
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
53 parser.add_option("-l", "--libFileName", dest="libFileName", default = None, action="store", type="string", help="custom library [optional]")
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
54 parser.add_option("-n", "--outputDir", dest="outputDir", default=".", action="store", type="string", help="outputDir (default : current directory) [optional] ")
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
55 parser.add_option("-c", "--cutOff", dest="cutOff", default=225, action="store", type="int", help="Sets cutoff score for masking repeats when using -lib (default 225) [optional] ")
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
56 parser.add_option("-e", "--engine", dest="engine", default = "wu", action="store", type="string", help="engine [optional] ")
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
57 parser.add_option("-u", "--sensitivity", dest="sensitivity", default = "", action="store", type="string", help="sensitivity can be s, q, qq[optional] ")
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
58 parser.add_option("-v", "--verbosity", dest="verbosity", default = 0, action="store", type="int", help="verbosity [optional] ")
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
59
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
60 (options, args) = parser.parse_args()
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
61 self._setAttributesFromOptions(options)
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
62
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
63 def _setAttributesFromOptions(self, options):
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
64 self._queryFileName = options.queryFileName
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
65 self._libFileName = options.libFileName
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
66 self._outputDir = options.outputDir
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
67 self._engine = options.engine
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
68 self._sensitivity = options.sensitivity
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
69 self._cutOff = options.cutOff
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
70 self._verbosity = options.verbosity
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
71
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
72 def checkOptions(self):
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
73 if self._queryFileName != "":
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
74 if not FileUtils.isRessourceExists(self._queryFileName):
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
75 raise Exception("ERROR: Query file: %s does not exist!" % self._queryFileName)
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
76 else:
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
77 raise Exception("ERROR: No specified --query option!")
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
78
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
79 def run(self):
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
80 if not CheckerUtils.isExecutableInUserPath("RepeatMasker") :
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
81 print "ERROR: RepeatMasker must be in your path"
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
82 else:
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
83 self.checkOptions()
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
84
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
85 engine = ""
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
86 if self._engine == "wu":
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
87 engine = "-e wublast"
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
88 elif self._engine == "cm":
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
89 engine = "-e crossmatch"
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
90 sensitivity = ""
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
91 if self._sensitivity:
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
92 sensitivity = "-%s" % self._sensitivity
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
93 libFileName = ""
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
94 if self._libFileName != "":
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
95 libFileName = "-lib %s" % self._libFileName
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
96
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
97 cmd = "RepeatMasker %s -dir %s -pa 1 -gccalc -no_is -nolow %s %s %s" % (self._queryFileName,self._outputDir,engine,sensitivity,libFileName)
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
98 cmd = cmd.split()
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
99
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
100 if self._verbosity>0:
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
101 print("Running RepeatMasker with following commands : %s" %cmd)
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
102
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
103 process = subprocess.Popen(cmd, stdout=subprocess.PIPE,stderr = subprocess.PIPE)
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
104 # process.wait()
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
105 output= process.communicate()
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
106 if self._verbosity>0:
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
107 print("".join(output))
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
108 return process.returncode
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
109
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
110 if __name__ == "__main__":
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
111 iLaunchRepeatMasker = LaunchRepeatMasker()
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
112 iLaunchRepeatMasker.setAttributesFromCmdLine()
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
113 iLaunchRepeatMasker.run()