annotate SMART/Java/Python/CompareOverlappingSmallQuery.py @ 9:1eb55963fe39

Updated CompareOverlappingSmall*.py
author m-zytnicki
date Thu, 14 Mar 2013 05:23:05 -0400
parents 769e306b7933
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
6
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
1 #! /usr/bin/env python
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
2 #
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
3 # Copyright INRA-URGI 2009-2011
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
4 #
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
5 # This software is governed by the CeCILL license under French law and
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
6 # abiding by the rules of distribution of free software. You can use,
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
7 # modify and/ or redistribute the software under the terms of the CeCILL
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
8 # license as circulated by CEA, CNRS and INRIA at the following URL
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
9 # "http://www.cecill.info".
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
10 #
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
11 # As a counterpart to the access to the source code and rights to copy,
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
12 # modify and redistribute granted by the license, users are provided only
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
13 # with a limited warranty and the software's author, the holder of the
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
14 # economic rights, and the successive licensors have only limited
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
15 # liability.
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
16 #
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
17 # In this respect, the user's attention is drawn to the risks associated
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
18 # with loading, using, modifying and/or developing or reproducing the
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
19 # software by the user in light of its specific status of free software,
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
20 # that may mean that it is complicated to manipulate, and that also
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
21 # therefore means that it is reserved for developers and experienced
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
22 # professionals having in-depth computer knowledge. Users are therefore
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
23 # encouraged to load and test the software's suitability as regards their
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
24 # requirements in conditions enabling the security of their systems and/or
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
25 # data to be ensured and, more generally, to use and operate it in the
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
26 # same conditions as regards security.
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
27 #
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
28 # The fact that you are presently reading this means that you have had
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
29 # knowledge of the CeCILL license and that you accept its terms.
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
30 #
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
31 from optparse import OptionParser
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
32 from commons.core.parsing.ParserChooser import ParserChooser
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
33 from commons.core.writer.TranscriptWriter import TranscriptWriter
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
34 from SMART.Java.Python.structure.Interval import Interval
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
35 from SMART.Java.Python.structure.Transcript import Transcript
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
36 from SMART.Java.Python.structure.Mapping import Mapping
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
37 from SMART.Java.Python.misc.Progress import Progress
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
38 from SMART.Java.Python.misc.UnlimitedProgress import UnlimitedProgress
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
39
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
40 MINBIN = 3
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
41 MAXBIN = 7
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
42 REFERENCE = 0
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
43 QUERY = 1
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
44
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
45 def getBin(start, end):
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
46 for i in range(MINBIN, MAXBIN + 1):
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
47 binLevel = 10 ** i
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
48 if int(start / binLevel) == int(end / binLevel):
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
49 return int(i * 10 ** (MAXBIN + 1) + int(start / binLevel))
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
50 return int((MAXBIN + 1) * 10 ** (MAXBIN + 1))
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
51
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
52 def getOverlappingBins(start, end):
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
53 array = []
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
54 bigBin = int((MAXBIN + 1) * 10 ** (MAXBIN + 1))
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
55 for i in range(MINBIN, MAXBIN + 1):
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
56 binLevel = 10 ** i
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
57 array.append((int(i * 10 ** (MAXBIN + 1) + int(start / binLevel)), int(i * 10 ** (MAXBIN + 1) + int(end / binLevel))))
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
58 array.append((bigBin, bigBin))
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
59 return array
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
60
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
61
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
62 class CompareOverlappingSmallQuery(object):
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
63
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
64 def __init__(self, verbosity):
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
65 self.verbosity = verbosity
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
66 self.tableNames = {}
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
67 self.nbQueries = 0
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
68 self.nbRefs = 0
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
69 self.nbWritten = 0
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
70 self.nbOverlaps = 0
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
71 self.distance = None
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
72 self.invert = False
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
73 self.antisense = False
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
74 self.collinear = False
9
1eb55963fe39 Updated CompareOverlappingSmall*.py
m-zytnicki
parents: 6
diff changeset
75 self.pcOverlapQuery = False
1eb55963fe39 Updated CompareOverlappingSmall*.py
m-zytnicki
parents: 6
diff changeset
76 self.pcOverlapRef = False
1eb55963fe39 Updated CompareOverlappingSmall*.py
m-zytnicki
parents: 6
diff changeset
77 self.minOverlap = False
1eb55963fe39 Updated CompareOverlappingSmall*.py
m-zytnicki
parents: 6
diff changeset
78 self.included = False
1eb55963fe39 Updated CompareOverlappingSmall*.py
m-zytnicki
parents: 6
diff changeset
79 self.including = False
6
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
80 self.bins = {}
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
81 self.overlaps = {}
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
82 self.notOverlapping = False
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
83
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
84 def setReferenceFile(self, fileName, format):
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
85 chooser = ParserChooser(self.verbosity)
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
86 chooser.findFormat(format)
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
87 self.refParser = chooser.getParser(fileName)
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
88
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
89 def setQueryFile(self, fileName, format):
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
90 chooser = ParserChooser(self.verbosity)
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
91 chooser.findFormat(format)
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
92 self.queryParser = chooser.getParser(fileName)
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
93
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
94 def setOutputFile(self, fileName):
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
95 self.writer = TranscriptWriter(fileName, "gff3", self.verbosity)
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
96
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
97 def setDistance(self, distance):
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
98 self.distance = distance
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
99
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
100 def setInvert(self, boolean):
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
101 self.invert = boolean
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
102
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
103 def setCollinear(self, boolean):
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
104 self.collinear = boolean
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
105
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
106 def setAntisense(self, boolean):
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
107 self.antisense = boolean
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
108
9
1eb55963fe39 Updated CompareOverlappingSmall*.py
m-zytnicki
parents: 6
diff changeset
109 def setMinPercentOverlap(self, pcOverlapQuery, pcOverlapRef):
1eb55963fe39 Updated CompareOverlappingSmall*.py
m-zytnicki
parents: 6
diff changeset
110 self.pcOverlapQuery = pcOverlapQuery
1eb55963fe39 Updated CompareOverlappingSmall*.py
m-zytnicki
parents: 6
diff changeset
111 self.pcOverlapRef = pcOverlapRef
1eb55963fe39 Updated CompareOverlappingSmall*.py
m-zytnicki
parents: 6
diff changeset
112
1eb55963fe39 Updated CompareOverlappingSmall*.py
m-zytnicki
parents: 6
diff changeset
113 def setMinOverlap(self, minOverlap):
1eb55963fe39 Updated CompareOverlappingSmall*.py
m-zytnicki
parents: 6
diff changeset
114 self.minOverlap = minOverlap
1eb55963fe39 Updated CompareOverlappingSmall*.py
m-zytnicki
parents: 6
diff changeset
115
1eb55963fe39 Updated CompareOverlappingSmall*.py
m-zytnicki
parents: 6
diff changeset
116 def setInclude(self, included, including):
1eb55963fe39 Updated CompareOverlappingSmall*.py
m-zytnicki
parents: 6
diff changeset
117 self.included = included
1eb55963fe39 Updated CompareOverlappingSmall*.py
m-zytnicki
parents: 6
diff changeset
118 self.including = including
1eb55963fe39 Updated CompareOverlappingSmall*.py
m-zytnicki
parents: 6
diff changeset
119
6
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
120 def includeNotOverlapping(self, boolean):
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
121 self.notOverlapping = boolean
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
122
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
123 def loadQuery(self):
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
124 progress = UnlimitedProgress(10000, "Reading queries", self.verbosity)
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
125 for transcript in self.queryParser.getIterator():
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
126 if transcript.__class__.__name__ == "Mapping":
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
127 transcript = transcript.getTranscript()
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
128 chromosome = transcript.getChromosome()
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
129 bin = getBin(transcript.getStart(), transcript.getEnd())
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
130 if chromosome not in self.bins:
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
131 self.bins[chromosome] = {}
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
132 if bin not in self.bins[chromosome]:
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
133 self.bins[chromosome][bin] = []
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
134 self.bins[chromosome][bin].append(transcript)
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
135 if self.notOverlapping or self.invert:
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
136 self.overlaps[transcript] = {}
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
137 self.nbQueries += 1
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
138 progress.inc()
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
139 progress.done()
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
140
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
141 def _compareTwoTranscripts(self, queryTranscript, refTranscript):
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
142 if not queryTranscript.overlapWithExon(refTranscript):
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
143 return False
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
144 if self.collinear and queryTranscript.getDirection() != refTranscript.getDirection():
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
145 return False
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
146 if self.antisense and queryTranscript.getDirection() == refTranscript.getDirection():
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
147 return False
9
1eb55963fe39 Updated CompareOverlappingSmall*.py
m-zytnicki
parents: 6
diff changeset
148 if self.included and not refTranscript.include(queryTranscript):
1eb55963fe39 Updated CompareOverlappingSmall*.py
m-zytnicki
parents: 6
diff changeset
149 return False
1eb55963fe39 Updated CompareOverlappingSmall*.py
m-zytnicki
parents: 6
diff changeset
150 if self.including and not queryTranscript.include(refTranscript):
1eb55963fe39 Updated CompareOverlappingSmall*.py
m-zytnicki
parents: 6
diff changeset
151 return False
1eb55963fe39 Updated CompareOverlappingSmall*.py
m-zytnicki
parents: 6
diff changeset
152 querySize = queryTranscript.getSize()
1eb55963fe39 Updated CompareOverlappingSmall*.py
m-zytnicki
parents: 6
diff changeset
153 if self.pcOverlapQuery and not queryTranscript.overlapWithExon(refTranscript, int(querySize * self.pcOverlapQuery / 100.0)):
1eb55963fe39 Updated CompareOverlappingSmall*.py
m-zytnicki
parents: 6
diff changeset
154 return False
1eb55963fe39 Updated CompareOverlappingSmall*.py
m-zytnicki
parents: 6
diff changeset
155 refSize = refTranscript.getSize()
1eb55963fe39 Updated CompareOverlappingSmall*.py
m-zytnicki
parents: 6
diff changeset
156 if self.pcOverlapRef and not queryTranscript.overlapWithExon(refTranscript, int(refSize * self.pcOverlapRef / 100.0)):
1eb55963fe39 Updated CompareOverlappingSmall*.py
m-zytnicki
parents: 6
diff changeset
157 return False
1eb55963fe39 Updated CompareOverlappingSmall*.py
m-zytnicki
parents: 6
diff changeset
158 if self.minOverlap and not queryTranscript.overlapWithExon(refTranscript, self.minOverlap):
1eb55963fe39 Updated CompareOverlappingSmall*.py
m-zytnicki
parents: 6
diff changeset
159 return False
6
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
160 return True
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
161
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
162 def _alterTranscript(self, transcript, type):
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
163 if type == REFERENCE:
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
164 if self.distance != None:
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
165 transcript.extendExons(self.distance)
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
166 return transcript
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
167
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
168 def _compareTranscript(self, refTranscript):
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
169 refChromosome = refTranscript.getChromosome()
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
170 if refChromosome not in self.bins:
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
171 return []
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
172 refStart = refTranscript.getStart()
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
173 refEnd = refTranscript.getEnd()
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
174 bins = getOverlappingBins(refStart, refEnd)
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
175 for binRange in bins:
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
176 for bin in range(binRange[0], binRange[1]+1):
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
177 if bin not in self.bins[refChromosome]:
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
178 continue
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
179 for queryTranscript in self.bins[refChromosome][bin]:
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
180 if self._compareTwoTranscripts(queryTranscript, refTranscript):
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
181 if queryTranscript not in self.overlaps:
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
182 self.overlaps[queryTranscript] = {}
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
183 nbElements = int(float(refTranscript.getTagValue("nbElements"))) if "nbElements" in refTranscript.getTagNames() else 1
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
184 self.overlaps[queryTranscript][refTranscript.getName()] = int(float(refTranscript.getTagValue("nbElements"))) if "nbElements" in refTranscript.getTagNames() else 1
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
185 self.nbOverlaps += nbElements
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
186
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
187 def _updateTranscript(self, queryTranscript):
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
188 overlaps = self.overlaps[queryTranscript]
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
189 queryTranscript.setTagValue("nbOverlaps", sum(overlaps.values()))
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
190 if overlaps:
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
191 queryTranscript.setTagValue("overlapsWith", "--".join(overlaps.keys())[:100])
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
192 return queryTranscript
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
193
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
194 def compare(self):
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
195 progress = UnlimitedProgress(10000, "Comparing references", self.verbosity)
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
196 for refTranscript in self.refParser.getIterator():
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
197 if refTranscript.__class__.__name__ == "Mapping":
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
198 refTranscript = refTranscript.getTranscript()
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
199 refTranscript = self._alterTranscript(refTranscript, REFERENCE)
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
200 self._compareTranscript(refTranscript)
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
201 self.nbRefs += 1
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
202 progress.inc()
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
203 progress.done()
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
204
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
205 def printResults(self):
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
206 for transcript in self.overlaps:
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
207 if not self.invert or not self.overlaps[transcript]:
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
208 if not self.invert:
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
209 transcript = self._updateTranscript(transcript)
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
210 self.writer.addTranscript(transcript)
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
211 self.nbWritten += 1
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
212 self.writer.close()
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
213
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
214 def displayResults(self):
9
1eb55963fe39 Updated CompareOverlappingSmall*.py
m-zytnicki
parents: 6
diff changeset
215 if self.verbosity:
1eb55963fe39 Updated CompareOverlappingSmall*.py
m-zytnicki
parents: 6
diff changeset
216 print "# queries: %d" % (self.nbQueries)
1eb55963fe39 Updated CompareOverlappingSmall*.py
m-zytnicki
parents: 6
diff changeset
217 print "# refs: %d" % (self.nbRefs)
1eb55963fe39 Updated CompareOverlappingSmall*.py
m-zytnicki
parents: 6
diff changeset
218 print "# written: %d (%d overlaps)" % (self.nbWritten, self.nbOverlaps)
6
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
219
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
220 def run(self):
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
221 self.loadQuery()
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
222 self.compare()
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
223 self.printResults()
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
224 self.displayResults()
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
225
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
226 if __name__ == "__main__":
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
227
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
228 description = "Compare Overlapping Small Query v1.0.1: Provide the queries that overlap with a reference, when the query is small. [Category: Data Comparison]"
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
229
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
230 parser = OptionParser(description = description)
9
1eb55963fe39 Updated CompareOverlappingSmall*.py
m-zytnicki
parents: 6
diff changeset
231 parser.add_option("-i", "--input1", dest="inputFileName1", action="store", type="string", help="query input file [compulsory] [format: file in transcript format given by -f]")
1eb55963fe39 Updated CompareOverlappingSmall*.py
m-zytnicki
parents: 6
diff changeset
232 parser.add_option("-f", "--format1", dest="format1", action="store", type="string", help="format of previous file [compulsory] [format: transcript file format]")
1eb55963fe39 Updated CompareOverlappingSmall*.py
m-zytnicki
parents: 6
diff changeset
233 parser.add_option("-j", "--input2", dest="inputFileName2", action="store", type="string", help="reference input file [compulsory] [format: file in transcript format given by -g]")
1eb55963fe39 Updated CompareOverlappingSmall*.py
m-zytnicki
parents: 6
diff changeset
234 parser.add_option("-g", "--format2", dest="format2", action="store", type="string", help="format of previous file [compulsory] [format: transcript file format]")
1eb55963fe39 Updated CompareOverlappingSmall*.py
m-zytnicki
parents: 6
diff changeset
235 parser.add_option("-o", "--output", dest="outputFileName", action="store", type="string", help="output file [format: output file in GFF3 format]")
6
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
236 parser.add_option("-O", "--notOverlapping", dest="notOverlapping", action="store_true", default=False, help="also output not overlapping data [format: bool] [default: false]")
9
1eb55963fe39 Updated CompareOverlappingSmall*.py
m-zytnicki
parents: 6
diff changeset
237 parser.add_option("-d", "--distance", dest="distance", action="store", default=0, type="int", help="accept some distance between query and reference [format: int]")
6
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
238 parser.add_option("-c", "--collinear", dest="collinear", action="store_true", default=False, help="provide collinear features [format: bool] [default: false]")
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
239 parser.add_option("-a", "--antisense", dest="antisense", action="store_true", default=False, help="provide antisense features [format: bool] [default: false]")
9
1eb55963fe39 Updated CompareOverlappingSmall*.py
m-zytnicki
parents: 6
diff changeset
240 parser.add_option("-m", "--minOverlap", dest="minOverlap", action="store", default=False, type="int", help="min. #nt overlap [format: bool] [default: false]")
1eb55963fe39 Updated CompareOverlappingSmall*.py
m-zytnicki
parents: 6
diff changeset
241 parser.add_option("-p", "--pcOverlapQuery", dest="pcOverlapQuery", action="store", default=False, type="int", help="min. % overlap of the query [format: bool] [default: false]")
1eb55963fe39 Updated CompareOverlappingSmall*.py
m-zytnicki
parents: 6
diff changeset
242 parser.add_option("-P", "--pcOverlapRef", dest="pcOverlapRef", action="store", default=False, type="int", help="min. % overlap of the reference [format: bool] [default: false]")
1eb55963fe39 Updated CompareOverlappingSmall*.py
m-zytnicki
parents: 6
diff changeset
243 parser.add_option("-k", "--included", dest="included", action="store_true", default=False, help="provide query elements which are nested in reference elements [format: bool] [default: false]")
1eb55963fe39 Updated CompareOverlappingSmall*.py
m-zytnicki
parents: 6
diff changeset
244 parser.add_option("-K", "--including", dest="including", action="store_true", default=False, help="provide query elements in which reference elements are nested [format: bool] [default: false]")
6
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
245 parser.add_option("-x", "--exclude", dest="exclude", action="store_true", default=False, help="invert the match [format: bool] [default: false]")
9
1eb55963fe39 Updated CompareOverlappingSmall*.py
m-zytnicki
parents: 6
diff changeset
246 parser.add_option("-v", "--verbosity", dest="verbosity", action="store", default=1, type="int", help="trace level [format: int]")
6
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
247 (options, args) = parser.parse_args()
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
248
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
249 cosq = CompareOverlappingSmallQuery(options.verbosity)
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
250 cosq.setQueryFile(options.inputFileName1, options.format1)
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
251 cosq.setReferenceFile(options.inputFileName2, options.format2)
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
252 cosq.setOutputFile(options.outputFileName)
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
253 cosq.includeNotOverlapping(options.notOverlapping)
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
254 cosq.setDistance(options.distance)
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
255 cosq.setCollinear(options.collinear)
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
256 cosq.setAntisense(options.antisense)
9
1eb55963fe39 Updated CompareOverlappingSmall*.py
m-zytnicki
parents: 6
diff changeset
257 cosq.setMinPercentOverlap(options.pcOverlapQuery, options.pcOverlapRef)
1eb55963fe39 Updated CompareOverlappingSmall*.py
m-zytnicki
parents: 6
diff changeset
258 cosq.setMinOverlap(options.minOverlap)
1eb55963fe39 Updated CompareOverlappingSmall*.py
m-zytnicki
parents: 6
diff changeset
259 cosq.setInclude(options.included, options.including)
6
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
260 cosq.setInvert(options.exclude)
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
261 cosq.run()