annotate SMART/Java/Python/GetFlanking.py @ 22:1e3f2c2657a3

Deleted selected files
author m-zytnicki
date Mon, 29 Apr 2013 03:26:07 -0400
parents 94ab73e8a190
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
6
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
1 #! /usr/bin/env python
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
2 #
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
3 # Copyright INRA-URGI 2009-2011
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
4 #
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
5 # This software is governed by the CeCILL license under French law and
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
6 # abiding by the rules of distribution of free software. You can use,
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
7 # modify and/ or redistribute the software under the terms of the CeCILL
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
8 # license as circulated by CEA, CNRS and INRIA at the following URL
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
9 # "http://www.cecill.info".
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
10 #
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
11 # As a counterpart to the access to the source code and rights to copy,
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
12 # modify and redistribute granted by the license, users are provided only
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
13 # with a limited warranty and the software's author, the holder of the
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
14 # economic rights, and the successive licensors have only limited
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
15 # liability.
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
16 #
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
17 # In this respect, the user's attention is drawn to the risks associated
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
18 # with loading, using, modifying and/or developing or reproducing the
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
19 # software by the user in light of its specific status of free software,
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
20 # that may mean that it is complicated to manipulate, and that also
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
21 # therefore means that it is reserved for developers and experienced
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
22 # professionals having in-depth computer knowledge. Users are therefore
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
23 # encouraged to load and test the software's suitability as regards their
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
24 # requirements in conditions enabling the security of their systems and/or
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
25 # data to be ensured and, more generally, to use and operate it in the
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
26 # same conditions as regards security.
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
27 #
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
28 # The fact that you are presently reading this means that you have had
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
29 # knowledge of the CeCILL license and that you accept its terms.
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
30 #
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
31 from optparse import OptionParser
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
32 from commons.core.parsing.ParserChooser import ParserChooser
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
33 from commons.core.writer.TranscriptWriter import TranscriptWriter
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
34 from SMART.Java.Python.structure.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"}
18
94ab73e8a190 Uploaded
m-zytnicki
parents: 6
diff changeset
47 TAGS_SENSE = {-1: "antisense", 0: "", 1: "collinear"}
6
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
18
94ab73e8a190 Uploaded
m-zytnicki
parents: 6
diff changeset
51 def getOrderKey(transcript, direction, input):
94ab73e8a190 Uploaded
m-zytnicki
parents: 6
diff changeset
52 if direction == 1:
94ab73e8a190 Uploaded
m-zytnicki
parents: 6
diff changeset
53 if input == QUERY:
94ab73e8a190 Uploaded
m-zytnicki
parents: 6
diff changeset
54 return (transcript.getEnd(), -transcript.getStart())
94ab73e8a190 Uploaded
m-zytnicki
parents: 6
diff changeset
55 return (transcript.getStart(), -transcript.getEnd())
94ab73e8a190 Uploaded
m-zytnicki
parents: 6
diff changeset
56 if input == QUERY:
94ab73e8a190 Uploaded
m-zytnicki
parents: 6
diff changeset
57 return (-transcript.getStart(), transcript.getEnd())
94ab73e8a190 Uploaded
m-zytnicki
parents: 6
diff changeset
58 return (-transcript.getEnd(), transcript.getStart())
6
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
59
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
60
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
61 class GetFlanking(object):
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
62
18
94ab73e8a190 Uploaded
m-zytnicki
parents: 6
diff changeset
63 def __init__(self, verbosity):
94ab73e8a190 Uploaded
m-zytnicki
parents: 6
diff changeset
64 self.verbosity = verbosity
94ab73e8a190 Uploaded
m-zytnicki
parents: 6
diff changeset
65 self.transcripts = dict([id, {}] for id in INPUTS)
94ab73e8a190 Uploaded
m-zytnicki
parents: 6
diff changeset
66 self.directions = []
94ab73e8a190 Uploaded
m-zytnicki
parents: 6
diff changeset
67 self.noOverlap = False
94ab73e8a190 Uploaded
m-zytnicki
parents: 6
diff changeset
68 self.colinear = False
94ab73e8a190 Uploaded
m-zytnicki
parents: 6
diff changeset
69 self.antisense = False
94ab73e8a190 Uploaded
m-zytnicki
parents: 6
diff changeset
70 self.distance = None
94ab73e8a190 Uploaded
m-zytnicki
parents: 6
diff changeset
71 self.minDistance = None
94ab73e8a190 Uploaded
m-zytnicki
parents: 6
diff changeset
72 self.maxDistance = None
94ab73e8a190 Uploaded
m-zytnicki
parents: 6
diff changeset
73 self.tagName = "flanking"
6
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
74
18
94ab73e8a190 Uploaded
m-zytnicki
parents: 6
diff changeset
75 def setInputFile(self, fileName, format, id):
94ab73e8a190 Uploaded
m-zytnicki
parents: 6
diff changeset
76 chooser = ParserChooser(self.verbosity)
94ab73e8a190 Uploaded
m-zytnicki
parents: 6
diff changeset
77 chooser.findFormat(format)
94ab73e8a190 Uploaded
m-zytnicki
parents: 6
diff changeset
78 parser = chooser.getParser(fileName)
94ab73e8a190 Uploaded
m-zytnicki
parents: 6
diff changeset
79 for transcript in parser.getIterator():
94ab73e8a190 Uploaded
m-zytnicki
parents: 6
diff changeset
80 chromosome = transcript.getChromosome()
94ab73e8a190 Uploaded
m-zytnicki
parents: 6
diff changeset
81 if chromosome not in self.transcripts[id]:
94ab73e8a190 Uploaded
m-zytnicki
parents: 6
diff changeset
82 self.transcripts[id][chromosome] = []
94ab73e8a190 Uploaded
m-zytnicki
parents: 6
diff changeset
83 self.transcripts[id][chromosome].append(transcript)
6
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
84
18
94ab73e8a190 Uploaded
m-zytnicki
parents: 6
diff changeset
85 def setOutputFile(self, fileName):
94ab73e8a190 Uploaded
m-zytnicki
parents: 6
diff changeset
86 self.writer = TranscriptWriter(fileName, "gff3", self.verbosity)
6
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
87
18
94ab73e8a190 Uploaded
m-zytnicki
parents: 6
diff changeset
88 def addUpstreamDirection(self, upstream):
94ab73e8a190 Uploaded
m-zytnicki
parents: 6
diff changeset
89 if upstream:
94ab73e8a190 Uploaded
m-zytnicki
parents: 6
diff changeset
90 self.directions.append(-1)
6
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
91
18
94ab73e8a190 Uploaded
m-zytnicki
parents: 6
diff changeset
92 def addDownstreamDirection(self, downstream):
94ab73e8a190 Uploaded
m-zytnicki
parents: 6
diff changeset
93 if downstream:
94ab73e8a190 Uploaded
m-zytnicki
parents: 6
diff changeset
94 self.directions.append(1)
6
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
95
18
94ab73e8a190 Uploaded
m-zytnicki
parents: 6
diff changeset
96 def setColinear(self, colinear):
94ab73e8a190 Uploaded
m-zytnicki
parents: 6
diff changeset
97 self.colinear = colinear
6
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
98
18
94ab73e8a190 Uploaded
m-zytnicki
parents: 6
diff changeset
99 def setAntisense(self, antisense):
94ab73e8a190 Uploaded
m-zytnicki
parents: 6
diff changeset
100 self.antisense = antisense
94ab73e8a190 Uploaded
m-zytnicki
parents: 6
diff changeset
101
94ab73e8a190 Uploaded
m-zytnicki
parents: 6
diff changeset
102 def setNoOverlap(self, noOverlap):
94ab73e8a190 Uploaded
m-zytnicki
parents: 6
diff changeset
103 self.noOverlap = noOverlap
6
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
104
18
94ab73e8a190 Uploaded
m-zytnicki
parents: 6
diff changeset
105 def setMinDistance(self, distance):
94ab73e8a190 Uploaded
m-zytnicki
parents: 6
diff changeset
106 self.minDistance = distance
94ab73e8a190 Uploaded
m-zytnicki
parents: 6
diff changeset
107
94ab73e8a190 Uploaded
m-zytnicki
parents: 6
diff changeset
108 def setMaxDistance(self, distance):
94ab73e8a190 Uploaded
m-zytnicki
parents: 6
diff changeset
109 self.maxDistance = distance
94ab73e8a190 Uploaded
m-zytnicki
parents: 6
diff changeset
110
94ab73e8a190 Uploaded
m-zytnicki
parents: 6
diff changeset
111 def setNewTagName(self, tagName):
94ab73e8a190 Uploaded
m-zytnicki
parents: 6
diff changeset
112 self.tagName = tagName
6
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
113
18
94ab73e8a190 Uploaded
m-zytnicki
parents: 6
diff changeset
114 def match(self, transcriptQuery, transcriptRef, direction):
94ab73e8a190 Uploaded
m-zytnicki
parents: 6
diff changeset
115 #print "comparing", transcriptQuery, "with", transcriptRef, "on direction", direction
94ab73e8a190 Uploaded
m-zytnicki
parents: 6
diff changeset
116 if direction == 1 and transcriptRef.getEnd() < transcriptQuery.getStart():
94ab73e8a190 Uploaded
m-zytnicki
parents: 6
diff changeset
117 return False
94ab73e8a190 Uploaded
m-zytnicki
parents: 6
diff changeset
118 if direction == -1 and transcriptQuery.getEnd() < transcriptRef.getStart():
94ab73e8a190 Uploaded
m-zytnicki
parents: 6
diff changeset
119 return False
94ab73e8a190 Uploaded
m-zytnicki
parents: 6
diff changeset
120 if self.noOverlap and transcriptRef.overlapWith(transcriptQuery):
94ab73e8a190 Uploaded
m-zytnicki
parents: 6
diff changeset
121 return False
94ab73e8a190 Uploaded
m-zytnicki
parents: 6
diff changeset
122 if self.colinear and transcriptRef.getDirection() != transcriptQuery.getDirection():
94ab73e8a190 Uploaded
m-zytnicki
parents: 6
diff changeset
123 return False
94ab73e8a190 Uploaded
m-zytnicki
parents: 6
diff changeset
124 if self.antisense and transcriptRef.getDirection() == transcriptQuery.getDirection():
94ab73e8a190 Uploaded
m-zytnicki
parents: 6
diff changeset
125 return False
94ab73e8a190 Uploaded
m-zytnicki
parents: 6
diff changeset
126 if self.minDistance != None or self.maxDistance != None:
94ab73e8a190 Uploaded
m-zytnicki
parents: 6
diff changeset
127 distance = transcriptRef.getDistance(transcriptQuery)
94ab73e8a190 Uploaded
m-zytnicki
parents: 6
diff changeset
128 if self.minDistance != None and distance < self.minDistance:
94ab73e8a190 Uploaded
m-zytnicki
parents: 6
diff changeset
129 return False
94ab73e8a190 Uploaded
m-zytnicki
parents: 6
diff changeset
130 if self.maxDistance != None and distance > self.maxDistance:
94ab73e8a190 Uploaded
m-zytnicki
parents: 6
diff changeset
131 return False
94ab73e8a190 Uploaded
m-zytnicki
parents: 6
diff changeset
132 return True
94ab73e8a190 Uploaded
m-zytnicki
parents: 6
diff changeset
133
94ab73e8a190 Uploaded
m-zytnicki
parents: 6
diff changeset
134 def getFlanking(self, chromosome, direction):
94ab73e8a190 Uploaded
m-zytnicki
parents: 6
diff changeset
135 if chromosome not in self.transcripts[REFERENCE]:
94ab73e8a190 Uploaded
m-zytnicki
parents: 6
diff changeset
136 return
94ab73e8a190 Uploaded
m-zytnicki
parents: 6
diff changeset
137 sortedTranscripts = dict([id, {}] for id in INPUTS)
94ab73e8a190 Uploaded
m-zytnicki
parents: 6
diff changeset
138 for id in INPUTS:
94ab73e8a190 Uploaded
m-zytnicki
parents: 6
diff changeset
139 sortedTranscripts[id] = sorted(self.transcripts[id][chromosome], key = lambda t: getOrderKey(t, direction, id))
94ab73e8a190 Uploaded
m-zytnicki
parents: 6
diff changeset
140 refIndex = 0
94ab73e8a190 Uploaded
m-zytnicki
parents: 6
diff changeset
141 progress = Progress(len(sortedTranscripts[QUERY]), "Reading chr %s %s" % (chromosome, STRANDSTOSTR[direction]), self.verbosity)
94ab73e8a190 Uploaded
m-zytnicki
parents: 6
diff changeset
142 for query in sortedTranscripts[QUERY]:
94ab73e8a190 Uploaded
m-zytnicki
parents: 6
diff changeset
143 #print "Q: ", query
94ab73e8a190 Uploaded
m-zytnicki
parents: 6
diff changeset
144 #print "R1: ", sortedTranscripts[REFERENCE][refIndex]
94ab73e8a190 Uploaded
m-zytnicki
parents: 6
diff changeset
145 while not self.match(query, sortedTranscripts[REFERENCE][refIndex], direction):
94ab73e8a190 Uploaded
m-zytnicki
parents: 6
diff changeset
146 refIndex += 1
94ab73e8a190 Uploaded
m-zytnicki
parents: 6
diff changeset
147 if refIndex == len(sortedTranscripts[REFERENCE]):
94ab73e8a190 Uploaded
m-zytnicki
parents: 6
diff changeset
148 progress.done()
94ab73e8a190 Uploaded
m-zytnicki
parents: 6
diff changeset
149 #print "done"
94ab73e8a190 Uploaded
m-zytnicki
parents: 6
diff changeset
150 return
94ab73e8a190 Uploaded
m-zytnicki
parents: 6
diff changeset
151 #print "R2: ", sortedTranscripts[REFERENCE][refIndex]
94ab73e8a190 Uploaded
m-zytnicki
parents: 6
diff changeset
152 self.flankings[query][direction] = sortedTranscripts[REFERENCE][refIndex]
94ab73e8a190 Uploaded
m-zytnicki
parents: 6
diff changeset
153 progress.inc()
94ab73e8a190 Uploaded
m-zytnicki
parents: 6
diff changeset
154 progress.done()
6
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
155
18
94ab73e8a190 Uploaded
m-zytnicki
parents: 6
diff changeset
156 def setTags(self, query, reference, direction):
94ab73e8a190 Uploaded
m-zytnicki
parents: 6
diff changeset
157 refName = reference.getTagValue("ID")
94ab73e8a190 Uploaded
m-zytnicki
parents: 6
diff changeset
158 if refName == None:
94ab73e8a190 Uploaded
m-zytnicki
parents: 6
diff changeset
159 refName = reference.getName()
94ab73e8a190 Uploaded
m-zytnicki
parents: 6
diff changeset
160 if refName == None:
94ab73e8a190 Uploaded
m-zytnicki
parents: 6
diff changeset
161 refName = reference.__str__()
94ab73e8a190 Uploaded
m-zytnicki
parents: 6
diff changeset
162 query.setTagValue("%s%s" % (self.tagName, TAGS_REGION[direction*query.getDirection()]), refName)
94ab73e8a190 Uploaded
m-zytnicki
parents: 6
diff changeset
163 query.setTagValue("%s_%s%s" % (TAG_DISTANCE, self.tagName, TAGS_REGION[direction*query.getDirection()]), query.getDistance(reference))
94ab73e8a190 Uploaded
m-zytnicki
parents: 6
diff changeset
164 query.setTagValue("%s_%s" % (TAG_SENSE, self.tagName), TAGS_SENSE[query.getDirection() * reference.getDirection()])
94ab73e8a190 Uploaded
m-zytnicki
parents: 6
diff changeset
165 if direction == 0:
94ab73e8a190 Uploaded
m-zytnicki
parents: 6
diff changeset
166 query.setTagValue("%s_%s" % (TAG_REGION, self.tagName), TAGS_RREGION[cmp(query.getRelativeDistance(reference), 0)])
94ab73e8a190 Uploaded
m-zytnicki
parents: 6
diff changeset
167 for tag in reference.getTagNames():
94ab73e8a190 Uploaded
m-zytnicki
parents: 6
diff changeset
168 if tag not in ("quality", "feature"):
94ab73e8a190 Uploaded
m-zytnicki
parents: 6
diff changeset
169 query.setTagValue("%s%s_%s" % (self.tagName, TAGS_REGION[direction*query.getDirection()], tag), reference.getTagValue(tag))
94ab73e8a190 Uploaded
m-zytnicki
parents: 6
diff changeset
170 return query
6
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
171
18
94ab73e8a190 Uploaded
m-zytnicki
parents: 6
diff changeset
172 def write(self):
94ab73e8a190 Uploaded
m-zytnicki
parents: 6
diff changeset
173 progress = Progress(len(self.flankings.keys()), "Printing data", self.verbosity)
94ab73e8a190 Uploaded
m-zytnicki
parents: 6
diff changeset
174 for transcriptQuery in self.flankings.keys():
94ab73e8a190 Uploaded
m-zytnicki
parents: 6
diff changeset
175 if not self.flankings[transcriptQuery]:
94ab73e8a190 Uploaded
m-zytnicki
parents: 6
diff changeset
176 self.writer.addTranscript(transcriptQuery)
94ab73e8a190 Uploaded
m-zytnicki
parents: 6
diff changeset
177 elif self.directions:
94ab73e8a190 Uploaded
m-zytnicki
parents: 6
diff changeset
178 for direction in self.directions:
94ab73e8a190 Uploaded
m-zytnicki
parents: 6
diff changeset
179 #relativeDirection = direction if transcriptQuery.getDirection() == 1 else - direction
94ab73e8a190 Uploaded
m-zytnicki
parents: 6
diff changeset
180 relativeDirection = direction * transcriptQuery.getDirection()
94ab73e8a190 Uploaded
m-zytnicki
parents: 6
diff changeset
181 if relativeDirection in self.flankings[transcriptQuery]:
94ab73e8a190 Uploaded
m-zytnicki
parents: 6
diff changeset
182 transcriptRef = self.flankings[transcriptQuery][relativeDirection]
94ab73e8a190 Uploaded
m-zytnicki
parents: 6
diff changeset
183 transcriptQuery = self.setTags(transcriptQuery, transcriptRef, relativeDirection)
94ab73e8a190 Uploaded
m-zytnicki
parents: 6
diff changeset
184 self.writer.addTranscript(transcriptQuery)
94ab73e8a190 Uploaded
m-zytnicki
parents: 6
diff changeset
185 else:
94ab73e8a190 Uploaded
m-zytnicki
parents: 6
diff changeset
186 transcriptRef = sorted(self.flankings[transcriptQuery].values(), key = lambda transcriptRef: transcriptQuery.getDistance(transcriptRef))[0]
94ab73e8a190 Uploaded
m-zytnicki
parents: 6
diff changeset
187 self.writer.addTranscript(self.setTags(transcriptQuery, transcriptRef, 0))
94ab73e8a190 Uploaded
m-zytnicki
parents: 6
diff changeset
188 progress.inc()
94ab73e8a190 Uploaded
m-zytnicki
parents: 6
diff changeset
189 progress.done()
6
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
190
18
94ab73e8a190 Uploaded
m-zytnicki
parents: 6
diff changeset
191 def run(self):
94ab73e8a190 Uploaded
m-zytnicki
parents: 6
diff changeset
192 for chromosome in sorted(self.transcripts[QUERY].keys()):
94ab73e8a190 Uploaded
m-zytnicki
parents: 6
diff changeset
193 self.flankings = dict([query, {}] for query in self.transcripts[QUERY][chromosome])
94ab73e8a190 Uploaded
m-zytnicki
parents: 6
diff changeset
194 for direction in STRANDS:
94ab73e8a190 Uploaded
m-zytnicki
parents: 6
diff changeset
195 #print "comparison", chromosome, direction
94ab73e8a190 Uploaded
m-zytnicki
parents: 6
diff changeset
196 self.getFlanking(chromosome, direction)
94ab73e8a190 Uploaded
m-zytnicki
parents: 6
diff changeset
197 self.write()
94ab73e8a190 Uploaded
m-zytnicki
parents: 6
diff changeset
198 self.writer.close()
6
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
199
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
200 if __name__ == "__main__":
18
94ab73e8a190 Uploaded
m-zytnicki
parents: 6
diff changeset
201
94ab73e8a190 Uploaded
m-zytnicki
parents: 6
diff changeset
202 description = "Get Flanking v1.0.1: Get the flanking regions of a set of reference. [Category: Data Selection]"
6
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
203
18
94ab73e8a190 Uploaded
m-zytnicki
parents: 6
diff changeset
204 parser = OptionParser(description = description)
94ab73e8a190 Uploaded
m-zytnicki
parents: 6
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]")
94ab73e8a190 Uploaded
m-zytnicki
parents: 6
diff changeset
206 parser.add_option("-f", "--format1", dest="format1", action="store", type="string", help="format of previous file [compulsory] [format: transcript file format]")
94ab73e8a190 Uploaded
m-zytnicki
parents: 6
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]")
94ab73e8a190 Uploaded
m-zytnicki
parents: 6
diff changeset
208 parser.add_option("-g", "--format2", dest="format2", action="store", type="string", help="format of previous file [compulsory] [format: transcript file format]")
94ab73e8a190 Uploaded
m-zytnicki
parents: 6
diff changeset
209 parser.add_option("-5", "--upstream", dest="upstream", action="store_true", default=False, help="output upstream elements [format: boolean] [default: False]")
94ab73e8a190 Uploaded
m-zytnicki
parents: 6
diff changeset
210 parser.add_option("-3", "--downstream", dest="downstream", action="store_true", default=False, help="output downstream elements [format: boolean] [default: False]")
94ab73e8a190 Uploaded
m-zytnicki
parents: 6
diff changeset
211 parser.add_option("-c", "--colinear", dest="colinear", action="store_true", default=False, help="find first colinear element [format: boolean] [default: False]")
94ab73e8a190 Uploaded
m-zytnicki
parents: 6
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]")
94ab73e8a190 Uploaded
m-zytnicki
parents: 6
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]")
94ab73e8a190 Uploaded
m-zytnicki
parents: 6
diff changeset
214 parser.add_option("-d", "--minDistance", dest="minDistance", action="store", default=None, type="int", help="minimum distance between 2 elements [format: int]")
94ab73e8a190 Uploaded
m-zytnicki
parents: 6
diff changeset
215 parser.add_option("-D", "--maxDistance", dest="maxDistance", action="store", default=None, type="int", help="maximum distance between 2 elements [format: int]")
94ab73e8a190 Uploaded
m-zytnicki
parents: 6
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]")
94ab73e8a190 Uploaded
m-zytnicki
parents: 6
diff changeset
217 parser.add_option("-o", "--output", dest="outputFileName", action="store", type="string", help="output file [format: output file in GFF3 format]")
94ab73e8a190 Uploaded
m-zytnicki
parents: 6
diff changeset
218 parser.add_option("-v", "--verbosity", dest="verbosity", action="store", default=1, type="int", help="trace level [format: int]")
94ab73e8a190 Uploaded
m-zytnicki
parents: 6
diff changeset
219 (options, args) = parser.parse_args()
6
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
220
18
94ab73e8a190 Uploaded
m-zytnicki
parents: 6
diff changeset
221 gf = GetFlanking(options.verbosity)
94ab73e8a190 Uploaded
m-zytnicki
parents: 6
diff changeset
222 gf.setInputFile(options.inputFileName1, options.format1, QUERY)
94ab73e8a190 Uploaded
m-zytnicki
parents: 6
diff changeset
223 gf.setInputFile(options.inputFileName2, options.format2, REFERENCE)
94ab73e8a190 Uploaded
m-zytnicki
parents: 6
diff changeset
224 gf.setOutputFile(options.outputFileName)
94ab73e8a190 Uploaded
m-zytnicki
parents: 6
diff changeset
225 gf.addUpstreamDirection(options.upstream)
94ab73e8a190 Uploaded
m-zytnicki
parents: 6
diff changeset
226 gf.addDownstreamDirection(options.downstream)
94ab73e8a190 Uploaded
m-zytnicki
parents: 6
diff changeset
227 gf.setColinear(options.colinear)
94ab73e8a190 Uploaded
m-zytnicki
parents: 6
diff changeset
228 gf.setAntisense(options.antisense)
94ab73e8a190 Uploaded
m-zytnicki
parents: 6
diff changeset
229 gf.setNoOverlap(options.noOverlap)
94ab73e8a190 Uploaded
m-zytnicki
parents: 6
diff changeset
230 gf.setMinDistance(options.minDistance)
94ab73e8a190 Uploaded
m-zytnicki
parents: 6
diff changeset
231 gf.setMaxDistance(options.maxDistance)
94ab73e8a190 Uploaded
m-zytnicki
parents: 6
diff changeset
232 gf.setNewTagName(options.tagName)
94ab73e8a190 Uploaded
m-zytnicki
parents: 6
diff changeset
233 gf.run()