Mercurial > repos > urgi-team > teiso
comparison TEisotools-1.0/commons/core/coord/Path.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 | |
| 32 from commons.core.coord.Set import Set | |
| 33 from commons.core.coord.Align import Align | |
| 34 from commons.core.coord.Range import Range | |
| 35 | |
| 36 | |
| 37 ## Handle a match between two sequences, query and subject (pair of coordinates with E-value, score and identity) with an identifier | |
| 38 # | |
| 39 class Path( Align ): | |
| 40 | |
| 41 __slots__ = ("id") | |
| 42 | |
| 43 ## Constructor | |
| 44 # | |
| 45 # @param id identifier | |
| 46 # @param range_q: a Range instance for the query | |
| 47 # @param range_s: a Range instance for the subject | |
| 48 # @param e_value: E-value of the match | |
| 49 # @param score: score of the match | |
| 50 # @param identity: identity percentage of the match | |
| 51 # | |
| 52 def __init__( self, id=-1, range_q=Range(), range_s=Range(), e_value=0, score=0, identity=0 ): | |
| 53 self.id = int( id ) | |
| 54 Align.__init__( self, range_q, range_s, e_value, score, identity ) | |
| 55 | |
| 56 ## Equal operator | |
| 57 # | |
| 58 def __eq__(self, o): | |
| 59 if type(o) is not type(self) or self.id != o.id: | |
| 60 return False | |
| 61 return Align.__eq__(self, o) | |
| 62 | |
| 63 ## Not equal operator | |
| 64 # | |
| 65 def __ne__(self, o): | |
| 66 return not self.__eq__(o) | |
| 67 | |
| 68 ## repr | |
| 69 # | |
| 70 def __repr__(self): | |
| 71 return self.toString() | |
| 72 | |
| 73 ## Set attributes from tuple | |
| 74 # | |
| 75 # @param tuple a tuple with (id,queryName,queryStart,queryEnd,subjectName,subjectStar,subjectEnd,E-value,score,identity) | |
| 76 # @note data are loaded such that the query is always on the direct strand | |
| 77 # | |
| 78 def setFromTuple(self, tuple): | |
| 79 self.id = int(tuple[0]) | |
| 80 Align.setFromTuple(self, tuple[1:]) | |
| 81 | |
| 82 ## Reset | |
| 83 # | |
| 84 def reset(self): | |
| 85 self.id = -1 | |
| 86 Align.reset(self) | |
| 87 | |
| 88 ## Return the attributes as a formatted string | |
| 89 # | |
| 90 def toString(self): | |
| 91 string = "%i" % ( self.id ) | |
| 92 string += "\t%s" % (Align.toString(self)) | |
| 93 return string | |
| 94 | |
| 95 | |
| 96 ## Return the identifier of the Path instance | |
| 97 # | |
| 98 def getIdentifier( self ): | |
| 99 return self.id | |
| 100 | |
| 101 ## Return a Set instance with the subject mapped on the query | |
| 102 # | |
| 103 def getSubjectAsSetOfQuery(self): | |
| 104 iSet = Set() | |
| 105 iSet.id = self.id | |
| 106 iSet.name = self.range_subject.seqname | |
| 107 iSet.seqname = self.range_query.seqname | |
| 108 if self.range_subject.isOnDirectStrand(): | |
| 109 iSet.start = self.range_query.start | |
| 110 iSet.end = self.range_query.end | |
| 111 else: | |
| 112 iSet.start = self.range_query.end | |
| 113 iSet.end = self.range_query.start | |
| 114 return iSet | |
| 115 | |
| 116 #TODO: add tests !!!! | |
| 117 #WARNING: subject always in direct strand !!! | |
| 118 ## Return a Set instance with the subject mapped on the query | |
| 119 # | |
| 120 def getQuerySetOfSubject(self): | |
| 121 iSet = Set() | |
| 122 iSet.id = self.id | |
| 123 iSet.name = self.range_query.seqname | |
| 124 iSet.seqname = self.range_subject.seqname | |
| 125 if self.range_subject.isOnDirectStrand(): | |
| 126 iSet.start = self.range_subject.start | |
| 127 iSet.end = self.range_subject.end | |
| 128 else: | |
| 129 iSet.start = self.range_subject.end | |
| 130 iSet.end = self.range_subject.start | |
| 131 return iSet | |
| 132 | |
| 133 ## Return True if the instance can be merged with another Path instance, False otherwise | |
| 134 # | |
| 135 # @param o a Path instance | |
| 136 # | |
| 137 def canMerge(self, o): | |
| 138 return o.id != self.id \ | |
| 139 and o.range_query.seqname == self.range_query.seqname \ | |
| 140 and o.range_subject.seqname == self.range_subject.seqname \ | |
| 141 and o.range_query.isOnDirectStrand() == self.range_query.isOnDirectStrand() \ | |
| 142 and o.range_subject.isOnDirectStrand() == self.range_subject.isOnDirectStrand() \ | |
| 143 and o.range_query.isOverlapping(self.range_query) \ | |
| 144 and o.range_subject.isOverlapping(self.range_subject) | |
| 145 | |
| 146 ## Return an Align instance with the same attributes, except the identifier | |
| 147 # | |
| 148 def getAlignInstance(self): | |
| 149 iAlign = Align() | |
| 150 lAttributes = [] | |
| 151 lAttributes.append( self.range_query.seqname ) | |
| 152 lAttributes.append( self.range_query.start ) | |
| 153 lAttributes.append( self.range_query.end ) | |
| 154 lAttributes.append( self.range_subject.seqname ) | |
| 155 lAttributes.append( self.range_subject.start ) | |
| 156 lAttributes.append( self.range_subject.end ) | |
| 157 lAttributes.append( self.e_value ) | |
| 158 lAttributes.append( self.score ) | |
| 159 lAttributes.append( self.identity ) | |
| 160 iAlign.setFromTuple( lAttributes ) | |
| 161 return iAlign |
