18
|
1 import unittest
|
|
2 import os, os.path
|
|
3 from optparse import OptionParser
|
|
4 from SMART.Java.Python.misc import Utils
|
|
5 from SMART.Java.Python.clusterize import Clusterize
|
|
6 #TODO: test for n option when option corrected
|
|
7
|
|
8 SMART_PATH = os.environ["REPET_PATH"] + "/SMART"
|
|
9
|
|
10 class Test_F_Clusterize(unittest.TestCase):
|
|
11
|
|
12 def setUp(self):
|
|
13 self._inputFileName = "inputFileTest.bed"
|
|
14 self._expOutputFileName = "expOutput.gff3"
|
|
15 self._outputFileName = "output.gff3"
|
|
16 self._writeInputFile()
|
|
17
|
|
18 def tearDown(self):
|
|
19 for file in (self._inputFileName, self._expOutputFileName, self._outputFileName):
|
|
20 if os.path.exists(file):
|
|
21 os.remove(file)
|
|
22
|
|
23 def test_run_2DifferentStrand(self):
|
|
24 self._writeOutputFile_2DiffStrand(self._expOutputFileName)
|
|
25
|
|
26 args = ["-i", self._inputFileName, "-f", "bed", "-o", self._outputFileName, "-v", "0"]
|
|
27 parser = OptionParser()
|
|
28 parser.add_option("-i", "--input", dest="inputFileName", action="store", type="string", help="input file [compulsory] [format: file in transcript format given by -f]")
|
|
29 parser.add_option("-f", "--format", dest="format", action="store", type="string", help="format of file [format: transcript file format]")
|
|
30 parser.add_option("-o", "--output", dest="outputFileName", action="store", type="string", help="output file [compulsory] [format: output file in GFF3 format]")
|
|
31 parser.add_option("-c", "--colinear", dest="colinear", action="store_true", default=False, help="merge colinear transcripts only [format: bool] [default: false]")
|
|
32 parser.add_option("-d", "--distance", dest="distance", action="store", default=0, type="int", help="max. distance between two transcripts to be merged [format: int] [default: 0]")
|
|
33 parser.add_option("-n", "--normalize", dest="normalize", action="store_true", default=False, help="normalize the number of reads per cluster by the number of mappings per read [format: bool] [default: false]")
|
|
34 parser.add_option("-v", "--verbosity", dest="verbosity", action="store", default=1, type="int", help="trace level [format: int] [default: 1]")
|
|
35 (options, args) = parser.parse_args(args)
|
|
36 iClusterize = Clusterize(options.verbosity)
|
|
37 iClusterize.setInputFile(options.inputFileName, options.format)
|
|
38 iClusterize.setOutputFileName(options.outputFileName)
|
|
39 iClusterize.setColinear(options.colinear)
|
|
40 iClusterize.setDistance(options.distance)
|
|
41 iClusterize.setNormalize(options.normalize)
|
|
42 iClusterize.run()
|
|
43 self.assertTrue(Utils.diff(self._expOutputFileName, self._outputFileName))
|
|
44
|
|
45 def test_runAsScript_2DifferentStrand(self):
|
|
46 self._writeOutputFile_2DiffStrand(self._expOutputFileName)
|
|
47 os.system("python %s/Java/Python/clusterize.py -i %s -f bed -o %s -v 0" % (SMART_PATH, self._inputFileName, self._outputFileName))
|
|
48 self.assertTrue(Utils.diff(self._expOutputFileName, self._outputFileName))
|
|
49
|
|
50 def test_runAsScript_2DifferentStrand_map_output(self):
|
|
51 self._expOutputFileName = "expOutput.map"
|
|
52 self._outputFileName = "output.map"
|
|
53 self._writeOutputFile_2DiffStrandMapFormat(self._expOutputFileName)
|
|
54 os.system("python %s/Java/Python/clusterize.py -i %s -f bed -o %s -u map -v 0" % (SMART_PATH, self._inputFileName, self._outputFileName))
|
|
55 self.assertTrue(Utils.diff(self._expOutputFileName, self._outputFileName))
|
|
56
|
|
57 def test_runAsScript_2SameStrand(self):
|
|
58 self._writeOutputFile_2SameStrand(self._expOutputFileName)
|
|
59 os.system("python %s/Java/Python/clusterize.py -i %s -f bed -o %s -c -v 0" % (SMART_PATH, self._inputFileName, self._outputFileName))
|
|
60 self.assertTrue(Utils.diff(self._expOutputFileName, self._outputFileName))
|
|
61
|
|
62 def test_runAsScript_distance(self):
|
|
63 self._writeOutputFile_distance(self._expOutputFileName)
|
|
64 os.system("python %s/Java/Python/clusterize.py -i %s -f bed -o %s -d 40 -v 0" % (SMART_PATH, self._inputFileName, self._outputFileName))
|
|
65 self.assertTrue(Utils.diff(self._expOutputFileName, self._outputFileName))
|
|
66
|
|
67 def _writeInputFile(self):
|
|
68 f = open(self._inputFileName, "w")
|
|
69 f.write("arm_X\t10000100\t10000200\ttest1.1\t100\t+\t10000100\t10000200\t0\t1\t100,\t0,\n")
|
|
70 f.write("arm_X\t10000100\t10000200\ttest1.2\t100\t-\t10000100\t10000200\t0\t1\t100,\t0,\n")
|
|
71 f.write("arm_2R\t10000100\t10000200\ttest1.3\t100\t+\t10000100\t10000200\t0\t1\t100,\t0,\n")
|
|
72 f.write("arm_X\t10000000\t10000100\ttest1.4\t100\t+\t10000000\t10000100\t0\t1\t100,\t0,\n")
|
|
73 f.write("arm_X\t10000200\t10000300\ttest1.5\t100\t+\t10000200\t10000300\t0\t1\t100,\t0,\n")
|
|
74 f.write("arm_X\t9999900\t9999950\ttest1.6\t100\t+\t9999900\t9999950\t0\t1\t50,\t0,\n")
|
|
75 f.write("arm_X\t10000000\t10000050\ttest1.7\t100\t-\t10000000\t10000050\t0\t1\t50,\t0,\n")
|
|
76 f.close()
|
|
77
|
|
78 def _writeOutputFile_2DiffStrand(self, outputFileName):
|
|
79 f = open(outputFileName, "w")
|
|
80 f.write("arm_2R\tS-MART\ttranscript\t10000100\t10000199\t.\t+\t.\tID=test1.3;Name=test1.3\n")
|
|
81 f.write("arm_X\tS-MART\ttranscript\t9999900\t9999949\t.\t+\t.\tID=test1.6;Name=test1.6\n")
|
|
82 f.write("arm_X\tS-MART\ttranscript\t10000000\t10000099\t.\t-\t.\tnbElements=2.000000;ID=test1.7--test1.4;Name=test1.7--test1.4\n")
|
|
83 f.write("arm_X\tS-MART\ttranscript\t10000100\t10000199\t.\t-\t.\tnbElements=2.000000;ID=test1.2--test1.1;Name=test1.2--test1.1\n")
|
|
84 f.write("arm_X\tS-MART\ttranscript\t10000200\t10000299\t.\t+\t.\tID=test1.5;Name=test1.5\n")
|
|
85 f.close()
|
|
86
|
|
87 def _writeOutputFile_2SameStrand(self, outputFileName):
|
|
88 f = open(outputFileName, "w")
|
|
89 f.write("arm_2R\tS-MART\ttranscript\t10000100\t10000199\t.\t+\t.\tID=test1.3;Name=test1.3\n")
|
|
90 f.write("arm_X\tS-MART\ttranscript\t9999900\t9999949\t.\t+\t.\tID=test1.6;Name=test1.6\n")
|
|
91 f.write("arm_X\tS-MART\ttranscript\t10000000\t10000099\t.\t+\t.\tID=test1.4;Name=test1.4\n")
|
|
92 f.write("arm_X\tS-MART\ttranscript\t10000000\t10000049\t.\t-\t.\tID=test1.7;Name=test1.7\n")
|
|
93 f.write("arm_X\tS-MART\ttranscript\t10000100\t10000199\t.\t+\t.\tID=test1.1;Name=test1.1\n")
|
|
94 f.write("arm_X\tS-MART\ttranscript\t10000100\t10000199\t.\t-\t.\tID=test1.2;Name=test1.2\n")
|
|
95 f.write("arm_X\tS-MART\ttranscript\t10000200\t10000299\t.\t+\t.\tID=test1.5;Name=test1.5\n")
|
|
96 f.close()
|
|
97
|
|
98 def _writeOutputFile_distance(self, outputFileName):
|
|
99 f = open(outputFileName, "w")
|
|
100 f.write("arm_2R\tS-MART\ttranscript\t10000100\t10000199\t.\t+\t.\tID=test1.3;Name=test1.3\n")
|
|
101 f.write("arm_X\tS-MART\ttranscript\t9999900\t9999949\t.\t+\t.\tID=test1.6;Name=test1.6\n")
|
|
102 f.write("arm_X\tS-MART\ttranscript\t10000000\t10000299\t.\t+\t.\tnbElements=5.000000;ID=test1.5--test1.2--test1.1--test1.7--test1.4;Name=test1.5--test1.2--test1.1--test1.7--test1.4\n")
|
|
103 f.write("arm_X\tS-MART\texon\t10000000\t10000099\t.\t+\t.\tID=test1.5--test1.2--test1.1--test1.7--test1.4-exon1;Name=test1.5--test1.2--test1.1--test1.7--test1.4-exon1;Parent=test1.5--test1.2--test1.1--test1.7--test1.4\n")
|
|
104 f.write("arm_X\tS-MART\texon\t10000100\t10000199\t.\t+\t.\tID=test1.5--test1.2--test1.1--test1.7--test1.4-exon2;Name=test1.5--test1.2--test1.1--test1.7--test1.4-exon2;Parent=test1.5--test1.2--test1.1--test1.7--test1.4\n")
|
|
105 f.write("arm_X\tS-MART\texon\t10000200\t10000299\t.\t+\t.\tID=test1.5--test1.2--test1.1--test1.7--test1.4-exon3;Name=test1.5--test1.2--test1.1--test1.7--test1.4-exon3;Parent=test1.5--test1.2--test1.1--test1.7--test1.4\n")
|
|
106 f.close()
|
|
107
|
|
108 def _writeOutputFile_2DiffStrandMapFormat(self, outputFileName):
|
|
109 f = open(outputFileName, "w")
|
|
110 f.write("test1.3\tarm_2R\t10000100\t10000200\n")
|
|
111 f.write("test1.6\tarm_X\t9999900\t9999950\n")
|
|
112 f.write("test1.7--test1.4\tarm_X\t10000000\t10000100\n")
|
|
113 f.write("test1.2--test1.1\tarm_X\t10000100\t10000200\n")
|
|
114 f.write("test1.5\tarm_X\t10000200\t10000300\n")
|
|
115 f.close()
|
|
116
|
|
117
|
|
118 if __name__ == "__main__":
|
|
119 unittest.main()
|