Mercurial > repos > yufei-luo > s_mart
comparison commons/tools/tests/Test_F_LaunchBlaster.py @ 18:94ab73e8a190
Uploaded
author | m-zytnicki |
---|---|
date | Mon, 29 Apr 2013 03:20:15 -0400 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
17:b0e8584489e6 | 18:94ab73e8a190 |
---|---|
1 from commons.core.utils.FileUtils import FileUtils | |
2 import unittest | |
3 import os | |
4 import glob | |
5 from commons.tools.LaunchBlaster import LaunchBlaster | |
6 | |
7 class Test_F_LaunchBlaster(unittest.TestCase): | |
8 | |
9 def setUp(self): | |
10 self._inFileName = "DmelChr4.fa" | |
11 inFilePath = "%s/Tools/%s" % (os.environ["REPET_DATA"], self._inFileName) | |
12 try: | |
13 os.remove(self._inFileName) | |
14 except: | |
15 pass | |
16 os.symlink(inFilePath, self._inFileName) | |
17 self._iLaunchBlaster = LaunchBlaster(self._inFileName) | |
18 self._iLaunchBlaster.setDoAllByall(True) | |
19 self._iLaunchBlaster.setVerbosity(4) | |
20 | |
21 def tearDown(self): | |
22 try: | |
23 FileUtils.removeFilesByPattern("%s*" % self._inFileName) | |
24 os.remove("formatdb.log") | |
25 except: | |
26 pass | |
27 | |
28 def test_run_as_class_1_file(self): | |
29 expFileName = "%s/Tools/DmelChr4.align" % os.environ["REPET_DATA"] | |
30 obsFileName = "%s.align" % self._inFileName | |
31 | |
32 self._iLaunchBlaster.run() | |
33 | |
34 self.assertTrue(FileUtils.are2FilesIdentical(expFileName, obsFileName)) | |
35 | |
36 def test_run_as_class_1_file_changed_params(self): | |
37 expFileName = "DmelChr4.align" | |
38 with open(expFileName, "w") as fh: | |
39 fh.write("dmel_chr4\t691910\t692326\tdmel_chr4\t700019\t700435\t0\t827\t100\n") | |
40 obsFileName = "%s.align" % self._inFileName | |
41 | |
42 self._iLaunchBlaster.setIdentity(100) | |
43 self._iLaunchBlaster.setCPU(4) | |
44 self._iLaunchBlaster.setDoClean(True) | |
45 self._iLaunchBlaster.run() | |
46 | |
47 self.assertTrue(FileUtils.are2FilesIdentical(expFileName, obsFileName)) | |
48 os.remove(expFileName) | |
49 self.assertTrue(glob.glob("*fa_cut*") == []) | |
50 self.assertTrue(glob.glob("*Nstretch*") == []) | |
51 self.assertTrue(glob.glob("*seq_treated*") == []) | |
52 self.assertTrue(glob.glob("*.log") == []) | |
53 | |
54 def test_run_as_script_1bank_1file(self): | |
55 inputFileName = "chunks.fa" | |
56 with open(inputFileName, "w") as f: | |
57 f.write(">chunk1\n") | |
58 f.write("GAATTCGCGTCCGCTTACCCATGTGCCTGTGGATGCCGAACAGGAGGCGCCGTTGACGGC\n") | |
59 f.write("GAATGACTTACTCAAGGGAGTAGCCAATCTGTCGGATACGCCCGGATTGGAGCTGCCCAT\n") | |
60 expFileName = "exp.align" | |
61 with open(expFileName, "w") as f: | |
62 f.write("chunk1\t1\t120\tdmel_chr4\t1\t120\t2e-64\t238\t100\n") | |
63 obsFileName = "%s.align" % inputFileName | |
64 | |
65 cmd = "LaunchBlaster.py -q %s -s %s -e 0.1 -a" % (inputFileName, self._inFileName) | |
66 os.system(cmd) | |
67 | |
68 self.assertTrue(FileUtils.are2FilesIdentical(expFileName, obsFileName)) | |
69 FileUtils.removeFilesByPattern("%s*" % inputFileName) | |
70 os.remove(expFileName) | |
71 | |
72 def test_run_as_script_1bank_1file_withoutABA(self): | |
73 queryFileName = "chunks.fa" | |
74 with open(queryFileName, "w") as f: | |
75 f.write(">chunk1\n") | |
76 f.write("GAATTCGCGTCCGCTTACCCATGTGCCTGTGGATGCCGAACAGGAGGCGCCGTTGACGGC\n") | |
77 f.write("GAATGACTTACTCAAGGGAGTAGCCAATCTGTCGGATACGCCCGGATTGGAGCTGCCCAT\n") | |
78 subjectFileName = "genome.fa" | |
79 with open(subjectFileName, "w") as f: | |
80 f.write(">chunk1\n") | |
81 f.write("GAATTCGCGTCCGCTTACCCATGTGCCTGTGGATGCCGAACAGGAGGCGCCGTTGACGGC\n") | |
82 f.write("GAATGACTTACTCAAGGGAGTAGCCAATCTGTCGGATACGCCCGGATTGGAGCTGCCCAT\n") | |
83 f.write(">chunk2\n") | |
84 f.write("GAATTCGCGTCCGCTTACCCATGTGCCTGTGGATGCCGAACAGGAGGCGCCGTTGACGGC\n") | |
85 f.write("GAATGACTTACTCAAGGGAGTAGCCAATCTGTCGGATACGCCCGGATTGGAGCTGCCCAT\n") | |
86 expFileName = "exp.align" | |
87 with open(expFileName, "w") as f: | |
88 f.write("chunk1\t1\t120\tchunk1\t1\t120\t4e-68\t238\t100\n") | |
89 f.write("chunk1\t1\t120\tchunk2\t1\t120\t4e-68\t238\t100\n") | |
90 obsFileName = "%s.align" % queryFileName | |
91 | |
92 cmd = "LaunchBlaster.py -q %s -s %s -e 0.1" % (queryFileName, subjectFileName) | |
93 os.system(cmd) | |
94 | |
95 self.assertTrue(FileUtils.are2FilesIdentical(expFileName, obsFileName)) | |
96 FileUtils.removeFilesByPattern("%s*" % queryFileName) | |
97 FileUtils.removeFilesByPattern("%s*" % subjectFileName) | |
98 os.remove(expFileName) | |
99 | |
100 if __name__ == "__main__": | |
101 unittest.main() |