annotate SMART/Java/Python/structure/Interval.py @ 6:769e306b7933

Change the repository level.
author yufei-luo
date Fri, 18 Jan 2013 04:54:14 -0500
parents
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 #
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
2 # Copyright INRA-URGI 2009-2010
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
3 #
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
4 # This software is governed by the CeCILL license under French law and
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
5 # abiding by the rules of distribution of free software. You can use,
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
6 # modify and/ or redistribute the software under the terms of the CeCILL
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
7 # license as circulated by CEA, CNRS and INRIA at the following URL
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
8 # "http://www.cecill.info".
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
9 #
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
10 # As a counterpart to the access to the source code and rights to copy,
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
11 # modify and redistribute granted by the license, users are provided only
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
12 # with a limited warranty and the software's author, the holder of the
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
13 # economic rights, and the successive licensors have only limited
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
14 # liability.
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
15 #
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
16 # In this respect, the user's attention is drawn to the risks associated
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
17 # with loading, using, modifying and/or developing or reproducing the
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
18 # software by the user in light of its specific status of free software,
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
19 # that may mean that it is complicated to manipulate, and that also
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
20 # therefore means that it is reserved for developers and experienced
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
21 # professionals having in-depth computer knowledge. Users are therefore
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
22 # encouraged to load and test the software's suitability as regards their
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
23 # requirements in conditions enabling the security of their systems and/or
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
24 # data to be ensured and, more generally, to use and operate it in the
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
25 # same conditions as regards security.
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
26 #
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
27 # The fact that you are presently reading this means that you have had
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
28 # knowledge of the CeCILL license and that you accept its terms.
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
29 #
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
30
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
31 from SMART.Java.Python.structure.Bins import *
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
32 from commons.core.coord.Range import Range
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
33
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
34 class Interval(Range):
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
35 """
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
36 Store a genomic interval
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
37 @ivar name: name of the interval [optional]
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
38 @type name: string
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
39 @ivar id: id of the interval [optional]
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
40 @type id: int
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
41 @ivar bin: bin in which the interval should be if stored in a database [computed]
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
42 @type bin: int
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
43 @ival tags: information about the transcript [optional]
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
44 @type tags: dict
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
45 @ivar verbosity: verbosity
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
46 @type verbosity: int [default: 0]
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
47 """
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
48
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
49 def __init__(self, interval = None, verbosity = 0):
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
50 """
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
51 Constructor
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
52 @param interval: interval to be copied
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
53 @type interval: class L{Interval<Interval>}
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
54 @param verbosity: verbosity
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
55 @type verbosity: int
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
56 """
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
57 Range.__init__(self)
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
58 self.name = None
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
59 self.id = None
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
60 self.bin = None
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
61 self.verbosity = verbosity
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
62 self.tags = {}
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
63 if interval != None:
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
64 self.copy(interval)
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
65
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
66 #!!!! Warning: two methods getStart() and getEnd() give the information maximum and minimum in interval.!!!!#
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
67 #In case strand = "+", start < end; strand = "-", start > end
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
68 def getStart(self):
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
69 if self.start == -1:
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
70 return -1
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
71 if self.end == -1:
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
72 return self.start
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
73 return self.getMin()
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
74
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
75
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
76 def getEnd(self):
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
77 if self.end == -1:
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
78 return -1
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
79 if self.start == -1:
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
80 return self.end
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
81 return self.getMax()
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
82
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
83
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
84 def getChromosome(self):
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
85 return self.getSeqname()
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
86
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
87
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
88 def getDirection(self):
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
89 return 1 if self.getStrand() == "+" else -1
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
90
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
91
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
92 def getName(self):
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
93 return self.name
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
94
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
95
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
96 def isSet(self):
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
97 """
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
98 Check if the interval is set
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
99 """
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
100 return self.getStart() == None and self.getEnd() == None
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
101
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
102
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
103 def copy(self, interval):
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
104 """
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
105 Copy method
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
106 @param interval: interval to be copied
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
107 @type interval: class L{Interval<Interval>}
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
108 """
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
109 self.setStart(interval.getStart())
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
110 self.setEnd(interval.getEnd())
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
111 self.setChromosome(interval.getChromosome())
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
112 self.setDirection(interval.getDirection())
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
113 self.name = interval.name
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
114 self.id = interval.id
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
115 self.bin = interval.bin
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
116 self.tags = {}
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
117 for tag in interval.tags:
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
118 self.tags[tag] = interval.tags[tag]
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
119 self.verbosity = interval.verbosity
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
120
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
121
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
122 def setName(self, name):
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
123 """
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
124 Set the name
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
125 @param name: name of the interval
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
126 @type name: string
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
127 """
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
128 if len(name) > 100:
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
129 name = name[:100]
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
130 self.name = name
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
131
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
132
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
133 def setChromosome(self, chromosome=""):
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
134 """
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
135 Set the chromosome
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
136 @param chromosome: chromosome on which the interval is
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
137 @type chromosome: string
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
138 """
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
139 if not chromosome:
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
140 self.seqname = None
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
141 else:
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
142 self.seqname = chromosome.replace(".", "_").replace("|", "_")
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
143
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
144
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
145 def setStart(self, start):
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
146 """
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
147 Set the start point
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
148 Possibly reset bin
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
149 @param start: start point of the interval
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
150 @type start: int
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
151 """
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
152 self.bin = None
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
153 direction = self.getDirection()
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
154 if self.start == -1:
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
155 self.start = start
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
156 elif self.end == -1:
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
157 self.end = start
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
158 else:
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
159 if direction == 1:
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
160 self.start = start
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
161 else:
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
162 self.end = start
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
163 if direction == 1:
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
164 self.start, self.end = min(self.start, self.end), max(self.start, self.end)
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
165 else:
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
166 self.start, self.end = max(self.start, self.end), min(self.start, self.end)
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
167
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
168
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
169 def setEnd(self, end):
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
170 """
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
171 Set the end point
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
172 Possibly reset bin
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
173 @param end: end point of the interval of the interval
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
174 @type end: int
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
175 """
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
176 self.bin = None
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
177 direction = self.getDirection()
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
178 if self.end == -1:
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
179 self.end = end
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
180 elif self.start == -1:
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
181 self.start = end
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
182 else:
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
183 if direction == 1:
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
184 self.end = end
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
185 else:
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
186 self.start = end
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
187 if direction == 1:
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
188 self.start, self.end = min(self.start, self.end), max(self.start, self.end)
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
189 else:
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
190 self.start, self.end = max(self.start, self.end), min(self.start, self.end)
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
191
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
192
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
193 def setSize(self, size):
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
194 """
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
195 Possibly modify the end point
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
196 @param size: size of the transcript
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
197 @type size: int
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
198 """
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
199 if self.end == None and self.start != None:
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
200 self.setEnd(self.start + self.getSize() - 1)
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
201 elif self.start == None and self.end != None:
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
202 self.setStart(self.end - self.getSize() + 1)
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
203
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
204
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
205 def getSize(self):
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
206 """
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
207 Get the size
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
208 """
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
209 return self.getEnd() - self.getStart() + 1
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
210
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
211
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
212 def _setDirection(self, direction):
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
213 """
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
214 Set the direction of the interval (connection to Range)
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
215 @param direction: direction of the transcript (+ / -)
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
216 @type direction: int (1 or -1)
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
217 """
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
218 if direction * self.getDirection() < 0:
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
219 self.reverse()
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
220
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
221
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
222 def setDirection(self, direction):
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
223 """
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
224 Set the direction of the interval
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
225 Possibly parse different formats
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
226 @param direction: direction of the transcript (+ / -)
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
227 @type direction: int or string
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
228 """
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
229 if type(direction).__name__ == 'int':
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
230 self._setDirection(direction / abs(direction))
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
231 elif type(direction).__name__ == 'str':
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
232 if direction == "+":
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
233 self._setDirection(1)
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
234 elif direction == "-":
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
235 self._setDirection(-1)
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
236 elif direction == "1" or direction == "-1":
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
237 self._setDirection(int(direction))
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
238 elif direction.lower() == "plus":
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
239 self._setDirection(1)
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
240 elif direction.lower() == "minus":
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
241 self._setDirection(-1)
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
242 else:
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
243 raise Exception("Cannot understand direction %s" % (direction))
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
244 else:
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
245 raise Exception("Cannot understand direction %s" % (direction))
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
246
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
247
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
248 def extendStart(self, size):
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
249 """
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
250 Extend the interval by the 5' end
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
251 @param size: the size to be exended
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
252 @type size: int
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
253 """
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
254 if self.getDirection() == 1:
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
255 self.setStart(max(0, self.getStart() - size))
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
256 else:
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
257 self.setEnd(self.getEnd() + size)
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
258 self.bin = None
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
259
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
260
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
261 def extendEnd(self, size):
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
262 """
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
263 Extend the interval by the 3' end
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
264 @param size: the size to be exended
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
265 @type size: int
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
266 """
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
267 if self.getDirection() == 1:
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
268 self.setEnd(self.getEnd() + size)
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
269 else:
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
270 self.setStart(max(0, self.getStart() - size))
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
271 self.bin = None
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
272
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
273
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
274 def restrictStart(self, size = 1):
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
275 """
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
276 Restrict the interval by some nucleotides, start from its start position
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
277 Remove the exons
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
278 @param size: the size to be restricted to
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
279 @type size: int
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
280 """
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
281 if self.getDirection() == 1:
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
282 self.setEnd(min(self.getEnd(), self.getStart() + size - 1))
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
283 else:
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
284 self.setStart(max(self.getStart(), self.getEnd() - size + 1))
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
285 self.bin = None
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
286
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
287
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
288 def restrictEnd(self, size = 1):
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
289 """
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
290 Restrict the interval by some nucleotides, end from its end position
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
291 Remove the exons
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
292 @param size: the size to be restricted to
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
293 @type size: int
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
294 """
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
295 if self.getDirection() == 1:
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
296 self.setStart(max(self.getStart(), self.getEnd() - size + 1))
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
297 else:
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
298 self.setEnd(min(self.getEnd(), self.getStart() + size - 1))
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
299 self.bin = None
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
300
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
301
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
302
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
303 def setTagValue(self, name, value):
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
304 """
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
305 Set a tag
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
306 @param name: name of the tag
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
307 @type name: string
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
308 @param value: value of the tag
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
309 @type value: int or string
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
310 """
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
311 self.tags[name] = value
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
312
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
313
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
314 def getTagNames(self):
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
315 """
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
316 Get all the names of the tags
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
317 """
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
318 return self.tags.keys()
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
319
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
320
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
321 def getTagValue(self, tag):
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
322 """
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
323 Get the value of a tag
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
324 @param tag: name of a tag
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
325 @type tag: string
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
326 """
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
327 if tag not in self.tags:
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
328 return None
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
329 return self.tags[tag]
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
330
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
331
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
332 def getTagValues(self, tagSep = "; ", fieldSep = " ", surrounder = ""):
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
333 """
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
334 Get the formatted tag values
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
335 @param tagSep: separator between tags
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
336 @type tagSep: string
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
337 @param fieldSep: separator between tag name and tag value
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
338 @type fieldSep: string
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
339 @param surrounder: string which optionally surround values
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
340 @type surrounder: string
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
341 """
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
342 tags = []
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
343 for name in self.tags:
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
344 value = self.tags[name]
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
345 if value == None:
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
346 continue
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
347 if isinstance(value, basestring):
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
348 tags.append("%s%s%s%s%s" % (name, fieldSep, surrounder, self.tags[name], surrounder))
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
349 elif type(value) is int:
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
350 tags.append("%s%s%s%i%s" % (name, fieldSep, surrounder, self.tags[name], surrounder))
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
351 elif type(value) is float:
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
352 tags.append("%s%s%s%f%s" % (name, fieldSep, surrounder, self.tags[name], surrounder))
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
353 else:
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
354 raise Exception("Do not know how to print '" + value + "'.")
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
355 if self.getName() != None:
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
356 tags.append("%s%s%s%s%s" % ("Name", fieldSep, surrounder, self.getName(), surrounder))
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
357 return tagSep.join(tags)
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
358
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
359
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
360 def setTagValues(self, tags, tagSep = "; ", fieldSep = " "):
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
361 """
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
362 Set the tag values using given string
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
363 @param tags: the tags, concatenated
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
364 @type tags: string
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
365 @param tagSep: separator between tags
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
366 @type tagSep: string
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
367 @param fieldSep: separator between tag name and tag value
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
368 @type fieldSep: string
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
369 """
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
370 if tags == "":
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
371 self.tags = {}
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
372 return
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
373 for splittedTag in tags.split(tagSep):
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
374 if fieldSep not in splittedTag:
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
375 raise Exception("Weird field '%s' in tags '%s'" % (splittedTag, tags))
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
376 tag, value = splittedTag.split(fieldSep, 1)
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
377 if tag == "Name":
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
378 self.setName(value)
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
379 continue
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
380 try:
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
381 intValue = int(value)
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
382 self.tags[tag] = intValue
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
383 except ValueError:
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
384 try:
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
385 floatValue = float(value)
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
386 self.tags[tag] = floatValue
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
387 except ValueError:
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
388 self.tags[tag] = value
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
389
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
390
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
391 def deleteTag(self, tag):
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
392 """
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
393 Remove a tag
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
394 @param tag: the tag to be removed
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
395 @type tag: string
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
396 """
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
397 if tag in self.tags:
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
398 del self.tags[tag]
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
399
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
400
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
401 def setNbOccurrences(self, nbOccurrences):
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
402 """
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
403 Set the number of occurrences of the interval
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
404 @param nbOccurrences: number of occurrences of the interval
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
405 @type nbOccurrences: int
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
406 """
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
407 self.setTagValue("nbOccurrences", nbOccurrences)
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
408
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
409
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
410 def setOccurrence(self, occurrence):
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
411 """
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
412 Set the occurrence of this interval
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
413 @param occurrence: an occurrence for this transcript
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
414 @type occurrence: int
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
415 """
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
416 self.setTagValue("occurrence", occurrence)
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
417
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
418 def __eq__(self, interval):
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
419 """
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
420 Whether two intervals are equal (start and end at same position)
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
421 @param interval: object to be compared to
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
422 @type interval: class L{Interval<Interval>}
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
423 """
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
424 if not interval:
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
425 return False
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
426 return self.getChromosome() == interval.getChromosome() and self.getStart() == interval.getStart() and self.getEnd() == interval.getEnd() and self.getDirection() == interval.getDirection()
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
427
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
428
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
429 def overlapWith(self, interval, nbNucleotides = 1):
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
430 """
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
431 Whether two intervals overlap
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
432 @param interval: object to be compared to
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
433 @type interval: class L{Interval<Interval>}
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
434 @param nbNucleotides: minimum number of nucleotides to declare and overlap
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
435 @type nbNucleotides: int
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
436 """
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
437 if self.getChromosome() != interval.getChromosome():
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
438 return False
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
439 return (min(self.getEnd(), interval.getEnd()) - max(self.getStart(), interval.getStart()) + 1 >= nbNucleotides)
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
440
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
441 def isIncludeIn(self, interval):
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
442 return interval.include(self)
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
443
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
444
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
445 def include(self, interval):
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
446 """
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
447 Whether this interval includes the other one
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
448 @param interval: object to be compared to
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
449 @type interval: class L{Interval<Interval>}
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
450 """
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
451 if self.getChromosome() != interval.getChromosome():
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
452 return False
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
453 return ((self.getStart() <= interval.getStart()) and (self.getEnd() >= interval.getEnd()))
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
454
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
455
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
456 def getDifference(self, interval, sameStrand = False):
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
457 """
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
458 Get the difference between this cluster and another one
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
459 @param interval: object to be compared to
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
460 @type interval: class L{Interval<Interval>}
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
461 @param sameStrand: do the comparison iff the intervals are on the same strand
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
462 @type sameStrand: boolean
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
463 @return: a (possibly empty) list of intervals
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
464 """
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
465 newInterval = Interval()
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
466 newInterval.copy(self)
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
467 if self.getChromosome() != interval.getChromosome():
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
468 return [newInterval]
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
469 if not self.overlapWith(interval):
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
470 return [newInterval]
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
471 if sameStrand and self.getDirection() != interval.getDirection():
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
472 return [newInterval]
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
473 intervals = []
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
474 if self.getStart() < interval.getStart():
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
475 newInterval = Interval()
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
476 newInterval.copy(self)
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
477 newInterval.setEnd(min(self.getEnd(), interval.getStart() - 1))
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
478 intervals.append(newInterval)
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
479 if self.getEnd() > interval.getEnd():
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
480 newInterval = Interval()
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
481 newInterval.copy(self)
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
482 newInterval.setStart(max(self.getStart(), interval.getEnd() + 1))
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
483 intervals.append(newInterval)
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
484 return intervals
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
485
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
486
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
487 def getIntersection(self, interval):
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
488 """
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
489 Get the intersection between this interval and another one
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
490 @param interval: object to be compared to
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
491 @type interval: class L{Interval<Interval>}
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
492 @return: an other interval
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
493 """
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
494 if not self.overlapWith(interval):
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
495 return None
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
496 newInterval = Interval()
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
497 newInterval.setChromosome(self.getChromosome())
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
498 newInterval.setDirection(self.getDirection())
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
499 newInterval.setName("%s_intersect_%s" % (self.getName(), interval.getName()))
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
500 newInterval.setStart(max(self.getStart(), interval.getStart()))
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
501 newInterval.setEnd(min(self.getEnd(), interval.getEnd()))
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
502 return newInterval
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
503
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
504
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
505 def getDistance(self, interval):
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
506 """
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
507 Get the distance between two intervals (a non-negative value)
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
508 @param interval: another interval
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
509 @type interval: class L{Interval<Interval>}
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
510 """
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
511 if self.overlapWith(interval):
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
512 return 0
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
513 if self.getChromosome() != interval.getChromosome():
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
514 raise Exception("Cannot get the distance between %s and %s" % (str(self), str(interval)))
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
515 return min(abs(self.getStart() - interval.getEnd()), abs(self.getEnd() - interval.getStart()))
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
516
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
517
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
518 def getRelativeDistance(self, interval):
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
519 """
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
520 Get the distance between two intervals (negative if first interval is before)
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
521 @param interval: another interval
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
522 @type interval: class L{Interval<Interval>}
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
523 """
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
524 if self.overlapWith(interval):
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
525 return 0
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
526 if self.getChromosome() != interval.getChromosome():
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
527 raise Exception("Cannot get the distance between %s and %s" % (str(self), str(interval)))
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
528 if self.getEnd() < interval.getStart():
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
529 distance = interval.getStart() - self.getEnd()
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
530 else:
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
531 distance = interval.getEnd() - self.getStart()
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
532 distance *= self.getDirection()
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
533 return distance
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
534
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
535
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
536 def merge(self, interval, normalization = False):
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
537 """
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
538 Merge two intervals
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
539 @param interval: another interval
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
540 @type interval: class L{Interval<Interval>}
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
541 @param normalization: whether the sum of the merge should be normalized wrt the number of mappings of each elements
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
542 @type normalization: boolean
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
543 """
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
544 if self.getChromosome() != interval.getChromosome():
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
545 raise Exception("Cannot merge '%s' and '%s' for they are on different chromosomes." % (str(self), str(interval)))
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
546 direction = None
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
547 if self.getStart() == self.getEnd():
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
548 direction = interval.getDirection()
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
549 elif interval.getStart() == interval.getEnd():
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
550 direction = self.getDirection()
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
551 elif self.getDirection() != interval.getDirection():
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
552 raise Exception("Cannot merge '%s' and '%s' for they are on different strands." % (str(self), str(interval)))
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
553 self.setStart(min(self.getStart(), interval.getStart()))
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
554 self.setEnd(max(self.getEnd(), interval.getEnd()))
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
555 if direction != None:
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
556 self.setDirection(direction)
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
557 nbElements = 0.0
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
558 for element in (self, interval):
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
559 for tagName in ("nbElements", "nbOccurrences"):
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
560 if tagName not in element.getTagNames():
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
561 element.setTagValue(tagName, 1)
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
562 nbElements += float(element.getTagValue("nbElements")) / float(element.getTagValue("nbOccurrences")) if normalization else float(element.getTagValue("nbElements"))
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
563 self.setTagValue("nbElements", nbElements)
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
564 self.bin = None
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
565 for tagName in ("identity", "nbOccurrences", "occurrence", "nbMismatches", "nbGaps", "rank", "evalue", "bestRegion"):
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
566 if tagName in self.getTagNames():
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
567 del self.tags[tagName]
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
568
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
569
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
570 def getBin(self):
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
571 """
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
572 Get the bin of the interval
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
573 Computed on the fly
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
574 """
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
575 if self.bin == None:
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
576 self.bin = getBin(self.getStart(), self.getEnd())
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
577 return self.bin
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
578
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
579
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
580 def getBins(self):
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
581 """
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
582 Get all the bin this interval could fall into
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
583 """
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
584 return getOverlappingBins(self.getStart(), self.getEnd())
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
585
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
586
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
587 def getSqlVariables(cls):
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
588 """
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
589 Get the properties of the object that should be saved in a database
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
590 """
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
591 variables = ["name", "chromosome", "start", "end", "direction", "tags", "bin"]
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
592 return variables
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
593 getSqlVariables = classmethod(getSqlVariables)
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
594
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
595
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
596 def setSqlValues(self, array):
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
597 """
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
598 Set the values of the properties of this object as given by a results line of a SQL query
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
599 """
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
600 self.id = array[0]
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
601 self.name = array[1].strip("'")
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
602 self.setChromosome(array[2].strip("'"))
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
603 self.setStart(array[3])
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
604 self.setEnd(array[4])
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
605 self.setDirection(array[5])
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
606 self.setTagValues(array[6].strip("'"), ";", "=")
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
607 self.bin = array[7]
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
608
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
609
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
610 def getSqlValues(self):
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
611 """
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
612 Get the values of the properties that should be saved in a database
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
613 """
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
614 values = dict()
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
615 values["name"] = self.name
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
616 values["chromosome"] = self.getChromosome()
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
617 values["start"] = self.getStart()
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
618 values["end"] = self.getEnd()
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
619 values["direction"] = self.getDirection()
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
620 values["tags"] = self.getTagValues(";", "=")
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
621 values["bin"] = self.getBin()
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
622 return values
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
623
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
624
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
625 def getSqlTypes(cls):
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
626 """
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
627 Get the values of the properties that should be saved in a database
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
628 """
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
629 types = dict()
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
630 types["name"] = "varchar"
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
631 types["chromosome"] = "varchar"
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
632 types["start"] = "int"
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
633 types["end"] = "int"
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
634 types["direction"] = "tinyint"
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
635 types["tags"] = "varchar"
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
636 types["bin"] = "int"
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
637 return types
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
638 getSqlTypes = classmethod(getSqlTypes)
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
639
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
640
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
641 def getSqlSizes(cls):
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
642 """
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
643 Get the sizes of the properties that should be saved in a database
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
644 """
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
645 sizes = dict()
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
646 sizes["name"] = 255
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
647 sizes["chromosome"] = 255
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
648 sizes["start"] = 11
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
649 sizes["end"] = 11
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
650 sizes["direction"] = 4
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
651 sizes["tags"] = 1023
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
652 sizes["bin"] = 11
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
653 return sizes
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
654 getSqlSizes = classmethod(getSqlSizes)
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
655
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
656
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
657 def printCoordinates(self):
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
658 """
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
659 Print start and end positions (depending on the direction of the interval)
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
660 """
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
661 if self.getDirection() == 1:
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
662 return "%d-%d" % (self.getStart(), self.getEnd())
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
663 else:
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
664 return "%d-%d" % (self.getEnd(), self.getStart())
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
665
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
666
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
667 def extractSequence(self, parser):
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
668 """
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
669 Get the sequence corresponding to this interval
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
670 @param parser: a parser to a FASTA file
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
671 @type parser: class L{SequenceListParser<SequenceListParser>}
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
672 @return : a instance of L{Sequence<Sequence>}
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
673 """
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
674 return parser.getSubSequence(self.getChromosome(), self.getStart(), self.getEnd(), self.getDirection(), self.name)
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
675
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
676
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
677 def extractWigData(self, parser):
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
678 """
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
679 Get the data retrieved from a wig file
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
680 @param parser: a parser class to a WIG file
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
681 @type parser: class L{WigParser<WigParser>}
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
682 """
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
683 data = parser.getRange(self.getChromosome(), self.getStart(), self.getEnd())
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
684 if self.getDirection() == -1:
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
685 if parser.strands:
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
686 newData = {}
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
687 for strand in data:
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
688 data[strand].reverse()
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
689 newData[-strand] = data[strand]
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
690 data = newData
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
691 else:
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
692 data.reverse()
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
693 return data
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
694
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
695
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
696 def __str__(self):
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
697 """
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
698 Output a simple representation of this interval
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
699 """
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
700 direction = "+"
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
701 if self.getDirection() == -1:
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
702 direction = "-"
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
703 string = "%s:%d-%d (%s)" % (self.getChromosome(), self.getStart(), self.getEnd(), direction)
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
704 if self.name != "":
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
705 string = "(%s) %s" % (self.name, string)
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
706 return string
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
707