예제 #1
0
파일: mapping.py 프로젝트: antonwang/pygr
 def __init__(self,sourceDB,targetDB,saveDict=None,IDAttr='id',targetIDAttr='id',
              itemAttr=None,multiValue=False,inverseAttr=None,**kwargs):
     '''sourceDB: dictionary that maps key ID values to key objects
     targetDB: dictionary that maps value IDs to value objects
     saveDict, if not None, is the internal mapping to use as our storage
     IDAttr: attribute name to obtain an ID from a key object
     targetIDAttr: attribute name to obtain an ID from a value object
     itemAttr, if not None, the attribute to obtain target (value) ID
        from an internal storage value
     multiValue: if True, treat each value as a list of values.
     filename: if provided, is a file path to a shelve (BerkeleyDB) file to
           store the data in.
     dictClass: if not None, is the class to use for storage of the dict data'''
     if saveDict is None:
         self.d=classutil.get_shelve_or_dict(**kwargs)
     else:
         self.d=saveDict
     self.IDAttr=IDAttr
     self.targetIDAttr=targetIDAttr
     self.itemAttr=itemAttr
     self.multiValue=multiValue
     self.sourceDB=sourceDB
     self.targetDB=targetDB
     if inverseAttr is not None:
         self.inverseAttr=inverseAttr
예제 #2
0
파일: mapping.py 프로젝트: mamanambiya/pygr
 def __init__(self,
              sourceDB,
              targetDB,
              saveDict=None,
              IDAttr='id',
              targetIDAttr='id',
              itemAttr=None,
              multiValue=False,
              inverseAttr=None,
              **kwargs):
     '''sourceDB: dictionary that maps key ID values to key objects
     targetDB: dictionary that maps value IDs to value objects
     saveDict, if not None, is the internal mapping to use as our storage
     IDAttr: attribute name to obtain an ID from a key object
     targetIDAttr: attribute name to obtain an ID from a value object
     itemAttr, if not None, the attribute to obtain target (value) ID
        from an internal storage value
     multiValue: if True, treat each value as a list of values.
     filename: if provided, is a file path to a shelve (BerkeleyDB) file to
           store the data in.
     dictClass: if not None, is the class to use for storage of dict data'''
     if saveDict is None:
         self.d = classutil.get_shelve_or_dict(**kwargs)
     else:
         self.d = saveDict
     self.IDAttr = IDAttr
     self.targetIDAttr = targetIDAttr
     self.itemAttr = itemAttr
     self.multiValue = multiValue
     self.sourceDB = sourceDB
     self.targetDB = targetDB
     if inverseAttr is not None:
         self.inverseAttr = inverseAttr
예제 #3
0
    def __init__(
            self,
            sliceDB,
            seqDB,
            annotationType=None,
            itemClass=AnnotationSeq,
            itemSliceClass=AnnotationSlice,
            itemAttrDict=None,  # GET RID OF THIS BACKWARDS-COMPATIBILITY KLUGE!!
            sliceAttrDict=None,
            maxCache=None,
            autoGC=True,
            checkFirstID=True,
            **kwargs):
        '''sliceDB must map identifier to a sliceInfo object;
        sliceInfo must have attributes: id, start, stop, orientation;
        seqDB must map sequence ID to a sliceable sequence object;
        sliceAttrDict gives optional dict of item attributes that
        should be mapped to sliceDB item attributes.
        maxCache specfies the maximum number of annotation objects
        to keep in the cache.'''
        if autoGC:  # automatically garbage collect unused objects
            self._weakValueDict = classutil.RecentValueDictionary(autoGC)
        else:
            self._weakValueDict = {}  # object cache
        self.autoGC = autoGC
        if sliceAttrDict is None:
            sliceAttrDict = {}
        if sliceDB is not None:
            self.sliceDB = sliceDB
        else:  # NEED TO CREATE / OPEN A DATABASE FOR THE USER
            self.sliceDB = classutil.get_shelve_or_dict(**kwargs)
        self.seqDB = seqDB
        self.annotationType = annotationType
        self.itemClass = itemClass
        self.itemSliceClass = itemSliceClass
        self.sliceAttrDict = sliceAttrDict  # USER-PROVIDED ALIASES
        if maxCache is not None:
            self.maxCache = maxCache
        if checkFirstID:
            try:  # don't cache anything now; schema may change itemClass!
                k = iter(self).next()  # get the first ID if any
                self.get_annot_obj(k, self.sliceDB[k])  # valid annotation?
            except KeyError:  # a convenient warning to the user...
                raise KeyError('''\
cannot create annotation object %s; sequence database %s may not be correct'''
                               % (
                                   k,
                                   repr(seqDB),
                               ))
            except StopIteration:
                pass  # dataset is empty so there is nothing we can check...
예제 #4
0
파일: annotation.py 프로젝트: jqian/pygr
    def __init__(
        self,
        sliceDB,
        seqDB,
        annotationType=None,
        itemClass=AnnotationSeq,
        itemSliceClass=AnnotationSlice,
        itemAttrDict=None,  # GET RID OF THIS BACKWARDS-COMPATIBILITY KLUGE!!
        sliceAttrDict=None,
        maxCache=None,
        autoGC=True,
        **kwargs
    ):
        """sliceDB must map identifier to a sliceInfo object;
sliceInfo must have name,start,stop,ori attributes;
seqDB must map sequence ID to a sliceable sequence object;
sliceAttrDict gives optional dict of item attributes that
should be mapped to sliceDB item attributes.
maxCache specfies the maximum number of annotation objects to keep in the cache."""
        if autoGC:  # automatically garbage collect unused objects
            self._weakValueDict = classutil.RecentValueDictionary(autoGC)
        else:
            self._weakValueDict = {}  # object cache
        self.autoGC = autoGC
        if sliceAttrDict is None:
            sliceAttrDict = {}
        if sliceDB is not None:
            self.sliceDB = sliceDB
        else:  # NEED TO CREATE / OPEN A DATABASE FOR THE USER
            self.sliceDB = classutil.get_shelve_or_dict(**kwargs)
        self.seqDB = seqDB
        self.annotationType = annotationType
        self.itemClass = itemClass
        self.itemSliceClass = itemSliceClass
        self.sliceAttrDict = sliceAttrDict  # USER-PROVIDED ALIASES
        if maxCache is not None:
            self.maxCache = maxCache
        try:  # don't cache anything now; schema may change itemClass!
            k = iter(self).next()  # get the first ID if any
            self.get_annot_obj(k, self.sliceDB[k])  # valid annotation object?
        except KeyError:  # a convenient warning to the user...
            raise KeyError(
                """\
 cannot create annotation object; sequence database %s may not be correct"""
                % (repr(seqDB),)
            )
        except StopIteration:
            pass  # dataset is empty so there is nothing we can check...