annotate commons/core/coord/Map.py @ 14:c79b9ae3f65f

Deleted selected files
author m-zytnicki
date Fri, 19 Apr 2013 10:13:11 -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.Range import Range
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
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
36 #
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
37 class Map( Range ):
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 name the name of the region
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
42 # @param seqname the name of the sequence
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
43 # @param start the start coordinate
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
44 # @param end the end coordinate
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
45 #
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
46 def __init__(self, name="", seqname="", start=-1, end=-1):
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
47 self.name = name
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
48 Range.__init__( self, seqname, start, end )
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
49
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
50 ## Equal operator
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
51 #
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
52 # @param o a Map instance
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
53 #
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
54 def __eq__(self, o):
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
55 if self.name == o.name:
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
56 return Range.__eq__(self, o)
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
57 return False
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
58
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
59 ## Return name
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
60 #
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
61 def getName( self ):
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
62 return self.name
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
63
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
64 ## Set attributes from tuple
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
65 #
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
66 # @param tuple: a tuple with (name,seqname,start,end)
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
67 #
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
68 def setFromTuple(self, tuple):
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
69 self.name = tuple[0]
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
70 Range.setFromTuple(self, tuple[1:])
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
71
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
72 ## Set attributes from string
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
73 #
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
74 # @param string a string formatted like name<sep>seqname<sep>start<sep>end
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
75 # @param sep field separator
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
76 #
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
77 def setFromString(self, string, sep="\t"):
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
78 if string[-1] == "\n":
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
79 string = string[:-1]
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
80 self.setFromTuple( string.split(sep) )
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
81
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
82 ## Reset
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
83 #
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
84 def reset(self):
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
85 self.setFromTuple( [ "", "", -1, -1 ] )
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
86
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
87 ## Read attributes from a Map file
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
88 #
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
89 # @param fileHandler: file handler of the file being read
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
90 # @return: 1 on success, 0 at the end of the file
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
91 #
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
92 def read(self, fileHandler):
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
93 self.reset()
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
94 line = fileHandler.readline()
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
95 if line == "":
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
96 return 0
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
97 tokens = line.split("\t")
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
98 if len(tokens) < len(self.__dict__.keys()):
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
99 return 0
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
100 self.setFromTuple(tokens)
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
101 return 1
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
102
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
103 ## Return the attributes as a formatted string
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
104 #
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
105 def toString(self):
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
106 string = "%s" % (self.name)
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
107 string += "\t%s" % (Range.toString(self))
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
108 return string
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
109
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
110 ## Write attributes into a Map file
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
111 #
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
112 # @param fileHandler: file handler of the file being filled
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
113 #
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
114 def write(self, fileHandler):
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
115 fileHandler.write("%s\n" % (self.toString()))
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
116
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
117 ## Save attributes into a Map file
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
118 #
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
119 # @param file: name of the file being filled
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
120 #
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
121 def save(self, file):
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
122 fileHandler = open( file, "a" )
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
123 self.write( fileHandler )
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
124 fileHandler.close()
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
125
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
126 ## Return a Range instance with the attributes
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
127 #
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
128 def getRange(self):
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
129 return Range( self.seqname, self.start, self.end)
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
130
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
131 ## Remove in the instance the region overlapping with another Map instance
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
132 #
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
133 # @param o a Map instance
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
134 #
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
135 def diff(self, o):
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
136 iRange = Range.diff(self, o.getRange())
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
137 new = Map()
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
138 if not iRange.isEmpty():
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
139 new.name = self.name
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
140 new.seqname = self.seqname
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
141 new.start = iRange.start
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
142 new.end = iRange.end
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
143 return new
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
144
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
145 ## Write attributes in a Path file, the name being the subject and the rest the Range query
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
146 #
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
147 # @param fileHandler: file handler of a Path file
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
148 #
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
149 def writeAsQueryOfPath(self, fileHandler):
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
150 string = "0"
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
151 string += "\t%s" % ( self.seqname )
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
152 string += "\t%i" % ( self.getMin() )
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
153 string += "\t%i" % ( self.getMax() )
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
154 string += "\t%s" % ( self.name )
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
155 string += "\t0"
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
156 string += "\t0"
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
157 string += "\t0.0"
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
158 string += "\t0"
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
159 string += "\t0"
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
160 fileHandler.write( "%s\n" % ( string ) )
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
161