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