Mercurial > repos > urgi-team > teiso
comparison TEisotools-1.0/commons/core/coord/MergedRange.py @ 6:20ec0d14798e draft
Uploaded
| author | urgi-team |
|---|---|
| date | Wed, 20 Jul 2016 05:00:24 -0400 |
| parents | |
| children |
comparison
equal
deleted
inserted
replaced
| 5:4093a2fb58be | 6:20ec0d14798e |
|---|---|
| 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 __slots__ = ("_lId", "_start", "_end") | |
| 36 | |
| 37 ## Constructor | |
| 38 # | |
| 39 # @param lId list of Path ID | |
| 40 # @param start the start coordinate | |
| 41 # @param end the end coordinate | |
| 42 # | |
| 43 def __init__(self, lId = None, start = -1, end = -1): | |
| 44 self._lId = lId or [] | |
| 45 self._start = start | |
| 46 self._end = end | |
| 47 | |
| 48 ## Equal operator | |
| 49 # | |
| 50 # @param o a MergedRange instance | |
| 51 # | |
| 52 def __eq__(self, o): | |
| 53 if type(o) is type(self): | |
| 54 return o._lId == self._lId and o._start == self._start and o._end == self._end | |
| 55 else: | |
| 56 return False | |
| 57 | |
| 58 ## Not equal operator | |
| 59 # | |
| 60 def __ne__(self, o): | |
| 61 return not self.__eq__(o) | |
| 62 | |
| 63 ## Return True if the MergedRange instance overlaps with another MergedRange instance, False otherwise | |
| 64 # | |
| 65 # @param o a MergedRange instance | |
| 66 # @return boolean False or True | |
| 67 # | |
| 68 def isOverlapping(self, o): | |
| 69 if o._start <= self._start and o._end >= self._end: | |
| 70 return True | |
| 71 if o._start >= self._start and o._start <= self._end or o._end >= self._start and o._end <= self._end: | |
| 72 return True | |
| 73 return False | |
| 74 | |
| 75 ## Merge coordinates and ID of two Merged Range | |
| 76 # | |
| 77 # @param o a MergedRange instance | |
| 78 # | |
| 79 def merge(self, o): | |
| 80 self._start = min(self._start, o._start) | |
| 81 self._end = max(self._end, o._end) | |
| 82 self._lId.extend(o._lId) | |
| 83 self._lId.sort() | |
| 84 | |
| 85 ## Set a Merged Range instance using a Match instance | |
| 86 # | |
| 87 # @param iMatch instance Match instance | |
| 88 # | |
| 89 def setFromMatch(self, iMatch): | |
| 90 self._lId= [iMatch.id] | |
| 91 self._start = iMatch.range_query.start | |
| 92 self._end = iMatch.range_query.end | |
| 93 | |
| 94 ## Get a Merged Range instance list using a Match instance list | |
| 95 # | |
| 96 # @param lIMatch list Match instance list | |
| 97 # @return lMergedRange list MergedRange instance list | |
| 98 # | |
| 99 @staticmethod | |
| 100 def getMergedRangeListFromMatchList(lIMatch): | |
| 101 lMergedRange = [] | |
| 102 for iMatch in lIMatch: | |
| 103 mr = MergedRange() | |
| 104 mr.setFromMatch(iMatch) | |
| 105 lMergedRange.append(mr) | |
| 106 return lMergedRange |
