annotate SMART/Java/Python/ncList/NCListFilePickle.py @ 28:2a3fdec156e0

Deleted selected files
author m-zytnicki
date Mon, 29 Apr 2013 03:31:52 -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 try:
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
33 import cPickle as pickle
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
34 except:
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
35 import pickle
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
36 from SMART.Java.Python.structure.Transcript import Transcript
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
37
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
38
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
39 class NCListFilePickle(object):
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
40
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
41 def __init__(self, fileName, verbosity = 1):
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
42 self.fileName = fileName
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
43 self.handle = open(fileName, "wb")
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
44 self.verbosity = verbosity
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
45
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
46 def __del__(self):
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
47 if self.handle != None:
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
48 self.handle.close()
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
49
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
50 def addTranscript(self, transcript):
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
51 pickle.dump(transcript, self.handle, -1)
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
52
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
53 def write(self):
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
54 pass
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
55
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
56 def close(self):
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
57 self.__del__()
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
58
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
59
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
60 class NCListFileUnpickle(object):
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
61
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
62 def __init__(self, fileName, verbosity = 1):
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
63 self.handle = open(fileName, "rb")
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.initAddress = 0
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
66 self.address = self.initAddress
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
67 self.nbTranscripts = None
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.over = False
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
70 self.chromosome = None
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
71
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
72 def __del__(self):
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
73 if self.handle != None:
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
74 self.handle.close()
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
75
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
76 def reset(self):
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
77 self.handle.seek(0)
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
78 self.initAddress = 0
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
79
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
80 def setChromosome(self, chromosome):
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
81 self.chromosome = chromosome
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
82
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
83 def getNbTranscripts(self):
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
84 if self.nbTranscripts != None:
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
85 return self._nbTranscripts
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
86 self.nbTranscripts = 0
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
87 for transcript in self.getIterator():
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
88 self_nbTranscripts += 1
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
89 return self.nbTranscripts
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
90
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
91 def gotoAddress(self, address):
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
92 self.handle.seek(address)
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
93 self.address = address
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
94
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
95 def getNextTranscript(self):
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
96 self.address = self.handle.tell()
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
97 try:
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
98 transcript = pickle.load(self.handle)
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
99 if self.chromosome != None and transcript.getChromosome() != self.chromosome:
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
100 self.over = True
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
101 return False
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
102 return transcript
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
103 except EOFError:
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
104 self.over = True
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
105 return False
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
106
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
107 def getIterator(self):
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
108 self.gotoAddress(self.initAddress)
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
109 while True:
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
110 transcript = self.getNextTranscript()
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
111 if not transcript:
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
112 self.over = True
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
113 return
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
114 yield transcript
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
115
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
116 def setInitAddress(self, address):
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
117 self.initAddress = address
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
118
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
119 def getCurrentTranscriptAddress(self):
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
120 return self.address
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
121
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
122 def isOver(self):
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
123 return self.over