view commons/launcher/tests/Test_F_LaunchTRF.py @ 18:94ab73e8a190

Uploaded
author m-zytnicki
date Mon, 29 Apr 2013 03:20:15 -0400
parents
children
line wrap: on
line source

import unittest
import os
from commons.core.utils.FileUtils import FileUtils
from commons.launcher.LaunchTRF import LaunchTRF


class Test_F_LaunchTRF(unittest.TestCase):
    
    def setUp(self):
        self._inputFastaFileName = "input.fa"
        self._obsTRFOutputFileName = "obsTRF.TRF.set"
        self._expTRFOutputFileName = "expTRF.TRF.set"
        self._writeInputFile()
        self._writeExpTRFOutputFile()
        
    def tearDown(self):
        try:
            os.remove(self._inputFastaFileName)
        except:pass
    
        try:
            os.remove(self._expTRFOutputFileName)
        except:pass
        try:
            os.remove(self._obsTRFOutputFileName)
        except:pass
        try:
            os.remove("input.fa.2.3.5.80.10.20.15.dat")
        except:pass
    
    def test_run(self):
        ilauncher = LaunchTRF(self._inputFastaFileName,self._obsTRFOutputFileName,verbosity=5)
        ilauncher.run()
        self.assertTrue(FileUtils.are2FilesIdentical(self._expTRFOutputFileName, self._obsTRFOutputFileName))
        
    def test_run_as_script(self):
        cmd = 'LaunchTRF.py -i %s -o %s -v 3' % (self._inputFastaFileName, self._obsTRFOutputFileName)
        os.system(cmd)
        self.assertTrue(FileUtils.are2FilesIdentical(self._expTRFOutputFileName, self._obsTRFOutputFileName))    

    def test_run_as_scriptNoOutputGiven(self):
        cmd = 'LaunchTRF.py -i %s -v 3' % (self._inputFastaFileName)
        os.system(cmd)
        self._obsTRFOutputFileName = "input.fa.TRF.set"
        self.assertTrue(FileUtils.are2FilesIdentical(self._expTRFOutputFileName, self._obsTRFOutputFileName))  
        
    def test_run_as_scriptNoOutputGivenDoClean(self):
        cmd = 'LaunchTRF.py -i %s -c -v 3' % (self._inputFastaFileName)
        os.system(cmd)
        self._obsTRFOutputFileName = "input.fa.TRF.set"
        datFilePath = os.path.join(os.getcwd(),"%s.2.3.5.80.10.20.15.dat" % self._inputFastaFileName)
        self.assertFalse(os.path.exists(datFilePath))
        
    def _writeInputFile(self):        
        InputFile = open(self._inputFastaFileName, 'w')
        InputFile.write('>sequence\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('>sequence2\n')
        InputFile.write('GGGCAGCCTGGGTGGCTCAGCGGTTTAGCGCCTGCCTTTGGCCCAGGGCGTGATCCTGGA\n')
        InputFile.write('GACCCGGGATCGAGTCCCACATCGGGCTCCCTGCATGGAGCCTGCTTCTCCCTCTGCCTG\n')
        InputFile.write('TGTCTCTGCCTCTCTCTCTCTCTGTGTCTCTCATGAATAAA\n')
        InputFile.close()    
        
    def _writeExpTRFOutputFile(self):
        with open(self._expTRFOutputFileName,'w') as expTRFOutputFile:
            expTRFOutputFile.write("""1\t(GTGGT)2\tsequence\t11\t21
2\t(GGT)5\tsequence\t10\t23
3\t(GTGTGA)4\tsequence\t222\t242
4\t(GTCCA)2\tsequence\t282\t292
5\t(AGTG)4\tsequence\t355\t371
6\t(GCCTGTCTCTCCTCT)4\tsequence2\t100\t152
7\t(CTCTGCCTGTGT)3\tsequence2\t112\t151
8\t(TC)23\tsequence2\t107\t152
""")

                       
if __name__ == "__main__":
    unittest.main()