annotate commons/launcher/tests/Test_F_LaunchTRF.py @ 18:94ab73e8a190

Uploaded
author m-zytnicki
date Mon, 29 Apr 2013 03:20:15 -0400
parents
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 from commons.launcher.LaunchTRF import LaunchTRF
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
5
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
6
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
7 class Test_F_LaunchTRF(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._inputFastaFileName = "input.fa"
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
11 self._obsTRFOutputFileName = "obsTRF.TRF.set"
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
12 self._expTRFOutputFileName = "expTRF.TRF.set"
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
13 self._writeInputFile()
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
14 self._writeExpTRFOutputFile()
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
15
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
16 def tearDown(self):
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
17 try:
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
18 os.remove(self._inputFastaFileName)
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
19 except:pass
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
20
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
21 try:
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
22 os.remove(self._expTRFOutputFileName)
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
23 except:pass
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
24 try:
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
25 os.remove(self._obsTRFOutputFileName)
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
26 except:pass
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
27 try:
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
28 os.remove("input.fa.2.3.5.80.10.20.15.dat")
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
29 except:pass
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
30
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
31 def test_run(self):
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
32 ilauncher = LaunchTRF(self._inputFastaFileName,self._obsTRFOutputFileName,verbosity=5)
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
33 ilauncher.run()
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
34 self.assertTrue(FileUtils.are2FilesIdentical(self._expTRFOutputFileName, self._obsTRFOutputFileName))
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
35
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
36 def test_run_as_script(self):
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
37 cmd = 'LaunchTRF.py -i %s -o %s -v 3' % (self._inputFastaFileName, self._obsTRFOutputFileName)
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
38 os.system(cmd)
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
39 self.assertTrue(FileUtils.are2FilesIdentical(self._expTRFOutputFileName, self._obsTRFOutputFileName))
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
40
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
41 def test_run_as_scriptNoOutputGiven(self):
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
42 cmd = 'LaunchTRF.py -i %s -v 3' % (self._inputFastaFileName)
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
43 os.system(cmd)
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
44 self._obsTRFOutputFileName = "input.fa.TRF.set"
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
45 self.assertTrue(FileUtils.are2FilesIdentical(self._expTRFOutputFileName, self._obsTRFOutputFileName))
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
46
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
47 def test_run_as_scriptNoOutputGivenDoClean(self):
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
48 cmd = 'LaunchTRF.py -i %s -c -v 3' % (self._inputFastaFileName)
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
49 os.system(cmd)
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
50 self._obsTRFOutputFileName = "input.fa.TRF.set"
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
51 datFilePath = os.path.join(os.getcwd(),"%s.2.3.5.80.10.20.15.dat" % self._inputFastaFileName)
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
52 self.assertFalse(os.path.exists(datFilePath))
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
53
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
54 def _writeInputFile(self):
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
55 InputFile = open(self._inputFastaFileName, 'w')
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
56 InputFile.write('>sequence\n')
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
57 InputFile.write('GGGCGGCACGGTGGTGTGGTGGTTAGCACTGTTGCCTCACAGCAAGAAGGCCCCGGGTTC\n')
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
58 InputFile.write('GATCCCCGGTTGGGACTGAGGCTGGGGACTTTCTGTGTGGAGTTTGCATGTTCTCCCTGT\n')
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
59 InputFile.write('GCCTGCGTGGGTTCTCTCCGGGTACTCCGGCTTCCTCCCACAGTCCAAAGACATGCATGA\n')
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
60 InputFile.write('TTGGGGATTAGGCTAATTGGAAACTCTAAAATTGCCCGTAGGTGTGAGTGTGAGAGAGAA\n')
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
61 InputFile.write('TGGTTGTTTGTCTATATGTGTTAGCCCTGCGATTGACTGGCGTCCAGTCCAGGGTGTACC\n')
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
62 InputFile.write('CTGCCTCCGCCCATTGTGCTGGGATAGGCTCCAGTCCCCCCG\n')
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
63 InputFile.write('CAAGCGGTAGAAAGTGAGTGAGTGAGTGA\n')
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
64 InputFile.write('>sequence2\n')
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
65 InputFile.write('GGGCAGCCTGGGTGGCTCAGCGGTTTAGCGCCTGCCTTTGGCCCAGGGCGTGATCCTGGA\n')
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
66 InputFile.write('GACCCGGGATCGAGTCCCACATCGGGCTCCCTGCATGGAGCCTGCTTCTCCCTCTGCCTG\n')
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
67 InputFile.write('TGTCTCTGCCTCTCTCTCTCTCTGTGTCTCTCATGAATAAA\n')
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
68 InputFile.close()
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
69
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
70 def _writeExpTRFOutputFile(self):
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
71 with open(self._expTRFOutputFileName,'w') as expTRFOutputFile:
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
72 expTRFOutputFile.write("""1\t(GTGGT)2\tsequence\t11\t21
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
73 2\t(GGT)5\tsequence\t10\t23
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
74 3\t(GTGTGA)4\tsequence\t222\t242
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
75 4\t(GTCCA)2\tsequence\t282\t292
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
76 5\t(AGTG)4\tsequence\t355\t371
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
77 6\t(GCCTGTCTCTCCTCT)4\tsequence2\t100\t152
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
78 7\t(CTCTGCCTGTGT)3\tsequence2\t112\t151
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
79 8\t(TC)23\tsequence2\t107\t152
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
80 """)
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
81
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
82
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
83 if __name__ == "__main__":
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
84 unittest.main()