Back to index

python-biopython  1.60
Public Member Functions | Private Member Functions | Private Attributes | Static Private Attributes
Bio.Index._InMemoryIndex Class Reference
Collaboration diagram for Bio.Index._InMemoryIndex:
Collaboration graph
[legend]

List of all members.

Public Member Functions

def __init__
def update
def __setitem__
def __delitem__
def clear
def __del__

Private Member Functions

def _tostr
def _toobj

Private Attributes

 _indexname
 __changed

Static Private Attributes

int __version = 3
string __version_key = '__version'

Detailed Description

This creates an in-memory index file.

Definition at line 66 of file Index.py.


Constructor & Destructor Documentation

def Bio.Index._InMemoryIndex.__init__ (   self,
  indexname,
  truncate = None 
)

Definition at line 78 of file Index.py.

00078 
00079     def __init__(self, indexname, truncate=None):
00080         self._indexname = indexname
00081         dict.__init__(self)
00082         self.__changed = 0     # the index hasn't changed
00083         
00084         # Remove the database if truncate is true.
00085         if truncate and os.path.exists(indexname):
00086             os.unlink(indexname)
00087             self.__changed = 1
00088 
00089         # Load the database if it exists
00090         if os.path.exists(indexname):
00091             handle = open(indexname)
00092             version = self._toobj(handle.readline().rstrip())
00093             if version != self.__version:
00094                 raise IOError("Version %s doesn't match my version %s" \
00095                               % (version, self.__version))
00096             for line in handle:
00097                 key, value = line.split()
00098                 key, value = self._toobj(key), self._toobj(value)
00099                 self[key] = value
00100             self.__changed = 0

Here is the caller graph for this function:

Definition at line 114 of file Index.py.

00114 
00115     def __del__(self):
00116         if self.__changed:
00117             handle = open(self._indexname, 'w')
00118             handle.write("%s\n" % self._tostr(self.__version))
00119             for key, value in self.items():
00120                 handle.write("%s %s\n" %
00121                              (self._tostr(key), self._tostr(value)))
00122             handle.close()

Here is the call graph for this function:


Member Function Documentation

def Bio.Index._InMemoryIndex.__delitem__ (   self,
  key 
)

Definition at line 107 of file Index.py.

00107 
00108     def __delitem__(self, key):
00109         self.__changed = 1
        dict.__delitem__(self, key)
def Bio.Index._InMemoryIndex.__setitem__ (   self,
  key,
  value 
)

Definition at line 104 of file Index.py.

00104 
00105     def __setitem__(self, key, value):
00106         self.__changed = 1
        dict.__setitem__(self, key, value)
def Bio.Index._InMemoryIndex._toobj (   self,
  str 
) [private]

Definition at line 136 of file Index.py.

00136 
00137     def _toobj(self, str):
00138         intlist = map(int, str.split(','))
00139         intlist = array.array('b', intlist)
00140         strlist = map(chr, intlist)
00141         return cPickle.loads(''.join(strlist))

def Bio.Index._InMemoryIndex._tostr (   self,
  obj 
) [private]

Definition at line 123 of file Index.py.

00123 
00124     def _tostr(self, obj):
00125         # I need a representation of the object that's saveable to
00126         # a file that uses whitespace as delimiters.  Thus, I'm
00127         # going to pickle the object, and then convert each character of
00128         # the string to its ASCII integer value.  Then, I'm going to convert
00129         # the integers into strings and join them together with commas. 
00130         # It's not the most efficient way of storing things, but it's
00131         # relatively fast.
00132         s = cPickle.dumps(obj)
00133         intlist = array.array('b', s)
00134         strlist = map(str, intlist)
00135         return ','.join(strlist)

Here is the caller graph for this function:

Definition at line 110 of file Index.py.

00110 
00111     def clear(self):
00112         self.__changed = 1
00113         dict.clear(self)
            
def Bio.Index._InMemoryIndex.update (   self,
  dict 
)

Definition at line 101 of file Index.py.

00101 
00102     def update(self, dict):
00103         self.__changed = 1
        dict.update(self, dict)

Here is the caller graph for this function:


Member Data Documentation

Definition at line 81 of file Index.py.

int Bio.Index._InMemoryIndex.__version = 3 [static, private]

Definition at line 75 of file Index.py.

string Bio.Index._InMemoryIndex.__version_key = '__version' [static, private]

Definition at line 76 of file Index.py.

Definition at line 79 of file Index.py.


The documentation for this class was generated from the following file: