18
|
1 import os
|
|
2 import sys
|
|
3 import unittest
|
|
4 from SMART.Java.Python.test.MockGetLetterDistribution import MockGetLetterDistributionFasta
|
|
5 from SMART.Java.Python.test.MockGetLetterDistribution import MockGetLetterDistributionFastq
|
|
6 from SMART.Java.Python.test.MockGetLetterDistribution import MockGetLetterDistributionExpectedCSV
|
|
7
|
|
8 class Test_F_getLetterDistribution(unittest.TestCase):
|
|
9
|
|
10 def tearDown(self):
|
|
11 os.system("rm tmp*.*")
|
|
12
|
|
13 def test_getLetterDistributionWithFasta(self):
|
|
14 iFastaMock = MockGetLetterDistributionFasta()
|
|
15 fastaFileName = "MockFasta_GetLetterDistribution.fa"
|
|
16 iFastaMock.write(fastaFileName)
|
|
17
|
|
18 outputName = "dummy_result_fasta"
|
|
19 os.system("python %s/SMART/Java/Python/getLetterDistribution.py -i %s -f fasta -o %s" % (os.environ["REPET_PATH"], fastaFileName, outputName))
|
|
20
|
|
21 self.assertTrue (os.path.exists(outputName + ".png"))
|
|
22 self.assertTrue (os.path.exists(outputName + "PerNt.png"))
|
|
23
|
|
24 os.remove(outputName + ".png")
|
|
25 os.remove(outputName + "PerNt.png")
|
|
26 os.remove(fastaFileName)
|
|
27
|
|
28 def test_getLetterDistributionWithFastq(self):
|
|
29 iFastqMock = MockGetLetterDistributionFastq()
|
|
30 fastqFileName = "MockFastq_GetLetterDistribution.fastq"
|
|
31 iFastqMock.write(fastqFileName)
|
|
32
|
|
33 outputName = "dummy_result_fastq"
|
|
34 os.system("python %s/SMART/Java/Python/getLetterDistribution.py -i %s -f fastq -o %s" % (os.environ["REPET_PATH"], fastqFileName, outputName))
|
|
35
|
|
36 self.assertTrue (os.path.exists(outputName + ".png"))
|
|
37 self.assertTrue (os.path.exists(outputName + "PerNt.png"))
|
|
38
|
|
39 os.remove(fastqFileName)
|
|
40 os.remove(outputName + ".png")
|
|
41 os.remove(outputName + "PerNt.png")
|
|
42
|
|
43 def test_getLetterDistributionWithFastaCSVOutput(self):
|
|
44 iFastaMock = MockGetLetterDistributionFasta()
|
|
45 fastaFileName = "MockFasta_GetLetterDistribution.fa"
|
|
46 iFastaMock.write(fastaFileName)
|
|
47
|
|
48 iCSVMock = MockGetLetterDistributionExpectedCSV()
|
|
49 expCSVFileName = "expCSV.csv"
|
|
50 iCSVMock.write(expCSVFileName)
|
|
51
|
|
52 outputName = "dummy_result_fasta"
|
|
53 os.system("python %s/SMART/Java/Python/getLetterDistribution.py -i %s -f fasta -o %s -c" % (os.environ["REPET_PATH"], fastaFileName, outputName))
|
|
54
|
|
55 obsCSVFileName = outputName + ".csv"
|
|
56
|
|
57 self.assertTrue (os.path.exists(outputName + ".png"))
|
|
58 self.assertTrue (os.path.exists(outputName + "PerNt.png"))
|
|
59 self.assertTrue (self._are2FilesIdentical(expCSVFileName, obsCSVFileName))
|
|
60
|
|
61 os.remove(outputName + ".png")
|
|
62 os.remove(outputName + "PerNt.png")
|
|
63 os.remove(fastaFileName)
|
|
64 os.remove(expCSVFileName)
|
|
65 os.remove(obsCSVFileName)
|
|
66
|
|
67 def test_getLetterDistributionWithFastqCVSOutput(self):
|
|
68 iFastqMock = MockGetLetterDistributionFastq()
|
|
69 fastqFileName = "MockFastq_GetLetterDistribution.fastq"
|
|
70 iFastqMock.write(fastqFileName)
|
|
71
|
|
72 iCSVMock = MockGetLetterDistributionExpectedCSV()
|
|
73 expCSVFileName = "expCSV.csv"
|
|
74 iCSVMock.write(expCSVFileName)
|
|
75
|
|
76 outputName = "dummy_result_fastq"
|
|
77 os.system("python %s/SMART/Java/Python/getLetterDistribution.py -i %s -f fastq -o %s -c" % (os.environ["REPET_PATH"], fastqFileName, outputName))
|
|
78
|
|
79 obsCSVFileName = outputName + ".csv"
|
|
80
|
|
81 self.assertTrue (os.path.exists(outputName + ".png"))
|
|
82 self.assertTrue (os.path.exists(outputName + "PerNt.png"))
|
|
83 self.assertTrue (self._are2FilesIdentical(expCSVFileName, obsCSVFileName))
|
|
84
|
|
85 os.remove(fastqFileName)
|
|
86 os.remove(outputName + ".png")
|
|
87 os.remove(outputName + "PerNt.png")
|
|
88 os.remove(expCSVFileName)
|
|
89 os.remove(obsCSVFileName)
|
|
90
|
|
91 def _are2FilesIdentical(self, file1, file2 ):
|
|
92 tmpFile = "diff_%s_%s" % ( os.path.basename(file1), os.path.basename(file2) )
|
|
93 cmd = "diff %s %s >> %s" % ( file1, file2, tmpFile )
|
|
94 returnStatus = os.system( cmd )
|
|
95 if returnStatus != 0:
|
|
96 msg = "ERROR: 'diff' returned '%i'" % ( returnStatus )
|
|
97 sys.stderr.write( "%s\n" % msg )
|
|
98 sys.stderr.flush()
|
|
99 os.remove( tmpFile )
|
|
100 return False
|
|
101 if self.isEmpty( tmpFile ):
|
|
102 os.remove( tmpFile )
|
|
103 return True
|
|
104 else:
|
|
105 os.remove( tmpFile )
|
|
106 return False
|
|
107
|
|
108 def getNbLinesInSingleFile(self, fileName):
|
|
109 fileHandler = open(fileName, "r" )
|
|
110 lines = fileHandler.readlines()
|
|
111 fileHandler.close()
|
|
112 return len(lines)
|
|
113
|
|
114 def isEmpty(self, fileName):
|
|
115 return 0 == self.getNbLinesInSingleFile( fileName )
|
|
116
|
|
117 if __name__ == "__main__":
|
|
118 unittest.main()
|