コード例 #1
0
ファイル: annotation_test.py プロジェクト: mamanambiya/pygr
    def setUp(self):
        class Annotation(object):
            def __init__(self, **kwargs):
                self.__dict__.update(kwargs)

        slicedb = dict(annot1=Annotation(id='seq', start=0, stop=10),
                       annot2=Annotation(id='seq', start=5, stop=9))
        sequence_dict = dict(seq=Sequence('ATGGGGCCGATTG', 'seq'))
        self.db = AnnotationDB(slicedb, sequence_dict)
コード例 #2
0
ファイル: annotation_test.py プロジェクト: antonwang/pygr
 def setUp(self):
     class Annotation(object):
         def __init__(self, **kwargs):
             self.__dict__.update(kwargs)
     slicedb = dict(annot1=Annotation(id='seq', start=0, stop=10),
                    annot2=Annotation(id='seq', start=5, stop=9))
     sequence_dict = dict(seq = Sequence('ATGGGGCCGATTG', 'seq'))
     self.db = AnnotationDB(slicedb, sequence_dict)
コード例 #3
0
ファイル: annotation_test.py プロジェクト: mamanambiya/pygr
    def test_bad_seqdict(self):
        "AnnotationDB bad seqdict"

        class Annotation(object):
            def __init__(self, **kwargs):
                self.__dict__.update(kwargs)

        slicedb = dict(annot1=Annotation(id='seq', start=0, stop=10),
                       annot2=Annotation(id='seq', start=5, stop=9))
        foo_dict = dict(foo=Sequence('ATGGGGCCGATTG', 'foo'))
        try:
            db = AnnotationDB(slicedb, foo_dict)
            assert 0, "incorrect seqdb; key error should be raised"
        except KeyError:
            pass
コード例 #4
0
ファイル: annotation_test.py プロジェクト: mamanambiya/pygr
    def setUp(self):
        class Annotation(object):
            def __init__(self, **kwargs):
                self.__dict__.update(kwargs)

        slicedb = dict(X=Annotation(id='seq', start=0, stop=10),
                       Y=Annotation(id='seq', start=0, stop=10),
                       Z=Annotation(id='seq2', start=0, stop=10))

        sequence_dict = dict(seq=Sequence(
            'ATGGGGCCGATTG',
            'seq',
        ),
                             seq2=Sequence('ATGGGGCCGATTG', 'seq2'))

        self.db = AnnotationDB(slicedb, sequence_dict)

        self.annot = self.db['X']
