Esempio n. 1
0
def get_prop_primers(primers, vector):
    vector_name = vector.name
    seq = str.lower(vector.sequence)
    seq = Dseq(seq.replace(' ', ''))
    L = len(str(seq))
    rseq = seq.reverse_complement()
    for primer in primers:
        primer_nor = primer.sequence.replace(' ', '')

        p_seq = Dseq(primer_nor)
        p_seq_s = str.lower(str(p_seq))  # all lower case
        nt = 'atcgn'
        idt_codes_subtract1 = ['icy5', 'icy3', '5biosg', '(am)']
        idt_codes_subtract2 = ['dspacer']
        idt_codes_subtract3 = ['dbcoteg']
        idt_codes_subtract4 = ['biotinteg']
        idt_codes_plus1 = ['ds', 'idsp']

        Lp_subtract = 0
        for s1 in idt_codes_subtract1:
            if p_seq_s.find(s1) >= 0:
                Lp_subtract += 1
        for s2 in idt_codes_subtract2:
            if p_seq_s.find(s2) >= 0:
                Lp_subtract += 2
        for s3 in idt_codes_subtract3:
            if p_seq_s.find(s3) >= 0:
                Lp_subtract += 3
        for s4 in idt_codes_subtract4:
            if p_seq_s.find(s4) >= 0:
                Lp_subtract += 4
        for p1 in idt_codes_plus1:
            if p_seq_s.find(p1) >= 0:
                Lp_subtract -= 1

        Lp = 0
        for i in nt:
            Lp += p_seq_s.count(i)
        Lp = Lp - Lp_subtract
        if seq.find(p_seq_s) != -1:  # match it
            position = seq.find(p_seq_s) + 1
            dir = 'forward'
            in_vector = True
        elif rseq.find(p_seq_s) != -1:
            position = rseq.find(p_seq_s) - L - 1
            dir = 'reverse'
            in_vector = True
        else:
            position = -1
            dir = 'none'
            in_vector = False
        primer.position = position
        primer.dir = dir
        primer.in_vector = in_vector
        primer.length = Lp
        primer.save()
    return vector_name, seq, L, position, dir, in_vector
