Mercurial > repos > yufei-luo > s_mart
diff commons/launcher/tests/Test_F_LaunchNucmer.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_LaunchNucmer.py Mon Apr 29 03:20:15 2013 -0400 @@ -0,0 +1,153 @@ +import unittest +import os +from commons.core.utils.FileUtils import FileUtils +from commons.launcher.LaunchNucmer import LaunchNucmer + +class Test_F_LaunchNucmer(unittest.TestCase): + + def setUp(self): + self._queryFastaFileName = "query.fa" + self._refFastaFileName = "ref.fa" + self._writeInputFastaFiles() + self._expDeltaFileName = "expNucmer.delta" + self._writeExpDeltaFile() + self._obsDeltaFileName = "obsNucmer.delta" + self._obsCoordFileName= "obsNucmer.coords" + self._expCoordFileName= "expNucmer.coords" + + def tearDown(self): + try: + os.remove(self._queryFastaFileName) + except:pass + try: + os.remove(self._refFastaFileName) + except:pass + try: + os.remove(self._expDeltaFileName) + except:pass + try: + os.remove(self._obsDeltaFileName) + except:pass + + def test_run(self): + ilauncher = LaunchNucmer(self._refFastaFileName, self._queryFastaFileName,"obsNucmer",verbosity=1) + ilauncher.run() + self.assertTrue(FileUtils.are2FilesIdentical(self._expDeltaFileName, self._obsDeltaFileName)) + + def test_run_as_script(self): + cmd = 'LaunchNucmer.py --query %s --ref %s --prefix %s' % (self._refFastaFileName, self._queryFastaFileName, "obsNucmer") + os.system(cmd) + self.assertTrue(FileUtils.are2FilesIdentical(self._expDeltaFileName, self._obsDeltaFileName)) + + def test_run_as_script_gencoords_output(self): + self._writeExpGenCoordsFile() + cmd = 'LaunchNucmer.py --query %s --ref %s --prefix %s --gencoords' % (self._refFastaFileName, self._queryFastaFileName, "obsNucmer") + os.system(cmd) + self.assertTrue(FileUtils.are2FilesIdentical(self._expCoordFileName, self._obsCoordFileName)) + os.remove(self._obsCoordFileName) + os.remove(self._expCoordFileName) + + def test_run_as_script_with_mincluster(self): + cmd = 'LaunchNucmer.py --query %s --ref %s --prefix %s --mincluster 30' % (self._refFastaFileName, self._queryFastaFileName, "obsNucmer") + os.system(cmd) + self.assertTrue(FileUtils.are2FilesIdentical(self._expDeltaFileName, self._obsDeltaFileName)) + + def test_run_as_script_showcoords_output(self): + self._writeExpShowCoordsFile() + cmd = 'LaunchNucmer.py --query %s --ref %s --prefix %s --showcoords' % (self._refFastaFileName, self._queryFastaFileName, "obsNucmer") + os.system(cmd) + self.assertTrue(FileUtils.are2FilesIdentical(self._expCoordFileName, self._obsCoordFileName)) + os.remove(self._obsCoordFileName) + os.remove(self._expCoordFileName) + + 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 _writeExpDeltaFile(self): + f = open(self._expDeltaFileName, '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() + + def _writeExpGenCoordsFile(self): + f = open(self._expCoordFileName, 'w') + f.write("%s %s\n" %(os.path.abspath(self._queryFastaFileName), os.path.abspath(self._refFastaFileName))) + f.write('NUCMER\n\n') + f.write(' [S1] [E1] | [S2] [E2] | [LEN 1] [LEN 2] | [% IDY] | [TAGS]\n') + f.write('=====================================================================================\n') + f.write(' 1 161 | 1 161 | 161 161 | 100.00 | SINEC1B2_CF:classI:SINE:?\tSINEC1B2_CF:classI:SINE:?\n') + f.write(' 1 343 | 1 343 | 343 343 | 100.00 | SINE_FR2:classI:SINE:?\tSINE_FR2:classI:SINE:?\n') + f.close() + + def _writeExpShowCoordsFile(self): + f = open(self._expCoordFileName, 'w') + f.write("%s %s\n" %(os.path.abspath(self._queryFastaFileName), os.path.abspath(self._refFastaFileName))) + f.write('NUCMER\n\n') + f.write('[S1]\t[E1]\t[S2]\t[E2]\t[LEN 1]\t[LEN 2]\t[% IDY]\t[LEN R]\t[LEN Q]\t[COV R]\t[COV Q]\t[FRM]\t[TAGS]\n') + f.write('1\t161\t1\t161\t161\t161\t100.00\t164\t161\t98.17\t100.00\t1\t1\tSINEC1B2_CF:classI:SINE:?\tSINEC1B2_CF:classI:SINE:?\n') + f.write('1\t343\t1\t343\t343\t343\t100.00\t389\t371\t88.17\t92.45\t1\t1\tSINE_FR2:classI:SINE:?\tSINE_FR2:classI:SINE:?\n') + f.close() + +if __name__ == "__main__": + unittest.main() \ No newline at end of file