annotate commons/launcher/LaunchMCL.py @ 31:0ab839023fe4

Uploaded
author m-zytnicki
date Tue, 30 Apr 2013 14:33:21 -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.LoggerFactory import LoggerFactory
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
34 from commons.core.utils.RepetOptionParser import RepetOptionParser
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
35 from commons.core.seq.FastaUtils import FastaUtils
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
36 from commons.core.coord.MatchUtils import MatchUtils
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
37 import subprocess
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
38 import os
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
39 import time
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
40 import shutil
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
41 from commons.tools.ChangeSequenceHeaders import ChangeSequenceHeaders
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
42
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
43 LOG_DEPTH = "repet.base"
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
44
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
45 ##Launch MCL
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
46 #
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
47 class LaunchMCL(object):
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
48
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
49 def __init__(self, fastaFileName = "", outFilePrefix = "", inflate = 1.5, covThres = 0.0, isJoined = False, isCluster2Map = False, isClusterConsensusHeaders = False, doClean = False, verbosity = 0):
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
50 self._fastaFileName = fastaFileName
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
51 self.setOutFilePrefix(outFilePrefix)
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
52 self._inflate = inflate
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
53 self._coverageThreshold = covThres
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
54 self._isJoined = isJoined
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
55 self._isCluster2Map = isCluster2Map
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
56 self._isClusterConsensusHeaders = isClusterConsensusHeaders
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
57 self._doClean = doClean
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
58 self._verbosity = verbosity
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
59 self._log = LoggerFactory.createLogger("%s.%s" % (LOG_DEPTH, self.__class__.__name__), self._verbosity)
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
60
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
61 def setAttributesFromCmdLine(self):
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
62 description = "Launch MCL clustering program."
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
63 epilog = "\nExample: launch without verbosity and keep temporary files.\n"
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
64 epilog += "\t$ python LaunchMCL.py -i file.fa -v 0\n"
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
65 parser = RepetOptionParser(description = description, epilog = epilog)
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
66 parser.add_option("-i", "--fasta", dest = "fastaFileName", action = "store", type = "string", help = "input fasta file name [compulsory] [format: fasta]", default = "")
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
67 parser.add_option("-o", "--out", dest = "outFilePrefix", action = "store", type = "string", help = "prefix of the output files [default=input fasta file name]", default = "")
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
68 parser.add_option("-I", "--inflate", dest = "inflate", action = "store", type = "float", help = "inflate parameter of MCL [optional] [default: 1.5]", default = 1.5)
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
69 parser.add_option("-T", "--coverage", dest = "coverageThreshold", action = "store", type = "float", help = "length coverage threshold (default=0.0, 0.0 <= value <= 1.0)", default = 0.0)
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
70 parser.add_option("-j", "--join", dest = "isJoined", action = "store_true", help = "join hits after alignement [optional] [default: False]" , default = False)
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
71 parser.add_option("-m", "--map", dest = "isCluster2Map", action = "store_true", help = "generate an additional output file in map format (Warning: only works if MCL's fasta input headers are formated like LTRharvest fasta output)", default = False)
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
72 parser.add_option("", "--isClusterConsensusHeaders", dest = "isClusterConsensusHeaders", action="store_true", help = "format headers for Cluster Consensus tool", default = False)
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
73 parser.add_option("-c", "--clean", dest = "doClean", action = "store_true", help = "clean temporary files [optional] [default: False]", default = False)
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
74 parser.add_option("-v", "--verbosity", dest = "verbosity", action = "store", type = "int", help = "verbosity [optional] [default: 1]", default = 1)
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
75 options = parser.parse_args()[0]
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
76 self._setAttributesFromOptions(options)
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
77
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
78 def _setAttributesFromOptions(self, options):
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
79 self.setFastaFileName(options.fastaFileName)
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
80 self.setOutFilePrefix(options.outFilePrefix)
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
81 self.setInflate(options.inflate)
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
82 self.setCoverageThreshold(options.coverageThreshold)
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
83 self.setIsJoined(options.isJoined)
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
84 self.setIsCluster2Map(options.isCluster2Map)
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
85 self.setIsClusterConsensusHeaders(options.isClusterConsensusHeaders)
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
86 self.setDoClean(options.doClean)
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
87 self.setVerbosity(options.verbosity)
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
88
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
89 def setFastaFileName(self, fastaFileName):
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
90 self._fastaFileName = fastaFileName
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
91
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
92 def setOutFilePrefix(self, outFilePrefix):
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
93 if outFilePrefix == "":
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
94 self._outFilePrefix = os.path.splitext(self._fastaFileName)[0]
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
95 else:
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
96 self._outFilePrefix = outFilePrefix
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
97
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
98 def setInflate(self, inflate):
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
99 self._inflate = inflate
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
100
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
101 def setCoverageThreshold(self, covThres):
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
102 self._coverageThreshold = float(covThres)
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
103
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
104 def setIsJoined(self, isJoined):
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
105 self._isJoined = isJoined
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
106
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
107 def setDoClean(self, doClean):
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
108 self._doClean = doClean
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
109
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
110 def setIsCluster2Map(self, isCluster2Map):
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
111 self._isCluster2Map = isCluster2Map
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
112
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
113 def setIsClusterConsensusHeaders(self, isClusterConsensusHeaders):
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
114 self._isClusterConsensusHeaders = isClusterConsensusHeaders
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
115
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
116 def setVerbosity(self, verbosity):
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
117 self._verbosity = verbosity
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
118
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
119 def _checkOptions(self):
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
120 if self._fastaFileName == "":
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
121 self._logAndRaise("ERROR: Missing input fasta file name")
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
122 if self._isCluster2Map and self._isClusterConsensusHeaders:
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
123 self._logAndRaise("ERROR: You can't use both '--isClusterConsensusHeaders' and '-m' options")
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
124 if self._coverageThreshold > 1 or self._coverageThreshold < 0:
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
125 self._logAndRaise("ERROR: Coverage Threshold must be in [0.0 , 1.0]")
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
126
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
127 def _logAndRaise(self, errorMsg):
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
128 self._log.error(errorMsg)
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
129 raise Exception(errorMsg)
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
130
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
131 def run(self):
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
132 LoggerFactory.setLevel(self._log, self._verbosity)
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
133 self._checkOptions()
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
134 self._log.info("START Launch MCL")
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
135 self._log.debug("With parameters: -i %s -o %s -I %.2f -T %.2f -j %r -m %r -clusterHeaders %r " % (self._fastaFileName, self._outFilePrefix , self._inflate , self._coverageThreshold, self._isJoined, self._isCluster2Map, self._isClusterConsensusHeaders))
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
136 #self._log.debug("With parameters: -i %s -o %s -I %.2f -T %.2f" % (self._fastaFileName, self._outFilePrefix , self._inflate , self._coverageThreshold))
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
137 self._log.debug("Fasta file name: %s" % self._fastaFileName)
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
138 workingDir = "MCLtmpDirectory"
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
139 if os.path.exists(workingDir):
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
140 self._logAndRaise("ERROR: %s already exists." % workingDir)
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
141 os.mkdir(workingDir)
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
142 os.chdir(workingDir)
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
143 linkToFastaFile = "%s2.fa" % os.path.splitext(self._fastaFileName)[0]
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
144 os.symlink("../%s" % self._fastaFileName, self._fastaFileName)
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
145 fastaFileNameShorten = "%s.shortH" % self._fastaFileName
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
146 iChangeSequenceHeaders = ChangeSequenceHeaders(inFile=self._fastaFileName, format="fasta", step=1, outFile=fastaFileNameShorten, verbosity=self._verbosity - 1)
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
147 iChangeSequenceHeaders.run()
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
148 os.symlink(fastaFileNameShorten, linkToFastaFile)
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
149
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
150 self._log.info("START Blaster-Matcher (%s)" % time.strftime("%Y-%m-%d %H:%M:%S"))
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
151 cmd = "LaunchBlaster.py"
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
152 cmd += " -q %s" % fastaFileNameShorten
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
153 cmd += " -s %s" % linkToFastaFile
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
154 cmd += " -a"
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
155 cmd += " 1>&2 >> blasterMatcher.log"
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
156 process = subprocess.Popen(cmd, shell = True)
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
157 self._log.debug("Running : %s" % cmd)
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
158 process.communicate()
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
159 if process.returncode != 0:
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
160 self._logAndRaise("ERROR when launching '%s'" % cmd)
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
161 outBlasterFileName = "%s.align" % fastaFileNameShorten
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
162
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
163 cmd = "matcher"
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
164 cmd += " -m %s" % outBlasterFileName
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
165 cmd += " -q %s" % fastaFileNameShorten
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
166 cmd += " -s %s" % linkToFastaFile
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
167 cmd += " -a"
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
168 if self._isJoined:
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
169 cmd += " -j"
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
170 cmd += " 1>&2 >> blasterMatcher.log"
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
171 process = subprocess.Popen(cmd, shell=True)
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
172 self._log.debug("Running : %s" % cmd)
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
173 process.communicate()
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
174 if process.returncode != 0:
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
175 self._logAndRaise("ERROR when launching '%s'" % cmd)
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
176 self._log.info("END Blaster-Matcher (%s)" % time.strftime("%Y-%m-%d %H:%M:%S"))
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
177
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
178 outMatcherFileName = "%s.match.tab" % outBlasterFileName
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
179 inputABCFileName = "%s.shortH.abc" % os.path.splitext(fastaFileNameShorten)[0]
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
180 MatchUtils.convertMatchFileIntoABCFileOnQueryCoverage(outMatcherFileName, inputABCFileName, coverage = self._coverageThreshold)
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
181 outMCLPreprocessFileName = "MCLPreprocess.out"
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
182
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
183 self._log.info("START MCL (%s)" % time.strftime("%Y-%m-%d %H:%M:%S"))
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
184 cmd = "mcxload"
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
185 cmd += " -abc %s" % inputABCFileName
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
186 cmd += " --stream-mirror"
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
187 cmd += " --stream-neg-log10"
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
188 cmd += " -stream-tf 'ceil(200)'"
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
189 cmd += " -o %s" % outMCLPreprocessFileName
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
190 cmd += " -write-tab %s.tab" % outMCLPreprocessFileName
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
191 cmd += " 1>&2 > MCLpreprocess.log"
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
192 process = subprocess.Popen(cmd, shell = True)
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
193 self._log.debug("Running : %s" % cmd)
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
194 process.communicate()
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
195 if process.returncode != 0:
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
196 self._logAndRaise("ERROR when launching '%s'" % cmd)
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
197
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
198 outMCLFileName = "out.shortH.mcl"
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
199 cmd = "mcl"
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
200 cmd += " %s" % outMCLPreprocessFileName
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
201 cmd += " -I %s" % self._inflate
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
202 cmd += " -use-tab %s.tab" % outMCLPreprocessFileName
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
203 cmd += " -o %s" % outMCLFileName
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
204 cmd += " 1>&2 > MCL.log"
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
205 process = subprocess.Popen(cmd, shell = True)
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
206 self._log.debug("Running : %s" % cmd)
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
207 process.communicate()
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
208 if process.returncode != 0:
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
209 self._logAndRaise("ERROR when launching '%s'" % cmd)
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
210 self._log.info("END MCL (%s)" % time.strftime("%Y-%m-%d %H:%M:%S"))
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
211
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
212 outFastaFileNameShorten = "%s.fa" % os.path.splitext(outMCLFileName)[0]
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
213
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
214 FastaUtils.convertClusterFileToFastaFile(outMCLFileName, fastaFileNameShorten, outFastaFileNameShorten, "MCL", verbosity = self._verbosity - 1)
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
215
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
216 outFastaFileName = "%s_MCL.fa" % self._outFilePrefix
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
217 linkFileName = "%s.newHlink" % self._fastaFileName
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
218 headerStyle = "A"
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
219 if self._isClusterConsensusHeaders:
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
220 headerStyle = "B"
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
221 iChangeSequenceHeaders = ChangeSequenceHeaders(inFile=outFastaFileNameShorten, format="fasta", step=2, outFile=outFastaFileName, linkFile=linkFileName, whichCluster = headerStyle, verbosity=self._verbosity - 1)
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
222 iChangeSequenceHeaders.run()
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
223
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
224 if self._isCluster2Map:
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
225 outMapFileName = "%s_MCL.map" % self._outFilePrefix
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
226 FastaUtils.convertClusteredFastaFileToMapFile(outFastaFileName, outMapFileName)
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
227 shutil.move(outMapFileName, "..")
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
228
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
229 shutil.move(outFastaFileName, "..")
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
230 os.chdir("..")
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
231 if self._doClean:
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
232 self._log.warning("Working directory will be cleaned")
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
233 shutil.rmtree(workingDir)
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
234 self._log.info("END Launch MCL")
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
235
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
236 if __name__ == "__main__":
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
237 iLaunch = LaunchMCL()
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
238 iLaunch.setAttributesFromCmdLine()
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
239 iLaunch.run()