Esempio n. 2
0
def test_dseq():

    import textwrap
    from pydna.dseq import Dseq

    obj1 = Dseq("a", "t", circular=True)
    obj2 = Dseq("a", "t")

    with pytest.raises(TypeError):
        obj1 + obj2

    with pytest.raises(TypeError):
        obj2 + obj1

    with pytest.raises(TypeError):
        obj1 + ""

    with pytest.raises(AttributeError):
        obj2 + ""

    obj1 = Dseq("at", "t")
    obj2 = Dseq("a", "t")

    with pytest.raises(TypeError):
        obj1 + obj2

    obj = Dseq("aaa", "ttt", circular=True)
    assert obj[1:2] == Dseq("a", "t", 0)

    assert obj[:] == Dseq("aaa", "ttt", circular=False)

    obj = Dseq("atg", "cat", 0, circular=False)

    assert obj[1:2]._data == "atg"[1:2]

    assert obj[2:1]._data == "atg"[2:1]

    assert obj.reverse_complement() == obj.rc() == Dseq("cat", "atg", 0)

    obj = Dseq("atg", "cat", circular=True)

    assert obj.looped() == obj

    assert obj[:] == Dseq("atg", "cat", 0, circular=False)

    assert obj[1:2]._data == "atg"[1:2]

    assert obj[2:1]._data == "ga"

    obj = Dseq("G", "", 0)
    assert obj.five_prime_end() == ("5'", "g")
    obj = Dseq("", "C", 0)
    assert obj.five_prime_end() == ("3'", "c")

    obj = Dseq("ccGGATCC", "aaggatcc", -2)
    assert obj._data == "ccGGATCCtt"
    assert str(obj.mung()) == "GGATCC"
    rpr = textwrap.dedent(
        """
    Dseq(-10)
    ccGGATCC
      cctaggaa
    """
    ).strip()
    assert repr(obj) == rpr

    assert obj[3] == Dseq("G", "c", 0)

    assert obj.fill_in() == Dseq("ccGGATCCtt", "aaggatccgg", 0)

    assert obj + Dseq("") == obj
    assert Dseq("") + obj == obj

    obj = Dseq("gatcAAAAAA", "gatcTTTTTT")
    assert obj.fill_in("gatc") == Dseq("gatcAAAAAAgatc", "gatcTTTTTTgatc")
    assert obj.fill_in("atc") == obj
    assert obj.fill_in("ac") == obj
    assert obj.fill_in("at") == obj

    obj = Dseq("AAAAAAgatc", "TTTTTTgatc")
    assert obj.fill_in("gatc") == obj
    assert obj.fill_in("atc") == obj
    assert obj.fill_in("ac") == obj
    assert obj.fill_in("at") == obj

    obj = Dseq("gatcAAAAAA", "gatcTTTTTT")
    assert obj.t4() == Dseq("gatcAAAAAAgatc", "gatcTTTTTTgatc")

    assert obj.t4("at") == obj
    assert obj.t4("atg") == Dseq("gatcAAAAAAgat", "gatcTTTTTTgat")
    assert obj.t4("atgc") == Dseq("gatcAAAAAAgatc", "gatcTTTTTTgatc")
    assert obj.mung() == Dseq("AAAAAA", "TTTTTT")

    obj = Dseq("AAAAAAgatc", "TTTTTTgatc")
    assert obj.t4() == obj.t4("at") == Dseq("AAAAAA")
    assert obj.t4("atc") == obj.t4("atg") == obj.t4("atcg") == Dseq("AAAAAA")

    assert Dseq("GGATCC", "GGATCC").t4() == Dseq("GGATCC", "GGATCC")
    assert Dseq("GGATCCa", "GGATCC").t4() == Dseq("GGATCC", "GGATCC")
    assert Dseq("aGGATCC", "GGATCC").t4() == Dseq("aGGATCC", "GGATCCt")
    assert Dseq("aGGATCCa", "GGATCC").t4() == Dseq("aGGATCC", "GGATCCt")
    assert Dseq("GGATCC", "aGGATCC").t4() == Dseq("GGATCCt", "aGGATCC")
    assert Dseq("GGATCC", "GGATCCa").t4() == Dseq("GGATCC", "GGATCC")
    assert Dseq("GGATCC", "aGGATCCa").t4() == Dseq("GGATCCt", "aGGATCC")

    assert Dseq("GGATCC", "ATCC").t4("g") == Dseq("gg", "", ovhg=0)
    assert Dseq("GGATCC", "GGATCC").t4("gat") == Dseq("ggat", "ggat", ovhg=-2)

    a2 = Dseq("ccGGATCCaa", "ggatcc", -2)
    assert a2._data == "ccGGATCCaa"
    assert a2._data == "ccGGATCCaa"
    assert str(a2.mung()) == "GGATCC"
    rpr = textwrap.dedent(
        """
    Dseq(-10)
    ccGGATCCaa
      cctagg
    """
    ).strip()
    assert repr(a2) == rpr

    a3 = Dseq("ccGGATCC", "ggatcc", -2)
    assert a3._data == "ccGGATCC"
    assert a3._data == "ccGGATCC"
    assert str(a3.mung()) == "GGATCC"
    rpr = textwrap.dedent(
        """
    Dseq(-8)
    ccGGATCC
      cctagg
    """
    ).strip()
    assert repr(a3) == rpr

    b = Dseq("GGATCC", "aaggatcccc", 2)
    assert b._data == "ggGGATCCtt"
    assert b._data == "ggGGATCCtt"
    assert str(b.mung()) == "GGATCC"
    rpr = textwrap.dedent(
        """
    Dseq(-10)
      GGATCC
    cccctaggaa
    """
    ).strip()
    assert repr(b) == rpr

    b2 = Dseq("GGATCCaa", "ggatcccc", 2)
    assert b2._data == "ggGGATCCaa"
    assert b2._data == "ggGGATCCaa"
    assert str(b2.mung()) == "GGATCC"
    rpr = textwrap.dedent(
        """
    Dseq(-10)
      GGATCCaa
    cccctagg
    """
    ).strip()
    assert repr(b2) == rpr

    assert b2.seguid() == "hPNrcQ0sluXyfu4XuUh1trsnygc"

    b3 = Dseq("GGATCC", "ggatcccc", 2)
    assert b3._data == "ggGGATCC"
    assert b3._data == "ggGGATCC"
    assert str(b3.mung()) == "GGATCC"
    rpr = textwrap.dedent(
        """
    Dseq(-8)
      GGATCC
    cccctagg
    """
    ).strip()
    assert repr(b3) == rpr

    c = Dseq("GGATCCaaa", "ggatcc", 0)
    assert c._data == "GGATCCaaa"
    assert c._data == "GGATCCaaa"
    assert str(c.mung()) == "GGATCC"
    rpr = textwrap.dedent(
        """
    Dseq(-9)
    GGATCCaaa
    cctagg
    """
    ).strip()
    assert repr(c) == rpr

    d = Dseq("GGATCC", "aaaggatcc", 0)
    assert d._data == "GGATCCttt"
    assert d._data == "GGATCCttt"
    assert str(d.mung()) == "GGATCC"
    rpr = textwrap.dedent(
        """
    Dseq(-9)
    GGATCC
    cctaggaaa
    """
    ).strip()
    assert repr(d) == rpr

    obj = Dseq("GGATCCaaa", "ggatcc", 0)
    from Bio.Restriction import BamHI

    frag1 = Dseq("G", "gatcc", 0)
    frag2 = Dseq("GATCCaaa", "g", -4)

    assert obj.cut(BamHI) == (frag1, frag2)

    assert frag1 + frag2 == obj

    obj.seguid() == "HtK7-_BmOJw0BmtYE8f1yGdHc0c"

    assert frag1.seguid() == "yJkorWG5V2etvSLp6E6QNK-KMlQ"
    assert frag2.seguid() == "Aw3buI-N85OztBZAzeGJvXGlwO8"

    obj = Dseq("tagcgtagctgtagtatgtgatctggtcta", "tagaccagatcacatactacagctacgcta")
    assert (
        repr(obj)
        == "Dseq(-30)\ntagcgtagctgtagtatgtgatctggtcta\natcgcatcgacatcatacactagaccagat"
    )

    obj2 = Dseq("tagcgtagctgtagtatgtgatctggtcta")

    obj3 = obj = Dseq(
        "tagcgtagctgtagtatgtgatctggtcta", "tagaccagatcacatactacagctacgcta", 0
    )

    assert obj == obj2 == obj3

    assert obj.find("ggatcc") == -1

    assert obj.find("tgtagta") == 9

    obj = Dseq("tagcgtagctgtagtatgtgatctggtctaa", "ttagaccagatcacatactacagctacgcta")

    obj = Dseq("tagcgtagctgtagtatgtgatctggtctaa", "CCCttagaccagatcacatactacagctacgcta")

    assert repr(obj) == "Dseq(-34)\ntagc..ctaa   \natcg..gattCCC"

    obj = Dseq("tagcgtagctgtagtatgtgatctggtctaaCCC", "ttagaccagatcacatactacagctacgcta")

    assert repr(obj) == "Dseq(-34)\ntagc..ctaaCCC\natcg..gatt   "

    obj = Dseq("agcgtagctgtagtatgtgatctggtctaa", "ttagaccagatcacatactacagctacgcta")
    assert repr(obj) == "Dseq(-31)\n agcg..ctaa\natcgc..gatt"

    obj = Dseq("Atagcgtagctgtagtatgtgatctggtctaa", "ttagaccagatcacatactacagctacgcta")
    assert repr(obj) == "Dseq(-32)\nAtagc..ctaa\n atcg..gatt"

    obj = Dseq(
        "tagcgtagctgtagtatgtgatctggtctaa", "tatcgcatcgacatcatacactagaccagatt"[::-1]
    )

    assert repr(obj) == "Dseq(-32)\n tagc..ctaa\ntatcg..gatt"

    assert round(obj.mw(), 1) == 19535.6

    obj1 = Dseq(
        "tagcgtagctgtagtatgtgatctggtcta",
        "tagaccagatcacatactacagctacgcta",
        circular=True,
        linear=False,
    )
    obj2 = Dseq(
        "tagcgtagctgtagtatgtgatctggtcta",
        "tagaccagatcacatactacagctacgcta",
        circular=True,
    )
    obj3 = Dseq(
        "tagcgtagctgtagtatgtgatctggtcta", "tagaccagatcacatactacagctacgcta", linear=False
    )

    assert obj1 == obj2 == obj3

    assert obj1.find("ggatcc") == -1

    assert obj1.find("tgtagta") == 9

    assert (
        Dseq(
            "tagcgtagctgtagtatgtgatctggtcta", "tagaccagatcacatactacagctacgcta"
        ).looped()
        == obj1
    )

    from Bio.Restriction import BglII, BamHI

    obj = Dseq("ggatcc")

    assert BglII in obj.no_cutters()
    assert BamHI not in obj.no_cutters()

    assert BamHI in obj.unique_cutters()

    assert BamHI in obj.once_cutters()

    assert BamHI in (obj + obj).twice_cutters()
    assert BamHI not in obj.twice_cutters()

    assert BamHI in obj.n_cutters(1)
    assert BamHI in obj.cutters()

    from Bio.Restriction import RestrictionBatch

    rb = RestrictionBatch((BamHI, BglII))

    assert obj.cut(rb) == obj.cut(BamHI, BglII) == obj.cut(BglII, BamHI)

    obj = Dseq("ggatccAGATCT")

    assert obj.cut(rb) == obj.cut(BamHI, BglII) == obj.cut(BglII, BamHI)

    obj = Dseq("AGATCTggatcc")

    assert obj.cut(rb) == obj.cut(BamHI, BglII) == obj.cut(BglII, BamHI)

    obj = Dseq("ggatccAGATCT", circular=True)

    assert obj.cut(rb) == obj.cut(BamHI, BglII) != obj.cut(BglII, BamHI)

    obj = Dseq("AGATCTggatcc", circular=True)

    assert obj.cut(rb) == obj.cut(BglII, BamHI) != obj.cut(BamHI, BglII)
