annotate SMART/Java/Python/ncList/NCListHandler.py @ 16:6135c3075bc5

Deleted selected files
author m-zytnicki
date Mon, 22 Apr 2013 11:09:41 -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 #! /usr/bin/env python
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
2 #
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
3 # Copyright INRA-URGI 2009-2010
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 struct
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
33 try:
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
34 import cPickle as pickle
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
35 except:
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
36 import pickle
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
37 from SMART.Java.Python.ncList.NCList import NCList
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
38 from SMART.Java.Python.ncList.NCIndex import NCIndex
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
39 from SMART.Java.Python.ncList.NCListFilePickle import NCListFileUnpickle
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
40
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
41 LONG_SIZE = struct.calcsize('l')
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
42
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
43 INFO_PER_NCLIST = 5
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
44 H_FILE = 0
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
45 L_FILE = 1
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
46 G_FILE = 2
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
47 FIRST_LIST_SIZE = 3
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
48 INDEX = 4
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
49
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
50 H = 0
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
51 L = 1
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
52 T = 2
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
53 G = 3
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
54
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
55 def pack(input):
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
56 return struct.pack("l", long(input))
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
57 def unpack(input):
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
58 return struct.unpack("l", input)[0]
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
59
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
60
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
61 class NCListHandler(object):
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
62
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
63 def __init__(self, verbosity):
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
64 self._verbosity = verbosity
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
65 self._index = False
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
66
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
67 def setFileName(self, fileName):
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
68 self._fileName = fileName
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
69 self._handle = open(fileName, "rb")
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
70
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
71 def loadData(self):
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
72 self._chromosomes = pickle.load(self._handle)
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
73 self._nbElements = 0
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
74 self._nbElementsPerChromosome = {}
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
75 self._ncLists = {}
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
76 for chromosome in self._chromosomes:
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
77 self._nbElementsPerChromosome[chromosome] = unpack(self._handle.read(LONG_SIZE))
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
78 self._nbElements += self._nbElementsPerChromosome[chromosome]
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
79 self._headerPos = self._handle.tell()
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
80 for i, chromosome in enumerate(self._chromosomes):
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
81 ncList = NCList(self._verbosity)
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
82 ncList._hHandle = self._handle
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
83 ncList._lHandle = self._handle
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
84 ncList._parser = NCListFileUnpickle(self._fileName)
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
85 self._handle.seek(self._headerPos + i * INFO_PER_NCLIST * LONG_SIZE + H_FILE * LONG_SIZE)
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
86 ncList.setOffset(H, unpack(self._handle.read(LONG_SIZE)))
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
87 self._handle.seek(self._headerPos + i * INFO_PER_NCLIST * LONG_SIZE + L_FILE * LONG_SIZE)
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
88 ncList.setOffset(L, unpack(self._handle.read(LONG_SIZE)))
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
89 self._handle.seek(self._headerPos + i * INFO_PER_NCLIST * LONG_SIZE + G_FILE * LONG_SIZE)
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
90 ncList.setOffset(G, unpack(self._handle.read(LONG_SIZE)))
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
91 self._handle.seek(self._headerPos + i * INFO_PER_NCLIST * LONG_SIZE + FIRST_LIST_SIZE * LONG_SIZE)
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
92 ncList._sizeFirstList = unpack(self._handle.read(LONG_SIZE))
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
93 self._handle.seek(self._headerPos + i * INFO_PER_NCLIST * LONG_SIZE + INDEX * LONG_SIZE)
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
94 indices = unpack(self._handle.read(LONG_SIZE))
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
95 if indices != -1:
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
96 self._handle.seek(indices)
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
97 data = pickle.load(self._handle)
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
98 index = NCIndex(self._verbosity)
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
99 index._indices = data
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
100 ncList._index = index
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
101 self._ncLists[chromosome] = ncList
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
102
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
103 def getChromosomes(self):
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
104 return self._chromosomes
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
105
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
106 def getNbElements(self):
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
107 return self._nbElements
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
108
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
109 def getNbElementsPerChromosome(self):
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
110 return self._nbElementsPerChromosome
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
111
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
112 def getNCLists(self):
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
113 return self._ncLists
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
114
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
115 def getParser(self, chromosome = None):
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
116 parser = NCListFileUnpickle(self._fileName)
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
117 if chromosome == None:
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
118 parser.setInitAddress(unpack(self._handle, self._headerPos + G_FILE * LONG_SIZE))
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
119 return parser
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
120 i = self._chromosomes.index(chromosome)
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
121 self._handle.seek(self._headerPos + i * INFO_PER_NCLIST * LONG_SIZE + G_FILE * LONG_SIZE)
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
122 pos = unpack(self._handle.read(LONG_SIZE))
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
123 parser.setInitAddress(pos)
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
124 parser.setChromosome(chromosome)
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
125 return parser