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 import sys
|
|
34 import os
|
|
35 import optparse
|
|
36 from commons.core.checker.CheckerUtils import CheckerUtils
|
|
37 from commons.core.utils.FileUtils import FileUtils
|
|
38 from subprocess import Popen
|
|
39 from commons.core.utils.RepetOptionParser import RepetOptionParser
|
|
40 import subprocess
|
|
41 import tempfile
|
|
42
|
|
43 class LaunchLastZ(object):
|
|
44
|
|
45 def __init__(self,queryFileName="", refFileName ="", outputFileName=None,outputFileFormat="axt",noTransition=True, ambiguous=None, step=1,gfextend=False, chain=False, verbosity=1 ):
|
|
46 self.queryFileName = queryFileName
|
|
47 self.refFileName = refFileName
|
|
48 self.outputFileName = outputFileName
|
|
49 self.outputFileFormat = outputFileFormat
|
|
50 self.noTransition = noTransition
|
|
51 self.step = step
|
|
52 self.ambiguous = ambiguous
|
|
53 self.gfextend = gfextend
|
|
54 self.chain = chain
|
|
55 self.verbosity = verbosity
|
|
56
|
|
57 def setAttributesFromCmdLine(self):
|
|
58 description = "LaunchLastZ runs the LastZ program ."
|
|
59 parser = RepetOptionParser(description = description)
|
|
60 parser.add_option("-q", "--query", dest="queryFileName", default = None, action="store", type="string", help="input query file [compulsory] [format: fasta]")
|
|
61 parser.add_option("-r", "--ref", dest="refFileName", default = None, action="store", type="string", help="input ref file [compulsory] [format: fasta]")
|
|
62 parser.add_option("-o", "--output", dest="outputFileName", default = None, action="store", type="string", help="output file [compulsory] ")
|
|
63 parser.add_option("-f", "--format", dest="outputFileFormat", default = "axt", action="store", type="string", help="output file format[optional] ")
|
|
64 parser.add_option("-n", "--notransition", dest="noTransition", action="store_false", default=True, help="noTransition (default True) [optional] ")
|
|
65 parser.add_option("-a", "--ambiguous", dest="ambiguous", action="store", type="string", help="ambiguous [optional] ")
|
|
66 parser.add_option("-s", "--step", dest="step", default = 1, action="store", type="int", help="stepsize (default 1) [optional] ")
|
|
67 parser.add_option("-g", "--gfextend", dest="gfextend", action="store_true", help="extend gf (default false)[optional] ")
|
|
68 parser.add_option("-c", "--chain", dest="chain", action="store_true", help="chain (default false)[optional] ")
|
|
69 parser.add_option("-v", "--verbosity", dest="verbosity", default = 1, action="store", type="int", help="verbosity [optional] ")
|
|
70 (self._options, args) = parser.parse_args()
|
|
71 self._setAttributesFromOptions(self._options)
|
|
72
|
|
73 def _setAttributesFromOptions(self, options):
|
|
74 self.queryFileName = options.queryFileName
|
|
75 self.refFileName = options.refFileName
|
|
76 self.outputFileName = options.outputFileName
|
|
77 self.outputFileFormat = options.outputFileFormat
|
|
78 self.ambiguous = options.ambiguous
|
|
79 self.noTransition = options.noTransition
|
|
80 self.step = options.step
|
|
81 self.gfextend = options.gfextend
|
|
82 self.chain = options.chain
|
|
83 self.verbosity = options.verbosity
|
|
84
|
|
85 def checkOptions(self):
|
|
86 if self.queryFileName != "":
|
|
87 if not FileUtils.isRessourceExists(self.queryFileName):
|
|
88 raise Exception("ERROR: Query file does not exist!")
|
|
89 else:
|
|
90 raise Exception("ERROR: No specified --query option!")
|
|
91 if self.refFileName != "":
|
|
92 if not FileUtils.isRessourceExists(self.refFileName):
|
|
93 raise Exception("ERROR: Ref file does not exist!")
|
|
94 else:
|
|
95 raise Exception("ERROR: No specified --ref option!")
|
|
96 if self.outputFileName == None:
|
|
97 self.outputFileName = "%s_%s.axt" % (os.path.basename(self.queryFileName), os.path.basename(self.refFileName))
|
|
98
|
|
99 def run(self):
|
|
100 if not CheckerUtils.isExecutableInUserPath("lastz") :
|
|
101 print ("ERROR: LastZ must be in your path")
|
|
102 else:
|
|
103 self.checkOptions()
|
|
104
|
|
105 transition = ""
|
|
106 if self.noTransition:
|
|
107 transition = "--notransition"
|
|
108 ambiguous = ""
|
|
109 if self.ambiguous is not None:
|
|
110 ambiguous = "--ambiguous=%s" % self.ambiguous
|
|
111
|
|
112 gfextend = ""
|
|
113 if self.gfextend:
|
|
114 gfextend = "--gfextend"
|
|
115
|
|
116 chain = ""
|
|
117 if self.chain:
|
|
118 chain = "--chain"
|
|
119
|
|
120 cmd = "lastz %s[format=fasta] %s[format=fasta] --output=%s --format=%s %s %s --step=%i %s %s" % (self.refFileName, self.queryFileName, self.outputFileName
|
|
121 , self.outputFileFormat, ambiguous, transition,self.step, gfextend, chain)
|
|
122 if self.verbosity>0:
|
|
123 print("Running LastZ with following commands : %s" %cmd)
|
|
124 sys.stdout.flush()
|
|
125 cmd = cmd.split()
|
|
126 process = subprocess.Popen(cmd)
|
|
127 process.wait()
|
|
128 return process.returncode
|
|
129
|
|
130 if __name__ == "__main__":
|
|
131 iLaunchLastZ = LaunchLastZ()
|
|
132 iLaunchLastZ.setAttributesFromCmdLine()
|
|
133 iLaunchLastZ.run()
|