annotate commons/launcher/LaunchNucmer.py @ 19:9bcfa7936eec

Deleted selected files
author m-zytnicki
date Mon, 29 Apr 2013 03:23:29 -0400
parents 94ab73e8a190
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 from commons.core.LoggerFactory import LoggerFactory
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
38 import os
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
39
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
40 LOG_DEPTH = "repet.tools"
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
41
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
42 class LaunchNucmer(object):
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
43
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
44 def __init__(self,queryFileName="", refFileName ="", prefix = None, genCoords=False, showCoords = False, mum=False, maxGaps=90, minMatch=20, nooptimize=False,mincluster=65, minIdentity=50, minLength=100, verbosity=0):
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
45 self._queryFileName = queryFileName
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
46 self._refFileName = refFileName
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
47 self._prefix = prefix
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
48 self._genCoords = genCoords
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
49 self._showCoords = showCoords
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
50 self._mum = mum
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
51 self._maxgaps = maxGaps
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
52 self._minMatch = minMatch
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
53 self._nooptimize = nooptimize
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
54 self._mincluster = mincluster
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
55 self._minIdentity = minIdentity
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
56 self._minLength = minLength
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
57 self.verbosity = verbosity
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
58 self._log = LoggerFactory.createLogger("%s.%s" % (LOG_DEPTH, self.__class__.__name__), self.verbosity)
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
59
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
60 def setMincluster(self, value):
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
61 self._mincluster = value
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
62 def getMincluster(self):
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
63 return self._mincluster
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
64
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
65 mincluster = property(getMincluster, setMincluster)
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
66
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
67 def setAttributesFromCmdLine(self):
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
68 description = "LaunchNucmer runs the Nucmer program (part of the mummer package) ."
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
69 parser = RepetOptionParser(description = description)
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
70 parser.add_option("-q", "--query", dest="queryFileName", default = "", action="store", type="string", help="input query file [compulsory] [format: fasta]")
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
71 parser.add_option("-r", "--ref", dest="refFileName", default = "", action="store", type="string", help="input ref file [compulsory] [format: fasta]")
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
72 parser.add_option("-p", "--prefix", dest="prefix", default = None, action="store", type="string", help="prefix name [optional]")
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
73 parser.add_option("-o","--gencoords", dest="genCoords",action="store_true", help="generate coords file with minimal option (show-coords -r) [optional] ")
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
74 parser.add_option("-s","--showcoords", dest="showCoords",action="store_true", help="generate coords file with: show-coords -r -c -l -d -I 50 -L 100 -T [optional] ")
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
75 parser.add_option("-m", "--mum", dest="mum", action="store_true", help="Use anchor matches that are unique in both the reference and query [optional] ")
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
76 parser.add_option("-g", "--maxgaps", dest="maxgaps", default = 90, action="store", type="int", help="Maximum gap between two adjacent matches in a cluster (default 90) [optional] ")
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
77 parser.add_option("-l", "--minmatch", dest="minMatch", default = 20, action="store", type="int", help="Minimum length of an maximal exact match (default 20) [optional] ")
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
78 parser.add_option("-n", "--nooptimize", dest="nooptimize", action="store_true", help="nooptimize (default --optimize) [optional] ")
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
79 parser.add_option("-j", "--mincluster", dest="mincluster", default = 65, action="store", type="int", help="Minimum length of a cluster of matches (default 65) [optional] ")
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
80
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
81 parser.add_option("-i", "--minIdentity", dest="minIdentity", default = 50, action="store", type="int", help="Minimum identity for show_coords (default 50) [optional] ")
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
82 parser.add_option("-u", "--minLength", dest="minLength", default = 100, action="store", type="int", help="Minimum alignment length for show_coords (default 100) [optional] ")
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
83 parser.add_option("-v", "--verbosity", dest="verbosity", default = 0, action="store", type="int", help="verbosity [optional] ")
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
84
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
85 (self._options, args) = parser.parse_args()
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
86 self._setAttributesFromOptions(self._options)
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
87
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
88 def _setAttributesFromOptions(self, options):
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
89 self._queryFileName = options.queryFileName
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
90 self._refFileName = options.refFileName
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
91 self._prefix = options.prefix
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
92 self._genCoords = options.genCoords
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
93 self._showCoords = options.showCoords
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
94 self._mum = options.mum
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
95 self._maxgaps = options.maxgaps
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
96 self._minMatch = options.minMatch
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
97 self._nooptimize = options.nooptimize
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
98 self._mincluster = options.mincluster
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
99
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
100 self._minIdentity = options.minIdentity
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
101 self._minLength = options.minLength
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
102
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
103 self.verbosity = options.verbosity
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
104
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
105 def _logAndRaise(self, errorMsg):
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
106 self._log.error(errorMsg)
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
107 raise Exception(errorMsg)
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
108
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
109 def checkOptions(self):
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
110 if self._queryFileName != "":
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
111 if not FileUtils.isRessourceExists(self._queryFileName):
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
112 self._logAndRaise("ERROR: Query file: %s does not exist!" % self._queryFileName)
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
113 else:
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
114 self._logAndRaise("ERROR: No specified --query option!")
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
115
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
116 if self._refFileName != "":
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
117 if not FileUtils.isRessourceExists(self._refFileName):
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
118 self._logAndRaise("ERROR: Ref file does not exist!"% self._refFileName)
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
119 else:
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
120 self._logAndRaise("ERROR: No specified --ref option!")
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
121
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
122 def run(self):
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
123 LoggerFactory.setLevel(self._log, self.verbosity)
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
124 if not CheckerUtils.isExecutableInUserPath("nucmer") :
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
125 self._logAndRaise("ERROR: nucmer must be in your path")
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
126 self.checkOptions()
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
127
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
128 genCoords = ""
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
129 if self._genCoords:
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
130 genCoords = "-o"
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
131 mum = ""
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
132 if self._mum:
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
133 mum = "--mum"
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
134 nooptimize = "--optimize"
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
135 if self._nooptimize:
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
136 nooptimize = "--nooptimize"
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
137 prefix = ""
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
138 if self._prefix is not None:
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
139 prefix = "--prefix=%s" %(self._prefix)
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
140 cmd = "nucmer %s %s %s %s %s -g=%d -l=%d %s -c=%d" % (self._refFileName,self._queryFileName, prefix, genCoords, mum, self._maxgaps, self._minMatch, nooptimize, self._mincluster)
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
141 self._log.debug("Running nucmer with following commands : %s" %cmd)
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
142 cmd = cmd.split()
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
143 process = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
144 process.wait()
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
145
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
146 if self._showCoords:
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
147 #use of os.system because redirect on process is broken in python < 3.0
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
148 cmd = "show-coords -r -c -l -d -I %d -L %d -T %s.delta > %s.coords" % (self._minIdentity, self._minLength, self._prefix, self._prefix)
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
149 self._log.debug("Running show-coords with following commands : %s" %cmd)
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
150 os.system(cmd)
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
151
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
152
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
153 return process.returncode
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
154
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
155 if __name__ == "__main__":
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
156 iLaunchNucmer = LaunchNucmer()
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
157 iLaunchNucmer.setAttributesFromCmdLine()
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
158 iLaunchNucmer.run()