# Path: pygr/mapping.py
# class Collection(object):
#     'flexible storage mapping ID --> OBJECT'
# 
#     def __init__(self, saveDict=None, dictClass=dict, **kwargs):
#         '''saveDict, if not None, the internal mapping to use as our storage.
#         filename: if provided, a file path to a shelve (BerkeleyDB) file to
#               store the data in.
#         dictClass: if provided, the class to use for storage of dict data.'''
#         if saveDict is not None:
#             self.d = saveDict
#         elif 'filename' in kwargs: # USE A SHELVE (BERKELEY DB)
#             try:
#                 if kwargs['intKeys']: # ALLOW INT KEYS, HAVE TO USE IntShelve
#                     self.__class__ = IntShelve
#                 else:
#                     raise KeyError
#             except KeyError:
#                 self.__class__ = PicklableShelve
#             return self.__init__(**kwargs)
#         else:
#             self.d = dictClass()
#         classutil.apply_itemclass(self, kwargs)
# 
#     def __getitem__(self, k):
#         return self.d[k]
# 
#     def __setitem__(self, k, v):
#         self.d[k] = v
# 
#     def __delitem__(self, k):
#         del self.d[k]
# 
#     def __len__(self):
#         return len(self.d)
# 
#     def __contains__(self, k):
#         return k in self.d
# 
#     def __iter__(self):
#         return iter(self.d)
# 
#     def __getattr__(self, attr):
#         if attr == '__setstate__' or attr == '__dict__':
#             # This prevents infinite recursion during unpickling.
#             raise AttributeError
#         try: # PROTECT AGAINST INFINITE RECURSE IF NOT FULLY __init__ED...
#             return getattr(self.__dict__['d'], attr)
#         except KeyError:
#             raise AttributeError('Collection has no subdictionary')
#     close = close_if_possible
# 
#     def __del__(self):
#         'must ensure that shelve object is closed to save pending data'
#         try:
#             self.close()
#         except classutil.FileAlreadyClosedError:
#             pass


import unittest
import ConfigParser
import os
import string
import sys
import pygr.Data
    import hashlib
    import md5 as hashlib
        import random
from testlib import testutil, PygrTestProgram
from pygr.mapping import Collection
        from pygr import seqdb
        from pygr import seqdb, cnestedlist, sqlgraph
        from pygr import seqdb, cnestedlist, sqlgraph
        open(newname, 'w').write(open(filename, 'r').read())
        return newname

    def tearDown(self):
        'delete the temporary directory and files, restore pygr.Data path'
        # Delete them bottom-up for obvious reasons.
        for dirpath, subdirs, files in os.walk(self.path, topdown=False):
            # Note: this part may not work in directories on NFS due to
            # creation of lock files (.nfsXXXXXXXXX), which will only allow
            # deletion after pygr.Data has been closed.
            for filename in files:
                os.remove(os.path.join(dirpath, filename))
            os.rmdir(dirpath)
        # Restore original pygr.Data path to remedy lack of isolation
        # between tests from the same run
        pygr.Data.update(None)


class Build_Test(PygrBuildNLMSAMegabase):

    def test_seqdb(self):
        'Check pygr.Data contents'
        l = pygr.Data.dir('TEST')
        preList = ['TEST.Seq.Genome.' + orgstr for orgstr in msaSpeciesList]
        assert l == preList

    def test_collectionannot(self):
        'Test building an AnnotationDB from file'
        hg18 = pygr.Data.getResource('TEST.Seq.Genome.hg18')
        # BUILD ANNOTATION DATABASE FOR REFSEQ EXONS

# Path: pygr/mapping.py
# class Collection(object):
#     'flexible storage mapping ID --> OBJECT'
# 
#     def __init__(self, saveDict=None, dictClass=dict, **kwargs):
#         '''saveDict, if not None, the internal mapping to use as our storage.
#         filename: if provided, a file path to a shelve (BerkeleyDB) file to
#               store the data in.
#         dictClass: if provided, the class to use for storage of dict data.'''
#         if saveDict is not None:
#             self.d = saveDict
#         elif 'filename' in kwargs: # USE A SHELVE (BERKELEY DB)
#             try:
#                 if kwargs['intKeys']: # ALLOW INT KEYS, HAVE TO USE IntShelve
#                     self.__class__ = IntShelve
#                 else:
#                     raise KeyError
#             except KeyError:
#                 self.__class__ = PicklableShelve
#             return self.__init__(**kwargs)
#         else:
#             self.d = dictClass()
#         classutil.apply_itemclass(self, kwargs)
# 
#     def __getitem__(self, k):
#         return self.d[k]
# 
#     def __setitem__(self, k, v):
#         self.d[k] = v
# 
#     def __delitem__(self, k):
#         del self.d[k]
# 
#     def __len__(self):
#         return len(self.d)
# 
#     def __contains__(self, k):
#         return k in self.d
# 
#     def __iter__(self):
#         return iter(self.d)
# 
#     def __getattr__(self, attr):
#         if attr == '__setstate__' or attr == '__dict__':
#             # This prevents infinite recursion during unpickling.
#             raise AttributeError
#         try: # PROTECT AGAINST INFINITE RECURSE IF NOT FULLY __init__ED...
#             return getattr(self.__dict__['d'], attr)
#         except KeyError:
#             raise AttributeError('Collection has no subdictionary')
#     close = close_if_possible
# 
#     def __del__(self):
#         'must ensure that shelve object is closed to save pending data'
#         try:
#             self.close()
#         except classutil.FileAlreadyClosedError:
#             pass


# Path: tests/annotation_hg18_megatest.py
import unittest
import ConfigParser
import os
import string
import sys
import pygr.Data
    import hashlib
    import md5 as hashlib
        import random
from testlib import testutil, PygrTestProgram
from pygr.mapping import Collection
        from pygr import seqdb
        from pygr import seqdb, cnestedlist, sqlgraph
        from pygr import seqdb, cnestedlist, sqlgraph

        open(newname, 'w').write(open(filename, 'r').read())
        return newname

    def tearDown(self):
        'delete the temporary directory and files, restore pygr.Data path'
        # Delete them bottom-up for obvious reasons.
        for dirpath, subdirs, files in os.walk(self.path, topdown=False):
            # Note: this part may not work in directories on NFS due to
            # creation of lock files (.nfsXXXXXXXXX), which will only allow
            # deletion after pygr.Data has been closed.
            for filename in files:
                os.remove(os.path.join(dirpath, filename))
            os.rmdir(dirpath)
        # Restore original pygr.Data path to remedy lack of isolation
        # between tests from the same run
        pygr.Data.update(None)


class Build_Test(PygrBuildNLMSAMegabase):

    def test_seqdb(self):
        'Check pygr.Data contents'
        l = pygr.Data.dir('TEST')
        preList = ['TEST.Seq.Genome.' + orgstr for orgstr in msaSpeciesList]
        assert l == preList

    def test_collectionannot(self):
        'Test building an AnnotationDB from file'
        hg18 = pygr.Data.getResource('TEST.Seq.Genome.hg18')
        # BUILD ANNOTATION DATABASE FOR REFSEQ EXONS

        exon_slices = Collection(