diff commons/launcher/tests/Test_F_LaunchMummerPlot.py @ 18:94ab73e8a190

Uploaded
author m-zytnicki
date Mon, 29 Apr 2013 03:20:15 -0400
parents
children
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/commons/launcher/tests/Test_F_LaunchMummerPlot.py	Mon Apr 29 03:20:15 2013 -0400
@@ -0,0 +1,166 @@
+import unittest
+import os
+from commons.core.utils.FileUtils import FileUtils
+from commons.launcher.LaunchMummerPlot import LaunchMummerPlot
+
+class Test_F_LaunchMummerPlot(unittest.TestCase):
+    
+    def setUp(self):
+        self._queryFastaFileName = "query.fa"
+        self._refFastaFileName = "ref.fa"
+        self._writeInputFastaFiles()
+        
+        self._inputDeltaFileName = "inputNucmer.delta"
+        self._writeInputDeltaFileName()
+        
+        self._expGpFileName = "expMummerPlot.gp"
+        self._obsGpFileName = "obsMummerPlot.gp"
+        self._obsPngFileName = "obsMummerPlot.png"
+        
+    def tearDown(self):
+        try:
+            os.remove(self._queryFastaFileName)
+        except:pass
+        try:
+            os.remove(self._refFastaFileName)
+        except:pass
+        try:
+            os.remove(self._inputDeltaFileName)
+        except:pass
+        try:
+            os.remove(self._expGpFileName)
+        except:pass
+        try:
+            os.remove(self._obsGpFileName)
+        except:pass
+        try:
+            os.remove(self._obsPngFileName)
+        except:pass
+        
+    
+    def test_run(self):
+        self._writeExpGpFile()
+        ilaunchMummerPlot = LaunchMummerPlot(self._inputDeltaFileName, self._refFastaFileName, self._queryFastaFileName,"obsMummerPlot",fat=True, filter=True, clean=True, verbosity=1)
+        ilaunchMummerPlot.run()
+        self.assertTrue(FileUtils.are2FilesIdentical(self._expGpFileName, self._obsGpFileName))
+        
+    def test_run_as_script(self):
+        self._writeExpGpFile()
+        cmd = 'LaunchMummerPlot.py --input %s --Qfile %s --Rfile %s --prefix %s --fat --filter --clean' % (self._inputDeltaFileName, self._refFastaFileName, self._queryFastaFileName, "obsMummerPlot")
+        os.system(cmd)
+        self.assertTrue(FileUtils.are2FilesIdentical(self._expGpFileName, self._obsGpFileName))
+        
+    def _writeInputFastaFiles(self):
+        InputFile = open(self._queryFastaFileName, 'w')
+        InputFile.write('>Bovc-tA2:classI:SINE:SINE2/tRNA\n')
+        InputFile.write('GGGCTTCCCTGGTAGCTCAGCTGGTAAAGAATCCGCCTGCAATGCAGGAGACCCCGGTTC\n')
+        InputFile.write('GATTCCTGGGTCGGGAAGATCCCCTGGAGAAGGGATAGGCTACCCACTCCAGTATTCTTG\n')
+        InputFile.write('GGCTTCCCTGGTGGCTCAGACGGTAAAGAATCCGCCTGCAATGCGGGAGACCTGGGTTCG\n')
+        InputFile.write('ATCCCTGGGTTGGGAAGATCCCCTGGAGGAGGGCATGGCAACCCACTCCAGTATTCTTGC\n')
+        InputFile.write('CTGGAGAATCCCCATGGACAGAGGAGCCTGGCGGGCTACAGTCCATGGGGTCGCAAAGAG\n')
+        InputFile.write('TCGGACACGACTGAGCGACTAAGCACAGCACAG\n')
+        InputFile.write('>SUSINE2:classI:SINE:SINE2/tRNA\n')
+        InputFile.write('GGGAGTTCTCTGATGGCCTAGCGGGTTGAGGCTCCTGCGTTCTCACCGCTGTGGCTCTGG\n')
+        InputFile.write('TTGCTGCTGTGCGGCGTAGGTTCAATCCCTGGCCCAGGAATTCCCACATACTGCCTGTGT\n')
+        InputFile.write('GGCAAAAAAGAAAAAAAAAAAAAATACAAAAAAAAAAAAAACAAGAGAGAACCTGAAATA\n')
+        InputFile.write('AACGTTGCAACTCTCATTNAAAAAAAAAAA\n')
+        InputFile.write('>SINE1A_SS:classI:SINE:SINE2/tRNA\n')
+        InputFile.write('GGGAGTTCTCTTGTGGCACAGCAGGTTAAGGATCCAGCGTTGTCACTGCAGTGGCTTGGG\n')
+        InputFile.write('TCGCTGCTGTGGCACGGGTTCAATCCCTGGCCCAGGAACTTCCACATGCCACGGGCATGG\n')
+        InputFile.write('CCAAAAAAAAA\n')
+        InputFile.write('>SINE2-1_Pca:classI:SINE:SINE2/tRNA\n')
+        InputFile.write('GGGCAGTGGTGGTTCAGTGGTAGAATTCTTGCCTTCCATGCGGGAGACCCGGGTTCGATT\n')
+        InputFile.write('CCCGGCCAGTGCACCTCATGCGCAGCCACCACCCGTCTGTCAGTGGAGGCTTGCGTGTTG\n')
+        InputFile.write('CTGTGATGCTGAACAGGTTTCAGCGGAGCTTCCAGACTAAGACGGACTAGGAAGAAAGGC\n')
+        InputFile.write('CTGGCGATCTACTTCTGAAAATCAGCCAATGAAAACCCTGTGGATCACAGTGGTCTGATC\n')
+        InputFile.write('TGCAACTGATCATGGGGATGGCGCAGGACCGGGCAGCGTTTTGTTCTATTGTGCATGGGG\n')
+        InputFile.write('TCGCCATGAGTCGGGCCGACTCGATGGCAGCTAACAACAA\n')
+        InputFile.write('>SINE_FR2:classI:SINE:?\n')
+        InputFile.write('GGGCGGCACGGTGGTGTGGTGGTTAGCACTGTTGCCTCACAGCAAGAAGGCCCCGGGTTC\n')
+        InputFile.write('GATCCCCGGTTGGGACTGAGGCTGGGGACTTTCTGTGTGGAGTTTGCATGTTCTCCCTGT\n')
+        InputFile.write('GCCTGCGTGGGTTCTCTCCGGGTACTCCGGCTTCCTCCCACAGTCCAAAGACATGCATGA\n')
+        InputFile.write('TTGGGGATTAGGCTAATTGGAAACTCTAAAATTGCCCGTAGGTGTGAGTGTGAGAGAGAA\n')
+        InputFile.write('TGGTTGTTTGTCTATATGTGTTAGCCCTGCGATTGACTGGCGTCCAGTCCAGGGTGTACC\n')
+        InputFile.write('CTGCCTCCGCCCATTGTGCTGGGATAGGCTCCAGTCCCCCCGCGACCCTCAGTGGAGGAA\n')
+        InputFile.write('CAAGCGGTAGAAAGTGAGTGAGTGAGTGA\n')
+        InputFile.write('>SINEC1B2_CF:classI:SINE:?\n')
+        InputFile.write('GGGCAGCCTGGGTGGCTCAGCGGTTTAGCGCCTGCCTTTGGCCCAGGGCGTGATCCTGGA\n')
+        InputFile.write('GACCCGGGATCGAGTCCCACATCGGGCTCCCTGCATGGAGCCTGCTTCTCCCTCTGCCTG\n')
+        InputFile.write('TGTCTCTGCCTCTCTCTCTCTCTGTGTCTCTCATGAATAAATAA\n')
+        InputFile.write('>ALPINE1:classI:SINE:SINE2/tRNA\n')
+        InputFile.write('GGGGAGGGTATAGCTCAGTGGTAGAGCGCATGCTTAGCATGCACGAGGTCCTGGGTTCAA\n')
+        InputFile.write('TCCCCAGTACCTCCATTAAAAATAAATAAATAAATAAACCTAATTACCTCCCCCACCAAA\n')
+        InputFile.write('AAAAAAA\n')
+        InputFile.close()
+        
+        InputFile = open(self._refFastaFileName, 'w')
+        InputFile.write('>SINE_FR2:classI:SINE:?\n')
+        InputFile.write('GGGCGGCACGGTGGTGTGGTGGTTAGCACTGTTGCCTCACAGCAAGAAGGCCCCGGGTTC\n')
+        InputFile.write('GATCCCCGGTTGGGACTGAGGCTGGGGACTTTCTGTGTGGAGTTTGCATGTTCTCCCTGT\n')
+        InputFile.write('GCCTGCGTGGGTTCTCTCCGGGTACTCCGGCTTCCTCCCACAGTCCAAAGACATGCATGA\n')
+        InputFile.write('TTGGGGATTAGGCTAATTGGAAACTCTAAAATTGCCCGTAGGTGTGAGTGTGAGAGAGAA\n')
+        InputFile.write('TGGTTGTTTGTCTATATGTGTTAGCCCTGCGATTGACTGGCGTCCAGTCCAGGGTGTACC\n')
+        InputFile.write('CTGCCTCCGCCCATTGTGCTGGGATAGGCTCCAGTCCCCCCG\n')
+        InputFile.write('CAAGCGGTAGAAAGTGAGTGAGTGAGTGA\n')
+        InputFile.write('>SINEC1B2_CF:classI:SINE:?\n')
+        InputFile.write('GGGCAGCCTGGGTGGCTCAGCGGTTTAGCGCCTGCCTTTGGCCCAGGGCGTGATCCTGGA\n')
+        InputFile.write('GACCCGGGATCGAGTCCCACATCGGGCTCCCTGCATGGAGCCTGCTTCTCCCTCTGCCTG\n')
+        InputFile.write('TGTCTCTGCCTCTCTCTCTCTCTGTGTCTCTCATGAATAAA\n')
+        InputFile.close()
+        
+    def _writeExpGpFile(self):
+        f = open(self._expGpFileName, 'w')
+        f.write('set terminal png tiny size 800,800\n')
+        f.write('set output "obsMummerPlot.png"\n')
+        f.write('set xtics rotate ( \\\n')
+        f.write(' "SINE_FR2:classI:SINE:?" 1, \\\n')
+        f.write(' "SINEC1B2_CF:classI:SINE:?" 389, \\\n')
+        f.write(' "SINE1A_SS:classI:SINE:SINE2/tRNA" 552, \\\n')
+        f.write(' "SUSINE2:classI:SINE:SINE2/tRNA" 682, \\\n')
+        f.write(' "Bovc-tA2:classI:SINE:SINE2/tRNA" 891, \\\n')
+        f.write(' "ALPINE1:classI:SINE:SINE2/tRNA" 1223, \\\n')
+        f.write(' "SINE2-1_Pca:classI:SINE:SINE2/tRNA" 1349, \\\n')
+        f.write(' "" 1694 \\\n')
+        f.write(')\n')
+        f.write('set ytics ( \\\n')
+        f.write(' "SINE_FR2:classI:SINE:?" 1, \\\n')
+        f.write(' "SINEC1B2_CF:classI:SINE:?" 371, \\\n')
+        f.write(' "" 532 \\\n')
+        f.write(')\n')
+        f.write('set size 1,1\n')
+        f.write('set grid\n')
+        f.write('unset key\n')
+        f.write('set border 0\n')
+        f.write('set tics scale 0\n')
+        f.write('set xlabel "REF"\n')
+        f.write('set ylabel "QRY"\n')
+        f.write('set format "%.0f"\n')
+        f.write('set mouse format "%.0f"\n')
+        f.write('set mouse mouseformat "[%.0f, %.0f]"\n')
+        f.write('set mouse clipboardformat "[%.0f, %.0f]"\n')
+        f.write('set xrange [1:1694]\n')
+        f.write('set yrange [1:532]\n')
+        f.write('set style line 1  lt 1 lw 3 pt 6 ps 1\n')
+        f.write('set style line 2  lt 3 lw 3 pt 6 ps 1\n')
+        f.write('set style line 3  lt 2 lw 3 pt 6 ps 1\n')
+        f.write('plot \\\n')
+        f.write(' "obsMummerPlot.fplot" title "FWD" w lp ls 1, \\\n')
+        f.write(' "obsMummerPlot.rplot" title "REV" w lp ls 2\n')
+        f.write('')
+        f.close()
+        
+    def _writeInputDeltaFileName(self):
+        f = open(self._inputDeltaFileName, 'w')
+        f.write("%s %s\n" %(os.path.abspath(self._queryFastaFileName), os.path.abspath(self._refFastaFileName)))
+        f.write('NUCMER\n')
+        f.write('>SINE_FR2:classI:SINE:? SINE_FR2:classI:SINE:? 389 371\n')
+        f.write('1 343 1 343 0 0 0\n')
+        f.write('0\n')
+        f.write('>SINEC1B2_CF:classI:SINE:? SINEC1B2_CF:classI:SINE:? 164 161\n')
+        f.write('1 161 1 161 0 0 0\n')
+        f.write('0\n')
+        f.close()
+        
+if __name__ == "__main__":
+    unittest.main()
+        
\ No newline at end of file