コード例 #5
0
class AnnotationDB_Test(unittest.TestCase):
    """
    Test for all of the basic dictionary functions on 'AnnotationDB'.
    """

    def setUp(self):

        class Annotation(object):

            def __init__(self, **kwargs):
                self.__dict__.update(kwargs)

        slicedb = dict(annot1=Annotation(id='seq', start=0, stop=10),
                       annot2=Annotation(id='seq', start=5, stop=9))
        sequence_dict = dict(seq = Sequence('ATGGGGCCGATTG', 'seq'))
        self.db = AnnotationDB(slicedb, sequence_dict)

    def test_setitem(self):
        try:
            self.db['foo'] = 'bar'      # use 'add_annotation' instead
            assert 0, "should not reach this point"
        except KeyError:
            pass

    def test_hash(self):
        x = hash(self.db)               # works!
        d = dict(foo=self.db)           # also works!

    def test_keys(self):
        "AnnotationDB keys"
        k = self.db.keys()
        k.sort()
        assert k == ['annot1', 'annot2'], k

    def test_contains(self):
        "AnnotationDB contains"
        assert 'annot1' in self.db, self.db.keys()
        assert 'annot2' in self.db
        assert 'foo' not in self.db

    def test_has_key(self):
        "AnnotationDB has key"
        assert 'annot1' in self.db
        assert 'annot2' in self.db
        assert 'foo' not in self.db

    def test_get(self):
        "AnnotationDB get"
        assert self.db.get('foo') is None
        assert self.db.get('annot1') is not None
        assert str(self.db.get('annot1').sequence).startswith('ATGGGGC')
        assert self.db.get('annot2') is not None
        assert str(self.db.get('annot2').sequence).startswith('GCCG')

    def test_items(self):
        "AnnotationDB items"
        i = [k for (k, v) in self.db.items()]
        i.sort()
        assert i == ['annot1', 'annot2']

    def test_iterkeys(self):
        "AnnotationDB iterkeys"
        kk = self.db.keys()
        kk.sort()
        ik = list(self.db.iterkeys())
        ik.sort()
        assert kk == ik

    def test_itervalues(self):
        "AnnotationDB itervalues"
        kv = self.db.values()
        kv.sort()
        iv = list(self.db.itervalues())
        iv.sort()
        assert kv[0] == iv[0]
        assert kv == iv, (kv, iv)

    def test_iteritems(self):
        "AnnotationDB iteritems"
        ki = self.db.items()
        ki.sort()
        ii = list(self.db.iteritems())
        ii.sort()
        assert ki == ii, (ki, ii)

    def test_readonly(self):
        "AnnotationDB readonly"
        try:
            self.db.copy()              # what should 'copy' do on AD?
            assert 0, 'this method should raise NotImplementedError'
        except NotImplementedError:
            pass
        try:                           # what should 'setdefault' do on AD?
            self.db.setdefault('foo')
            assert 0, 'this method should raise NotImplementedError'
        except NotImplementedError:
            pass
        try:                           # what should 'update' do on AD?
            self.db.update({})
            assert 0, 'this method should raise NotImplementedError'
        except NotImplementedError:
            pass
        try:
            self.db.clear()
            assert 0, 'this method should raise NotImplementedError'
        except NotImplementedError:
            pass
        try:
            self.db.pop()
            assert 0, 'this method should raise NotImplementedError'
        except NotImplementedError:
            pass
        try:
            self.db.popitem()
            assert 0, 'this method should raise NotImplementedError'
        except NotImplementedError:
            pass

    def test_equality(self):
        "AnnotationDB equality"
        # Check that separately generated annotation objects test equal"
        key = 'annot1'
        db = self.db
        x = db.sliceAnnotation(key, db.sliceDB[key])
        y = db.sliceAnnotation(key, db.sliceDB[key])
        assert x == y

    def test_bad_seqdict(self):
        "AnnotationDB bad seqdict"

        class Annotation(object):

            def __init__(self, **kwargs):
                self.__dict__.update(kwargs)

        slicedb = dict(annot1=Annotation(id='seq', start=0, stop=10),
                       annot2=Annotation(id='seq', start=5, stop=9))
        foo_dict = dict(foo=Sequence('ATGGGGCCGATTG', 'foo'))
        try:
            db = AnnotationDB(slicedb, foo_dict)
            assert 0, "incorrect seqdb; key error should be raised"
        except KeyError:
            pass
