Exemple #1
0
    def test_get_slice_list_of_ints(self):
        span = Span(8, 22, 10, cyclic=True)
        x = list(range(20, 140))
        y = span.get_slice(x)
        print(list(span.get_slice_iter(x)))
        print(y)
        assert y == [x[_s] for _s in list(span)]

        span = Span(8, 22, 10, cyclic=True)
        x = tuple(range(20, 140))
        y = span.get_slice(x)
        assert y == tuple([x[_s] for _s in list(span)])
Exemple #2
0
    def test_get_slice_seqrecord(self):
        seq = SeqRecord(Seq("AGGGTGTGTGCGA"))
        span = Span(8, 22, len(seq), cyclic=True)

        seq2 = span.get_slice(seq)
        assert isinstance(seq2, SeqRecord)
        assert isinstance(seq2.seq, Seq)
        print(seq2)
Exemple #3
0
def pcr_amplify(
    fwd: SeqRecord,
    rev: SeqRecord,
    template: SeqRecord,
    cyclic: bool,
    cyclic_buffer: int = 100,
    name: str = None,
    return_matches: bool = False,
):
    original_template = template
    if cyclic:
        template = template + template + template[:cyclic_buffer]
    fwd_matches, rev_matches = anneal(str(template.seq), [str(fwd.seq), str(rev.seq)])

    products_by_sequence = {}
    for f, r in itertools.product(fwd_matches, rev_matches):
        i = f["top_strand_slice"][0]
        j = r["top_strand_slice"][1]

        try:
            span = Span(
                i,
                j,
                length=len(original_template.seq),
                cyclic=cyclic,
                ignore_wrap=True,
            )
        except IndexError as e:
            if not cyclic:
                continue
            else:
                raise e

        f_rec = new_sequence(
            f["overhang"], name=fwd.name + "_overhang", auto_annotate=True
        )
        r_rec = new_sequence(
            rc(r["overhang"]), name=rev.name + "_overhang", auto_annotate=True
        )

        product = span.get_slice(original_template)
        # annotate(template_chunk, name="source: {}".format(template_name[:40]))
        if len(f_rec.seq):
            product = f_rec + product
        if len(r_rec.seq):
            product = product + r_rec

        if not name:
            name = original_template.name or original_template.id
            name += "[{}:{}]".format(span.a, span.b)
        # annotate(product, name=name)
        if len(product) <= len(original_template.seq):
            products_by_sequence[str(product.seq)] = (product, span.a, span.b)
    product_list = list(products_by_sequence.values())
    product_list.sort(key=lambda x: (x[1], len(product)))
    if return_matches:
        return product_list, fwd_matches, rev_matches
    return product_list
Exemple #4
0
 def test_get_slice_str(self):
     span = Span(8, 22, 10, cyclic=True)
     x = "abcdefghijklmnopqrstuv"
     y = span.get_slice(x)
     print(y)