def test_Dseq_cutting_adding(): from pydna.dseq import Dseq from Bio.Restriction import BamHI, PstI, EcoRI a = Dseq( "GGATCCtcatctactatcatcgtagcgtactgatctattctgctgctcatcatcggtactctctataattatatatatatgcgcgtGGATCC", "CCTAGGagtagatgatagtagcatcgcatgactagataagacgacgagtagtagccatgagagatattaatatatatatacgcgcaCCTAGG"[:: -1], linear=True, ovhg=0, ) b = a.cut(BamHI)[1] assert ( b.watson == "GATCCtcatctactatcatcgtagcgtactgatctattctgctgctcatcatcggtactctctataattatatatatatgcgcgtG" ) assert ( b.crick == "GATCCacgcgcatatatatataattatagagagtaccgatgatgagcagcagaatagatcagtacgctacgatgatagtagatgaG" ) c = Dseq( "nCTGCAGtcatctactatcatcgtagcgtactgatctattctgctgctcatcatcggtactctctataattatatatatatgcgcgtGAATTCn", "nGACGTCagtagatgatagtagcatcgcatgactagataagacgacgagtagtagccatgagagatattaatatatatatacgcgcaCTTAAGn"[:: -1], linear=True, ovhg=0, ) f, d, l = c.cut((EcoRI, PstI)) assert ( d.watson == "GtcatctactatcatcgtagcgtactgatctattctgctgctcatcatcggtactctctataattatatatatatgcgcgtG" ) assert ( d.crick == "AATTCacgcgcatatatatataattatagagagtaccgatgatgagcagcagaatagatcagtacgctacgatgatagtagatgaCTGCA" ) e = Dseq( "nGAATTCtcatctactatcatcgtagcgtactgatctattctgctgctcatcatcggtactctctataattatatatatatgcgcgtCTGCAGn", "nCTTAAGagtagatgatagtagcatcgcatgactagataagacgacgagtagtagccatgagagatattaatatatatatacgcgcaGACGTCn"[:: -1], linear=True, ovhg=0, ) f = e.cut((EcoRI, PstI))[1] assert ( f.watson == "AATTCtcatctactatcatcgtagcgtactgatctattctgctgctcatcatcggtactctctataattatatatatatgcgcgtCTGCA" ) assert ( f.crick == "GacgcgcatatatatataattatagagagtaccgatgatgagcagcagaatagatcagtacgctacgatgatagtagatgaG" )
def test_cut_with_no_enzymes(): from pydna.dseq import Dseq x = Dseq("ctcgGCGGCCGCcagcggccg") assert x.cut([]) == () x = Dseq("ctcgGCGGCCGCcagcggccg", circular=True) assert x.cut([]) == ()
def test_Dseq_slicing2(): from pydna.dseq import Dseq from Bio.Restriction import BamHI, EcoRI, KpnI a = Dseq("aaGGATCCnnnnnnnnnGAATTCccc", circular=True) assert a.cut(EcoRI, BamHI, KpnI,) == a.cut( BamHI, EcoRI, KpnI, )[::-1]
def test_cut_missing_enzyme(): from pydna.dseq import Dseq x = Dseq("ctcgGCGGCCGCcagcggccg") from Bio.Restriction import PstI assert x.cut(PstI) == () x = Dseq("ctcgGCGGCCGCcagcggccg", circular=True) assert x.cut(PstI) == ()
def cut_and_religate_Dseq(seq_string, enz, top): ds = Dseq(seq_string, linear=top) frags = list(ds.cut(enz)) if not frags: return a = frags.pop(0) for f in frags: a += f if not top: a = a.looped() assert eq(a, ds)
def test_misc(): from pydna.dseq import Dseq x = Dseq("ctcgGCGGCCGCcagcggccg", circular=True) from Bio.Restriction import NotI a, b = x.cut(NotI) z = (a + b).looped() assert z.shifted(5) == x
def test_Dseq_slicing(): from pydna.dseq import Dseq from pydna.readers import read from pydna.utils import eq from Bio.Seq import Seq from Bio.SeqRecord import SeqRecord as Srec from Bio.Restriction import BamHI a = Dseq("ggatcc", "ggatcc", 0) assert a[:].watson == a.watson assert a[:].crick == a.crick assert a.ovhg == a[:].ovhg b, c = a.cut(BamHI) d = b[1:5] e = d.rc() #assert d+e == Dseq("gatc","gatc",0) assert e + d == Dseq("gatc", "gatc", 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)