comparison commons/pyRepetUnit/fastaTranslation/allFrames/tests/Test_TranslateAfastaFileInAllFrameAndReplaceStopsByX.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 os
2 import unittest
3 from commons.core.utils.FileUtils import FileUtils
4
5 class Test_TranslateAfastaFileInAllFrameAndReplaceStopsByX(unittest.TestCase):
6
7 def setUp(self):
8 self._inputFile = "dummyInputFile"
9 self._outputFile = "dummyOuputFile"
10 self._prg = "translateAfastaFileInAllFrameAndReplaceStopsByX_script.py"
11
12
13 def testTranslateAfastaFileInAllFrameAndReplaceStopsByX_script(self):
14 f = open(self._inputFile, "w")
15 f.write(">header1 description\n")
16 f.write("TGTGGCTTCTAGTTGATCAGTTTATGATCACAATGATTTCACGTAGGTGTCTCGTGGCTC\n")
17 f.write("CGACTAATCAACAATATAATGCGAGTAGAGCTTGA\n")
18 f.write(">header2\n")
19 f.write("TGTGGCTTCTAGTTGATCAGTTTATGATCACAATGATTTCACGTAGGTGTCTCGTGGCTA\n")
20 f.write("CGACTAATCAACAATATAATGCGAGTAGAGCTTGA")
21 f.close()
22 # expected fasta translated file
23 f = open("expectedTranslated.fa", "w")
24 f.write(">header1_1 description\n")
25 f.write("CGFXLISLXSQXFHVGVSWLRLINNIMRVEL\n")
26 f.write(">header1_2 description\n")
27 f.write("VASSXSVYDHNDFTXVSRGSDXSTIXCEXSL\n")
28 f.write(">header1_3 description\n")
29 f.write("WLLVDQFMITMISRRCLVAPTNQQYNASRAX\n")
30 f.write(">header1_4 description\n")
31 f.write("SSSTRIILLISRSHETPTXNHCDHKLINXKP\n")
32 f.write(">header1_5 description\n")
33 f.write("QALLALYCXLVGATRHLREIIVIINXSTRSH\n")
34 f.write(">header1_6 description\n")
35 f.write("KLYSHYIVDXSEPRDTYVKSLXSXTDQLEAT\n")
36 f.write(">header2_1\n")
37 f.write("CGFXLISLXSQXFHVGVSWLRLINNIMRVEL\n")
38 f.write(">header2_2\n")
39 f.write("VASSXSVYDHNDFTXVSRGYDXSTIXCEXSL\n")
40 f.write(">header2_3\n")
41 f.write("WLLVDQFMITMISRRCLVATTNQQYNASRAX\n")
42 f.write(">header2_4\n")
43 f.write("SSSTRIILLISRSHETPTXNHCDHKLINXKP\n")
44 f.write(">header2_5\n")
45 f.write("QALLALYCXLVVATRHLREIIVIINXSTRSH\n")
46 f.write(">header2_6\n")
47 f.write("KLYSHYIVDXSXPRDTYVKSLXSXTDQLEAT\n")
48 f.close()
49
50 #normal launch
51 cmd = self._prg
52 cmd += " -i %s" % ( self._inputFile )
53 cmd += " -o %s" % ( self._outputFile )
54 os.system( cmd )
55 self.assertTrue(FileUtils.are2FilesIdentical( self._outputFile, "expectedTranslated.fa"))
56 os.system( "rm " + self._outputFile )
57
58 #verbose option
59 cmd = self._prg
60 cmd += " -i %s" % ( self._inputFile )
61 cmd += " -o %s" % ( self._outputFile )
62 cmd += " -v 1"
63 os.system( cmd )
64 self.assertTrue(FileUtils.are2FilesIdentical( self._outputFile, "expectedTranslated.fa"))
65 os.system( "rm " + self._outputFile )
66
67 #clean option
68 cmd = self._prg
69 cmd += " -i %s" % ( self._inputFile )
70 cmd += " -o %s" % ( self._outputFile )
71 cmd += " -c"
72 os.system( cmd )
73 self.assertTrue( FileUtils.are2FilesIdentical( self._outputFile, "expectedTranslated.fa" ) )
74 self.assertFalse( FileUtils.isRessourceExists( self._inputFile ) )
75 os.system( "rm " + self._outputFile)
76 os.system("rm expectedTranslated.fa")
77
78
79 if __name__ == "__main__":
80 unittest.main()