コード例 #6
0
ファイル: seqdb_test.py プロジェクト: ctb/pygr
class AnnotationDB_Test(object):
    """
    Test for all of the basic dictionary functions on 'AnnotationDB'.
    """
    def setup(self):
        class Annotation(object):
            def __init__(self, **kwargs):
                self.__dict__.update(kwargs)
        slicedb = dict(annot1=Annotation(id='seq', start=0, stop=10),
                       annot2=Annotation(id='seq', start=5, stop=9))
        sequence_dict = dict(seq = Sequence('ATGGGGCCGATTG', 'seq'))
        
        self.db = AnnotationDB(slicedb, sequence_dict)
    def keys_test(self):
        k = self.db.keys()
        k.sort()
        assert k == ['annot1', 'annot2'], k
    def contains_test(self):
        assert 'annot1' in self.db, self.db.keys()
        assert 'annot2' in self.db
        assert 'foo' not in self.db
    def has_key_test(self):
        assert self.db.has_key('annot1')
        assert self.db.has_key('annot2')
        assert not self.db.has_key('foo')
    def get_test(self):
        assert self.db.get('foo') is None
        assert self.db.get('annot1') is not None
        assert str(self.db.get('annot1').sequence).startswith('ATGGGGC')
        assert self.db.get('annot2') is not None
        assert str(self.db.get('annot2').sequence).startswith('GCCG')
    def items_test(self):
        i = [ k for (k,v) in self.db.items() ]
        i.sort()
        assert i == ['annot1', 'annot2']
    def iterkeys_test(self):
        kk = self.db.keys()
        kk.sort()
        ik = list(self.db.iterkeys())
        ik.sort()
        assert kk == ik
    def itervalues_test(self):
        kv = self.db.values()
        kv.sort()
        iv = list(self.db.itervalues())
        iv.sort()
        assert kv[0] == iv[0]
        assert kv == iv, (kv, iv)
    def iteritems_test(self):
        ki = self.db.items()
        ki.sort()
        ii = list(self.db.iteritems())
        ii.sort()
        assert ki == ii, (ki, ii)
    def readonly_test(self):
        try:
            self.db.copy()              # what should 'copy' do on AD?
            assert 0, 'this method should raise NotImplementedError'
        except NotImplementedError:
            pass
        try:                           # what should 'setdefault' do on AD?
            self.db.setdefault('foo')
            assert 0, 'this method should raise NotImplementedError'
        except NotImplementedError:
            pass
        try:                           # what should 'update' do on AD?
            self.db.update({})
            assert 0, 'this method should raise NotImplementedError'
        except NotImplementedError:
            pass
        try:
            self.db.clear()
            assert 0, 'this method should raise NotImplementedError'
        except NotImplementedError:
            pass
        try:
            self.db.pop()
            assert 0, 'this method should raise NotImplementedError'
        except NotImplementedError:
            pass
        try:
            self.db.popitem()
            assert 0, 'this method should raise NotImplementedError'
        except NotImplementedError:
            pass
    def equality_test(self):
        "Check that separately generated annotation objects test equal"
        key = 'annot1'
        db = self.db
        x = db.sliceAnnotation(key, db.sliceDB[key])
        y = db.sliceAnnotation(key, db.sliceDB[key])
        assert x == y
    def bad_seqdict_test(self):
        class Annotation(object):
            def __init__(self, **kwargs):
                self.__dict__.update(kwargs)
        slicedb = dict(annot1=Annotation(id='seq', start=0, stop=10),
                       annot2=Annotation(id='seq', start=5, stop=9))
        foo_dict = dict(foo=Sequence('ATGGGGCCGATTG', 'foo'))
        try:
            db = AnnotationDB(slicedb, foo_dict)
            assert 0, "incorrect seqdb; key error should be raised"
        except KeyError:
            pass
    def translation_annot_test(self):
        db = SequenceFileDB('hbb1_mouse.fa')
        adb = AnnotationDB({1:('gi|171854975|dbj|AB364477.1|',3,441)},
                           db, itemClass=TranslationAnnot,
                           itemSliceClass=TranslationAnnotSlice,
                           sliceAttrDict=dict(id=0,start=1,stop=2))
        trseq = adb[1]
        assert len(trseq) == 146, 'wrong translation length!'
        assert len(trseq.sequence) == 438, 'wrong sequence length!'
        s = trseq[-10:]
        assert len(s) == 10, 'wrong translation length!'
        assert str(s.sequence) == 'GTGGCCACTGCCCTGGCTCACAAGTACCAC'
        assert str(s) == 'VATALAHKYH', 'bad ORF translation!'
