comparison commons/core/coord/Set.py @ 6:769e306b7933

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