annotate SMART/Java/Python/test/Test_F_Clusterize.py @ 22:1e3f2c2657a3

Deleted selected files
author m-zytnicki
date Mon, 29 Apr 2013 03:26:07 -0400
parents 94ab73e8a190
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
18
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
1 import unittest
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
2 import os, os.path
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
3 from optparse import OptionParser
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
4 from SMART.Java.Python.misc import Utils
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
5 from SMART.Java.Python.clusterize import Clusterize
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
6 #TODO: test for n option when option corrected
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
7
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
8 SMART_PATH = os.environ["REPET_PATH"] + "/SMART"
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
9
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
10 class Test_F_Clusterize(unittest.TestCase):
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
11
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
12 def setUp(self):
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
13 self._inputFileName = "inputFileTest.bed"
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
14 self._expOutputFileName = "expOutput.gff3"
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
15 self._outputFileName = "output.gff3"
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
16 self._writeInputFile()
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
17
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
18 def tearDown(self):
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
19 for file in (self._inputFileName, self._expOutputFileName, self._outputFileName):
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
20 if os.path.exists(file):
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
21 os.remove(file)
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
22
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
23 def test_run_2DifferentStrand(self):
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
24 self._writeOutputFile_2DiffStrand(self._expOutputFileName)
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
25
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
26 args = ["-i", self._inputFileName, "-f", "bed", "-o", self._outputFileName, "-v", "0"]
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
27 parser = OptionParser()
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
28 parser.add_option("-i", "--input", dest="inputFileName", action="store", type="string", help="input file [compulsory] [format: file in transcript format given by -f]")
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
29 parser.add_option("-f", "--format", dest="format", action="store", type="string", help="format of file [format: transcript file format]")
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
30 parser.add_option("-o", "--output", dest="outputFileName", action="store", type="string", help="output file [compulsory] [format: output file in GFF3 format]")
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
31 parser.add_option("-c", "--colinear", dest="colinear", action="store_true", default=False, help="merge colinear transcripts only [format: bool] [default: false]")
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
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]")
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
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]")
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
34 parser.add_option("-v", "--verbosity", dest="verbosity", action="store", default=1, type="int", help="trace level [format: int] [default: 1]")
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
35 (options, args) = parser.parse_args(args)
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
36 iClusterize = Clusterize(options.verbosity)
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
37 iClusterize.setInputFile(options.inputFileName, options.format)
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
38 iClusterize.setOutputFileName(options.outputFileName)
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
39 iClusterize.setColinear(options.colinear)
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
40 iClusterize.setDistance(options.distance)
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
41 iClusterize.setNormalize(options.normalize)
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
42 iClusterize.run()
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
43 self.assertTrue(Utils.diff(self._expOutputFileName, self._outputFileName))
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
44
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
45 def test_runAsScript_2DifferentStrand(self):
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
46 self._writeOutputFile_2DiffStrand(self._expOutputFileName)
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
47 os.system("python %s/Java/Python/clusterize.py -i %s -f bed -o %s -v 0" % (SMART_PATH, self._inputFileName, self._outputFileName))
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
48 self.assertTrue(Utils.diff(self._expOutputFileName, self._outputFileName))
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
49
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
50 def test_runAsScript_2DifferentStrand_map_output(self):
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
51 self._expOutputFileName = "expOutput.map"
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
52 self._outputFileName = "output.map"
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
53 self._writeOutputFile_2DiffStrandMapFormat(self._expOutputFileName)
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
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))
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
55 self.assertTrue(Utils.diff(self._expOutputFileName, self._outputFileName))
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
56
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
57 def test_runAsScript_2SameStrand(self):
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
58 self._writeOutputFile_2SameStrand(self._expOutputFileName)
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
59 os.system("python %s/Java/Python/clusterize.py -i %s -f bed -o %s -c -v 0" % (SMART_PATH, self._inputFileName, self._outputFileName))
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
60 self.assertTrue(Utils.diff(self._expOutputFileName, self._outputFileName))
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
61
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
62 def test_runAsScript_distance(self):
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
63 self._writeOutputFile_distance(self._expOutputFileName)
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
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))
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
65 self.assertTrue(Utils.diff(self._expOutputFileName, self._outputFileName))
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
66
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
67 def _writeInputFile(self):
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
68 f = open(self._inputFileName, "w")
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
69 f.write("arm_X\t10000100\t10000200\ttest1.1\t100\t+\t10000100\t10000200\t0\t1\t100,\t0,\n")
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
70 f.write("arm_X\t10000100\t10000200\ttest1.2\t100\t-\t10000100\t10000200\t0\t1\t100,\t0,\n")
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
71 f.write("arm_2R\t10000100\t10000200\ttest1.3\t100\t+\t10000100\t10000200\t0\t1\t100,\t0,\n")
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
72 f.write("arm_X\t10000000\t10000100\ttest1.4\t100\t+\t10000000\t10000100\t0\t1\t100,\t0,\n")
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
73 f.write("arm_X\t10000200\t10000300\ttest1.5\t100\t+\t10000200\t10000300\t0\t1\t100,\t0,\n")
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
74 f.write("arm_X\t9999900\t9999950\ttest1.6\t100\t+\t9999900\t9999950\t0\t1\t50,\t0,\n")
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
75 f.write("arm_X\t10000000\t10000050\ttest1.7\t100\t-\t10000000\t10000050\t0\t1\t50,\t0,\n")
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
76 f.close()
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
77
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
78 def _writeOutputFile_2DiffStrand(self, outputFileName):
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
79 f = open(outputFileName, "w")
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
80 f.write("arm_2R\tS-MART\ttranscript\t10000100\t10000199\t.\t+\t.\tID=test1.3;Name=test1.3\n")
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
81 f.write("arm_X\tS-MART\ttranscript\t9999900\t9999949\t.\t+\t.\tID=test1.6;Name=test1.6\n")
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
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")
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
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")
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
84 f.write("arm_X\tS-MART\ttranscript\t10000200\t10000299\t.\t+\t.\tID=test1.5;Name=test1.5\n")
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
85 f.close()
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
86
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
87 def _writeOutputFile_2SameStrand(self, outputFileName):
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
88 f = open(outputFileName, "w")
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
89 f.write("arm_2R\tS-MART\ttranscript\t10000100\t10000199\t.\t+\t.\tID=test1.3;Name=test1.3\n")
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
90 f.write("arm_X\tS-MART\ttranscript\t9999900\t9999949\t.\t+\t.\tID=test1.6;Name=test1.6\n")
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
91 f.write("arm_X\tS-MART\ttranscript\t10000000\t10000099\t.\t+\t.\tID=test1.4;Name=test1.4\n")
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
92 f.write("arm_X\tS-MART\ttranscript\t10000000\t10000049\t.\t-\t.\tID=test1.7;Name=test1.7\n")
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
93 f.write("arm_X\tS-MART\ttranscript\t10000100\t10000199\t.\t+\t.\tID=test1.1;Name=test1.1\n")
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
94 f.write("arm_X\tS-MART\ttranscript\t10000100\t10000199\t.\t-\t.\tID=test1.2;Name=test1.2\n")
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
95 f.write("arm_X\tS-MART\ttranscript\t10000200\t10000299\t.\t+\t.\tID=test1.5;Name=test1.5\n")
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
96 f.close()
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
97
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
98 def _writeOutputFile_distance(self, outputFileName):
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
99 f = open(outputFileName, "w")
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
100 f.write("arm_2R\tS-MART\ttranscript\t10000100\t10000199\t.\t+\t.\tID=test1.3;Name=test1.3\n")
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
101 f.write("arm_X\tS-MART\ttranscript\t9999900\t9999949\t.\t+\t.\tID=test1.6;Name=test1.6\n")
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
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")
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
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")
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
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")
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
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")
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
106 f.close()
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
107
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
108 def _writeOutputFile_2DiffStrandMapFormat(self, outputFileName):
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
109 f = open(outputFileName, "w")
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
110 f.write("test1.3\tarm_2R\t10000100\t10000200\n")
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
111 f.write("test1.6\tarm_X\t9999900\t9999950\n")
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
112 f.write("test1.7--test1.4\tarm_X\t10000000\t10000100\n")
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
113 f.write("test1.2--test1.1\tarm_X\t10000100\t10000200\n")
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
114 f.write("test1.5\tarm_X\t10000200\t10000300\n")
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
115 f.close()
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
116
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
117
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
118 if __name__ == "__main__":
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
119 unittest.main()