annotate commons/core/coord/Path.py @ 32:3441fe98a2ba

Deleted selected files
author m-zytnicki
date Tue, 30 Apr 2013 14:34:10 -0400
parents 769e306b7933
children
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 # Copyright INRA (Institut National de la Recherche Agronomique)
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
2 # http://www.inra.fr
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
3 # http://urgi.versailles.inra.fr
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
4 #
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
5 # This software is governed by the CeCILL license under French law and
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
6 # abiding by the rules of distribution of free software. You can use,
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
7 # modify and/ or redistribute the software under the terms of the CeCILL
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
8 # license as circulated by CEA, CNRS and INRIA at the following URL
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
9 # "http://www.cecill.info".
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
10 #
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
11 # As a counterpart to the access to the source code and rights to copy,
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
12 # modify and redistribute granted by the license, users are provided only
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
13 # with a limited warranty and the software's author, the holder of the
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
14 # economic rights, and the successive licensors have only limited
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
15 # liability.
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
16 #
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
17 # In this respect, the user's attention is drawn to the risks associated
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
18 # with loading, using, modifying and/or developing or reproducing the
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
19 # software by the user in light of its specific status of free software,
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
20 # that may mean that it is complicated to manipulate, and that also
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
21 # therefore means that it is reserved for developers and experienced
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
22 # professionals having in-depth computer knowledge. Users are therefore
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
23 # encouraged to load and test the software's suitability as regards their
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
24 # requirements in conditions enabling the security of their systems and/or
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
25 # data to be ensured and, more generally, to use and operate it in the
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
26 # same conditions as regards security.
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
27 #
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
28 # The fact that you are presently reading this means that you have had
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
29 # knowledge of the CeCILL license and that you accept its terms.
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
30
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
31
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
32 from commons.core.coord.Align import Align
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
33 from commons.core.coord.Set import Set
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
34 from commons.core.coord.Range import Range
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
35
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
36
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
37 ## Handle a match between two sequences, query and subject (pair of coordinates with E-value, score and identity) with an identifier
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
38 #
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
39 class Path( Align ):
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
40
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
41 ## Constructor
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
42 #
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
43 # @param id identifier
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
44 # @param range_q: a Range instance for the query
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
45 # @param range_s: a Range instance for the subject
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
46 # @param e_value: E-value of the match
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
47 # @param score: score of the match
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
48 # @param identity: identity percentage of the match
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
49 #
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
50 def __init__( self, id=-1, range_q=Range(), range_s=Range(), e_value=0, score=0, identity=0 ):
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
51 self.id = int( id )
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
52 Align.__init__( self, range_q, range_s, e_value, score, identity )
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
53
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
54 ## Equal operator
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
55 #
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
56 def __eq__(self, o):
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
57 if o == None or self.id != o.id:
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
58 return False
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
59 return Align.__eq__(self, o)
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
60
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
61 ## Set attributes from tuple
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
62 #
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
63 # @param tuple a tuple with (id,queryName,queryStart,queryEnd,subjectName,subjectStar,subjectEnd,E-value,score,identity)
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
64 # @note data are loaded such that the query is always on the direct strand
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
65 #
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
66 def setFromTuple(self, tuple):
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
67 self.id = int(tuple[0])
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
68 Align.setFromTuple(self, tuple[1:])
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
69
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
70 ## Reset
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
71 #
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
72 def reset(self):
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
73 self.id = -1
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
74 Align.reset(self)
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
75
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
76 ## Return the attributes as a formatted string
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
77 #
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
78 def toString(self):
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
79 string = "%i" % ( self.id )
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
80 string += "\t%s" % (Align.toString(self))
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
81 return string
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 ## Return the identifier of the Path instance
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
85 #
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
86 def getIdentifier( self ):
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
87 return self.id
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
88
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
89 ## Return a Set instance with the subject mapped on the query
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
90 #
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
91 def getSubjectAsSetOfQuery(self):
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
92 iSet = Set()
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
93 iSet.id = self.id
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
94 iSet.name = self.range_subject.seqname
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
95 iSet.seqname = self.range_query.seqname
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
96 if self.range_subject.isOnDirectStrand():
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
97 iSet.start = self.range_query.start
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
98 iSet.end = self.range_query.end
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
99 else:
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
100 iSet.start = self.range_query.end
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
101 iSet.end = self.range_query.start
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
102 return iSet
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
103
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
104 #TODO: add tests !!!!
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
105 #WARNING: subject always in direct strand !!!
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
106 ## Return a Set instance with the subject mapped on the query
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
107 #
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
108 def getQuerySetOfSubject(self):
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
109 iSet = Set()
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
110 iSet.id = self.id
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
111 iSet.name = self.range_query.seqname
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
112 iSet.seqname = self.range_subject.seqname
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
113 if self.range_subject.isOnDirectStrand():
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
114 iSet.start = self.range_subject.start
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
115 iSet.end = self.range_subject.end
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
116 else:
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
117 iSet.start = self.range_subject.end
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
118 iSet.end = self.range_subject.start
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
119 return iSet
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
120
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
121 ## Return True if the instance can be merged with another Path instance, False otherwise
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
122 #
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
123 # @param o a Path instance
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
124 #
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
125 def canMerge(self, o):
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
126 return o.id != self.id \
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
127 and o.range_query.seqname == self.range_query.seqname \
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
128 and o.range_subject.seqname == self.range_subject.seqname \
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
129 and o.range_query.isOnDirectStrand() == self.range_query.isOnDirectStrand() \
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
130 and o.range_subject.isOnDirectStrand() == self.range_subject.isOnDirectStrand() \
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
131 and o.range_query.isOverlapping(self.range_query) \
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
132 and o.range_subject.isOverlapping(self.range_subject)
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
133
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
134 ## Return an Align instance with the same attributes, except the identifier
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
135 #
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
136 def getAlignInstance(self):
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
137 iAlign = Align()
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
138 lAttributes = []
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
139 lAttributes.append( self.range_query.seqname )
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
140 lAttributes.append( self.range_query.start )
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
141 lAttributes.append( self.range_query.end )
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
142 lAttributes.append( self.range_subject.seqname )
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
143 lAttributes.append( self.range_subject.start )
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
144 lAttributes.append( self.range_subject.end )
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
145 lAttributes.append( self.e_value )
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
146 lAttributes.append( self.score )
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
147 lAttributes.append( self.identity )
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
148 iAlign.setFromTuple( lAttributes )
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
149 return iAlign