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