diff commons/tools/tests/Test_F_GetMultiAlignAndPhylogenyPerTErefSeq.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/tools/tests/Test_F_GetMultiAlignAndPhylogenyPerTErefSeq.py	Mon Apr 29 03:20:15 2013 -0400
@@ -0,0 +1,147 @@
+import subprocess
+import unittest
+import os
+from commons.core.utils.FileUtils import FileUtils
+from commons.core.sql.DbMySql import DbMySql
+from commons.tools.GetMultAlignAndPhylogenyPerTErefSeq import GetMultAlignAndPhylogenyPerTErefSeq
+from shutil import rmtree
+from glob import glob
+
+class Test_F_GetMultAlignAndPhylogenyPerTErefSeq(unittest.TestCase):
+    
+    def setUp(self):
+        self._verbosity = 3
+        
+        self._testPrefix = 'Test_GMAAPperTErefSeq_'
+        self._configFileName = "%sConfig.cfg" % self._testPrefix
+        self._iDb = DbMySql()
+
+        self.inPathTableName = "%sDmelChr4_chr_allTEs_nr_noSSR_join_path" % (self._testPrefix)
+        self.inPathFileName = "%s/Tools/DmelChr4_chr_allTEs_nr_noSSR_join_path.path" % os.environ["REPET_DATA"]
+        self._iDb.createTable(self.inPathTableName, "path", self.inPathFileName, True)
+        
+        self.RefTETableName = "%sDmelChr4_refTEs" % (self._testPrefix)
+        self.RefTEFileName = "%s/Tools/DmelChr4_refTEs.fa" % os.environ["REPET_DATA"]
+        self._iDb.createTable(self.RefTETableName, "seq", self.RefTEFileName, True)
+        
+        self.genomeTableName = "%sDmelChr4_chr" % (self._testPrefix)
+        self.genomeFileName = "%s/Tools/DmelChr4.fa" % os.environ["REPET_DATA"]
+        self._iDb.createTable(self.genomeTableName, "seq", self.genomeFileName, True)
+
+        try:
+            os.makedirs(self._testPrefix)
+        except:pass
+        os.chdir(self._testPrefix)
+        self._writeConfigFile()
+        
+#        self._expFileName_FullLengthCopy = "%s/Tools/GiveInfoTeAnnotFile_ConsensusWithFullLengthCopy.txt" % os.environ["REPET_DATA"]
+#        self._expFileName_Copy = "%s/Tools/GiveInfoTeAnnotFile_ConsensusWithCopy.txt" % os.environ["REPET_DATA"]
+#        self._expFileName_FullLengthFrag = "%s/Tools/GiveInfoTeAnnotFile_ConsensusWithFullLengthFrag.txt" % os.environ["REPET_DATA"]
+#        self._expFastaFileName_FullLengthCopy = "%s/Tools/GiveInfoTeAnnotFile_ConsensusWithFullLengthCopy.fa" % os.environ["REPET_DATA"]
+#        self._expFastaFileName_Copy = "%s/Tools/GiveInfoTeAnnotFile_ConsensusWithCopy.fa" % os.environ["REPET_DATA"]
+#        self._expFastaFileName_FullLengthFrag = "%s/Tools/GiveInfoTeAnnotFile_ConsensusWithFullLengthFrag.fa" % os.environ["REPET_DATA"]
+
+        
+#        inputFastaFileName = "input_TEannot_refTEs.fa"
+#        os.symlink(self._expFastaFileName_Copy, inputFastaFileName)
+        
+#        self._tableName = "Dummy_Atha_refTEs_seq"
+#        self._iDb.createTable(self._tableName, "seq", inputFastaFileName, True)
+#        os.remove(inputFastaFileName)      
+#        
+#        self._obsFileName_FullLengthCopy = "%s_FullLengthCopy.txt" % os.path.splitext(os.path.basename(self._inFileName))[0]
+#        self._obsFileName_Copy = "%s_OneCopyAndMore.txt" % os.path.splitext(os.path.basename(self._inFileName))[0]
+#        self._obsFileName_FullLengthFrag = "%s_FullLengthFrag.txt" % os.path.splitext(os.path.basename(self._inFileName))[0]
+#        self._obsFastaFileName_FullLengthCopy = "%s.fa" % os.path.splitext(self._obsFileName_FullLengthCopy)[0]
+#        self._obsFastaFileName_Copy = "%s.fa" % os.path.splitext(self._obsFileName_Copy)[0]
+#        self._obsFastaFileName_FullLengthFrag = "%s.fa" % os.path.splitext(self._obsFileName_FullLengthFrag)[0]
+        
+    def tearDown(self):
+#        self._iDb.dropTable(self.inPathTableName)
+#        self._iDb.dropTable(self.RefTETableName)
+#        self._iDb.dropTable(self.genomeTableName)
+#        self._iDb.close()
+        
+        os.chdir("..")
+#        try:
+#            rmtree(self._testPrefix)
+#        except:pass
+        
+
+#    def test_run_step1(self):
+#        iGMAAPperTErefSeq = GetMultAlignAndPhylogenyPerTErefSeq(pathTableName= self.inPathTableName, refSeqTableName=self.RefTETableName, genomeSeqTableName= self.genomeTableName, configFileName=self._configFileName, step=1, verbosity=self._verbosity)
+#        iGMAAPperTErefSeq.run()
+#        
+#        copiesFiles = glob("*_copies.fa")
+#        self.assertTrue(len(copiesFiles) > 0)
+#        self.assertTrue(os.stat("DmelChr4-B-R9-Map3_NoCat_copies.fa")[6] != 0)#check if file is empty
+#    
+#    def test_run_step1Step2Map(self):
+#        iGMAAPperTErefSeq = GetMultAlignAndPhylogenyPerTErefSeq(pathTableName= self.inPathTableName, refSeqTableName=self.RefTETableName, genomeSeqTableName= self.genomeTableName, mSAmethod="Map", configFileName=self._configFileName, step=1, verbosity=self._verbosity)
+#        iGMAAPperTErefSeq.run()
+#        iGMAAPperTErefSeq.step = 2
+#        iGMAAPperTErefSeq.run()
+#
+#        self.assertTrue(os.stat("DmelChr4-B-G9-Map3_NoCat_all.fa.oriented_map.fa_aln")[6] != 0)
+#
+#    def test_run_step1Step2RefAlign(self):
+#        iGMAAPperTErefSeq = GetMultAlignAndPhylogenyPerTErefSeq(pathTableName= self.inPathTableName, refSeqTableName=self.RefTETableName, genomeSeqTableName= self.genomeTableName, mSAmethod="RefAlign", configFileName=self._configFileName, step=1, verbosity=self._verbosity)
+#        iGMAAPperTErefSeq.run()
+#        iGMAAPperTErefSeq.step = 2
+#        iGMAAPperTErefSeq.run()
+#
+#        self.assertTrue(os.stat("DmelChr4-B-G9-Map3_NoCat_all.fa.oriented_refalign.fa_aln")[6] != 0)
+
+    def test_run_step1Step2Step3Map(self):
+        iGMAAPperTErefSeq = GetMultAlignAndPhylogenyPerTErefSeq(pathTableName= self.inPathTableName, refSeqTableName=self.RefTETableName, genomeSeqTableName= self.genomeTableName, mSAmethod="Map", configFileName=self._configFileName, step=1, verbosity=self._verbosity)
+        iGMAAPperTErefSeq.run()
+        iGMAAPperTErefSeq.step = 2
+        iGMAAPperTErefSeq.run()
+        iGMAAPperTErefSeq.step = 3
+        iGMAAPperTErefSeq.run()
+
+        self.assertTrue(os.stat("DmelChr4-B-G9-Map3_NoCat_all.fa.oriented_map.fa_aln")[6] != 0)
+    
+    def _writeConfigFile(self):
+        f = open(self._configFileName, "w")
+        f.write("[repet_env]\n")
+        f.write("repet_host: %s\n" % os.environ["REPET_HOST"])
+        f.write("repet_user: %s\n" % os.environ["REPET_USER"])
+        f.write("repet_pw: %s\n" % os.environ["REPET_PW"])
+        f.write("repet_db: %s\n" % os.environ["REPET_DB"])
+        f.write("repet_port: %s\n" % os.environ["REPET_PORT"])
+        f.write("repet_job_manager: SGE\n")
+        f.close()
+    
+                    
+#    def test_run_as_script_step1Step2Map(self):
+#        #cmd= "GetMultAlignAndPhylogenyPerTErefSeq.py -S 1 -m 'Map' -p %s -s %s -g %s -C %s" % (self._inPathTableName,self._RefTETableName, self._genomeTableName, self._configFileName)
+#        cmd= "GetMultAlignAndPhylogenyPerTErefSeq.py -S 1 -p %s -s %s -g %s -C %s" % (self.inPathTableName,self.RefTETableName, self.genomeTableName, self._configFileName)
+#        subprocess.call(cmd, shell = True)
+#        
+#        cmd= "GetMultAlignAndPhylogenyPerTErefSeq.py -S 2 -p %s -s %s -g %s -C %s" % (self.inPathTableName,self.RefTETableName, self.genomeTableName, self._configFileName)
+#        subprocess.call(cmd, shell = True)
+#        
+#        self.assertTrue(os.stat("DmelChr4-B-G9-Map3_NoCat_all.fa.oriented_map.fa_aln")[6] != 0)
+        
+        
+#        self.assertTrue(FileUtils.are2FilesIdentical(self._expFileName_FullLengthCopy, self._obsFileName_FullLengthCopy))
+#        self.assertTrue(FileUtils.are2FilesIdentical(self._expFileName_Copy, self._obsFileName_Copy))
+#        self.assertTrue(FileUtils.are2FilesIdentical(self._expFileName_FullLengthFrag, self._obsFileName_FullLengthFrag))
+#        self.assertTrue(FileUtils.are2FilesIdentical(self._expFastaFileName_FullLengthCopy, self._obsFastaFileName_FullLengthCopy))
+#        self.assertTrue(FileUtils.are2FilesIdentical(self._expFastaFileName_Copy, self._obsFastaFileName_Copy))
+#        self.assertTrue(FileUtils.are2FilesIdentical(self._expFastaFileName_FullLengthFrag, self._obsFastaFileName_FullLengthFrag))
+
+#    def test_run_as_script_step2(self):
+#        cmd= "GetMultAlignAndPhylogenyPerTErefSeq.py -S 1 -p %s -s %s -g %s -C %s" % (self._inPathTableName,self._RefTETableName, self._genomeTableName, self._configFileName)
+#        print cmd
+#        subprocess.call(cmd, shell = True)
+#        self.assertTrue(FileUtils.are2FilesIdentical(self._expFileName_FullLengthCopy, self._obsFileName_FullLengthCopy))
+#        self.assertTrue(FileUtils.are2FilesIdentical(self._expFileName_Copy, self._obsFileName_Copy))
+#        self.assertTrue(FileUtils.are2FilesIdentical(self._expFileName_FullLengthFrag, self._obsFileName_FullLengthFrag))
+#        self.assertTrue(FileUtils.are2FilesIdentical(self._expFastaFileName_FullLengthCopy, self._obsFastaFileName_FullLengthCopy))
+#        self.assertTrue(FileUtils.are2FilesIdentical(self._expFastaFileName_Copy, self._obsFastaFileName_Copy))
+#        self.assertTrue(FileUtils.are2FilesIdentical(self._expFastaFileName_FullLengthFrag, self._obsFastaFileName_FullLengthFrag))
+    
+if __name__ == "__main__":
+    unittest.main()