view commons/launcher/tests/Test_F_LaunchRepeatMasker.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.LaunchRepeatMasker import LaunchRepeatMasker


class Test_F_RepeatMasker(unittest.TestCase):
    
    def setUp(self):
        self._queryFastaFileName = "query.fa"
        self._libFastaFileName = "lib.fa"
        self._expMaskedQueryFileName = "expMaskedQuery.fa"
        self._obsMaskedQueryFileName = "%s.masked" % self._queryFastaFileName
        
        self._expCatFileName = "expCat.fa"
        self._obsCatFileName = "%s.cat" % self._queryFastaFileName
        
        self._writeInputFastaFiles()
        self._writeExpMaskedQueryFile()
        self._writeExpCatFile()
   
    def tearDown(self):
        os.remove(self._queryFastaFileName)
        os.remove(self._libFastaFileName)
        os.remove(self._expMaskedQueryFileName)
        os.remove(self._obsMaskedQueryFileName)
        os.remove(self._expCatFileName)
        os.remove(self._obsCatFileName)
        os.remove("%s.tbl" % self._queryFastaFileName)
        os.remove("%s.out" % self._queryFastaFileName)
        os.remove("%s.ori.out" % self._queryFastaFileName)
        
    def test_run(self):
        ilauncher = LaunchRepeatMasker(self._queryFastaFileName, self._libFastaFileName,verbosity=1 )
        ilauncher.run()
        self.assertTrue(FileUtils.are2FilesIdentical(self._obsMaskedQueryFileName, self._expMaskedQueryFileName))
        
    def test_run_as_script(self):
        #FIXME : change path to launcher
        cmd = 'python %s/commons/launcher/LaunchRepeatMasker.py -q %s -l %s' % (os.environ["REPET_PATH"],self._queryFastaFileName, self._libFastaFileName)
        os.system(cmd)
        self.assertTrue(FileUtils.are2FilesIdentical(self._obsMaskedQueryFileName, self._expMaskedQueryFileName))
        
    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('TCGGACACGACTGAGCGACTAAGCACAGCACAGGTCTTTCCTGCCACTTACCTCCTTCCA\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('GGGCAGCCTGGGTGGCTCAGCGGTTTAGCGCCTGCCTTTGGCCCAGGGCGTGATCCTGGA\n')
        InputFile.write('GACCCGGGATCGAGTCCCACATCGGGCTCCCTGCATGGAGCCTGCTTCTCCCTCTGCCTG\n')
        InputFile.write('GGGGAGGGTATAGCTCAGTGGTAGAGCGCATGCTTAGCATGCACGAGGTCCTGGGTTCAA\n')
        InputFile.write('TCCCCAGTACCTCCATTAAAAATAAATAAATAAATAAACCTAATTACCTCCCCCACCAAA\n')
        InputFile.write('AAAAAAA\n')
        InputFile.close()
        
        InputFile = open(self._libFastaFileName, 'w')
        InputFile.write('>RefLib\n')
        InputFile.write('GGGCGGCACGGTGGTGTGGTGGTTAGCACTGTTGCCTCACAGCAAGAAGGCCCCGGGTTC\n')
        InputFile.write('GATCCCCGGTTGGGACTGAGGCTGGGGACTTTCTGTGTGGAGTTTGCATGTTCTCCCTGT\n')
        InputFile.close()
        
    def _writeExpMaskedQueryFile(self):
        f = open(self._expMaskedQueryFileName, 'w')  
        f.write('>Bovc-tA2:classI:SINE:SINE2/tRNA\n')
        f.write('GGGCTTCCCTGGTAGCTCAGCTGGTAAAGAATCCGCCTGCAATGCAGGAG\n')
        f.write('ACCCCGGTTCGATTCCTGGGTCGGGAAGATCCCCTGGAGAAGGGATAGGC\n')
        f.write('TACCCACTCCAGTATTCTTGGGCTTCCCTGGTGGCTCAGACGGTAAAGAA\n')
        f.write('TCCGCCTGCAATGCGGGAGACCTGGGTTCGATCCCTGGGTTGGGAAGATC\n')
        f.write('CCCTGGAGGAGGGCATGGCAACCCACTCCAGTATTCTTGCCTGGAGAATC\n')
        f.write('CCCATGGACAGAGGAGCCTGGCGGGCTACAGTCCATGGGGTCGCAAAGAG\n')
        f.write('TCGGACACGACTGAGCGACTAAGCACAGCACAGGTCTTTCCTGCCACTTA\n')
        f.write('CCTCCTTCCANNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN\n')
        f.write('NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN\n')
        f.write('NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNGCCTGCGTGGGTTCTCTCCG\n')
        f.write('GGTACTCCGGCTTCCTCCCACAGTCCAAAGACATGCATGATTGGGGATTA\n')
        f.write('GGCTAATTGGAAACTCTAAAATTGCCCGTAGGTGTGAGTGTGAGAGAGAA\n')
        f.write('TGGTTGTTTGTCTATATGTGTTAGCCCTGCGATTGACTGGCGTCCAGTCC\n')
        f.write('AGGGTGTACCCTGCCTCCGCCCATTGTGCTGGGATAGGCTCCAGTCCCCC\n')
        f.write('CGCGACCCTCAGTGGAGGAAGGGCAGCCTGGGTGGCTCAGCGGTTTAGCG\n')
        f.write('CCTGCCTTTGGCCCAGGGCGTGATCCTGGAGACCCGGGATCGAGTCCCAC\n')
        f.write('ATCGGGCTCCCTGCATGGAGCCTGCTTCTCCCTCTGCCTGGGGGAGGGTA\n')
        f.write('TAGCTCAGTGGTAGAGCGCATGCTTAGCATGCACGAGGTCCTGGGTTCAA\n')
        f.write('TCCCCAGTACCTCCATTAAAAATAAATAAATAAATAAACCTAATTACCTC\n')
        f.write('CCCCACCAAAAAAAAAA\n')
        f.close()
        
    def _writeExpCatFile(self):
        f = open(self._expCatFileName, 'w')  
        f.write('958 0.00 0.00 0.00 Bovc-tA2:classI:SINE:SINE2/tRNA 361 480 (487) RefLib 1 120 (0) 5\n')
        f.write('## Total Sequences: 1\n')
        f.write('## Total Length: 967\n')
        f.write('## Total NonMask ( excluding >20bp runs of N/X bases ): 967\n')
        f.write('## Total NonSub ( excluding all non ACGT bases ):967\n')
        f.write('RepeatMasker version open-3.2.6 , default mode\n')
        f.write('run with blastp version 2.0MP-WashU\n')
        f.write('RepBase Update 20080801, RM database version 20080801\n')
        f.close()
                       
if __name__ == "__main__":
    unittest.main()