18
|
1 from commons.core.utils.FileUtils import FileUtils
|
|
2 import unittest
|
|
3 import os
|
|
4 import shutil
|
|
5 from commons.tools.LaunchBlasterInParallel import LaunchBlasterInParallel
|
|
6
|
|
7 class Test_F_LaunchBlasterInParallel(unittest.TestCase):
|
|
8
|
|
9 CLUSTER_HOST = "compute-2-46.local"
|
|
10
|
|
11 def setUp(self):
|
|
12 self._inFilePath = "%s/Tools/DmelChr4_chunks.fa" % os.environ["REPET_DATA"]
|
|
13 self._configFileName = "TE.cfg"
|
|
14 self._outputFileName = "out.align.not_over"
|
|
15
|
|
16 def tearDown(self):
|
|
17 try:
|
|
18 os.remove(self._outputFileName)
|
|
19 os.remove(self._configFileName)
|
|
20 except:
|
|
21 pass
|
|
22
|
|
23 def test_run_as_script_1bank_1file_withoutABA(self):
|
|
24 self._outputFileName = "out.align"
|
|
25 os.mkdir("tmp")
|
|
26 os.chdir("tmp")
|
|
27 queryFileName = "chunks.fa"
|
|
28 with open(queryFileName, "w") as f:
|
|
29 f.write(">chunk1\n")
|
|
30 f.write("GAATTCGCGTCCGCTTACCCATGTGCCTGTGGATGCCGAACAGGAGGCGCCGTTGACGGC\n")
|
|
31 f.write("GAATGACTTACTCAAGGGAGTAGCCAATCTGTCGGATACGCCCGGATTGGAGCTGCCCAT\n")
|
|
32 os.chdir("..")
|
|
33 subjectFileName = "genome.fa"
|
|
34 with open(subjectFileName, "w") as f:
|
|
35 f.write(">chunk1\n")
|
|
36 f.write("GAATTCGCGTCCGCTTACCCATGTGCCTGTGGATGCCGAACAGGAGGCGCCGTTGACGGC\n")
|
|
37 f.write("GAATGACTTACTCAAGGGAGTAGCCAATCTGTCGGATACGCCCGGATTGGAGCTGCCCAT\n")
|
|
38 f.write(">chunk2\n")
|
|
39 f.write("GAATTCGCGTCCGCTTACCCATGTGCCTGTGGATGCCGAACAGGAGGCGCCGTTGACGGC\n")
|
|
40 f.write("GAATGACTTACTCAAGGGAGTAGCCAATCTGTCGGATACGCCCGGATTGGAGCTGCCCAT\n")
|
|
41 expFileName = "expected"
|
|
42 with open(expFileName, "w") as f:
|
|
43 f.write("chunk1\t1\t120\tchunk1\t1\t120\t4e-68\t238\t100\n")
|
|
44 f.write("chunk1\t1\t120\tchunk2\t1\t120\t4e-68\t238\t100\n")
|
|
45 self._writeConfig(0.1)
|
|
46
|
|
47 cmd = "LaunchBlasterInParallel.py -q %s/tmp -s %s/%s -C %s -o %s" % (os.getcwd(), os.getcwd(), subjectFileName, self._configFileName, self._outputFileName)
|
|
48 os.system(cmd)
|
|
49
|
|
50 self.assertTrue(FileUtils.are2FilesIdentical(expFileName, self._outputFileName))
|
|
51 FileUtils.removeFilesByPattern("*.param")
|
|
52 shutil.rmtree("tmp")
|
|
53 os.remove(subjectFileName)
|
|
54 os.remove(expFileName)
|
|
55
|
|
56 def test_run_as_script_1bank_2_batches(self):
|
|
57 os.mkdir("tmp")
|
|
58 os.chdir("tmp")
|
|
59 os.symlink("%s/Tools/batches/batch_1.fa" % os.environ["REPET_DATA"], "batch_1.fa")
|
|
60 os.symlink("%s/Tools/batches/batch_2.fa" % os.environ["REPET_DATA"], "batch_2.fa")
|
|
61 os.chdir("..")
|
|
62
|
|
63 expFileName = "%s/Tools/DmelChr4.align.not_over" % os.environ["REPET_DATA"]
|
|
64 self._writeConfig()
|
|
65
|
|
66 cmd = "LaunchBlasterInParallel.py -q %s/tmp -s %s -a -o %s -C %s" % (os.getcwd(), self._inFilePath, self._outputFileName, self._configFileName)
|
|
67 os.system(cmd)
|
|
68
|
|
69 self.assertTrue(FileUtils.are2FilesIdentical(expFileName, self._outputFileName))
|
|
70 FileUtils.removeFilesByPattern("*.param")
|
|
71 shutil.rmtree("tmp")
|
|
72
|
|
73 def test_run_1bank_1bank_2_batches(self):
|
|
74 os.mkdir("tmp")
|
|
75 os.chdir("tmp")
|
|
76 os.symlink("%s/Tools/batches/batch_1.fa" % os.environ["REPET_DATA"], "batch_1.fa")
|
|
77 os.symlink("%s/Tools/batches/batch_2.fa" % os.environ["REPET_DATA"], "batch_2.fa")
|
|
78 os.chdir("..")
|
|
79
|
|
80 expFileName = "%s/Tools/DmelChr4.align.not_over" % os.environ["REPET_DATA"]
|
|
81 self._writeConfig()
|
|
82
|
|
83 iLaunchBlaster = LaunchBlasterInParallel(configFileName = self._configFileName, outFileName = self._outputFileName)
|
|
84 iLaunchBlaster.setDoAllByall(True)
|
|
85 iLaunchBlaster.setVerbosity(4)
|
|
86 iLaunchBlaster.setQueryDirectory("%s/tmp" % os.getcwd())
|
|
87 iLaunchBlaster.setSubjectFilePath(self._inFilePath)
|
|
88 iLaunchBlaster.run()
|
|
89
|
|
90 self.assertTrue(FileUtils.are2FilesIdentical(expFileName, self._outputFileName))
|
|
91 FileUtils.removeFilesByPattern("*.param")
|
|
92 shutil.rmtree("tmp")
|
|
93
|
|
94 def _writeConfig(self, eValue = 1e-300):
|
|
95 with open(self._configFileName, "w") as fh:
|
|
96 fh.write("[jobs]\n")
|
|
97 if os.getenv("HOSTNAME") == self.CLUSTER_HOST:
|
|
98 fh.write("resources: test\n")
|
|
99 else:
|
|
100 fh.write("resources:\n")
|
|
101 fh.write("tmpDir:\n")
|
|
102 fh.write("copy: no\n")
|
|
103 fh.write("clean: yes\n")
|
|
104 fh.write("\n")
|
|
105 fh.write("[prepare_data]\n")
|
|
106 fh.write("chunk_length: 200000\n")
|
|
107 fh.write("chunk_overlap: 10000\n")
|
|
108 fh.write("\n")
|
|
109 fh.write("[alignment]\n")
|
|
110 fh.write("blast: ncbi\n")
|
|
111 fh.write("Evalue: %s\n" % eValue)
|
|
112 fh.write("length: 100\n")
|
|
113 fh.write("identity: 90\n")
|
|
114
|
|
115 if __name__ == "__main__":
|
|
116 unittest.main() |