annotate commons/tools/TEclassifierPE_parallelized.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 import os
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
34 import sys
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
35 import shutil
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
36
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
37 if not "REPET_PATH" in os.environ.keys():
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
38 print "ERROR: no environment variable REPET_PATH"
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
39 sys.exit(1)
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
40 sys.path.append(os.environ["REPET_PATH"])
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
41 if not "PYTHONPATH" in os.environ.keys():
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
42 os.environ["PYTHONPATH"] = os.environ["REPET_PATH"]
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
43 else:
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
44 os.environ["PYTHONPATH"] = "%s:%s" % (os.environ["REPET_PATH"], os.environ["PYTHONPATH"])
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
45
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
46 from commons.core.LoggerFactory import LoggerFactory
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
47 from commons.core.utils.RepetOptionParser import RepetOptionParser
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
48 from commons.core.utils.FileUtils import FileUtils
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
49 from commons.core.checker.ConfigChecker import ConfigRules
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
50 from commons.core.checker.ConfigChecker import ConfigChecker
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
51 from commons.core.seq.FastaUtils import FastaUtils
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
52 from commons.core.sql.DbFactory import DbFactory
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
53 from commons.core.sql.TableJobAdaptatorFactory import TableJobAdaptatorFactory
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
54 from commons.core.launcher.Launcher import Launcher
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
55 from denovo_pipe.ReverseComplementAccordingToClassif import ReverseComplementAccordingToClassif
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
56 from denovo_pipe.DetectTEFeatures_parallelized import DetectTEFeatures_parallelized
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
57 from denovo_pipe.RenameHeaderClassif import RenameHeaderClassif
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
58 from denovo_pipe.LaunchPASTEC import LaunchPASTEC
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
59 from PASTEC.StatPastec import StatPastec
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
60
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
61 LOG_DEPTH = "repet.tools"
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
62 #LOG_FORMAT = "%(message)s"
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
63
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
64 ####TEclassifier PASTEC Edition - parallelized
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
65 #
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
66 class TEclassifierPE_parallelized(object):
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
67
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
68 def __init__(self, fastaFileName = "", configFileName = "", addWickerCode = False, reverseComp = False, doClean = False, verbosity = 0):
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
69 self._fastaFileName = fastaFileName
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
70 self._addWickerCode = addWickerCode
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
71 self._reverseComp = reverseComp
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
72 self._configFileName = configFileName
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
73 self._doClean = doClean
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
74 self._verbosity = verbosity
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
75 self._projectName = ""
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
76 self._log = LoggerFactory.createLogger("%s.%s" % (LOG_DEPTH, self.__class__.__name__), self._verbosity)
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
77
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
78 def setAttributesFromCmdLine(self):
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
79 description = "TE classifier PASTEC Edition.\n"
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
80 description += "Detect TE features on consensus and classify them. Give some classification statistics.\n"
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
81 description += "Can rename headers with classification info and Wicker's code at the beginning.\n"
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
82 description += "Can reverse-complement consensus if they are detected in reverse strand.\n"
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
83 epilog = "\n"
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
84 epilog += "Example 1: launch and clean temporary files\n"
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
85 epilog += "\t$ python TEclassifierPE.py -i consensus.fa -C TEclassifier.cfg -c\n"
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
86 epilog += "\n"
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
87 epilog += "Example 2: launch with 'rename headers' and 'reverse-complement' options\n"
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
88 epilog += "\t$ python TEclassifierPE.py -i consensus.fa -C TEclassifier.cfg -c -w -r\n"
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
89 parser = RepetOptionParser(description = description, epilog = epilog)
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
90 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
91 parser.add_option("-C", "--config", dest = "configFileName",action = "store", type = "string", help = "configuration file name (e.g. TEclassifier.cfg) [compulsory]", default = "")
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
92 parser.add_option("-w", "--wicker", dest = "addWickerCode", action = "store_true", help = "add classification info and Wicker's code at the beginning of the headers [optional] [default: False]", default = False)
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
93 parser.add_option("-r", "--reverse", dest = "reverseComp", action = "store_true", help = "reverse-complement consensus if they are detected in reverse strand [optional] [default: False]", default = False)
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
94 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
95 parser.add_option("-v", "--verbosity", dest = "verbosity", action = "store", type = "int", help = "verbosity [optional] [default: 3, from 1 to 4]", default = 3)
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
96 options = parser.parse_args()[0]
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
97 self._setAttributesFromOptions(options)
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
98
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
99 def _setAttributesFromOptions(self, options):
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
100 self.setFastaFileName(options.fastaFileName)
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
101 self.setAddWickerCode(options.addWickerCode)
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
102 self.setReverseComp(options.reverseComp)
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
103 self.setConfigFileName(options.configFileName)
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
104 self.setDoClean(options.doClean)
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
105 self.setVerbosity(options.verbosity)
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
106
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
107 def _checkConfig(self):
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
108 iConfigRules = ConfigRules()
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
109 iConfigRules.addRuleOption(section="project", option ="project_name", mandatory=True, type="string")
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
110 sectionName = "classif_consensus"
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
111 iConfigRules.addRuleOption(section=sectionName, option ="clean", mandatory=True, type="bool")
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
112 iConfigRules.addRuleOption(section=sectionName, option ="limit_job_nb", type="int")
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
113 iConfigRules.addRuleOption(section=sectionName, option ="resources", type="string")
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
114 iConfigRules.addRuleOption(section=sectionName, option ="tmpDir", type="string")
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
115 iConfigChecker = ConfigChecker(self._configFileName, iConfigRules)
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
116 iConfig = iConfigChecker.getConfig()
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
117 self._setAttributesFromConfig(iConfig)
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
118
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
119 def _setAttributesFromConfig(self, iConfig):
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
120 self.setProjectName(iConfig.get("project", "project_name"))
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
121 sectionName = "classif_consensus"
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
122 self.setDoClean(iConfig.get(sectionName, "clean"))
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
123 self._maxJobNb = iConfig.get(sectionName, "limit_job_nb")
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
124 self._resources = iConfig.get(sectionName, "resources")
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
125 self._tmpDir = iConfig.get(sectionName, "tmpDir")
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
126
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
127 def setFastaFileName(self, fastaFileName):
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
128 self._fastaFileName = fastaFileName
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
129
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
130 def setConfigFileName(self, configFileName):
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
131 self._configFileName = configFileName
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
132
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
133 def setAddWickerCode(self, addWickerCode):
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
134 self._addWickerCode = addWickerCode
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
135
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
136 def setReverseComp(self, reverseComp):
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
137 self._reverseComp = reverseComp
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
138
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
139 def setDoClean(self, doClean):
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
140 self._doClean = doClean
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
141
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
142 def setVerbosity(self, verbosity):
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
143 self._verbosity = verbosity
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
144
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
145 def setProjectName(self, projectName):
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
146 self._projectName = projectName
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
147
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
148 def _checkOptions(self):
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
149 if self._fastaFileName == "":
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
150 self._logAndRaise("ERROR: Missing input fasta file name")
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
151
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
152 def _logAndRaise(self, errorMsg):
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
153 self._log.error(errorMsg)
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
154 raise Exception(errorMsg)
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
155
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
156 # def setup_env(config):
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
157 # os.environ["REPET_HOST"] = config.get("repet_env", "repet_host")
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
158 # os.environ["REPET_USER"] = config.get("repet_env", "repet_user")
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
159 # os.environ["REPET_PW"] = config.get("repet_env", "repet_pw")
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
160 # os.environ["REPET_DB"] = config.get("repet_env", "repet_db")
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
161 # os.environ["REPET_PORT"] = config.get("repet_env", "repet_port")
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
162 # os.environ["REPET_JOB_MANAGER"] = config.get("repet_env", "repet_job_manager")
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
163 # os.environ["REPET_QUEUE"] = config.get("repet_env", "repet_job_manager")
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
164 # os.environ["REPET_JOBS"] = "MySQL"
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
165
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
166 def getPASTECcommand(self, iLauncher, fileName):
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
167 lArgs = []
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
168 lArgs.append("-C %s" % self._configFileName)
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
169 lArgs.append("-P %s" % self._projectName)
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
170 lArgs.append("-S 2")
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
171 lArgs.append("-i %s" % fileName)
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
172 lArgs.append("-v %s" % self._verbosity)
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
173 return iLauncher.getSystemCommand("LaunchPASTEC.py", lArgs)
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
174
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
175 def run(self):
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
176 LoggerFactory.setLevel(self._log, self._verbosity)
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
177 if self._configFileName:
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
178 self._checkConfig()
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
179 self._checkOptions()
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
180 self._log.info("START TEclassifier PASTEC Edition")
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
181 self._log.debug("Fasta file name: %s" % self._fastaFileName)
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
182 nbSeq = FastaUtils.dbSize(self._fastaFileName)
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
183 self._log.debug("Total number of sequences: %i)" % nbSeq)
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
184
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
185 self._log.debug("Launch DetectTEFeatures on each batch")
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
186 iDF = DetectTEFeatures_parallelized(self._fastaFileName, self._projectName, self._configFileName, self._doClean, self._verbosity)
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
187 iDF.run()
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
188
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
189 self._log.debug("Insert banks in database")
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
190 iLP = LaunchPASTEC(self._configFileName, "1", projectName = self._projectName, verbose = self._verbosity)
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
191 iLP.run()
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
192
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
193 self._log.info("Split fasta file")
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
194 if self._maxJobNb == 0 or nbSeq / self._maxJobNb <= 1.0:
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
195 nbSeqPerBatch = nbSeq
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
196 else:
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
197 nbSeqPerBatch = nbSeq / self._maxJobNb + 1
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
198 FastaUtils.dbSplit(self._fastaFileName, nbSeqPerBatch, True, verbose = self._verbosity - 2)
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
199
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
200 self._log.info("Launch PASTEC on each batch")
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
201 queue = self._resources
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
202 cDir = os.getcwd()
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
203 if self._tmpDir != "":
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
204 tmpDir = self._tmpDir
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
205 else:
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
206 tmpDir = cDir
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
207
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
208 #TODO: allow not to parallelize
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
209 groupid = "%s_PASTEC" % self._projectName
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
210 acronym = "PASTEC"
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
211 iDb = DbFactory.createInstance()
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
212 iTJA = TableJobAdaptatorFactory.createInstance(iDb, "jobs")
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
213 iLauncher = Launcher(iTJA, os.getcwd(), "", "", cDir, tmpDir, "jobs", queue, groupid)
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
214 lCmdsTuples = []
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
215 lFiles = FileUtils.getFileNamesList("%s/batches" % cDir, "batch_")
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
216 if len(lFiles) == 0:
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
217 self._logAndRaise("ERROR: directory 'batches' is empty")
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
218 classifFileName = "%s.classif" % self._projectName
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
219 count = 0
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
220 for file in lFiles:
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
221 count += 1
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
222 lCmds = [self.getPASTECcommand(iLauncher, file)]
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
223 lCmdStart = []
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
224 lCmdStart.append("shutil.copy(\"%s/batches/%s\", \".\")" % (cDir, file))
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
225 lCmdStart.append("shutil.copy(\"%s/%s\", \".\")" % (cDir, self._configFileName))
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
226 lCmdFinish = []
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
227 lCmdFinish.append("shutil.move(\"%s\", \"%s/%s_%i\")" % (classifFileName, cDir, classifFileName, count))
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
228 lCmdsTuples.append(iLauncher.prepareCommands_withoutIndentation(lCmds, lCmdStart, lCmdFinish))
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
229 iLauncher.runLauncherForMultipleJobs(acronym, lCmdsTuples, self._doClean)
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
230
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
231 FileUtils.catFilesByPattern("%s_*" % classifFileName, classifFileName)
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
232 if self._doClean:
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
233 FileUtils.removeFilesByPattern("%s_*" % classifFileName)
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
234 shutil.rmtree("batches")
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
235
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
236 self._log.debug("Compute stats about classification")
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
237 iSP = StatPastec(classifFileName)
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
238 iSP.run()
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
239
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
240 if self._reverseComp:
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
241 self._log.debug("Reverse complement")
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
242 iRevComplAccording2Classif = ReverseComplementAccordingToClassif()
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
243 iRevComplAccording2Classif.setFastaFile(self._fastaFileName)
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
244 iRevComplAccording2Classif.setClassifFile(classifFileName)
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
245 iRevComplAccording2Classif.run()
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
246 newFastaFileName = "%s_negStrandReversed.fa" % os.path.splitext(self._fastaFileName)[0]
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
247 else:
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
248 newFastaFileName = self._fastaFileName
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
249
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
250 if self._addWickerCode:
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
251 self._log.debug("Rename headers according to Wicker's code")
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
252 iRHC = RenameHeaderClassif(classifFileName, newFastaFileName, self._projectName)
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
253 iRHC.setOutputFileName("")
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
254 iRHC.run()
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
255
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
256 self._log.info("END TEclassifier PASTEC Edition")
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
257
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
258 if __name__ == "__main__":
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
259 iLaunch = TEclassifierPE_parallelized()
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
260 iLaunch.setAttributesFromCmdLine()
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
261 iLaunch.run()