annotate SMART/Java/Python/test/Test_F_RestrictFromCoverage.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.structure.Transcript import Transcript
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
6 from commons.core.writer.Gff3Writer import Gff3Writer
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
7 from commons.core.parsing.GffParser import GffParser
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
8 from SMART.Java.Python.RestrictFromCoverage import RestrictFromCoverage
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
9
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
10 REFERENCE = 0
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
11 QUERY = 1
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
12
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
13 class Test_F_Clusterize(unittest.TestCase):
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
14
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
15 def setUp(self):
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
16 self._queryFileName = "testQuery.gff3"
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
17 self._refFileName = "testRef.gff3"
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
18 self._outputFileName = "output.gff3"
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
19 self._parsers = {QUERY: Gff3Writer(self._queryFileName, 0), REFERENCE: Gff3Writer(self._refFileName, 0)}
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
20 self._writeQuery()
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
21
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
22 def tearDown(self):
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
23 for file in (self._queryFileName, self._refFileName, self._outputFileName):
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
24 if os.path.exists(file):
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
25 os.remove(file)
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
26
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
27 def _writeQuery(self):
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
28 self._addTranscript(QUERY, 1, 1000, 2000, "+")
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
29 self._parsers[QUERY].close()
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
30
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
31 def _writeReferences(self, values):
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
32 for value in values:
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
33 self._addTranscript(REFERENCE, value["cpt"], value["start"], value["end"], value["strand"])
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
34 self._parsers[REFERENCE].close()
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
35
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
36 def _addTranscript(self, type, cpt, start, end, strand):
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
37 t = Transcript()
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
38 t.setChromosome("chr1")
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
39 t.setName("test%d" % (cpt))
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
40 t.setStart(start)
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
41 t.setEnd(end)
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
42 t.setDirection(strand)
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
43 self._parsers[type].addTranscript(t)
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
44
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
45 def _checkTranscript(self, transcript, start, end, strand):
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
46 self.assertEquals(transcript.getStart(), start)
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
47 self.assertEquals(transcript.getEnd(), end)
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
48 self.assertEquals(transcript.getDirection(), strand)
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
49
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
50 def _startTool(self, minNucleotides = None, maxNucleotides = None, minPercent = None, maxPercent = None, minOverlap = None, maxOverlap = None, strands = False):
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
51 rfc = RestrictFromCoverage(0)
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
52 rfc.setInputFileName(self._queryFileName, "gff3", QUERY)
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
53 rfc.setInputFileName(self._refFileName, "gff3", REFERENCE)
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
54 rfc.setOutputFileName(self._outputFileName)
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
55 rfc.setNbNucleotides(minNucleotides, maxNucleotides)
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
56 rfc.setPercent(minPercent, maxPercent)
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
57 rfc.setOverlap(minOverlap, maxOverlap)
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
58 rfc.setStrands(strands)
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
59 rfc.run()
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
60 return GffParser(self._outputFileName, 0)
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
61
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
62 def test_simple(self):
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
63 self._writeReferences([{"cpt": 1, "start": 1000, "end": 2000, "strand": "+"}])
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
64 parser = self._startTool()
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
65 self.assertEquals(parser.getNbTranscripts(), 1)
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
66 for transcript in parser.getIterator():
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
67 self._checkTranscript(transcript, 1000, 2000, 1)
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
68
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
69 def test_nbOverlapsMin_pos(self):
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
70 self._writeReferences([{"cpt": 1, "start": 1000, "end": 2000, "strand": "+"}, {"cpt": 2, "start": 1000, "end": 2000, "strand": "+"}])
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
71 parser = self._startTool(1, None, None, None, 2)
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
72 self.assertEquals(parser.getNbTranscripts(), 1)
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
73 for transcript in parser.getIterator():
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
74 self._checkTranscript(transcript, 1000, 2000, 1)
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
75
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
76 def test_nbOverlapsMin_neg(self):
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
77 self._writeReferences([{"cpt": 1, "start": 1000, "end": 2000, "strand": "+"}])
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
78 parser = self._startTool(1, None, None, None, 2)
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
79 self.assertEquals(parser.getNbTranscripts(), 0)
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
80
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
81 def test_nbOverlapsMax_pos(self):
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
82 self._writeReferences([{"cpt": 1, "start": 1000, "end": 2000, "strand": "+"}])
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
83 parser = self._startTool(1, None, None, None, None, 1)
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
84 self.assertEquals(parser.getNbTranscripts(), 1)
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
85 for transcript in parser.getIterator():
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
86 self._checkTranscript(transcript, 1000, 2000, 1)
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
87
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
88 def test_nbOverlapsMax_neg(self):
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
89 self._writeReferences([{"cpt": 1, "start": 1000, "end": 2000, "strand": "+"}, {"cpt": 2, "start": 1000, "end": 2000, "strand": "+"}])
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
90 parser = self._startTool(1, None, None, None, None, 1)
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
91 self.assertEquals(parser.getNbTranscripts(), 0)
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
92
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
93 def test_nbNucleotidesMin_pos(self):
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
94 self._writeReferences([{"cpt": 1, "start": 1000, "end": 1100, "strand": "+"}])
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
95 parser = self._startTool(100, None, None, None, 1)
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
96 self.assertEquals(parser.getNbTranscripts(), 1)
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
97 for transcript in parser.getIterator():
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
98 self._checkTranscript(transcript, 1000, 2000, 1)
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
99
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
100 def test_nbNucleotidesMin_neg(self):
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
101 self._writeReferences([{"cpt": 1, "start": 1000, "end": 1100, "strand": "+"}])
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
102 parser = self._startTool(200, None, None, None, 1)
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
103 self.assertEquals(parser.getNbTranscripts(), 0)
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
104
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
105 def test_PercentMin_pos(self):
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
106 self._writeReferences([{"cpt": 1, "start": 1000, "end": 1500, "strand": "+"}])
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
107 parser = self._startTool(None, None, 50, None, 1)
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
108 self.assertEquals(parser.getNbTranscripts(), 1)
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
109 for transcript in parser.getIterator():
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
110 self._checkTranscript(transcript, 1000, 2000, 1)
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
111
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
112 def test_PercentMin_neg(self):
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
113 self._writeReferences([{"cpt": 1, "start": 1000, "end": 1500, "strand": "+"}])
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
114 parser = self._startTool(None, None, 100, None, 1)
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
115 self.assertEquals(parser.getNbTranscripts(), 0)
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
116
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
117 def test_NoStrand_neg(self):
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
118 self._writeReferences([{"cpt": 1, "start": 1000, "end": 1500, "strand": "-"}])
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
119 parser = self._startTool(1, None, None, None, 1)
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
120 self.assertEquals(parser.getNbTranscripts(), 1)
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
121
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
122 def test_strand_pos(self):
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
123 self._writeReferences([{"cpt": 1, "start": 1000, "end": 1500, "strand": "+"}])
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
124 parser = self._startTool(1, None, None, None, 1, None, True)
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
125 self.assertEquals(parser.getNbTranscripts(), 1)
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
126
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
127 def test_strand_neg(self):
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
128 self._writeReferences([{"cpt": 1, "start": 1000, "end": 1500, "strand": "-"}])
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
129 parser = self._startTool(1, None, None, None, 1, None, True)
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
130 self.assertEquals(parser.getNbTranscripts(), 0)
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
131
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
132 if __name__ == "__main__":
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
133 unittest.main()