annotate commons/launcher/tests/Test_LaunchTallymer.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 from commons.core.utils.FileUtils import FileUtils
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
2 import os
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
3 import unittest
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
4 from commons.launcher.LaunchTallymer import ConvertUtils
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
5
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
6 class Test_ConvertUtils(unittest.TestCase):
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
7
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
8 def test_convertTallymerFormatIntoMapFormatAndGenerateData(self):
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
9 inputFastaFileName = "input.fa"
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
10 inputTallymerSearchFileName = "input.tallymer"
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
11 expMapFileName = "exp.map"
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
12 obsMapFileName = "obs.map"
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
13 self._writeInputFasta(inputFastaFileName)
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
14 self._writeInputTallymerSearch(inputTallymerSearchFileName)
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
15 self._writeExpMap(expMapFileName)
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
16
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
17 expOccNb = 4
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
18 expDKmer2Occ = {"caagatgcgtaacggccata":1,
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
19 "aagatgcgtaacggccatac":1,
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
20 "agatgcgtaacggccataca":1,
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
21 "gatgcgtaacggccatacat":1}
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
22 expPlotData = {4379: 17,
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
23 4380: 17,
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
24 4381: 16,
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
25 4382: 16}
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
26
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
27 obsOccNb, obsDKmer2Occ, obsPlotData, obsPlotData2 = ConvertUtils.convertTallymerFormatIntoMapFormatAndGenerateData(inputFastaFileName, inputTallymerSearchFileName, obsMapFileName)
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
28
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
29 self.assertEquals(expOccNb, obsOccNb)
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
30 self.assertEquals(expDKmer2Occ, obsDKmer2Occ)
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
31 self.assertEquals(expPlotData, obsPlotData)
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
32 self.assertTrue(FileUtils.are2FilesIdentical(expMapFileName, obsMapFileName))
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
33
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
34 os.remove(inputFastaFileName)
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
35 os.remove(inputTallymerSearchFileName)
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
36 os.remove(expMapFileName)
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
37 os.remove(obsMapFileName)
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
38
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
39 def test_convertTallymerFormatIntoMapFormatAndGenerateDataMultiFasta(self):
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
40 inputFastaFileName = "input.fa"
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
41 inputTallymerSearchFileName = "input.tallymer"
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
42 expMapFileName = "exp.map"
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
43 obsMapFileName = "obs.map"
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
44 self._writeInputMultiFasta(inputFastaFileName)
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
45 self._writeInputTallymerSearchMultiFasta(inputTallymerSearchFileName)
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
46 self._writeExpMapMultiFasta(expMapFileName)
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
47
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
48 expOccNb = 6
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
49 expDKmer2Occ = {"caagatgcgtaacggccata":1,
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
50 "aagatgcgtaacggccatac":1,
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
51 "agatgcgtaacggccataca":1,
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
52 "gatgcgtaacggccatacat":1,
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
53 "agatgcgtaacggccataca":2,
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
54 "gatgcgtaacggccatacat":2}
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
55 expPlotData = {4379: 17, 4380: 17, 4381: 16, 4382: 35}
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
56
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
57 obsOccNb, obsDKmer2Occ, obsPlotData, obsPlotData2 = ConvertUtils.convertTallymerFormatIntoMapFormatAndGenerateData(inputFastaFileName, inputTallymerSearchFileName, obsMapFileName)
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
58
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
59 self.assertEquals(expOccNb, obsOccNb)
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
60 self.assertEquals(expDKmer2Occ, obsDKmer2Occ)
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
61 self.assertEquals(expPlotData, obsPlotData)
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
62 self.assertTrue(FileUtils.are2FilesIdentical(expMapFileName, obsMapFileName))
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
63
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
64 os.remove(inputFastaFileName)
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
65 os.remove(inputTallymerSearchFileName)
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
66 os.remove(expMapFileName)
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
67 os.remove(obsMapFileName)
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
68
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
69 def _writeInputTallymerSearch(self, tallymerFormatFileName):
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
70 with open(tallymerFormatFileName, 'w') as f:
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
71 f.write("0\t+4378\t17\tcaagatgcgtaacggccata\n")
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
72 f.write("0\t+4379\t17\taagatgcgtaacggccatac\n")
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
73 f.write("0\t+4380\t16\tagatgcgtaacggccataca\n")
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
74 f.write("0\t+4381\t16\tgatgcgtaacggccatacat\n")
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
75
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
76 def _writeInputFasta(self, fastaFileName):
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
77 with open(fastaFileName, 'w') as f:
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
78 f.write(">Seq1\n")
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
79 f.write("caagatgcgtaacggccata\n")
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
80 f.write("aagatgcgtaacggccatac\n")
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
81 f.write("agatgcgtaacggccataca\n")
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
82 f.write("gatgcgtaacggccatacat\n")
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
83
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
84 def _writeExpMap(self, mapFileName):
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
85 with open(mapFileName, 'w') as f:
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
86 f.write("caagatgcgtaacggccata_17\tSeq1\t4379\t4399\t17\n")
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
87 f.write("aagatgcgtaacggccatac_17\tSeq1\t4380\t4400\t17\n")
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
88 f.write("agatgcgtaacggccataca_16\tSeq1\t4381\t4401\t16\n")
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
89 f.write("gatgcgtaacggccatacat_16\tSeq1\t4382\t4402\t16\n")
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
90
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
91 def _writeInputTallymerSearchMultiFasta(self, tallymerFormatFileName):
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
92 with open(tallymerFormatFileName, 'w') as f:
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
93 f.write("0\t+4378\t17\tcaagatgcgtaacggccata\n")
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
94 f.write("0\t+4379\t17\taagatgcgtaacggccatac\n")
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
95 f.write("0\t+4380\t16\tagatgcgtaacggccataca\n")
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
96 f.write("0\t+4381\t16\tgatgcgtaacggccatacat\n")
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
97 f.write("1\t+4380\t16\tagatgcgtaacggccataca\n")
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
98 f.write("1\t+4381\t35\tgatgcgtaacggccatacat\n")
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
99
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
100 def _writeInputMultiFasta(self, fastaFileName):
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
101 with open(fastaFileName, 'w') as f:
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
102 f.write(">Seq1\n")
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
103 f.write("caagatgcgtaacggccata\n")
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
104 f.write("aagatgcgtaacggccatac\n")
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
105 f.write("agatgcgtaacggccataca\n")
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
106 f.write("gatgcgtaacggccatacat\n")
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
107 f.write(">Seq2\n")
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
108 f.write("agatgcgtaacggccataca\n")
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
109 f.write("gatgcgtaacggccatacat\n")
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
110
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
111 def _writeExpMapMultiFasta(self, mapFileName):
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
112 with open(mapFileName, 'w') as f:
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
113 f.write("caagatgcgtaacggccata_17\tSeq1\t4379\t4399\t17\n")
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
114 f.write("aagatgcgtaacggccatac_17\tSeq1\t4380\t4400\t17\n")
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
115 f.write("agatgcgtaacggccataca_16\tSeq1\t4381\t4401\t16\n")
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
116 f.write("gatgcgtaacggccatacat_16\tSeq1\t4382\t4402\t16\n")
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
117 f.write("agatgcgtaacggccataca_16\tSeq2\t4381\t4401\t16\n")
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
118 f.write("gatgcgtaacggccatacat_35\tSeq2\t4382\t4402\t35\n")
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
119
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
120 if __name__ == "__main__":
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
121 unittest.main()