annotate SMART/Java/Python/GetFlanking.py @ 71:d96f6c9a39e0 draft default tip

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