Esempio n. 1
0
def test_add_multiple_transformations():
    """We expect that when we add a record with a transformation, that the we
    can obtain the origin record and transformed record."""

    db = SeqRecordDB()
    from uuid import uuid4
    from pyblast.constants import Constants as C

    def pseudocircularize(r):
        pseudor = r + r
        pseudor.name = C.PSEUDOCIRCULAR + "__" + r.name
        pseudor.id = str(uuid4())
        return pseudor

    record = SeqRecord(
        Seq("ACGTTCGTGATTGTGCTGTGTGTATGGTATGATTATAGTGATGTAGTGATGATGTAGTAGTATA")
    )
    r1 = deepcopy(record)
    r2 = deepcopy(record)
    r1.id = "record1"
    r2.id = "record2"
    records = make_circular([r1, r2])

    keys = db.add_many_with_transformations(records, pseudocircularize,
                                            C.PSEUDOCIRCULAR)
    assert len(keys) == 2
    assert len(db) == 4
Esempio n. 2
0
def test_add_with_transform():
    """We expect that when we add a record with a transformation, that the we
    can obtain the origin record and transformed record."""

    db = SeqRecordDB()
    from uuid import uuid4
    from pyblast.constants import Constants as C

    def pseudocircularize(r):
        r2 = r + r
        r2.name = C.PSEUDOCIRCULAR + "__" + r.name
        r2.id = str(uuid4())
        return r2

    record = SeqRecord(
        Seq("ACGTTCGTGATTGTGCTGTGTGTATGGTATGATTATAGTGATGTAGTGATGATGTAGTAGTATA")
    )
    records = make_circular([record])

    keys = db.add_many_with_transformations(records, pseudocircularize,
                                            C.PSEUDOCIRCULAR)

    key = keys[0]
    origin_key = db.get_origin_key(key)
    origin = db.get_origin(key)
    transformed = db.get(key)

    assert origin is record
    assert origin is not transformed
    assert origin_key is not key
    assert len(transformed) == 2 * len(record)
Esempio n. 3
0
def test_add_same_transformation():
    """We expect that when we add a record with a transformation, that the we
    can obtain the origin record and transformed record."""

    db = SeqRecordDB()
    from uuid import uuid4
    from pyblast.constants import Constants as C

    def pseudocircularize(r):
        r2 = r + r
        r2.name = C.PSEUDOCIRCULAR + "__" + r.name
        r2.id = str(uuid4())
        return r2

    record = SeqRecord(
        Seq("ACGTTCGTGATTGTGCTGTGTGTATGGTATGATTATAGTGATGTAGTGATGATGTAGTAGTATA")
    )
    records = make_circular([record, record])

    keys = db.add_many_with_transformations(records, pseudocircularize,
                                            C.PSEUDOCIRCULAR)
    assert len(set(keys)) == 1
    assert len(db) == 2
Esempio n. 4
0
    def __init__(self, seq_db=None, span_origin=True, config=None):
        """Initialize a new BioBlastFactory.

        :param seq_db: the optional SeqRecordDB. If not provided, a new one will be
            created.
        :type seq_db: SeqRecordDB
        """
        if seq_db is None:
            self.db = SeqRecordDB()
        else:
            self.db = seq_db
        self.span_origin = span_origin
        self.record_groups = {}
        self.logger = logger(self)
        self.config = config
Esempio n. 5
0
def test_get_records():
    db = SeqRecordDB()
    keys = db.add_many([random_record(), random_record()])
    assert keys
    assert db.get_many(keys)
Esempio n. 6
0
def test_get_record():
    db = SeqRecordDB()
    r = random_record()
    k = db.add(r)
    assert k
    assert db.get(k) is r
Esempio n. 7
0
def test_add_records():
    db = SeqRecordDB()
    db.add_many([random_record(), random_record()])
Esempio n. 8
0
def test_add_record():
    db = SeqRecordDB()
    db.add(random_record())
Esempio n. 9
0
def test_init():
    SeqRecordDB()