annotate commons/core/coord/Set.py @ 49:80a080dc3ee8

Deleted selected files
author m-zytnicki
date Fri, 13 Dec 2013 10:37:16 -0500
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.Map import Map
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
33
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
34
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
35 ## Record a named region on a given sequence with an identifier
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
36 #
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
37 class Set( Map ):
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
38
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
39 ## Constructor
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
40 #
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
41 # @param id identifier
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
42 # @param name the name of the region
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
43 # @param seqname the name of the sequence
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
44 # @param start the start coordinate
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
45 # @param end the end coordinate
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
46 #
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
47 def __init__(self, id=-1, name="", seqname="", start=-1, end=-1):
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
48 Map.__init__( self, name, seqname, start, end )
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
49 self.id = id
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
50
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
51 ## Equal operator
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
52 #
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
53 def __eq__(self, o):
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
54 if self.id != o.id:
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
55 return False
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
56 else:
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
57 return Map.__eq__(self, o)
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
58
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
59 def getId(self):
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
60 return self.id
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
61
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
62 ## Reset
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
63 #
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
64 def reset(self):
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
65 self.setFromTuple([-1, "", "", -1, -1 ])
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
66
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
67 ## Set attributes from tuple
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
68 #
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
69 # @param tuple: a tuple with (id, name, seqname, start, end)
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
70 #
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
71 def setFromTuple(self, tuple):
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
72 self.id = int(tuple[0])
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
73 Map.setFromTuple(self, tuple[1:])
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
74
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
75 ## Return the attributes as a formatted string
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
76 #
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
77 def toString(self):
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
78 string = "%i" % (self.id)
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
79 string += "\t%s" % (Map.toString(self))
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
80 return string
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
81
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
82 ## Merge the instance with another Set instance
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
83 #
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
84 # @param o a Set instance
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
85 #
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
86 def merge(self, o):
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
87 if self.seqname == o.seqname:
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
88 Map.merge(self, o)
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
89 self.id = min(self.id, o.id)
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
90
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
91 ## Return a Map instance with the attributes
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
92 #
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
93 def getMap(self):
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
94 return Map(self.name, self.seqname, self.start, self.end)
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
95
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
96 ## Remove in the instance the region overlapping with another Set instance
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
97 #
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
98 # @param o a Set instance
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
99 #
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
100 def diff(self, o):
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
101 iMap = Map.diff(self, o.getMap())
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
102 new = Set()
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
103 if not iMap.isEmpty():
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
104 new.id = self.id
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
105 new.name = self.name
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
106 new.seqname = self.seqname
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
107 new.start = iMap.start
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
108 new.end = iMap.end
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
109 return new
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
110
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
111 ## Return a Map instance with the identifier in the name
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
112 #
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
113 def set2map(self):
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
114 return Map(self.name+"::"+str(self.id),self.seqname,self.start,self.end)
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
115
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
116
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
117 def getMapInstance( self ):
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
118 iMap = Map()
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
119 lAttributes = []
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
120 lAttributes.append( self.name )
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
121 lAttributes.append( self.seqname )
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
122 lAttributes.append( self.start )
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
123 lAttributes.append( self.end )
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
124 iMap.setFromTuple( lAttributes )
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
125 return iMap