comparison commons/tools/tests/Test_F_LaunchMatcherInParallel.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 from commons.core.utils.FileUtils import FileUtils
2 import shutil
3 import unittest
4 import os
5 from commons.tools.LaunchMatcherInParallel import LaunchMatcherInParallel
6
7 class Test_F_LaunchMatcherInParallel(unittest.TestCase):
8
9 CLUSTER_HOST = "compute-2-46.local"
10
11 def setUp(self):
12 self._configFileName = "TE.cfg"
13 self._writeConfig()
14
15 def tearDown(self):
16 FileUtils.removeFilesByPattern("DmelChr4*")
17 os.remove(self._configFileName)
18
19 def test_run_as_class_1_seq(self):
20 inFileName = "DmelChr4.align"
21 fastaFileName = "DmelChr4.fa"
22 inFilePath = "%s/Tools/%s" % (os.environ["REPET_DATA"], inFileName)
23 inFastaPath = "%s/Tools/%s" % (os.environ["REPET_DATA"], fastaFileName)
24 os.symlink(inFilePath, inFileName)
25 os.symlink(inFastaPath, fastaFileName)
26 expPathFileName = "%s/Tools/DmelChr4.align.match.path" % os.environ["REPET_DATA"]
27 expTabFileName = "%s/Tools/DmelChr4.align.match.tab" % os.environ["REPET_DATA"]
28
29 obsPathFileName = "%s.match.path" % inFileName
30 obsTabFileName = "%s.match.tab" % inFileName
31
32 iLaunchMatcherInParallel = LaunchMatcherInParallel(align=inFileName, queryFileName=fastaFileName, subjectFileName=fastaFileName, doJoin=True, evalue="1e-20", keepConflict=True, config=self._configFileName)
33 iLaunchMatcherInParallel.run()
34
35 self.assertTrue(FileUtils.are2FilesIdentical(expPathFileName, obsPathFileName))
36 self.assertTrue(FileUtils.are2FilesIdentical(expTabFileName, obsTabFileName))
37
38 def test_run_as_class_n_seq_less_jobs_than_n(self):
39 inFileName = "DmelChr4_dummy.align"
40 fastaFileName = "DmelChr4.fa"
41 inFilePath = "%s/Tools/%s" % (os.environ["REPET_DATA"], inFileName)
42 inFastaPath = "%s/Tools/%s" % (os.environ["REPET_DATA"], fastaFileName)
43 os.symlink(inFilePath, inFileName)
44 os.symlink(inFastaPath, fastaFileName)
45 expPathFileName = "%s/Tools/DmelChr4_dummy.align.match.path" % os.environ["REPET_DATA"]
46 expTabFileName = "%s/Tools/DmelChr4_dummy.align.match.tab" % os.environ["REPET_DATA"]
47
48 obsPathFileName = "%s.match.path" % inFileName
49 obsTabFileName = "%s.match.tab" % inFileName
50
51 iLaunchMatcherInParallel = LaunchMatcherInParallel(align=inFileName, queryFileName=fastaFileName, subjectFileName=fastaFileName, doJoin=True, evalue="1e-20", keepConflict=True, config=self._configFileName, doClean=True)
52 iLaunchMatcherInParallel.run()
53
54 self.assertTrue(FileUtils.are2FilesIdentical(expPathFileName, obsPathFileName))
55 self.assertTrue(FileUtils.are2FilesIdentical(expTabFileName, obsTabFileName))
56
57 def test_run_as_class_n_seq_less_jobs_than_n_not_merged_results(self):
58 inFileName = "DmelChr4_dummy.align"
59 fastaFileName = "DmelChr4.fa"
60 inFilePath = "%s/Tools/%s" % (os.environ["REPET_DATA"], inFileName)
61 inFastaPath = "%s/Tools/%s" % (os.environ["REPET_DATA"], fastaFileName)
62 os.symlink(inFilePath, inFileName)
63 os.symlink(inFastaPath, fastaFileName)
64
65 iLaunchMatcherInParallel = LaunchMatcherInParallel(align=inFileName, queryFileName=fastaFileName, subjectFileName=fastaFileName, doJoin=True, evalue="1e-20", keepConflict=True, config=self._configFileName, maxFileSize=100, mergeResults=False)
66 iLaunchMatcherInParallel.run()
67
68 baseFileName = os.path.splitext(inFileName)[0]
69 lExpMatchFileNames = ["%s_1.align.match.path" % baseFileName, "%s_2.align.match.path" % baseFileName, "%s_3.align.match.path" % baseFileName]
70 lExpTabFileNames = ["%s_1.align.match.tab" % baseFileName, "%s_2.align.match.tab" % baseFileName, "%s_3.align.match.tab" % baseFileName]
71 for i in range(0,3):
72 self.assertTrue(FileUtils.isRessourceExists("tmpMatcher/%s" % lExpMatchFileNames[i]))
73 self.assertTrue(FileUtils.isRessourceExists("tmpMatcher/%s" % lExpTabFileNames[i]))
74 shutil.rmtree("tmpMatcher")
75
76 def _writeConfig(self):
77 with open(self._configFileName, "w") as fh:
78 fh.write("[jobs]\n")
79 if os.getenv("HOSTNAME") == self.CLUSTER_HOST:
80 fh.write("resources: test\n")
81 else:
82 fh.write("resources:\n")
83 fh.write("tmpDir:\n")
84 fh.write("copy: no\n")
85 fh.write("clean: yes\n")
86
87 if __name__ == "__main__":
88 unittest.main()