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