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