annotate SMART/Java/Python/GetFlanking.py @ 13:03045debed6e

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