annotate SMART/Java/Python/CompareOverlappingSmallRef.py @ 56:97aa2e42bfdf

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