コード例 #7
0
ファイル: annotation_test.py プロジェクト: mamanambiya/pygr
class AnnotationDB_Test(unittest.TestCase):
    """
    Test for all of the basic dictionary functions on 'AnnotationDB'.
    """
    def setUp(self):
        class Annotation(object):
            def __init__(self, **kwargs):
                self.__dict__.update(kwargs)

        slicedb = dict(annot1=Annotation(id='seq', start=0, stop=10),
                       annot2=Annotation(id='seq', start=5, stop=9))
        sequence_dict = dict(seq=Sequence('ATGGGGCCGATTG', 'seq'))
        self.db = AnnotationDB(slicedb, sequence_dict)

    def test_setitem(self):
        try:
            self.db['foo'] = 'bar'  # use 'add_annotation' instead
            assert 0, "should not reach this point"
        except KeyError:
            pass

    def test_hash(self):
        x = hash(self.db)  # works!
        d = dict(foo=self.db)  # also works!

    def test_keys(self):
        "AnnotationDB keys"
        k = self.db.keys()
        k.sort()
        assert k == ['annot1', 'annot2'], k

    def test_contains(self):
        "AnnotationDB contains"
        assert 'annot1' in self.db, self.db.keys()
        assert 'annot2' in self.db
        assert 'foo' not in self.db

    def test_has_key(self):
        "AnnotationDB has key"
        assert 'annot1' in self.db
        assert 'annot2' in self.db
        assert 'foo' not in self.db

    def test_get(self):
        "AnnotationDB get"
        assert self.db.get('foo') is None
        assert self.db.get('annot1') is not None
        assert str(self.db.get('annot1').sequence).startswith('ATGGGGC')
        assert self.db.get('annot2') is not None
        assert str(self.db.get('annot2').sequence).startswith('GCCG')

    def test_items(self):
        "AnnotationDB items"
        i = [k for (k, v) in self.db.items()]
        i.sort()
        assert i == ['annot1', 'annot2']

    def test_iterkeys(self):
        "AnnotationDB iterkeys"
        kk = self.db.keys()
        kk.sort()
        ik = list(self.db.iterkeys())
        ik.sort()
        assert kk == ik

    def test_itervalues(self):
        "AnnotationDB itervalues"
        kv = self.db.values()
        kv.sort()
        iv = list(self.db.itervalues())
        iv.sort()
        assert kv[0] == iv[0]
        assert kv == iv, (kv, iv)

    def test_iteritems(self):
        "AnnotationDB iteritems"
        ki = self.db.items()
        ki.sort()
        ii = list(self.db.iteritems())
        ii.sort()
        assert ki == ii, (ki, ii)

    def test_readonly(self):
        "AnnotationDB readonly"
        try:
            self.db.copy()  # what should 'copy' do on AD?
            assert 0, 'this method should raise NotImplementedError'
        except NotImplementedError:
            pass
        try:  # what should 'setdefault' do on AD?
            self.db.setdefault('foo')
            assert 0, 'this method should raise NotImplementedError'
        except NotImplementedError:
            pass
        try:  # what should 'update' do on AD?
            self.db.update({})
            assert 0, 'this method should raise NotImplementedError'
        except NotImplementedError:
            pass
        try:
            self.db.clear()
            assert 0, 'this method should raise NotImplementedError'
        except NotImplementedError:
            pass
        try:
            self.db.pop()
            assert 0, 'this method should raise NotImplementedError'
        except NotImplementedError:
            pass
        try:
            self.db.popitem()
            assert 0, 'this method should raise NotImplementedError'
        except NotImplementedError:
            pass

    def test_equality(self):
        "AnnotationDB equality"
        # Check that separately generated annotation objects test equal"
        key = 'annot1'
        db = self.db
        x = db.sliceAnnotation(key, db.sliceDB[key])
        y = db.sliceAnnotation(key, db.sliceDB[key])
        assert x == y

    def test_bad_seqdict(self):
        "AnnotationDB bad seqdict"

        class Annotation(object):
            def __init__(self, **kwargs):
                self.__dict__.update(kwargs)

        slicedb = dict(annot1=Annotation(id='seq', start=0, stop=10),
                       annot2=Annotation(id='seq', start=5, stop=9))
        foo_dict = dict(foo=Sequence('ATGGGGCCGATTG', 'foo'))
        try:
            db = AnnotationDB(slicedb, foo_dict)
            assert 0, "incorrect seqdb; key error should be raised"
        except KeyError:
            pass