18
|
1 import unittest
|
|
2 import os
|
|
3 from commons.core.utils.FileUtils import FileUtils
|
|
4 from commons.launcher.LaunchMummerPlot import LaunchMummerPlot
|
|
5
|
|
6 class Test_F_LaunchMummerPlot(unittest.TestCase):
|
|
7
|
|
8 def setUp(self):
|
|
9 self._queryFastaFileName = "query.fa"
|
|
10 self._refFastaFileName = "ref.fa"
|
|
11 self._writeInputFastaFiles()
|
|
12
|
|
13 self._inputDeltaFileName = "inputNucmer.delta"
|
|
14 self._writeInputDeltaFileName()
|
|
15
|
|
16 self._expGpFileName = "expMummerPlot.gp"
|
|
17 self._obsGpFileName = "obsMummerPlot.gp"
|
|
18 self._obsPngFileName = "obsMummerPlot.png"
|
|
19
|
|
20 def tearDown(self):
|
|
21 try:
|
|
22 os.remove(self._queryFastaFileName)
|
|
23 except:pass
|
|
24 try:
|
|
25 os.remove(self._refFastaFileName)
|
|
26 except:pass
|
|
27 try:
|
|
28 os.remove(self._inputDeltaFileName)
|
|
29 except:pass
|
|
30 try:
|
|
31 os.remove(self._expGpFileName)
|
|
32 except:pass
|
|
33 try:
|
|
34 os.remove(self._obsGpFileName)
|
|
35 except:pass
|
|
36 try:
|
|
37 os.remove(self._obsPngFileName)
|
|
38 except:pass
|
|
39
|
|
40
|
|
41 def test_run(self):
|
|
42 self._writeExpGpFile()
|
|
43 ilaunchMummerPlot = LaunchMummerPlot(self._inputDeltaFileName, self._refFastaFileName, self._queryFastaFileName,"obsMummerPlot",fat=True, filter=True, clean=True, verbosity=1)
|
|
44 ilaunchMummerPlot.run()
|
|
45 self.assertTrue(FileUtils.are2FilesIdentical(self._expGpFileName, self._obsGpFileName))
|
|
46
|
|
47 def test_run_as_script(self):
|
|
48 self._writeExpGpFile()
|
|
49 cmd = 'LaunchMummerPlot.py --input %s --Qfile %s --Rfile %s --prefix %s --fat --filter --clean' % (self._inputDeltaFileName, self._refFastaFileName, self._queryFastaFileName, "obsMummerPlot")
|
|
50 os.system(cmd)
|
|
51 self.assertTrue(FileUtils.are2FilesIdentical(self._expGpFileName, self._obsGpFileName))
|
|
52
|
|
53 def _writeInputFastaFiles(self):
|
|
54 InputFile = open(self._queryFastaFileName, 'w')
|
|
55 InputFile.write('>Bovc-tA2:classI:SINE:SINE2/tRNA\n')
|
|
56 InputFile.write('GGGCTTCCCTGGTAGCTCAGCTGGTAAAGAATCCGCCTGCAATGCAGGAGACCCCGGTTC\n')
|
|
57 InputFile.write('GATTCCTGGGTCGGGAAGATCCCCTGGAGAAGGGATAGGCTACCCACTCCAGTATTCTTG\n')
|
|
58 InputFile.write('GGCTTCCCTGGTGGCTCAGACGGTAAAGAATCCGCCTGCAATGCGGGAGACCTGGGTTCG\n')
|
|
59 InputFile.write('ATCCCTGGGTTGGGAAGATCCCCTGGAGGAGGGCATGGCAACCCACTCCAGTATTCTTGC\n')
|
|
60 InputFile.write('CTGGAGAATCCCCATGGACAGAGGAGCCTGGCGGGCTACAGTCCATGGGGTCGCAAAGAG\n')
|
|
61 InputFile.write('TCGGACACGACTGAGCGACTAAGCACAGCACAG\n')
|
|
62 InputFile.write('>SUSINE2:classI:SINE:SINE2/tRNA\n')
|
|
63 InputFile.write('GGGAGTTCTCTGATGGCCTAGCGGGTTGAGGCTCCTGCGTTCTCACCGCTGTGGCTCTGG\n')
|
|
64 InputFile.write('TTGCTGCTGTGCGGCGTAGGTTCAATCCCTGGCCCAGGAATTCCCACATACTGCCTGTGT\n')
|
|
65 InputFile.write('GGCAAAAAAGAAAAAAAAAAAAAATACAAAAAAAAAAAAAACAAGAGAGAACCTGAAATA\n')
|
|
66 InputFile.write('AACGTTGCAACTCTCATTNAAAAAAAAAAA\n')
|
|
67 InputFile.write('>SINE1A_SS:classI:SINE:SINE2/tRNA\n')
|
|
68 InputFile.write('GGGAGTTCTCTTGTGGCACAGCAGGTTAAGGATCCAGCGTTGTCACTGCAGTGGCTTGGG\n')
|
|
69 InputFile.write('TCGCTGCTGTGGCACGGGTTCAATCCCTGGCCCAGGAACTTCCACATGCCACGGGCATGG\n')
|
|
70 InputFile.write('CCAAAAAAAAA\n')
|
|
71 InputFile.write('>SINE2-1_Pca:classI:SINE:SINE2/tRNA\n')
|
|
72 InputFile.write('GGGCAGTGGTGGTTCAGTGGTAGAATTCTTGCCTTCCATGCGGGAGACCCGGGTTCGATT\n')
|
|
73 InputFile.write('CCCGGCCAGTGCACCTCATGCGCAGCCACCACCCGTCTGTCAGTGGAGGCTTGCGTGTTG\n')
|
|
74 InputFile.write('CTGTGATGCTGAACAGGTTTCAGCGGAGCTTCCAGACTAAGACGGACTAGGAAGAAAGGC\n')
|
|
75 InputFile.write('CTGGCGATCTACTTCTGAAAATCAGCCAATGAAAACCCTGTGGATCACAGTGGTCTGATC\n')
|
|
76 InputFile.write('TGCAACTGATCATGGGGATGGCGCAGGACCGGGCAGCGTTTTGTTCTATTGTGCATGGGG\n')
|
|
77 InputFile.write('TCGCCATGAGTCGGGCCGACTCGATGGCAGCTAACAACAA\n')
|
|
78 InputFile.write('>SINE_FR2:classI:SINE:?\n')
|
|
79 InputFile.write('GGGCGGCACGGTGGTGTGGTGGTTAGCACTGTTGCCTCACAGCAAGAAGGCCCCGGGTTC\n')
|
|
80 InputFile.write('GATCCCCGGTTGGGACTGAGGCTGGGGACTTTCTGTGTGGAGTTTGCATGTTCTCCCTGT\n')
|
|
81 InputFile.write('GCCTGCGTGGGTTCTCTCCGGGTACTCCGGCTTCCTCCCACAGTCCAAAGACATGCATGA\n')
|
|
82 InputFile.write('TTGGGGATTAGGCTAATTGGAAACTCTAAAATTGCCCGTAGGTGTGAGTGTGAGAGAGAA\n')
|
|
83 InputFile.write('TGGTTGTTTGTCTATATGTGTTAGCCCTGCGATTGACTGGCGTCCAGTCCAGGGTGTACC\n')
|
|
84 InputFile.write('CTGCCTCCGCCCATTGTGCTGGGATAGGCTCCAGTCCCCCCGCGACCCTCAGTGGAGGAA\n')
|
|
85 InputFile.write('CAAGCGGTAGAAAGTGAGTGAGTGAGTGA\n')
|
|
86 InputFile.write('>SINEC1B2_CF:classI:SINE:?\n')
|
|
87 InputFile.write('GGGCAGCCTGGGTGGCTCAGCGGTTTAGCGCCTGCCTTTGGCCCAGGGCGTGATCCTGGA\n')
|
|
88 InputFile.write('GACCCGGGATCGAGTCCCACATCGGGCTCCCTGCATGGAGCCTGCTTCTCCCTCTGCCTG\n')
|
|
89 InputFile.write('TGTCTCTGCCTCTCTCTCTCTCTGTGTCTCTCATGAATAAATAA\n')
|
|
90 InputFile.write('>ALPINE1:classI:SINE:SINE2/tRNA\n')
|
|
91 InputFile.write('GGGGAGGGTATAGCTCAGTGGTAGAGCGCATGCTTAGCATGCACGAGGTCCTGGGTTCAA\n')
|
|
92 InputFile.write('TCCCCAGTACCTCCATTAAAAATAAATAAATAAATAAACCTAATTACCTCCCCCACCAAA\n')
|
|
93 InputFile.write('AAAAAAA\n')
|
|
94 InputFile.close()
|
|
95
|
|
96 InputFile = open(self._refFastaFileName, 'w')
|
|
97 InputFile.write('>SINE_FR2:classI:SINE:?\n')
|
|
98 InputFile.write('GGGCGGCACGGTGGTGTGGTGGTTAGCACTGTTGCCTCACAGCAAGAAGGCCCCGGGTTC\n')
|
|
99 InputFile.write('GATCCCCGGTTGGGACTGAGGCTGGGGACTTTCTGTGTGGAGTTTGCATGTTCTCCCTGT\n')
|
|
100 InputFile.write('GCCTGCGTGGGTTCTCTCCGGGTACTCCGGCTTCCTCCCACAGTCCAAAGACATGCATGA\n')
|
|
101 InputFile.write('TTGGGGATTAGGCTAATTGGAAACTCTAAAATTGCCCGTAGGTGTGAGTGTGAGAGAGAA\n')
|
|
102 InputFile.write('TGGTTGTTTGTCTATATGTGTTAGCCCTGCGATTGACTGGCGTCCAGTCCAGGGTGTACC\n')
|
|
103 InputFile.write('CTGCCTCCGCCCATTGTGCTGGGATAGGCTCCAGTCCCCCCG\n')
|
|
104 InputFile.write('CAAGCGGTAGAAAGTGAGTGAGTGAGTGA\n')
|
|
105 InputFile.write('>SINEC1B2_CF:classI:SINE:?\n')
|
|
106 InputFile.write('GGGCAGCCTGGGTGGCTCAGCGGTTTAGCGCCTGCCTTTGGCCCAGGGCGTGATCCTGGA\n')
|
|
107 InputFile.write('GACCCGGGATCGAGTCCCACATCGGGCTCCCTGCATGGAGCCTGCTTCTCCCTCTGCCTG\n')
|
|
108 InputFile.write('TGTCTCTGCCTCTCTCTCTCTCTGTGTCTCTCATGAATAAA\n')
|
|
109 InputFile.close()
|
|
110
|
|
111 def _writeExpGpFile(self):
|
|
112 f = open(self._expGpFileName, 'w')
|
|
113 f.write('set terminal png tiny size 800,800\n')
|
|
114 f.write('set output "obsMummerPlot.png"\n')
|
|
115 f.write('set xtics rotate ( \\\n')
|
|
116 f.write(' "SINE_FR2:classI:SINE:?" 1, \\\n')
|
|
117 f.write(' "SINEC1B2_CF:classI:SINE:?" 389, \\\n')
|
|
118 f.write(' "SINE1A_SS:classI:SINE:SINE2/tRNA" 552, \\\n')
|
|
119 f.write(' "SUSINE2:classI:SINE:SINE2/tRNA" 682, \\\n')
|
|
120 f.write(' "Bovc-tA2:classI:SINE:SINE2/tRNA" 891, \\\n')
|
|
121 f.write(' "ALPINE1:classI:SINE:SINE2/tRNA" 1223, \\\n')
|
|
122 f.write(' "SINE2-1_Pca:classI:SINE:SINE2/tRNA" 1349, \\\n')
|
|
123 f.write(' "" 1694 \\\n')
|
|
124 f.write(')\n')
|
|
125 f.write('set ytics ( \\\n')
|
|
126 f.write(' "SINE_FR2:classI:SINE:?" 1, \\\n')
|
|
127 f.write(' "SINEC1B2_CF:classI:SINE:?" 371, \\\n')
|
|
128 f.write(' "" 532 \\\n')
|
|
129 f.write(')\n')
|
|
130 f.write('set size 1,1\n')
|
|
131 f.write('set grid\n')
|
|
132 f.write('unset key\n')
|
|
133 f.write('set border 0\n')
|
|
134 f.write('set tics scale 0\n')
|
|
135 f.write('set xlabel "REF"\n')
|
|
136 f.write('set ylabel "QRY"\n')
|
|
137 f.write('set format "%.0f"\n')
|
|
138 f.write('set mouse format "%.0f"\n')
|
|
139 f.write('set mouse mouseformat "[%.0f, %.0f]"\n')
|
|
140 f.write('set mouse clipboardformat "[%.0f, %.0f]"\n')
|
|
141 f.write('set xrange [1:1694]\n')
|
|
142 f.write('set yrange [1:532]\n')
|
|
143 f.write('set style line 1 lt 1 lw 3 pt 6 ps 1\n')
|
|
144 f.write('set style line 2 lt 3 lw 3 pt 6 ps 1\n')
|
|
145 f.write('set style line 3 lt 2 lw 3 pt 6 ps 1\n')
|
|
146 f.write('plot \\\n')
|
|
147 f.write(' "obsMummerPlot.fplot" title "FWD" w lp ls 1, \\\n')
|
|
148 f.write(' "obsMummerPlot.rplot" title "REV" w lp ls 2\n')
|
|
149 f.write('')
|
|
150 f.close()
|
|
151
|
|
152 def _writeInputDeltaFileName(self):
|
|
153 f = open(self._inputDeltaFileName, 'w')
|
|
154 f.write("%s %s\n" %(os.path.abspath(self._queryFastaFileName), os.path.abspath(self._refFastaFileName)))
|
|
155 f.write('NUCMER\n')
|
|
156 f.write('>SINE_FR2:classI:SINE:? SINE_FR2:classI:SINE:? 389 371\n')
|
|
157 f.write('1 343 1 343 0 0 0\n')
|
|
158 f.write('0\n')
|
|
159 f.write('>SINEC1B2_CF:classI:SINE:? SINEC1B2_CF:classI:SINE:? 164 161\n')
|
|
160 f.write('1 161 1 161 0 0 0\n')
|
|
161 f.write('0\n')
|
|
162 f.close()
|
|
163
|
|
164 if __name__ == "__main__":
|
|
165 unittest.main()
|
|
166 |