comparison TEisotools-1.1.a/commons/core/coord/Set.py @ 16:836ce3d9d47a draft default tip

Uploaded
author urgi-team
date Thu, 21 Jul 2016 07:42:47 -0400
parents 255c852351c5
children
comparison
equal deleted inserted replaced
15:255c852351c5 16:836ce3d9d47a
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 __slots__ = ("id")
40
41 ## Constructor
42 #
43 # @param id identifier
44 # @param name the name of the region
45 # @param seqname the name of the sequence
46 # @param start the start coordinate
47 # @param end the end coordinate
48 #
49 def __init__(self, id=-1, name="", seqname="", start=-1, end=-1):
50 Map.__init__( self, name, seqname, start, end )
51 self.id = id
52
53 ## Equal operator
54 #
55 def __eq__(self, o):
56 if type(o) is not type(self) or self.id != o.id:
57 return False
58 else:
59 return Map.__eq__(self, o)
60
61 ## Not equal operator
62 #
63 def __ne__(self, o):
64 return not self.__eq__(o)
65
66 def getId(self):
67 return self.id
68
69 ## Reset
70 #
71 def reset(self):
72 self.setFromTuple([-1, "", "", -1, -1 ])
73
74 ## Set attributes from tuple
75 #
76 # @param tuple: a tuple with (id, name, seqname, start, end)
77 #
78 def setFromTuple(self, tuple):
79 self.id = int(tuple[0])
80 Map.setFromTuple(self, tuple[1:])
81
82 ## Return the attributes as a formatted string
83 #
84 def toString(self):
85 string = "%i" % (self.id)
86 string += "\t%s" % (Map.toString(self))
87 return string
88
89 ## Merge the instance with another Set instance
90 #
91 # @param o a Set instance
92 #
93 def merge(self, o):
94 if self.seqname == o.seqname:
95 Map.merge(self, o)
96 self.id = min(self.id, o.id)
97
98 ## Return a Map instance with the attributes
99 #
100 def getMap(self):
101 return Map(self.name, self.seqname, self.start, self.end)
102
103 ## Remove in the instance the region overlapping with another Set instance
104 #
105 # @param o a Set instance
106 #
107 def diff(self, o):
108 iMap = Map.diff(self, o.getMap())
109 new = Set()
110 if not iMap.isEmpty():
111 new.id = self.id
112 new.name = self.name
113 new.seqname = self.seqname
114 new.start = iMap.start
115 new.end = iMap.end
116 return new
117
118 ## Return a Map instance with the identifier in the name
119 #
120 def set2map(self):
121 return Map(self.name+"::"+str(self.id),self.seqname,self.start,self.end)
122
123
124 def getMapInstance( self ):
125 iMap = Map()
126 lAttributes = []
127 lAttributes.append( self.name )
128 lAttributes.append( self.seqname )
129 lAttributes.append( self.start )
130 lAttributes.append( self.end )
131 iMap.setFromTuple( lAttributes )
132 return iMap