18
|
1 import unittest
|
|
2 import os
|
|
3 import ConfigParser
|
|
4 import shutil
|
|
5 from commons.pyRepetUnit.hmmer.profilsSearchInTEClassifier.ProfilesSearch import ProfilesSearch
|
|
6
|
|
7 class Test_ProfilesSearch(unittest.TestCase):
|
|
8
|
|
9
|
|
10 def setUp(self):
|
|
11 self._section = 'detect_features'
|
|
12 self._option1 = 'TE_HMM_profiles'
|
|
13 self._option2 = 'TE_HMMER_evalue'
|
|
14 self._config = ConfigParser.ConfigParser()
|
|
15 self._config.add_section(self._section)
|
|
16 self._config.set(self._section, self._option1, './datas/hmmbank_test')
|
|
17 self._config.set(self._section, self._option2, '10')
|
|
18 self._iProfilesSearch = ProfilesSearch()
|
|
19 self._launch1 = 'First Command\n'
|
|
20 self._launch2 = '\nSecond Command\n'
|
|
21 self._cDir = '.'
|
|
22 self._profileBank = self._config.get(self._section, self._option1)
|
|
23 self._bank = os.path.basename(self._profileBank)
|
|
24 shutil.copy(self._profileBank, self._cDir + "/" + self._bank)
|
|
25
|
|
26 def tearDown(self):
|
|
27 os.remove(self._cDir + "/" + self._bank)
|
|
28
|
|
29 def test_prepareProfilesBank(self):
|
|
30 hmmpressLaunched = False
|
|
31 self._iProfilesSearch.prepareProfilesBank( self._launch1, self._launch2, self._config, self._cDir )
|
|
32 if ( os.path.exists(self._cDir + "/" + self._bank + ".h3m") \
|
|
33 and os.path.exists(self._cDir + "/" + self._bank + ".h3i") \
|
|
34 and os.path.exists(self._cDir + "/" + self._bank + ".h3f") \
|
|
35 and os.path.exists(self._cDir + "/" + self._bank + ".h3p")) :
|
|
36 hmmpressLaunched = True
|
|
37 os.remove(self._cDir + "/" + self._bank + ".h3m")
|
|
38 os.remove(self._cDir + "/" + self._bank + ".h3i")
|
|
39 os.remove(self._cDir + "/" + self._bank + ".h3f")
|
|
40 os.remove(self._cDir + "/" + self._bank + ".h3p")
|
|
41 self.assertTrue(hmmpressLaunched)
|
|
42
|
|
43 def test_detectHmmProfiles(self):
|
|
44 inputFileName = ' FileName'
|
|
45 dirTemp = 'Tempory directory'
|
|
46 eValueMax = self._config.get(self._section, self._option2)
|
|
47
|
|
48 expCommand = self._launch1
|
|
49 expCommand += os.environ["REPET_PATH"] + "/bin/translateAfastaFileInAllFrameAndReplaceStopsByX_script.py"
|
|
50 expCommand += " -i %s" % ( inputFileName ) + " -o %s_translated" % ( inputFileName )
|
|
51 expCommand += self._launch2
|
|
52
|
|
53 expCommand += self._launch1
|
|
54 expCommand += "hmmscan "
|
|
55 expCommand += " -o %s_tr.hmmScanOut" % ( inputFileName )
|
|
56 expCommand += " --domtblout %s_tr.hmmScanOutTab" % ( inputFileName )
|
|
57 expCommand += " --noali "
|
|
58 expCommand += "-E " + eValueMax
|
|
59 expCommand += " --cpu 1"
|
|
60 expCommand += " " + self._cDir + "/" + self._bank + " " + "%s_translated" % ( inputFileName )
|
|
61
|
|
62 expCommand += self._launch2
|
|
63
|
|
64 expCommand += "if os.path.exists( \"%s_translated\" ):\n" % ( inputFileName )
|
|
65 expCommand += "\tos.remove( \"%s_translated\" )\n" % ( inputFileName )
|
|
66
|
|
67 expCommand += self._launch1
|
|
68 expCommand += os.environ["REPET_PATH"] + "/bin/HmmOutput2alignAndTransformCoordInNtAndFilterScores_script.py"
|
|
69 expCommand += " -i %s_tr.hmmScanOutTab" % ( inputFileName )
|
|
70 expCommand += " -o %s_profiles_%s.align" % ( inputFileName, self._bank )
|
|
71 expCommand += " -T %s" % ( inputFileName )
|
|
72 expCommand += " -p hmmscan"
|
|
73 expCommand += " -c"
|
|
74 expCommand += self._launch2
|
|
75
|
|
76 expCommand += self._launch1
|
|
77 expCommand += os.environ["REPET_PATH"] + "/bin/matcher"
|
|
78 expCommand += " -m %s_profiles_%s.align" % ( inputFileName, self._bank )
|
|
79 expCommand += " -j"
|
|
80 expCommand += " -E 10"
|
|
81 expCommand += " -L 0"
|
|
82 expCommand += " -v 1"
|
|
83 expCommand += self._launch2
|
|
84
|
|
85 expCommand += "if not os.path.exists( \"%s/%s_profiles_%s.align.clean_match.path\" ):\n" % ( self._cDir, inputFileName, self._bank )
|
|
86 expCommand += "\tos.system( \"mv %s_profiles_%s.align.clean_match.path %s\" )\n" % ( inputFileName, self._bank, self._cDir )
|
|
87 expCommand += "if not os.path.exists( \"%s/%s_profiles_%s.align.clean_match.param\" ):\n" % ( self._cDir, inputFileName, self._bank )
|
|
88 expCommand += "\tos.system( \"mv %s_profiles_%s.align.clean_match.param %s\" )\n" % ( inputFileName, self._bank, self._cDir )
|
|
89 expCommand += "if os.path.exists( \"%s_profiles_%s.align\" ):\n" % ( inputFileName, self._bank )
|
|
90 expCommand += "\tos.remove( \"%s_profiles_%s.align\" )\n" % ( inputFileName, self._bank )
|
|
91 expCommand += "if os.path.exists( \"%s_profiles_%s.align.clean_match.map\" ):\n" % ( inputFileName, self._bank )
|
|
92 expCommand += "\tos.remove( \"%s_profiles_%s.align.clean_match.map\" )\n" % ( inputFileName, self._bank )
|
|
93 expCommand += "if os.path.exists( \"%s_hmmScanOut\" ):\n" % ( inputFileName )
|
|
94 expCommand += "\tos.remove( \"%s_hmmScanOut\" )\n" % ( inputFileName )
|
|
95
|
|
96 if dirTemp != dir:
|
|
97 expCommand += "if os.path.exists( \"%s\" ):\n" % ( self._bank )
|
|
98 expCommand += "\tos.remove( \"%s\" )\n" % ( self._bank )
|
|
99
|
|
100 obsCommand = self._iProfilesSearch.detectHmmProfiles( inputFileName, self._launch1, self._launch2, self._cDir, dirTemp, self._config )
|
|
101 self.assertEquals(expCommand, obsCommand)
|
|
102
|
|
103
|
|
104
|
|
105 if __name__ == "__main__":
|
|
106 unittest.main() |