Esempio n. 3
0
def calpcr(request):
    # pbr = Vector.objects.get(name='pbr322')
    primers = Primer.objects.all()
    vector = primers[0].vector
    vector_name = vector.name
    seq = str.lower(vector.sequence)
    seq = Dseq(seq.replace(' ', ''))
    L = len(str(seq))
    rseq = seq.reverse_complement()
    poss = []
    for primer in primers:
        p_seq = Dseq(primer.sequence.replace(' ', ''))
        p_seq_s = str.lower(str(p_seq)) # all lower case
        nt='atcgn'
        idt_codes_subtract1 = ['icy5', 'icy3', '5biosg', '(am)']
        idt_codes_subtract2 = ['dspacer']
        idt_codes_subtract3 = ['dbcoteg']
        idt_codes_subtract4 = ['biotinteg']
        idt_codes_plus1 = ['ds', 'idsp']

        Lp_subtract = 0
        for s1 in idt_codes_subtract1:
            if p_seq_s.find(s1) >= 0:
                Lp_subtract += 1
        for s2 in idt_codes_subtract2:
            if p_seq_s.find(s2) >= 0:
                Lp_subtract += 2
        for s3 in idt_codes_subtract3:
            if p_seq_s.find(s3) >= 0:
                Lp_subtract += 3
        for s4 in idt_codes_subtract4:
            if p_seq_s.find(s4) >= 0:
                Lp_subtract += 4
        for p1 in idt_codes_plus1:
            if p_seq_s.find(p1) >= 0:
                Lp_subtract -= 1

        Lp = 0
        for i in nt:
            Lp += p_seq_s.count(i)
        Lp = Lp - Lp_subtract
        # Lp = len(p_seq_s)
        if seq.find(p_seq_s) != -1: # match it
            position = seq.find(p_seq_s) + 1
            dir = 'forward'
            in_vector = True
        elif rseq.find(p_seq_s) != -1:
            position = rseq.find(p_seq_s) - L - 1
            dir = 'reverse'
            in_vector = True
        else:
            position = -1
            dir = 'none'
            in_vector = False
        primer.position = position
        primer.dir = dir
        primer.in_vector = in_vector
        primer.length = Lp
        primer.save()

    primers = primers.filter(in_vector=True).order_by('position')
    # primers = Primer.objects.all().order_by('-created_at')
    primerFilter = PrimerFilter(queryset=primers)

    if request.method == 'POST' and 'Search' in request.POST:
        primerFilter = PrimerFilter(request.POST, queryset=primers)

    L = len(str(seq))

    # if request.method == 'POST' and 'cal' in request.POST:
    check_box_list = request.POST.getlist("check_box")
    if len(check_box_list) == 2:
        primer_1 = Primer.objects.get(id=check_box_list[0])
        p1_name = primer_1.name
        primer_2 = Primer.objects.get(id=check_box_list[1])
        p2_name = primer_2.name


        if primer_1.dir == 'reverse' and primer_2.dir == 'forward':
            pr = primer_1.position
            pr_name = primer_1.name
            pr_seq = primer_1.sequence
            pf = primer_2.position
            pf_name = primer_2.name
            pf_seq = primer_2.sequence
        elif primer_2.dir == 'reverse' and primer_1.dir == 'forward':
            pr = primer_2.position
            pr_name = primer_2.name
            pr_seq = primer_2.sequence
            pf = primer_1.position
            pf_name = primer_1.name
            pf_seq = primer_1.sequence

        else:
            pr = 0
            pf = 0
        if abs(pr) >= abs(pf):
            L_pcr = -pr - pf
        else:
            L_pcr = L - pr - pf
        show_seq = plotpcr(str(seq), pf_seq, pr_seq)
        primer_name = [pf_name] + [pr_name]
        primer_position = [pf, pr]
    else:
        L_pcr = 'You can only select two primers!!'
        primer_name = ['','']
        show_seq = "can't pcr"
        primer_name = [''] + ['']
        primer_position = ['x', 'x']

    return render(request, template_name='primer/seq.html',
                  context={'seq': seq, 'L': L, 'primers': primers, 'show_seq': show_seq,
                           'primerFilter': primerFilter, 'primer_name': primer_name,
                           'L_pcr': L_pcr, 'vector_name': vector_name, 'primer_position': primer_position,
                           })