annotate SMART/Java/Python/test/Test_F_getLetterDistribution.py @ 25:7809e72960fe

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