Mercurial > repos > yufei-luo > s_mart
view commons/launcher/tests/Test_F_LaunchTallymer.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 import shutil from commons.launcher.LaunchTallymer import LaunchTallymer class Test_F_LaunchTallymer(unittest.TestCase): def setUp(self): self._inFastaFileName = "%s/Tools/DmelChr4.fa" % os.environ["REPET_DATA"] def test_run_output_as_gff_cleaned(self): iLaunchTallymer = LaunchTallymer(self._inFastaFileName, clean = True, verbosity=2) iLaunchTallymer.run() expFileName = "%s/Tools/DmelChr4.fa.tallymer_k20.gff" % os.environ["REPET_DATA"] obsFileName = "DmelChr4.tallymer.gff" self.assertTrue(FileUtils.are2FilesIdentical(expFileName, obsFileName)) os.remove(obsFileName) os.remove("DmelChr4.tallymer.stat") def test_run_with_remote_dir(self): os.makedirs("sourceDir") changedInFastaFileName = os.path.basename(self._inFastaFileName) changedInFastaFilepath = os.path.join("sourceDir",changedInFastaFileName) shutil.copy2(self._inFastaFileName, changedInFastaFilepath) iLaunchTallymer = LaunchTallymer(changedInFastaFilepath, clean = True, verbosity=2) iLaunchTallymer.run() expFileName = "%s/Tools/DmelChr4.fa.tallymer_k20.gff" % os.environ["REPET_DATA"] obsFileName = "DmelChr4.tallymer.gff" self.assertTrue(FileUtils.are2FilesIdentical(expFileName, obsFileName)) obsSourceDirFiles = os.listdir("sourceDir") expSourceDirFiles = [changedInFastaFileName,] self.assertEquals(expSourceDirFiles, obsSourceDirFiles) os.remove(obsFileName) os.remove("DmelChr4.tallymer.stat") shutil.rmtree("sourceDir") def test_run_output_as_gff_cleaned_changed_minOccs2(self): iLaunchTallymer = LaunchTallymer(self._inFastaFileName, minOccs=2, clean = True, verbosity=2) iLaunchTallymer.run() expFileName = "%s/Tools/DmelChr4.fa.tallymer_k20_minOcc2.gff" % os.environ["REPET_DATA"] obsFileName = "DmelChr4.tallymer.gff" self.assertTrue(FileUtils.are2FilesIdentical(expFileName, obsFileName)) os.remove(obsFileName) os.remove("DmelChr4.tallymer.stat") def test_run_output_as_gff_cleaned_relative_input(self): srcFastaFileName = self._inFastaFileName dstFastaFileName = os.path.basename(self._inFastaFileName) shutil.copy2(srcFastaFileName, dstFastaFileName) iLaunchTallymer = LaunchTallymer(dstFastaFileName, clean = True, verbosity=2) iLaunchTallymer.run() expFileName = "%s/Tools/DmelChr4.fa.tallymer_k20.gff" % os.environ["REPET_DATA"] obsFileName = "DmelChr4.tallymer.gff" self.assertTrue(FileUtils.are2FilesIdentical(expFileName, obsFileName)) os.remove(obsFileName) os.remove("DmelChr4.tallymer.stat") os.remove(dstFastaFileName) def test_run_as_script_output_as_gff_cleaned_relative_input_(self): srcFastaFileName = self._inFastaFileName dstFastaFileName = os.path.basename(self._inFastaFileName) shutil.copy2(srcFastaFileName, dstFastaFileName) cmd = 'LaunchTallymer.py -i %s -s 20 -c -v 3' % (self._inFastaFileName) os.system(cmd) expFileName = "%s/Tools/DmelChr4.fa.tallymer_k20.gff" % os.environ["REPET_DATA"] obsFileName = "DmelChr4.tallymer.gff" self.assertTrue(FileUtils.are2FilesIdentical(expFileName, obsFileName)) os.remove(obsFileName) os.remove("DmelChr4.tallymer.stat") os.remove(dstFastaFileName) def test_run_output_as_wig_cleaned(self): iLaunchTallymer = LaunchTallymer(self._inFastaFileName, outputFormats="wig", clean=True) iLaunchTallymer.run() expFileName = "%s/Tools/DmelChr4.fa.tallymer_k20.wig" % os.environ["REPET_DATA"] obsFileName = "DmelChr4.tallymer.wig" self.assertTrue(FileUtils.are2FilesIdentical(expFileName, obsFileName)) os.remove(obsFileName) os.remove("DmelChr4.tallymer.stat") def test_run_output_as_gff_and_wig_k15_cleaned(self): iLaunchTallymer = LaunchTallymer(self._inFastaFileName, merSize=15, outputFormats="wig,gff3", clean=True) iLaunchTallymer.run() expFileName = "%s/Tools/DmelChr4.fa.tallymer_k15.wig" % os.environ["REPET_DATA"] obsFileName = "DmelChr4.tallymer.wig" self.assertTrue(FileUtils.are2FilesIdentical(expFileName, obsFileName)) os.remove(obsFileName) expFileName = "%s/Tools/DmelChr4.fa.tallymer_k15.gff3" % os.environ["REPET_DATA"] obsFileName = "DmelChr4.tallymer.gff3" self.assertTrue(FileUtils.are2FilesIdentical(expFileName, obsFileName)) os.remove(obsFileName) os.remove("DmelChr4.tallymer.stat") def test_run_as_script_run_output_as_gff_and_wig_k15_cleaned(self): logFileName = "test.log" cmd = 'LaunchTallymer.py -i %s -s 15 -f gff,wig,vero -c -v 3 > %s' % (self._inFastaFileName, logFileName) os.system(cmd) expFileName = "%s/Tools/DmelChr4.fa.tallymer_k15.wig" % os.environ["REPET_DATA"] obsFileName = "DmelChr4.tallymer.wig" self.assertTrue(FileUtils.are2FilesIdentical(expFileName, obsFileName)) os.remove(obsFileName) expFileName = "%s/Tools/DmelChr4.fa.tallymer_k15.gff3" % os.environ["REPET_DATA"] obsFileName = "DmelChr4.tallymer.gff" self.assertTrue(FileUtils.are2FilesIdentical(expFileName, obsFileName)) os.remove(obsFileName) expLogFileName = "exp.log" with open(expLogFileName, "w") as f: f.write(" LaunchTallymer - WARNING - Warning: ignoring invalid formats: <vero>\n") f.write(" LaunchTallymer - INFO - Starting to run tallymer search of sequence DmelChr4.fa \n") f.write(" LaunchTallymer - INFO - Finished running tallymer scan of sequence DmelChr4.fa \n") f.write(" LaunchTallymer - INFO - Starting to run tallymer search to map conversion\n") f.write(" LaunchTallymer - INFO - Finished tallymer search to map conversion\n") f.write(" LaunchTallymer - INFO - Generating wig file\n") f.write(" LaunchTallymer - INFO - Generating gff file\n") obsLogFileName = "obs.log" os.system("cut -d'-' -f4,5,6 %s > %s" % (logFileName, obsLogFileName)) self.assertTrue(FileUtils.are2FilesIdentical(expLogFileName, obsLogFileName)) os.remove(logFileName) os.remove(expLogFileName) os.remove(obsLogFileName) os.remove("DmelChr4.tallymer.stat") if __name__ == "__main__": unittest.main()