comparison commons/launcher/tests/Test_F_LaunchTallymer.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 import unittest
2 import os
3 from commons.core.utils.FileUtils import FileUtils
4 import shutil
5 from commons.launcher.LaunchTallymer import LaunchTallymer
6
7 class Test_F_LaunchTallymer(unittest.TestCase):
8
9 def setUp(self):
10 self._inFastaFileName = "%s/Tools/DmelChr4.fa" % os.environ["REPET_DATA"]
11
12 def test_run_output_as_gff_cleaned(self):
13 iLaunchTallymer = LaunchTallymer(self._inFastaFileName, clean = True, verbosity=2)
14 iLaunchTallymer.run()
15
16 expFileName = "%s/Tools/DmelChr4.fa.tallymer_k20.gff" % os.environ["REPET_DATA"]
17 obsFileName = "DmelChr4.tallymer.gff"
18
19 self.assertTrue(FileUtils.are2FilesIdentical(expFileName, obsFileName))
20 os.remove(obsFileName)
21 os.remove("DmelChr4.tallymer.stat")
22
23 def test_run_with_remote_dir(self):
24 os.makedirs("sourceDir")
25 changedInFastaFileName = os.path.basename(self._inFastaFileName)
26 changedInFastaFilepath = os.path.join("sourceDir",changedInFastaFileName)
27 shutil.copy2(self._inFastaFileName, changedInFastaFilepath)
28
29 iLaunchTallymer = LaunchTallymer(changedInFastaFilepath, clean = True, verbosity=2)
30 iLaunchTallymer.run()
31
32 expFileName = "%s/Tools/DmelChr4.fa.tallymer_k20.gff" % os.environ["REPET_DATA"]
33 obsFileName = "DmelChr4.tallymer.gff"
34
35
36 self.assertTrue(FileUtils.are2FilesIdentical(expFileName, obsFileName))
37 obsSourceDirFiles = os.listdir("sourceDir")
38 expSourceDirFiles = [changedInFastaFileName,]
39 self.assertEquals(expSourceDirFiles, obsSourceDirFiles)
40
41 os.remove(obsFileName)
42 os.remove("DmelChr4.tallymer.stat")
43 shutil.rmtree("sourceDir")
44
45
46 def test_run_output_as_gff_cleaned_changed_minOccs2(self):
47 iLaunchTallymer = LaunchTallymer(self._inFastaFileName, minOccs=2, clean = True, verbosity=2)
48 iLaunchTallymer.run()
49
50 expFileName = "%s/Tools/DmelChr4.fa.tallymer_k20_minOcc2.gff" % os.environ["REPET_DATA"]
51 obsFileName = "DmelChr4.tallymer.gff"
52
53 self.assertTrue(FileUtils.are2FilesIdentical(expFileName, obsFileName))
54 os.remove(obsFileName)
55 os.remove("DmelChr4.tallymer.stat")
56
57 def test_run_output_as_gff_cleaned_relative_input(self):
58 srcFastaFileName = self._inFastaFileName
59 dstFastaFileName = os.path.basename(self._inFastaFileName)
60 shutil.copy2(srcFastaFileName, dstFastaFileName)
61 iLaunchTallymer = LaunchTallymer(dstFastaFileName, clean = True, verbosity=2)
62 iLaunchTallymer.run()
63
64 expFileName = "%s/Tools/DmelChr4.fa.tallymer_k20.gff" % os.environ["REPET_DATA"]
65 obsFileName = "DmelChr4.tallymer.gff"
66
67 self.assertTrue(FileUtils.are2FilesIdentical(expFileName, obsFileName))
68
69 os.remove(obsFileName)
70 os.remove("DmelChr4.tallymer.stat")
71 os.remove(dstFastaFileName)
72
73 def test_run_as_script_output_as_gff_cleaned_relative_input_(self):
74 srcFastaFileName = self._inFastaFileName
75 dstFastaFileName = os.path.basename(self._inFastaFileName)
76 shutil.copy2(srcFastaFileName, dstFastaFileName)
77
78 cmd = 'LaunchTallymer.py -i %s -s 20 -c -v 3' % (self._inFastaFileName)
79 os.system(cmd)
80 expFileName = "%s/Tools/DmelChr4.fa.tallymer_k20.gff" % os.environ["REPET_DATA"]
81 obsFileName = "DmelChr4.tallymer.gff"
82
83 self.assertTrue(FileUtils.are2FilesIdentical(expFileName, obsFileName))
84
85 os.remove(obsFileName)
86 os.remove("DmelChr4.tallymer.stat")
87 os.remove(dstFastaFileName)
88
89 def test_run_output_as_wig_cleaned(self):
90 iLaunchTallymer = LaunchTallymer(self._inFastaFileName, outputFormats="wig", clean=True)
91 iLaunchTallymer.run()
92
93 expFileName = "%s/Tools/DmelChr4.fa.tallymer_k20.wig" % os.environ["REPET_DATA"]
94 obsFileName = "DmelChr4.tallymer.wig"
95
96 self.assertTrue(FileUtils.are2FilesIdentical(expFileName, obsFileName))
97
98 os.remove(obsFileName)
99 os.remove("DmelChr4.tallymer.stat")
100
101 def test_run_output_as_gff_and_wig_k15_cleaned(self):
102 iLaunchTallymer = LaunchTallymer(self._inFastaFileName, merSize=15, outputFormats="wig,gff3", clean=True)
103 iLaunchTallymer.run()
104
105 expFileName = "%s/Tools/DmelChr4.fa.tallymer_k15.wig" % os.environ["REPET_DATA"]
106 obsFileName = "DmelChr4.tallymer.wig"
107 self.assertTrue(FileUtils.are2FilesIdentical(expFileName, obsFileName))
108 os.remove(obsFileName)
109
110 expFileName = "%s/Tools/DmelChr4.fa.tallymer_k15.gff3" % os.environ["REPET_DATA"]
111 obsFileName = "DmelChr4.tallymer.gff3"
112 self.assertTrue(FileUtils.are2FilesIdentical(expFileName, obsFileName))
113 os.remove(obsFileName)
114
115 os.remove("DmelChr4.tallymer.stat")
116
117 def test_run_as_script_run_output_as_gff_and_wig_k15_cleaned(self):
118 logFileName = "test.log"
119 cmd = 'LaunchTallymer.py -i %s -s 15 -f gff,wig,vero -c -v 3 > %s' % (self._inFastaFileName, logFileName)
120 os.system(cmd)
121
122 expFileName = "%s/Tools/DmelChr4.fa.tallymer_k15.wig" % os.environ["REPET_DATA"]
123 obsFileName = "DmelChr4.tallymer.wig"
124 self.assertTrue(FileUtils.are2FilesIdentical(expFileName, obsFileName))
125 os.remove(obsFileName)
126
127 expFileName = "%s/Tools/DmelChr4.fa.tallymer_k15.gff3" % os.environ["REPET_DATA"]
128 obsFileName = "DmelChr4.tallymer.gff"
129 self.assertTrue(FileUtils.are2FilesIdentical(expFileName, obsFileName))
130 os.remove(obsFileName)
131
132 expLogFileName = "exp.log"
133 with open(expLogFileName, "w") as f:
134 f.write(" LaunchTallymer - WARNING - Warning: ignoring invalid formats: <vero>\n")
135 f.write(" LaunchTallymer - INFO - Starting to run tallymer search of sequence DmelChr4.fa \n")
136 f.write(" LaunchTallymer - INFO - Finished running tallymer scan of sequence DmelChr4.fa \n")
137 f.write(" LaunchTallymer - INFO - Starting to run tallymer search to map conversion\n")
138 f.write(" LaunchTallymer - INFO - Finished tallymer search to map conversion\n")
139 f.write(" LaunchTallymer - INFO - Generating wig file\n")
140 f.write(" LaunchTallymer - INFO - Generating gff file\n")
141 obsLogFileName = "obs.log"
142 os.system("cut -d'-' -f4,5,6 %s > %s" % (logFileName, obsLogFileName))
143 self.assertTrue(FileUtils.are2FilesIdentical(expLogFileName, obsLogFileName))
144
145 os.remove(logFileName)
146 os.remove(expLogFileName)
147 os.remove(obsLogFileName)
148 os.remove("DmelChr4.tallymer.stat")
149
150 if __name__ == "__main__":
151 unittest.main()