view commons/launcher/tests/Test_F_LaunchMatcher.py @ 19:9bcfa7936eec

Deleted selected files
author m-zytnicki
date Mon, 29 Apr 2013 03:23:29 -0400
parents 94ab73e8a190
children
line wrap: on
line source

from commons.core.utils.FileUtils import FileUtils
import unittest
import os
import subprocess
from commons.launcher.LaunchMatcher import LaunchMatcher

class Test_F_LaunchMatcher(unittest.TestCase):

    def setUp(self):
        self._inFileName = "DmelChr4.align"
        self._fastaFileName = "DmelChr4.fa"
        inFilePath = "%s/Tools/%s" % (os.environ["REPET_DATA"], self._inFileName)
        inFastaPath = "%s/Tools/%s" % (os.environ["REPET_DATA"], self._fastaFileName)
        try:
            os.remove(self._inFileName)
        except:
            pass
        os.symlink(inFilePath, self._inFileName)
        os.symlink(inFastaPath, self._fastaFileName)
        self._iLaunchMatcher = LaunchMatcher(align=self._inFileName, queryFileName=self._fastaFileName, subjectFileName=self._fastaFileName, doJoin=True, evalue="1e-20", keepConflict=True)
        self._iLaunchMatcher.setVerbosity(2)

    def tearDown(self):
        try:
            FileUtils.removeFilesByPattern("%s*" % self._inFileName)
            os.remove(self._fastaFileName)
        except:
            pass

    def test_run_as_class_1_file(self):
        expPathFileName = "%s/Tools/DmelChr4.align.match.path" % os.environ["REPET_DATA"]
        expTabFileName = "%s/Tools/DmelChr4.align.match.tab" % os.environ["REPET_DATA"]
        
        obsPathFileName = "%s.match.path" % self._inFileName
        obsTabFileName = "%s.match.tab" % self._inFileName
        
        self._iLaunchMatcher.run()
        
        self.assertTrue(FileUtils.are2FilesIdentical(expPathFileName, obsPathFileName))
        self.assertTrue(FileUtils.are2FilesIdentical(expTabFileName, obsTabFileName))

    def test_run_as_script(self):
        expPathFileName = "%s/Tools/DmelChr4.align.match.path" % os.environ["REPET_DATA"]
        expTabFileName = "%s/Tools/DmelChr4.align.match.tab" % os.environ["REPET_DATA"]

        cmd = "LaunchMatcher.py "
        cmd += "-a %s " % self._inFileName
        cmd += "-q %s " % self._fastaFileName
        cmd += "-s %s " % self._fastaFileName
        cmd += "-o DmelChr4.align "
        cmd += "-j "
        cmd += "-k "
        cmd += "-e 1e-20 "
        process = subprocess.Popen(cmd, shell = True)
        process.communicate()
        obsPathFileName = "%s.match.path" % self._inFileName
        obsTabFileName = "%s.match.tab" % self._inFileName
        
        self.assertTrue(FileUtils.are2FilesIdentical(expPathFileName, obsPathFileName))
        self.assertTrue(FileUtils.are2FilesIdentical(expTabFileName, obsTabFileName))

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