annotate commons/core/coord/MapUtils.py @ 22:1e3f2c2657a3

Deleted selected files
author m-zytnicki
date Mon, 29 Apr 2013 03:26:07 -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 import sys
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
33 import os
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
34 from commons.core.coord.Map import Map
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
35 from commons.core.coord.Set import Set
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
36 try:
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
37 from commons.core.checker.CheckerUtils import CheckerUtils
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
38 except ImportError:
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
39 pass
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
40
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
41
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
42 ## static methods manipulating Map instances
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
43 #
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
44 class MapUtils( object ):
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
45
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
46 ## Return a list of Map instances sorted in increasing order according to the min, then the max, and finally their initial order
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
47 #
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
48 # @param lMaps list of Map instances
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
49 #
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
50 def getMapListSortedByIncreasingMinThenMax( lMaps ):
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
51 return sorted( lMaps, key=lambda iMap: ( iMap.getMin(), iMap.getMax() ) )
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
52
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
53 getMapListSortedByIncreasingMinThenMax = staticmethod( getMapListSortedByIncreasingMinThenMax )
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
54
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
55
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
56 ## Return a list of Map instances sorted in increasing order according to the name, then the seqname, then the min, then the max
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
57 #
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
58 # @param lMaps list of Map instances
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
59 #
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
60 def getMapListSortedByIncreasingNameThenSeqnameThenMinThenMax( lMaps ):
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
61 return sorted( lMaps, key=lambda iMap: ( iMap.getName(), iMap.getSeqname(), iMap.getMin(), iMap.getMax() ) )
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
62
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
63 getMapListSortedByIncreasingNameThenSeqnameThenMinThenMax = staticmethod( getMapListSortedByIncreasingNameThenSeqnameThenMinThenMax )
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
64
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
65
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
66 ## Return a dictionary which keys are Map names and values the corresponding Map instances
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
67 #
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
68 def getDictPerNameFromMapFile( mapFile ):
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
69 dName2Maps = {}
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
70 mapFileHandler = open( mapFile, "r" )
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
71 while True:
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
72 line = mapFileHandler.readline()
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
73 if line == "":
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
74 break
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
75 iMap = Map()
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
76 iMap.setFromString( line, "\t" )
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
77 if dName2Maps.has_key( iMap.name ):
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
78 if iMap == dName2Maps[ iMap.name ]:
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
79 continue
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
80 else:
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
81 msg = "ERROR: in file '%s' two different Map instances have the same name '%s'" % ( mapFile, iMap.name )
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
82 sys.stderr.write( "%s\n" % ( msg ) )
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
83 sys.exit(1)
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
84 dName2Maps[ iMap.name ] = iMap
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
85 mapFileHandler.close()
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
86 return dName2Maps
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
87
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
88 getDictPerNameFromMapFile = staticmethod( getDictPerNameFromMapFile )
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
89
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
90
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
91 ## Give a list of Set instances from a list of Map instances
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
92 #
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
93 # @param lMaps list of Map instances
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
94 # @return lSets list of Set instances
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
95 #
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
96 def mapList2SetList( lMaps ):
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
97 lSets = []
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
98 c = 0
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
99 for iMap in lMaps:
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
100 c += 1
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
101 iSet = Set()
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
102 iSet.id = c
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
103 iSet.name = iMap.getName()
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
104 iSet.seqname = iMap.getSeqname()
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
105 iSet.start = iMap.getStart()
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
106 iSet.end = iMap.getEnd()
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
107 lSets.append( iSet )
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
108 return lSets
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
109
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
110 mapList2SetList = staticmethod( mapList2SetList )
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
111
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
112
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
113 ## Merge the Map instances in a Map file using 'mapOp'
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
114 #
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
115 def mergeCoordsInFile( inFile, outFile ):
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
116 if not sys.modules.has_key( "commons.core.checker.CheckerUtils" ):
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
117 msg = "WARNING: can't find module 'CheckerUtils'"
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
118 sys.stderr.write( "%s\n" % msg )
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
119 elif not CheckerUtils.isExecutableInUserPath( "mapOp" ):
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
120 msg = "WARNING: can't find executable 'mapOp'"
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
121 sys.stderr.write( "%s\n" % msg )
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
122 else:
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
123 cmd = "mapOp"
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
124 cmd += " -q %s" % ( inFile )
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
125 cmd += " -m"
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
126 cmd += " 2>&1 > /dev/null"
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
127 returnStatus = os.system( cmd )
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
128 if returnStatus != 0:
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
129 print "ERROR: mapOp returned %i" % ( returnStatus )
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
130 sys.exit(1)
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
131 os.rename( "%s.merge" % inFile,
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
132 outFile )
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
133
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
134 mergeCoordsInFile = staticmethod( mergeCoordsInFile )
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
135
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
136
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
137 ## Return a dictionary which keys are Map seqnames and values the corresponding Map instances
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
138 #
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
139 def getDictPerSeqNameFromMapFile( mapFile ):
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
140 dSeqName2Maps = {}
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
141 mapFileHandler = open( mapFile, "r" )
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
142 while True:
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
143 line = mapFileHandler.readline()
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
144 if line == "":
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
145 break
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
146 iMap = Map()
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
147 iMap.setFromString( line, "\t" )
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
148 if not dSeqName2Maps.has_key( iMap.seqname ):
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
149 dSeqName2Maps[ iMap.seqname ] = []
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
150 dSeqName2Maps[ iMap.seqname ].append( iMap )
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
151 mapFileHandler.close()
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
152 return dSeqName2Maps
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
153
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
154 getDictPerSeqNameFromMapFile = staticmethod( getDictPerSeqNameFromMapFile )
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
155
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
156
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
157 ## Convert an Map file into a Set file
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
158 #
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
159 # @param mapFile string input map file name
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
160 # @param setFile string output set file name
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
161 #
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
162 def convertMapFileIntoSetFile( mapFileName, setFileName = "" ):
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
163 if setFileName == "":
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
164 setFileName = "%s.set" % mapFileName
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
165 mapFileHandler = open( mapFileName, "r" )
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
166 setFileHandler = open( setFileName, "w" )
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
167 iMap = Map()
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
168 count = 0
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
169 while True:
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
170 line = mapFileHandler.readline()
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
171 if line == "":
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
172 break
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
173 iMap.setFromString(line)
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
174 count += 1
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
175 iSet = Set()
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
176 iSet.id = count
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
177 iSet.name = iMap.getName()
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
178 iSet.seqname = iMap.getSeqname()
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
179 iSet.start = iMap.getStart()
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
180 iSet.end = iMap.getEnd()
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
181 iSet.write(setFileHandler)
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
182 mapFileHandler.close()
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
183 setFileHandler.close()
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
184
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
185 convertMapFileIntoSetFile = staticmethod( convertMapFileIntoSetFile )
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
186
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
187 ## Write Map instances contained in the given list
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
188 #
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
189 # @param lMaps list of Map instances
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
190 # @param fileName a file name
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
191 # @param mode the open mode of the file '"w"' or '"a"'
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
192 #
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
193 def writeListInFile(lMaps, fileName, mode="w"):
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
194 fileHandler = open(fileName, mode)
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
195 for iMap in lMaps:
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
196 iMap.write(fileHandler)
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
197 fileHandler.close()
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
198
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
199 writeListInFile = staticmethod( writeListInFile )
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
200
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
201
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
202 ## Get the length of the shorter seq in map file
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
203 #
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
204 # @param mapFileName
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
205 # @param mode the open mode of the file '"w"' or '"a"'
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
206 #
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
207 def getMinLengthOfMapFile(self, mapFileName):
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
208 fileHandler = open(mapFileName, "r")
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
209 line = fileHandler.readline()
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
210 start = int (line.split('\t')[2])
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
211 end = int (line.split('\t')[3])
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
212 min = end - start + 1
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
213 while True:
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
214 line = fileHandler.readline()
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
215 if line == "":
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
216 break
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
217 start = int (line.split('\t')[2])
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
218 end = int (line.split('\t')[3])
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
219 currentMin = end - start + 1
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
220 if min >= currentMin:
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
221 min = currentMin
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
222 fileHandler.close()
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
223 return min
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
224
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
225 ## Get the max length of the shorter seq in map file
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
226 #
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
227 # @param mapFileName
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
228 # @param mode the open mode of the file '"w"' or '"a"'
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
229 #
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
230 def getMaxLengthOfMapFile(self, mapFileName):
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
231 fileHandler = open(mapFileName, "r")
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
232 line = fileHandler.readline()
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
233 start = int (line.split('\t')[2])
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
234 end = int (line.split('\t')[3])
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
235 max = end - start + 1
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
236 while True:
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
237 line = fileHandler.readline()
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
238 if line == "":
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
239 break
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
240 start = int (line.split('\t')[2])
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
241 end = int (line.split('\t')[3])
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
242 currentMax = end - start + 1
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
243 if max <= currentMax:
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
244 max = currentMax
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
245 fileHandler.close()
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
246 return max