Mercurial > repos > yufei-luo > s_mart
comparison commons/tools/tests/Test_F_GetMultiAlignAndPhylogenyPerTErefSeq.py @ 18:94ab73e8a190
Uploaded
author | m-zytnicki |
---|---|
date | Mon, 29 Apr 2013 03:20:15 -0400 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
17:b0e8584489e6 | 18:94ab73e8a190 |
---|---|
1 import subprocess | |
2 import unittest | |
3 import os | |
4 from commons.core.utils.FileUtils import FileUtils | |
5 from commons.core.sql.DbMySql import DbMySql | |
6 from commons.tools.GetMultAlignAndPhylogenyPerTErefSeq import GetMultAlignAndPhylogenyPerTErefSeq | |
7 from shutil import rmtree | |
8 from glob import glob | |
9 | |
10 class Test_F_GetMultAlignAndPhylogenyPerTErefSeq(unittest.TestCase): | |
11 | |
12 def setUp(self): | |
13 self._verbosity = 3 | |
14 | |
15 self._testPrefix = 'Test_GMAAPperTErefSeq_' | |
16 self._configFileName = "%sConfig.cfg" % self._testPrefix | |
17 self._iDb = DbMySql() | |
18 | |
19 self.inPathTableName = "%sDmelChr4_chr_allTEs_nr_noSSR_join_path" % (self._testPrefix) | |
20 self.inPathFileName = "%s/Tools/DmelChr4_chr_allTEs_nr_noSSR_join_path.path" % os.environ["REPET_DATA"] | |
21 self._iDb.createTable(self.inPathTableName, "path", self.inPathFileName, True) | |
22 | |
23 self.RefTETableName = "%sDmelChr4_refTEs" % (self._testPrefix) | |
24 self.RefTEFileName = "%s/Tools/DmelChr4_refTEs.fa" % os.environ["REPET_DATA"] | |
25 self._iDb.createTable(self.RefTETableName, "seq", self.RefTEFileName, True) | |
26 | |
27 self.genomeTableName = "%sDmelChr4_chr" % (self._testPrefix) | |
28 self.genomeFileName = "%s/Tools/DmelChr4.fa" % os.environ["REPET_DATA"] | |
29 self._iDb.createTable(self.genomeTableName, "seq", self.genomeFileName, True) | |
30 | |
31 try: | |
32 os.makedirs(self._testPrefix) | |
33 except:pass | |
34 os.chdir(self._testPrefix) | |
35 self._writeConfigFile() | |
36 | |
37 # self._expFileName_FullLengthCopy = "%s/Tools/GiveInfoTeAnnotFile_ConsensusWithFullLengthCopy.txt" % os.environ["REPET_DATA"] | |
38 # self._expFileName_Copy = "%s/Tools/GiveInfoTeAnnotFile_ConsensusWithCopy.txt" % os.environ["REPET_DATA"] | |
39 # self._expFileName_FullLengthFrag = "%s/Tools/GiveInfoTeAnnotFile_ConsensusWithFullLengthFrag.txt" % os.environ["REPET_DATA"] | |
40 # self._expFastaFileName_FullLengthCopy = "%s/Tools/GiveInfoTeAnnotFile_ConsensusWithFullLengthCopy.fa" % os.environ["REPET_DATA"] | |
41 # self._expFastaFileName_Copy = "%s/Tools/GiveInfoTeAnnotFile_ConsensusWithCopy.fa" % os.environ["REPET_DATA"] | |
42 # self._expFastaFileName_FullLengthFrag = "%s/Tools/GiveInfoTeAnnotFile_ConsensusWithFullLengthFrag.fa" % os.environ["REPET_DATA"] | |
43 | |
44 | |
45 # inputFastaFileName = "input_TEannot_refTEs.fa" | |
46 # os.symlink(self._expFastaFileName_Copy, inputFastaFileName) | |
47 | |
48 # self._tableName = "Dummy_Atha_refTEs_seq" | |
49 # self._iDb.createTable(self._tableName, "seq", inputFastaFileName, True) | |
50 # os.remove(inputFastaFileName) | |
51 # | |
52 # self._obsFileName_FullLengthCopy = "%s_FullLengthCopy.txt" % os.path.splitext(os.path.basename(self._inFileName))[0] | |
53 # self._obsFileName_Copy = "%s_OneCopyAndMore.txt" % os.path.splitext(os.path.basename(self._inFileName))[0] | |
54 # self._obsFileName_FullLengthFrag = "%s_FullLengthFrag.txt" % os.path.splitext(os.path.basename(self._inFileName))[0] | |
55 # self._obsFastaFileName_FullLengthCopy = "%s.fa" % os.path.splitext(self._obsFileName_FullLengthCopy)[0] | |
56 # self._obsFastaFileName_Copy = "%s.fa" % os.path.splitext(self._obsFileName_Copy)[0] | |
57 # self._obsFastaFileName_FullLengthFrag = "%s.fa" % os.path.splitext(self._obsFileName_FullLengthFrag)[0] | |
58 | |
59 def tearDown(self): | |
60 # self._iDb.dropTable(self.inPathTableName) | |
61 # self._iDb.dropTable(self.RefTETableName) | |
62 # self._iDb.dropTable(self.genomeTableName) | |
63 # self._iDb.close() | |
64 | |
65 os.chdir("..") | |
66 # try: | |
67 # rmtree(self._testPrefix) | |
68 # except:pass | |
69 | |
70 | |
71 # def test_run_step1(self): | |
72 # iGMAAPperTErefSeq = GetMultAlignAndPhylogenyPerTErefSeq(pathTableName= self.inPathTableName, refSeqTableName=self.RefTETableName, genomeSeqTableName= self.genomeTableName, configFileName=self._configFileName, step=1, verbosity=self._verbosity) | |
73 # iGMAAPperTErefSeq.run() | |
74 # | |
75 # copiesFiles = glob("*_copies.fa") | |
76 # self.assertTrue(len(copiesFiles) > 0) | |
77 # self.assertTrue(os.stat("DmelChr4-B-R9-Map3_NoCat_copies.fa")[6] != 0)#check if file is empty | |
78 # | |
79 # def test_run_step1Step2Map(self): | |
80 # iGMAAPperTErefSeq = GetMultAlignAndPhylogenyPerTErefSeq(pathTableName= self.inPathTableName, refSeqTableName=self.RefTETableName, genomeSeqTableName= self.genomeTableName, mSAmethod="Map", configFileName=self._configFileName, step=1, verbosity=self._verbosity) | |
81 # iGMAAPperTErefSeq.run() | |
82 # iGMAAPperTErefSeq.step = 2 | |
83 # iGMAAPperTErefSeq.run() | |
84 # | |
85 # self.assertTrue(os.stat("DmelChr4-B-G9-Map3_NoCat_all.fa.oriented_map.fa_aln")[6] != 0) | |
86 # | |
87 # def test_run_step1Step2RefAlign(self): | |
88 # iGMAAPperTErefSeq = GetMultAlignAndPhylogenyPerTErefSeq(pathTableName= self.inPathTableName, refSeqTableName=self.RefTETableName, genomeSeqTableName= self.genomeTableName, mSAmethod="RefAlign", configFileName=self._configFileName, step=1, verbosity=self._verbosity) | |
89 # iGMAAPperTErefSeq.run() | |
90 # iGMAAPperTErefSeq.step = 2 | |
91 # iGMAAPperTErefSeq.run() | |
92 # | |
93 # self.assertTrue(os.stat("DmelChr4-B-G9-Map3_NoCat_all.fa.oriented_refalign.fa_aln")[6] != 0) | |
94 | |
95 def test_run_step1Step2Step3Map(self): | |
96 iGMAAPperTErefSeq = GetMultAlignAndPhylogenyPerTErefSeq(pathTableName= self.inPathTableName, refSeqTableName=self.RefTETableName, genomeSeqTableName= self.genomeTableName, mSAmethod="Map", configFileName=self._configFileName, step=1, verbosity=self._verbosity) | |
97 iGMAAPperTErefSeq.run() | |
98 iGMAAPperTErefSeq.step = 2 | |
99 iGMAAPperTErefSeq.run() | |
100 iGMAAPperTErefSeq.step = 3 | |
101 iGMAAPperTErefSeq.run() | |
102 | |
103 self.assertTrue(os.stat("DmelChr4-B-G9-Map3_NoCat_all.fa.oriented_map.fa_aln")[6] != 0) | |
104 | |
105 def _writeConfigFile(self): | |
106 f = open(self._configFileName, "w") | |
107 f.write("[repet_env]\n") | |
108 f.write("repet_host: %s\n" % os.environ["REPET_HOST"]) | |
109 f.write("repet_user: %s\n" % os.environ["REPET_USER"]) | |
110 f.write("repet_pw: %s\n" % os.environ["REPET_PW"]) | |
111 f.write("repet_db: %s\n" % os.environ["REPET_DB"]) | |
112 f.write("repet_port: %s\n" % os.environ["REPET_PORT"]) | |
113 f.write("repet_job_manager: SGE\n") | |
114 f.close() | |
115 | |
116 | |
117 # def test_run_as_script_step1Step2Map(self): | |
118 # #cmd= "GetMultAlignAndPhylogenyPerTErefSeq.py -S 1 -m 'Map' -p %s -s %s -g %s -C %s" % (self._inPathTableName,self._RefTETableName, self._genomeTableName, self._configFileName) | |
119 # cmd= "GetMultAlignAndPhylogenyPerTErefSeq.py -S 1 -p %s -s %s -g %s -C %s" % (self.inPathTableName,self.RefTETableName, self.genomeTableName, self._configFileName) | |
120 # subprocess.call(cmd, shell = True) | |
121 # | |
122 # cmd= "GetMultAlignAndPhylogenyPerTErefSeq.py -S 2 -p %s -s %s -g %s -C %s" % (self.inPathTableName,self.RefTETableName, self.genomeTableName, self._configFileName) | |
123 # subprocess.call(cmd, shell = True) | |
124 # | |
125 # self.assertTrue(os.stat("DmelChr4-B-G9-Map3_NoCat_all.fa.oriented_map.fa_aln")[6] != 0) | |
126 | |
127 | |
128 # self.assertTrue(FileUtils.are2FilesIdentical(self._expFileName_FullLengthCopy, self._obsFileName_FullLengthCopy)) | |
129 # self.assertTrue(FileUtils.are2FilesIdentical(self._expFileName_Copy, self._obsFileName_Copy)) | |
130 # self.assertTrue(FileUtils.are2FilesIdentical(self._expFileName_FullLengthFrag, self._obsFileName_FullLengthFrag)) | |
131 # self.assertTrue(FileUtils.are2FilesIdentical(self._expFastaFileName_FullLengthCopy, self._obsFastaFileName_FullLengthCopy)) | |
132 # self.assertTrue(FileUtils.are2FilesIdentical(self._expFastaFileName_Copy, self._obsFastaFileName_Copy)) | |
133 # self.assertTrue(FileUtils.are2FilesIdentical(self._expFastaFileName_FullLengthFrag, self._obsFastaFileName_FullLengthFrag)) | |
134 | |
135 # def test_run_as_script_step2(self): | |
136 # cmd= "GetMultAlignAndPhylogenyPerTErefSeq.py -S 1 -p %s -s %s -g %s -C %s" % (self._inPathTableName,self._RefTETableName, self._genomeTableName, self._configFileName) | |
137 # print cmd | |
138 # subprocess.call(cmd, shell = True) | |
139 # self.assertTrue(FileUtils.are2FilesIdentical(self._expFileName_FullLengthCopy, self._obsFileName_FullLengthCopy)) | |
140 # self.assertTrue(FileUtils.are2FilesIdentical(self._expFileName_Copy, self._obsFileName_Copy)) | |
141 # self.assertTrue(FileUtils.are2FilesIdentical(self._expFileName_FullLengthFrag, self._obsFileName_FullLengthFrag)) | |
142 # self.assertTrue(FileUtils.are2FilesIdentical(self._expFastaFileName_FullLengthCopy, self._obsFastaFileName_FullLengthCopy)) | |
143 # self.assertTrue(FileUtils.are2FilesIdentical(self._expFastaFileName_Copy, self._obsFastaFileName_Copy)) | |
144 # self.assertTrue(FileUtils.are2FilesIdentical(self._expFastaFileName_FullLengthFrag, self._obsFastaFileName_FullLengthFrag)) | |
145 | |
146 if __name__ == "__main__": | |
147 unittest.main() |