Mercurial > repos > yufei-luo > s_mart
comparison commons/core/coord/MergedRange.py @ 36:44d5973c188c
Uploaded
author | m-zytnicki |
---|---|
date | Tue, 30 Apr 2013 15:02:29 -0400 |
parents | 769e306b7933 |
children |
comparison
equal
deleted
inserted
replaced
35:d94018ca4ada | 36:44d5973c188c |
---|---|
1 # Copyright INRA (Institut National de la Recherche Agronomique) | |
2 # http://www.inra.fr | |
3 # http://urgi.versailles.inra.fr | |
4 # | |
5 # This software is governed by the CeCILL license under French law and | |
6 # abiding by the rules of distribution of free software. You can use, | |
7 # modify and/ or redistribute the software under the terms of the CeCILL | |
8 # license as circulated by CEA, CNRS and INRIA at the following URL | |
9 # "http://www.cecill.info". | |
10 # | |
11 # As a counterpart to the access to the source code and rights to copy, | |
12 # modify and redistribute granted by the license, users are provided only | |
13 # with a limited warranty and the software's author, the holder of the | |
14 # economic rights, and the successive licensors have only limited | |
15 # liability. | |
16 # | |
17 # In this respect, the user's attention is drawn to the risks associated | |
18 # with loading, using, modifying and/or developing or reproducing the | |
19 # software by the user in light of its specific status of free software, | |
20 # that may mean that it is complicated to manipulate, and that also | |
21 # therefore means that it is reserved for developers and experienced | |
22 # professionals having in-depth computer knowledge. Users are therefore | |
23 # encouraged to load and test the software's suitability as regards their | |
24 # requirements in conditions enabling the security of their systems and/or | |
25 # data to be ensured and, more generally, to use and operate it in the | |
26 # same conditions as regards security. | |
27 # | |
28 # The fact that you are presently reading this means that you have had | |
29 # knowledge of the CeCILL license and that you accept its terms. | |
30 | |
31 ## Record a region on multiple sequence using Path ID information | |
32 # | |
33 class MergedRange(object): | |
34 | |
35 ## Constructor | |
36 # | |
37 # @param lId list of Path ID | |
38 # @param start the start coordinate | |
39 # @param end the end coordinate | |
40 # | |
41 def __init__(self, lId = None, start = -1, end = -1): | |
42 self._lId = lId or [] | |
43 self._start = start | |
44 self._end = end | |
45 | |
46 ## Equal operator | |
47 # | |
48 # @param o a MergedRange instance | |
49 # | |
50 def __eq__(self, o): | |
51 return o._lId == self._lId and o._start == self._start and o._end == self._end | |
52 | |
53 | |
54 ## Return True if the MergedRange instance overlaps with another MergedRange instance, False otherwise | |
55 # | |
56 # @param o a MergedRange instance | |
57 # @return boolean False or True | |
58 # | |
59 def isOverlapping(self, o): | |
60 if o._start <= self._start and o._end >= self._end: | |
61 return True | |
62 if o._start >= self._start and o._start <= self._end or o._end >= self._start and o._end <= self._end: | |
63 return True | |
64 return False | |
65 | |
66 ## Merge coordinates and ID of two Merged Range | |
67 # | |
68 # @param o a MergedRange instance | |
69 # | |
70 def merge(self, o): | |
71 self._start = min(self._start, o._start) | |
72 self._end = max(self._end, o._end) | |
73 self._lId.extend(o._lId) | |
74 self._lId.sort() | |
75 | |
76 ## Set a Merged Range instance using a Match instance | |
77 # | |
78 # @param iMatch instance Match instance | |
79 # | |
80 def setFromMatch(self, iMatch): | |
81 self._lId= [iMatch.id] | |
82 self._start = iMatch.range_query.start | |
83 self._end = iMatch.range_query.end | |
84 | |
85 ## Get a Merged Range instance list using a Match instance list | |
86 # | |
87 # @param lIMatch list Match instance list | |
88 # @return lMergedRange list MergedRange instance list | |
89 # | |
90 def getMergedRangeListFromMatchList(lIMatch): | |
91 lMergedRange = [] | |
92 for iMatch in lIMatch: | |
93 mr = MergedRange() | |
94 mr.setFromMatch(iMatch) | |
95 lMergedRange.append(mr) | |
96 return lMergedRange | |
97 | |
98 getMergedRangeListFromMatchList = staticmethod(getMergedRangeListFromMatchList) |