def assemble(self, assemblies): primer_builder = ExtractionPrimerBuilder() for assembly in assemblies: part_records = [] part_amplicons = [] for part_node in assembly.parts: part = part_node.part part_amplicon, part_seq_record = primer_builder.design_primer_for_part(part) part_records.append(part_seq_record) part_amplicons.append(part_amplicon) fragments = assembly_fragments(part_amplicons) for idx in range(len(fragments)): fragments[idx].locus = part_records[idx].name #print(fragments) assemblyobj = Assembly( fragments, limit=20) linear_contigs = assemblyobj.assemble_linear() if len(linear_contigs) != 1: raise Exception( '%s resulted in %d contigs. We were hoping for just one.' % ( len(linear_contigs) )) assembly.contig = linear_contigs[0] #print(assembly.contig.figure()) return assemblies
def test_primer_Design_with_linker(): ''' test_primer_design''' b = Dseqrecord( "agctactgactattaggggttattctgatcatctgatctactatctgactgtactgatcta") l = Dseqrecord("AAATTTCCCGGG") c = Dseqrecord( "tctgatctactatctgactgtactgatctattgacactgtgatcattctagtgtattactc") frags = assembly_fragments((primer_design(b), l, primer_design(c))) asm1 = Assembly(frags) assert asm1.assemble_linear()[0].seguid(), ( b + l + c).seguid() == 'l95igKB8iKAKrvvqE9CYksyNx40' frags = assembly_fragments( (primer_design(b), l, primer_design(c), primer_design(b))) b2 = pcr(frags[-1].forward_primer, frags[0].reverse_primer, b) asm2 = Assembly((b2, frags[1], frags[2])) assert (b + l + c).looped().cseguid() == asm2.assemble_circular()[0].cseguid() assert (b + l + c).looped().cseguid() == 'jdHXfQI5k4Sk2ESiZYfKv4oP2FI'
def test_primer_design_four_fragments(): x = [primer_design(f) for f in frags] fourth = Dseqrecord("TAAAAATAAAATTGTTGACAGCAGAAGTGATATAGAAATTTGTTAATTATTA") y = assembly_fragments(x + [fourth], 20) z = Assembly(y, limit=20) result = z.assemble_linear()[0] assert result.seq == (frags[0] + frags[1] + frags[2] + fourth).seq
def test_primer_design_same_first_and_third_Dseqrecord(): from pydna.dseqrecord import Dseqrecord x = [primer_design(f) for f in frags] y = assembly_fragments([frags[0], x[1], frags[0]], 20) z = Assembly(y, limit=20) result = z.assemble_circular()[0] assert result.cseguid() == (frags[0] + frags[1]).looped().cseguid() a = Dseqrecord("ccaaggacacaatcgagctccgatccgtactgtcgagaaacttgtatcc", name="a") b = Dseqrecord( "ctgtcgagaaacttgtatccctctaactagtatggatagccgtgtcttcactgtgctgcggctacccatcccaaggacacaatcgagctc", name="b", ) z = Assembly((a, b, a), limit=20) result = z.assemble_linear()[0] assert ( str(result.seq) == "ccaaggacacaatcgagctccgatccgtactgtcgagaaacttgtatccctctaactagtatggatagccgtgtcttcactgtgctgcggctacccatcccaaggacacaatcgagctccgatccgtactgtcgagaaacttgtatcc" ) result = z.assemble_circular()[0] assert result.cseguid() == (frags[0] + frags[1]).looped().cseguid()
def test_primer_Design(): ''' test_primer_design''' a = Dseqrecord( "atgactgctaacccttccttggtgttgaacaagatcgacgacatttcgttcgaaacttacgatg") b = Dseqrecord( "ccaaacccaccaggtaccttatgtaagtacttcaagtcgccagaagacttcttggtcaagttgcc") c = Dseqrecord( "tgtactggtgctgaaccttgtatcaagttgggtgttgacgccattgccccaggtggtcgtttcgtt") frags = assembly_fragments([primer_design(r) for r in (a, b, c)]) asm = Assembly(frags) assert asm.assemble_linear()[0].seguid() == "1eNv3d_1PqDPP8qJZIVoA45Www8" frags = assembly_fragments([primer_design(r) for r in (a, b, c, a)]) a2 = pcr(frags[-1].forward_primer, frags[0].reverse_primer, a) asm = Assembly((a2, frags[1], frags[2])) assert asm.assemble_circular()[0].cseguid( ) == "V3Mi8zilejgyoH833UbjJOtDMbc"
def test_primer_design_linker_first(): x = [primer_design(f) for f in frags] y = assembly_fragments([bam, x[0], x[1], x[2]], 20) z = Assembly(y, limit=20) result = z.assemble_linear()[0] assert result.seq == (bam + frags[0] + frags[1] + frags[2]).seq
def test_primer_design_first_and_third_Dseqrecord(): x = [primer_design(f) for f in frags] y = assembly_fragments([frags[0], x[1], frags[2]], 20) z = Assembly(y, limit=20) result = z.assemble_linear()[0] assert result.seq == (frags[0] + frags[1] + frags[2]).seq
def test_primer_design_all_pcr_products(): x = [primer_design(f) for f in frags] y = assembly_fragments(x, 20) z = Assembly(y, limit=20) result = z.assemble_linear()[0] assert result.seq == (frags[0] + frags[1] + frags[2]).seq
def test_primer_design_two_fragments_flanking_linkers(): x = [primer_design(f) for f in frags] y = assembly_fragments([bam, x[0], x[1], bam], 20) z = Assembly(y, limit=20) result = z.assemble_linear()[0] assert result.seq == (bam + frags[0] + frags[1] + bam).seq
def test_primer_design_two_fragments_linker_in_between(): # x = [primer_design(f) for f in frags] y = assembly_fragments([x[0], bam, x[1]], 20, 20) z = Assembly(y, limit=20) result = z.assemble_linear()[0] assert result.seq == (frags[0] + bam + frags[1]).seq
def test_primer_design_two_fragments(): x = [primer_design(f) for f in frags] y = assembly_fragments([x[0], x[1]], 20) z = Assembly(y, limit=20) result = z.assemble_linear()[0] assert result.seq == (frags[0] + frags[1]).seq
def test_primer_design_linker_second_before_Dseqrecord(): x = [primer_design(f) for f in frags] y = assembly_fragments([x[0], bam, frags[1], x[2]], 20) z = Assembly(y, limit=20) result = z.assemble_linear()[0] assert result.seq == (frags[0] + bam + frags[1] + frags[2]).seq
def test_primer_design_linker_third(): # x = [primer_design(f) for f in frags] y = assembly_fragments([x[0], x[1], bam, x[2]], maxlink=6, overlap=20) z = Assembly(y, limit=20) result = z.assemble_linear()[0] assert result.seq == (frags[0] + frags[1] + bam + frags[2]).seq
def test_contig(monkeypatch): monkeypatch.setenv("pydna_cached_funcs", "") from pydna import contig from pydna.assembly import Assembly from pydna.dseqrecord import Dseqrecord a = Dseqrecord("acgatgctatactgCCCCCtgtgctgtgctcta", name="one") b = Dseqrecord("tgtgctgtgctctaTTTTTtattctggctgtatc", name="two") c = Dseqrecord("tattctggctgtatcGGGGGtacgatgctatactg", name="three") asm = Assembly((a, b, c), limit=14) cnt = asm.assemble_circular()[0] assert repr(cnt) == "Contig(o59)" assert cnt.detailed_figure() == str( "||||||||||||||\n" "acgatgctatactgCCCCCtgtgctgtgctcta\n" " TGTGCTGTGCTCTA\n" " tgtgctgtgctctaTTTTTtattctggctgtatc\n" " TATTCTGGCTGTATC\n" " tattctggctgtatcGGGGGtacgatgctatactg\n" " ACGATGCTATACTG\n" ) from textwrap import indent fig = """ -|one|14 | \\/ | /\\ | 14|two|15 | \\/ | /\\ | 15|three|14 | \\/ | /\\ | 14- | | -------------------------""" cnt2 = asm.assemble_linear()[0] fig = ('one|14\n' ' \\/\n' ' /\\\n' ' 14|two|15\n' ' \\/\n' ' /\\\n' ' 15|three') assert fig == cnt2.figure() assert repr(cnt2) == 'Contig(-73)' #print(repr(cnt2._repr_html_())) assert cnt2._repr_html_( ) == '<pre>one|14\n \\/\n /\\\n 14|two|15\n \\/\n /\\\n 15|three</pre>' from unittest.mock import MagicMock pp = MagicMock() cnt2._repr_pretty_(pp, None) pp.text.assert_called_with('Contig(-73)') from Bio.Seq import Seq from Bio.Alphabet.IUPAC import IUPACAmbiguousDNA from pydna.seqrecord import SeqRecord arg = SeqRecord(Seq("aaa", IUPACAmbiguousDNA())) import networkx as nx x = contig.Contig.from_SeqRecord(arg, graph=nx.MultiDiGraph())