annotate SMART/Java/Python/GetFlanking.py @ 36:44d5973c188c

Uploaded
author m-zytnicki
date Tue, 30 Apr 2013 15:02:29 -0400
parents
children 169d364ddd91
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.Transcript import Transcript
44d5973c188c Uploaded
m-zytnicki
parents:
diff changeset
35 from SMART.Java.Python.structure.Interval import Interval
44d5973c188c Uploaded
m-zytnicki
parents:
diff changeset
36 from SMART.Java.Python.misc.Progress import Progress
44d5973c188c Uploaded
m-zytnicki
parents:
diff changeset
37
44d5973c188c Uploaded
m-zytnicki
parents:
diff changeset
38 QUERY = 0
44d5973c188c Uploaded
m-zytnicki
parents:
diff changeset
39 REFERENCE = 1
44d5973c188c Uploaded
m-zytnicki
parents:
diff changeset
40 INPUTS = (QUERY, REFERENCE)
44d5973c188c Uploaded
m-zytnicki
parents:
diff changeset
41 STRANDS = (-1, 1)
44d5973c188c Uploaded
m-zytnicki
parents:
diff changeset
42 TAG_DISTANCE = "distance_"
44d5973c188c Uploaded
m-zytnicki
parents:
diff changeset
43 TAG_SENSE = "_sense"
44d5973c188c Uploaded
m-zytnicki
parents:
diff changeset
44 TAG_REGION = "_region"
44d5973c188c Uploaded
m-zytnicki
parents:
diff changeset
45 TAGS_REGION = {-1: "_upstream", 0: "", 1: "_downstream"}
44d5973c188c Uploaded
m-zytnicki
parents:
diff changeset
46 TAGS_RREGION = {-1: "upstream", 0: "overlapping", 1: "downstream"}
44d5973c188c Uploaded
m-zytnicki
parents:
diff changeset
47 TAGS_SENSE = {-1: "antisense", 0: "", 1: "collinear"}
44d5973c188c Uploaded
m-zytnicki
parents:
diff changeset
48 STRANDSTOSTR = {-1: "(-)", 0: "", 1: "(+)"}
44d5973c188c Uploaded
m-zytnicki
parents:
diff changeset
49
44d5973c188c Uploaded
m-zytnicki
parents:
diff changeset
50
44d5973c188c Uploaded
m-zytnicki
parents:
diff changeset
51 def getOrderKey(transcript, direction, input):
44d5973c188c Uploaded
m-zytnicki
parents:
diff changeset
52 if direction == 1:
44d5973c188c Uploaded
m-zytnicki
parents:
diff changeset
53 if input == QUERY:
44d5973c188c Uploaded
m-zytnicki
parents:
diff changeset
54 return (transcript.getEnd(), -transcript.getStart())
44d5973c188c Uploaded
m-zytnicki
parents:
diff changeset
55 return (transcript.getStart(), -transcript.getEnd())
44d5973c188c Uploaded
m-zytnicki
parents:
diff changeset
56 if input == QUERY:
44d5973c188c Uploaded
m-zytnicki
parents:
diff changeset
57 return (-transcript.getStart(), transcript.getEnd())
44d5973c188c Uploaded
m-zytnicki
parents:
diff changeset
58 return (-transcript.getEnd(), transcript.getStart())
44d5973c188c Uploaded
m-zytnicki
parents:
diff changeset
59
44d5973c188c Uploaded
m-zytnicki
parents:
diff changeset
60
44d5973c188c Uploaded
m-zytnicki
parents:
diff changeset
61 class GetFlanking(object):
44d5973c188c Uploaded
m-zytnicki
parents:
diff changeset
62
44d5973c188c Uploaded
m-zytnicki
parents:
diff changeset
63 def __init__(self, verbosity):
44d5973c188c Uploaded
m-zytnicki
parents:
diff changeset
64 self.verbosity = verbosity
44d5973c188c Uploaded
m-zytnicki
parents:
diff changeset
65 self.transcripts = dict([id, {}] for id in INPUTS)
44d5973c188c Uploaded
m-zytnicki
parents:
diff changeset
66 self.directions = []
44d5973c188c Uploaded
m-zytnicki
parents:
diff changeset
67 self.noOverlap = False
44d5973c188c Uploaded
m-zytnicki
parents:
diff changeset
68 self.colinear = False
44d5973c188c Uploaded
m-zytnicki
parents:
diff changeset
69 self.antisense = False
44d5973c188c Uploaded
m-zytnicki
parents:
diff changeset
70 self.distance = None
44d5973c188c Uploaded
m-zytnicki
parents:
diff changeset
71 self.minDistance = None
44d5973c188c Uploaded
m-zytnicki
parents:
diff changeset
72 self.maxDistance = None
44d5973c188c Uploaded
m-zytnicki
parents:
diff changeset
73 self.tagName = "flanking"
44d5973c188c Uploaded
m-zytnicki
parents:
diff changeset
74
44d5973c188c Uploaded
m-zytnicki
parents:
diff changeset
75 def setInputFile(self, fileName, format, id):
44d5973c188c Uploaded
m-zytnicki
parents:
diff changeset
76 chooser = ParserChooser(self.verbosity)
44d5973c188c Uploaded
m-zytnicki
parents:
diff changeset
77 chooser.findFormat(format)
44d5973c188c Uploaded
m-zytnicki
parents:
diff changeset
78 parser = chooser.getParser(fileName)
44d5973c188c Uploaded
m-zytnicki
parents:
diff changeset
79 for transcript in parser.getIterator():
44d5973c188c Uploaded
m-zytnicki
parents:
diff changeset
80 chromosome = transcript.getChromosome()
44d5973c188c Uploaded
m-zytnicki
parents:
diff changeset
81 if chromosome not in self.transcripts[id]:
44d5973c188c Uploaded
m-zytnicki
parents:
diff changeset
82 self.transcripts[id][chromosome] = []
44d5973c188c Uploaded
m-zytnicki
parents:
diff changeset
83 self.transcripts[id][chromosome].append(transcript)
44d5973c188c Uploaded
m-zytnicki
parents:
diff changeset
84
44d5973c188c Uploaded
m-zytnicki
parents:
diff changeset
85 def setOutputFile(self, fileName):
44d5973c188c Uploaded
m-zytnicki
parents:
diff changeset
86 self.writer = TranscriptWriter(fileName, "gff3", self.verbosity)
44d5973c188c Uploaded
m-zytnicki
parents:
diff changeset
87
44d5973c188c Uploaded
m-zytnicki
parents:
diff changeset
88 def addUpstreamDirection(self, upstream):
44d5973c188c Uploaded
m-zytnicki
parents:
diff changeset
89 if upstream:
44d5973c188c Uploaded
m-zytnicki
parents:
diff changeset
90 self.directions.append(-1)
44d5973c188c Uploaded
m-zytnicki
parents:
diff changeset
91
44d5973c188c Uploaded
m-zytnicki
parents:
diff changeset
92 def addDownstreamDirection(self, downstream):
44d5973c188c Uploaded
m-zytnicki
parents:
diff changeset
93 if downstream:
44d5973c188c Uploaded
m-zytnicki
parents:
diff changeset
94 self.directions.append(1)
44d5973c188c Uploaded
m-zytnicki
parents:
diff changeset
95
44d5973c188c Uploaded
m-zytnicki
parents:
diff changeset
96 def setColinear(self, colinear):
44d5973c188c Uploaded
m-zytnicki
parents:
diff changeset
97 self.colinear = colinear
44d5973c188c Uploaded
m-zytnicki
parents:
diff changeset
98
44d5973c188c Uploaded
m-zytnicki
parents:
diff changeset
99 def setAntisense(self, antisense):
44d5973c188c Uploaded
m-zytnicki
parents:
diff changeset
100 self.antisense = antisense
44d5973c188c Uploaded
m-zytnicki
parents:
diff changeset
101
44d5973c188c Uploaded
m-zytnicki
parents:
diff changeset
102 def setNoOverlap(self, noOverlap):
44d5973c188c Uploaded
m-zytnicki
parents:
diff changeset
103 self.noOverlap = noOverlap
44d5973c188c Uploaded
m-zytnicki
parents:
diff changeset
104
44d5973c188c Uploaded
m-zytnicki
parents:
diff changeset
105 def setMinDistance(self, distance):
44d5973c188c Uploaded
m-zytnicki
parents:
diff changeset
106 self.minDistance = distance
44d5973c188c Uploaded
m-zytnicki
parents:
diff changeset
107
44d5973c188c Uploaded
m-zytnicki
parents:
diff changeset
108 def setMaxDistance(self, distance):
44d5973c188c Uploaded
m-zytnicki
parents:
diff changeset
109 self.maxDistance = distance
44d5973c188c Uploaded
m-zytnicki
parents:
diff changeset
110
44d5973c188c Uploaded
m-zytnicki
parents:
diff changeset
111 def setNewTagName(self, tagName):
44d5973c188c Uploaded
m-zytnicki
parents:
diff changeset
112 self.tagName = tagName
44d5973c188c Uploaded
m-zytnicki
parents:
diff changeset
113
44d5973c188c Uploaded
m-zytnicki
parents:
diff changeset
114 def match(self, transcriptQuery, transcriptRef, direction):
44d5973c188c Uploaded
m-zytnicki
parents:
diff changeset
115 #print "comparing", transcriptQuery, "with", transcriptRef, "on direction", direction
44d5973c188c Uploaded
m-zytnicki
parents:
diff changeset
116 if direction == 1 and transcriptRef.getEnd() < transcriptQuery.getStart():
44d5973c188c Uploaded
m-zytnicki
parents:
diff changeset
117 return False
44d5973c188c Uploaded
m-zytnicki
parents:
diff changeset
118 if direction == -1 and transcriptQuery.getEnd() < transcriptRef.getStart():
44d5973c188c Uploaded
m-zytnicki
parents:
diff changeset
119 return False
44d5973c188c Uploaded
m-zytnicki
parents:
diff changeset
120 if self.noOverlap and transcriptRef.overlapWith(transcriptQuery):
44d5973c188c Uploaded
m-zytnicki
parents:
diff changeset
121 return False
44d5973c188c Uploaded
m-zytnicki
parents:
diff changeset
122 if self.colinear and transcriptRef.getDirection() != transcriptQuery.getDirection():
44d5973c188c Uploaded
m-zytnicki
parents:
diff changeset
123 return False
44d5973c188c Uploaded
m-zytnicki
parents:
diff changeset
124 if self.antisense and transcriptRef.getDirection() == transcriptQuery.getDirection():
44d5973c188c Uploaded
m-zytnicki
parents:
diff changeset
125 return False
44d5973c188c Uploaded
m-zytnicki
parents:
diff changeset
126 if self.minDistance != None or self.maxDistance != None:
44d5973c188c Uploaded
m-zytnicki
parents:
diff changeset
127 distance = transcriptRef.getDistance(transcriptQuery)
44d5973c188c Uploaded
m-zytnicki
parents:
diff changeset
128 if self.minDistance != None and distance < self.minDistance:
44d5973c188c Uploaded
m-zytnicki
parents:
diff changeset
129 return False
44d5973c188c Uploaded
m-zytnicki
parents:
diff changeset
130 if self.maxDistance != None and distance > self.maxDistance:
44d5973c188c Uploaded
m-zytnicki
parents:
diff changeset
131 return False
44d5973c188c Uploaded
m-zytnicki
parents:
diff changeset
132 return True
44d5973c188c Uploaded
m-zytnicki
parents:
diff changeset
133
44d5973c188c Uploaded
m-zytnicki
parents:
diff changeset
134 def getFlanking(self, chromosome, direction):
44d5973c188c Uploaded
m-zytnicki
parents:
diff changeset
135 if chromosome not in self.transcripts[REFERENCE]:
44d5973c188c Uploaded
m-zytnicki
parents:
diff changeset
136 return
44d5973c188c Uploaded
m-zytnicki
parents:
diff changeset
137 sortedTranscripts = dict([id, {}] for id in INPUTS)
44d5973c188c Uploaded
m-zytnicki
parents:
diff changeset
138 for id in INPUTS:
44d5973c188c Uploaded
m-zytnicki
parents:
diff changeset
139 sortedTranscripts[id] = sorted(self.transcripts[id][chromosome], key = lambda t: getOrderKey(t, direction, id))
44d5973c188c Uploaded
m-zytnicki
parents:
diff changeset
140 refIndex = 0
44d5973c188c Uploaded
m-zytnicki
parents:
diff changeset
141 progress = Progress(len(sortedTranscripts[QUERY]), "Reading chr %s %s" % (chromosome, STRANDSTOSTR[direction]), self.verbosity)
44d5973c188c Uploaded
m-zytnicki
parents:
diff changeset
142 for query in sortedTranscripts[QUERY]:
44d5973c188c Uploaded
m-zytnicki
parents:
diff changeset
143 #print "Q: ", query
44d5973c188c Uploaded
m-zytnicki
parents:
diff changeset
144 #print "R1: ", sortedTranscripts[REFERENCE][refIndex]
44d5973c188c Uploaded
m-zytnicki
parents:
diff changeset
145 while not self.match(query, sortedTranscripts[REFERENCE][refIndex], direction):
44d5973c188c Uploaded
m-zytnicki
parents:
diff changeset
146 refIndex += 1
44d5973c188c Uploaded
m-zytnicki
parents:
diff changeset
147 if refIndex == len(sortedTranscripts[REFERENCE]):
44d5973c188c Uploaded
m-zytnicki
parents:
diff changeset
148 progress.done()
44d5973c188c Uploaded
m-zytnicki
parents:
diff changeset
149 #print "done"
44d5973c188c Uploaded
m-zytnicki
parents:
diff changeset
150 return
44d5973c188c Uploaded
m-zytnicki
parents:
diff changeset
151 #print "R2: ", sortedTranscripts[REFERENCE][refIndex]
44d5973c188c Uploaded
m-zytnicki
parents:
diff changeset
152 self.flankings[query][direction] = sortedTranscripts[REFERENCE][refIndex]
44d5973c188c Uploaded
m-zytnicki
parents:
diff changeset
153 progress.inc()
44d5973c188c Uploaded
m-zytnicki
parents:
diff changeset
154 progress.done()
44d5973c188c Uploaded
m-zytnicki
parents:
diff changeset
155
44d5973c188c Uploaded
m-zytnicki
parents:
diff changeset
156 def setTags(self, query, reference, direction):
44d5973c188c Uploaded
m-zytnicki
parents:
diff changeset
157 refName = reference.getTagValue("ID")
44d5973c188c Uploaded
m-zytnicki
parents:
diff changeset
158 if refName == None:
44d5973c188c Uploaded
m-zytnicki
parents:
diff changeset
159 refName = reference.getName()
44d5973c188c Uploaded
m-zytnicki
parents:
diff changeset
160 if refName == None:
44d5973c188c Uploaded
m-zytnicki
parents:
diff changeset
161 refName = reference.__str__()
44d5973c188c Uploaded
m-zytnicki
parents:
diff changeset
162 query.setTagValue("%s%s" % (self.tagName, TAGS_REGION[direction*query.getDirection()]), refName)
44d5973c188c Uploaded
m-zytnicki
parents:
diff changeset
163 query.setTagValue("%s_%s%s" % (TAG_DISTANCE, self.tagName, TAGS_REGION[direction*query.getDirection()]), query.getDistance(reference))
44d5973c188c Uploaded
m-zytnicki
parents:
diff changeset
164 query.setTagValue("%s_%s" % (TAG_SENSE, self.tagName), TAGS_SENSE[query.getDirection() * reference.getDirection()])
44d5973c188c Uploaded
m-zytnicki
parents:
diff changeset
165 if direction == 0:
44d5973c188c Uploaded
m-zytnicki
parents:
diff changeset
166 query.setTagValue("%s_%s" % (TAG_REGION, self.tagName), TAGS_RREGION[cmp(query.getRelativeDistance(reference), 0)])
44d5973c188c Uploaded
m-zytnicki
parents:
diff changeset
167 for tag in reference.getTagNames():
44d5973c188c Uploaded
m-zytnicki
parents:
diff changeset
168 if tag not in ("quality", "feature"):
44d5973c188c Uploaded
m-zytnicki
parents:
diff changeset
169 query.setTagValue("%s%s_%s" % (self.tagName, TAGS_REGION[direction*query.getDirection()], tag), reference.getTagValue(tag))
44d5973c188c Uploaded
m-zytnicki
parents:
diff changeset
170 return query
44d5973c188c Uploaded
m-zytnicki
parents:
diff changeset
171
44d5973c188c Uploaded
m-zytnicki
parents:
diff changeset
172 def write(self):
44d5973c188c Uploaded
m-zytnicki
parents:
diff changeset
173 progress = Progress(len(self.flankings.keys()), "Printing data", self.verbosity)
44d5973c188c Uploaded
m-zytnicki
parents:
diff changeset
174 for transcriptQuery in self.flankings.keys():
44d5973c188c Uploaded
m-zytnicki
parents:
diff changeset
175 if not self.flankings[transcriptQuery]:
44d5973c188c Uploaded
m-zytnicki
parents:
diff changeset
176 self.writer.addTranscript(transcriptQuery)
44d5973c188c Uploaded
m-zytnicki
parents:
diff changeset
177 elif self.directions:
44d5973c188c Uploaded
m-zytnicki
parents:
diff changeset
178 for direction in self.directions:
44d5973c188c Uploaded
m-zytnicki
parents:
diff changeset
179 #relativeDirection = direction if transcriptQuery.getDirection() == 1 else - direction
44d5973c188c Uploaded
m-zytnicki
parents:
diff changeset
180 relativeDirection = direction * transcriptQuery.getDirection()
44d5973c188c Uploaded
m-zytnicki
parents:
diff changeset
181 if relativeDirection in self.flankings[transcriptQuery]:
44d5973c188c Uploaded
m-zytnicki
parents:
diff changeset
182 transcriptRef = self.flankings[transcriptQuery][relativeDirection]
44d5973c188c Uploaded
m-zytnicki
parents:
diff changeset
183 transcriptQuery = self.setTags(transcriptQuery, transcriptRef, relativeDirection)
44d5973c188c Uploaded
m-zytnicki
parents:
diff changeset
184 self.writer.addTranscript(transcriptQuery)
44d5973c188c Uploaded
m-zytnicki
parents:
diff changeset
185 else:
44d5973c188c Uploaded
m-zytnicki
parents:
diff changeset
186 transcriptRef = sorted(self.flankings[transcriptQuery].values(), key = lambda transcriptRef: transcriptQuery.getDistance(transcriptRef))[0]
44d5973c188c Uploaded
m-zytnicki
parents:
diff changeset
187 self.writer.addTranscript(self.setTags(transcriptQuery, transcriptRef, 0))
44d5973c188c Uploaded
m-zytnicki
parents:
diff changeset
188 progress.inc()
44d5973c188c Uploaded
m-zytnicki
parents:
diff changeset
189 progress.done()
44d5973c188c Uploaded
m-zytnicki
parents:
diff changeset
190
44d5973c188c Uploaded
m-zytnicki
parents:
diff changeset
191 def run(self):
44d5973c188c Uploaded
m-zytnicki
parents:
diff changeset
192 for chromosome in sorted(self.transcripts[QUERY].keys()):
44d5973c188c Uploaded
m-zytnicki
parents:
diff changeset
193 self.flankings = dict([query, {}] for query in self.transcripts[QUERY][chromosome])
44d5973c188c Uploaded
m-zytnicki
parents:
diff changeset
194 for direction in STRANDS:
44d5973c188c Uploaded
m-zytnicki
parents:
diff changeset
195 #print "comparison", chromosome, direction
44d5973c188c Uploaded
m-zytnicki
parents:
diff changeset
196 self.getFlanking(chromosome, direction)
44d5973c188c Uploaded
m-zytnicki
parents:
diff changeset
197 self.write()
44d5973c188c Uploaded
m-zytnicki
parents:
diff changeset
198 self.writer.close()
44d5973c188c Uploaded
m-zytnicki
parents:
diff changeset
199
44d5973c188c Uploaded
m-zytnicki
parents:
diff changeset
200 if __name__ == "__main__":
44d5973c188c Uploaded
m-zytnicki
parents:
diff changeset
201
44d5973c188c Uploaded
m-zytnicki
parents:
diff changeset
202 description = "Get Flanking v1.0.1: Get the flanking regions of a set of reference. [Category: Data Selection]"
44d5973c188c Uploaded
m-zytnicki
parents:
diff changeset
203
44d5973c188c Uploaded
m-zytnicki
parents:
diff changeset
204 parser = OptionParser(description = description)
44d5973c188c Uploaded
m-zytnicki
parents:
diff changeset
205 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
206 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
207 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
208 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
209 parser.add_option("-5", "--upstream", dest="upstream", action="store_true", default=False, help="output upstream elements [format: boolean] [default: False]")
44d5973c188c Uploaded
m-zytnicki
parents:
diff changeset
210 parser.add_option("-3", "--downstream", dest="downstream", action="store_true", default=False, help="output downstream elements [format: boolean] [default: False]")
44d5973c188c Uploaded
m-zytnicki
parents:
diff changeset
211 parser.add_option("-c", "--colinear", dest="colinear", action="store_true", default=False, help="find first colinear element [format: boolean] [default: False]")
44d5973c188c Uploaded
m-zytnicki
parents:
diff changeset
212 parser.add_option("-a", "--antisense", dest="antisense", action="store_true", default=False, help="find first anti-sense element [format: boolean] [default: False]")
44d5973c188c Uploaded
m-zytnicki
parents:
diff changeset
213 parser.add_option("-e", "--noOverlap", dest="noOverlap", action="store_true", default=False, help="do not consider elements which are overlapping reference elements [format: boolean] [default: False]")
44d5973c188c Uploaded
m-zytnicki
parents:
diff changeset
214 parser.add_option("-d", "--minDistance", dest="minDistance", action="store", default=None, type="int", help="minimum distance between 2 elements [format: int]")
44d5973c188c Uploaded
m-zytnicki
parents:
diff changeset
215 parser.add_option("-D", "--maxDistance", dest="maxDistance", action="store", default=None, type="int", help="maximum distance between 2 elements [format: int]")
44d5973c188c Uploaded
m-zytnicki
parents:
diff changeset
216 parser.add_option("-t", "--tag", dest="tagName", action="store", default="flanking", type="string", help="name of the new tag [format: string] [default: flanking]")
44d5973c188c Uploaded
m-zytnicki
parents:
diff changeset
217 parser.add_option("-o", "--output", dest="outputFileName", action="store", type="string", help="output file [format: output file in GFF3 format]")
44d5973c188c Uploaded
m-zytnicki
parents:
diff changeset
218 parser.add_option("-v", "--verbosity", dest="verbosity", action="store", default=1, type="int", help="trace level [format: int]")
44d5973c188c Uploaded
m-zytnicki
parents:
diff changeset
219 (options, args) = parser.parse_args()
44d5973c188c Uploaded
m-zytnicki
parents:
diff changeset
220
44d5973c188c Uploaded
m-zytnicki
parents:
diff changeset
221 gf = GetFlanking(options.verbosity)
44d5973c188c Uploaded
m-zytnicki
parents:
diff changeset
222 gf.setInputFile(options.inputFileName1, options.format1, QUERY)
44d5973c188c Uploaded
m-zytnicki
parents:
diff changeset
223 gf.setInputFile(options.inputFileName2, options.format2, REFERENCE)
44d5973c188c Uploaded
m-zytnicki
parents:
diff changeset
224 gf.setOutputFile(options.outputFileName)
44d5973c188c Uploaded
m-zytnicki
parents:
diff changeset
225 gf.addUpstreamDirection(options.upstream)
44d5973c188c Uploaded
m-zytnicki
parents:
diff changeset
226 gf.addDownstreamDirection(options.downstream)
44d5973c188c Uploaded
m-zytnicki
parents:
diff changeset
227 gf.setColinear(options.colinear)
44d5973c188c Uploaded
m-zytnicki
parents:
diff changeset
228 gf.setAntisense(options.antisense)
44d5973c188c Uploaded
m-zytnicki
parents:
diff changeset
229 gf.setNoOverlap(options.noOverlap)
44d5973c188c Uploaded
m-zytnicki
parents:
diff changeset
230 gf.setMinDistance(options.minDistance)
44d5973c188c Uploaded
m-zytnicki
parents:
diff changeset
231 gf.setMaxDistance(options.maxDistance)
44d5973c188c Uploaded
m-zytnicki
parents:
diff changeset
232 gf.setNewTagName(options.tagName)
44d5973c188c Uploaded
m-zytnicki
parents:
diff changeset
233 gf.run()