def test_repr_pretty_(): from pydna._pretty import pretty_str from unittest.mock import MagicMock pp = MagicMock() s = pretty_str("123") t = s._repr_pretty_(pp, None) pp.text.assert_called_with("123")
def small_fig(self): ''' Returns a small ascii representation of the assembled fragments. Each fragment is represented by: :: Size of common 5' substring|Name and size of DNA fragment| Size of common 5' substring Linear: :: frag20| 6 \\/ /\\ 6|frag23| 6 \\/ /\\ 6|frag14 Circular: :: -|2577|61 | \\/ | /\\ | 61|5681|98 | \\/ | /\\ | 98|2389|557 | \\/ | /\\ | 557- | | -------------------------- ''' if self.linear: ''' frag20| 6 \/ /\ 6|frag23| 6 \/ /\ 6|frag14 ''' f = self.source_fragments[0] space2 = len(f.name) fig = ("{name}|{o2:>2}\n" "{space2} \/\n" "{space2} /\\\n").format(name = f.name, o2 = f.right_overlap_size, space2 = " "*space2) space = len(f.name) for f in self.source_fragments[1:-1]: name= "{o1:>2}|{name}|".format(o1 = f.left_overlap_size, name = f.name) space2 = len(name) fig +=("{space} {name}{o2:>2}\n" "{space} {space2}\/\n" "{space} {space2}/\\\n").format( name = name, o2 = f.right_overlap_size, space = " "*space, space2 = " "*space2) space +=space2 f = self.source_fragments[-1] fig += ("{space} {o1:>2}|{name}").format(name = f.name, o1 = f.left_overlap_size, space = " "*(space)) else: ''' -|2577|61 | \/ | /\ | 61|5681|98 | \/ | /\ | 98|2389|557 | \/ | /\ | 557- | | -------------------------- ''' f = self.source_fragments[0] space = len(f.name)+3 fig =(" -|{name}|{o2:>2}\n" "|{space}\/\n" "|{space}/\\\n").format(name = f.name, o2 = f.right_overlap_size, space = " "*space) for f in self.source_fragments[1:]: name= "{o1:>2}|{name}|".format(o1 = f.left_overlap_size, name = f.name) space2 = len(name) fig +=("|{space}{name}{o2:>2}\n" "|{space}{space2}\/\n" "|{space}{space2}/\\\n").format(o2 = f.right_overlap_size, name = name, space = " "*space, space2 = " "*space2) space +=space2 fig +="|{space}{o1:>2}-\n".format(space=" "*(space), o1=self.source_fragments[0].left_overlap_size) fig +="|{space} |\n".format(space=" "*(space)) fig +=" {space}".format(space="-"*(space+3)) return pretty_str(dedent(fig))
def small_fig(self): ''' Returns a small ascii representation of the assembled fragments. Each fragment is represented by: :: Size of common 5' substring|Name and size of DNA fragment| Size of common 5' substring Linear: :: frag20| 6 \\/ /\\ 6|frag23| 6 \\/ /\\ 6|frag14 Circular: :: -|2577|61 | \\/ | /\\ | 61|5681|98 | \\/ | /\\ | 98|2389|557 | \\/ | /\\ | 557- | | -------------------------- ''' if self.linear: ''' frag20| 6 \/ /\ 6|frag23| 6 \/ /\ 6|frag14 ''' f = self.source_fragments[0] space2 = len(f.name) fig = ("{name}|{o2:>2}\n" "{space2} \/\n" "{space2} /\\\n").format(name=f.name, o2=f.right_overlap_size, space2=" " * space2) space = len(f.name) for f in self.source_fragments[1:-1]: name = "{o1:>2}|{name}|".format(o1=f.left_overlap_size, name=f.name) space2 = len(name) fig += ("{space} {name}{o2:>2}\n" "{space} {space2}\/\n" "{space} {space2}/\\\n").format( name=name, o2=f.right_overlap_size, space=" " * space, space2=" " * space2) space += space2 f = self.source_fragments[-1] fig += ("{space} {o1:>2}|{name}").format(name=f.name, o1=f.left_overlap_size, space=" " * (space)) else: ''' -|2577|61 | \/ | /\ | 61|5681|98 | \/ | /\ | 98|2389|557 | \/ | /\ | 557- | | -------------------------- ''' f = self.source_fragments[0] space = len(f.name) + 3 fig = (" -|{name}|{o2:>2}\n" "|{space}\/\n" "|{space}/\\\n").format(name=f.name, o2=f.right_overlap_size, space=" " * space) for f in self.source_fragments[1:]: name = "{o1:>2}|{name}|".format(o1=f.left_overlap_size, name=f.name) space2 = len(name) fig += ("|{space}{name}{o2:>2}\n" "|{space}{space2}\/\n" "|{space}{space2}/\\\n").format( o2=f.right_overlap_size, name=name, space=" " * space, space2=" " * space2) space += space2 fig += "|{space}{o1:>2}-\n".format( space=" " * (space), o1=self.source_fragments[0].left_overlap_size) fig += "|{space} |\n".format(space=" " * (space)) fig += " {space}".format(space="-" * (space + 3)) return pretty_str(dedent(fig))
def dbd_program(self): '''Returns a string containing a text representation of a proposed PCR program using a polymerase with a DNA binding domain such as Pfu-Sso7d. :: Pfu-Sso7d (rate 15s/kb) Three-step| 30 cycles | |Breslauer1986,SantaLucia1998 98.0°C |98.0°C | |SaltC 50mM __________|_____ 72.0°C |72.0°C|Primer1C 1µM 00min30s |10s \ 61.0°C ________|______|Primer2C 1µM | \______/ 0min 0s|10min | | 10s | |4-8°C ''' PfuSso7d_extension_rate = 15 #seconds/kB PCR product extension_time_PfuSso7d = PfuSso7d_extension_rate * len(self) / 1000 # seconds # Ta calculation for enzymes with dsDNA binding domains like Pfu-Sso7d # https://www.finnzymes.fi/tm_determination.html length_of_f = len(self.forward_primer.footprint) length_of_r = len(self.reverse_primer.footprint) if (length_of_f>20 and length_of_r>20 and self.tmf_dbd>=69.0 and self.tmr_dbd>=69.0) or (self.tmf_dbd>=72.0 and self.tmr_dbd>=72.0): f=textwrap.dedent( ''' Pfu-Sso7d (rate {rate}s/kb) Two-step| 30 cycles | |{size}bp 98.0°C |98.0C | |Breslauer1986,SantaLucia1998 _____ __|_____ | |SaltC {saltc:2}mM 00min30s|10s \ 72.0°C|72.0°C|Primer1C {forward_primer_concentration:3}µM | \_______|______|Primer2C {reverse_primer_concentration:3}µM | {0:2}min{1:2}s|10min |4-8°C '''.format(rate = PfuSso7d_extension_rate, forward_primer_concentration = self.forward_primer_concentration, reverse_primer_concentration = self.rc, saltc = self.saltc, *divmod(extension_time_PfuSso7d,60), size = len(self.seq))) else: if (length_of_f>20 and length_of_r>20): ta = min(self.tmf_dbd,self.tmr_dbd)+3 else: ta = min(self.tmf_dbd,self.tmr_dbd) f=textwrap.dedent( ''' Pfu-Sso7d (rate {rate}s/kb) Three-step| 30 cycles | |Breslauer1986,SantaLucia1998 98.0°C |98.0°C | |SaltC {saltc:2}mM __________|_____ 72.0°C |72.0°C|Primer1C {forward_primer_concentration:3}µM 00min30s |10s \ {ta}°C ________|______|Primer2C {reverse_primer_concentration:3}µM | \______/{0:2}min{1:2}s|10min | | 10s | |4-8°C '''.format(rate = PfuSso7d_extension_rate, ta = math.ceil(ta), forward_primer_concentration = self.forward_primer_concentration/1000, reverse_primer_concentration = self.reverse_primer_concentration/1000, saltc= self.saltc, *divmod(extension_time_PfuSso7d,60))) return pretty_str(f)
def figure(self): ''' This method returns a simple figure of the two primers binding to a part of the template. :: 5gctactacacacgtactgactg3 |||||||||||||||||||||| tm 52.6 (dbd) 58.3 5gctactacacacgtactgactg...caagatagagtcagtaaccaca3 3cgatgatgtgtgcatgactgac...gttctatctcagtcattggtgt5 |||||||||||||||||||||| tm 49.1 (dbd) 57.7 3gttctatctcagtcattggtgt5 Returns ------- figure:string A string containing a text representation of the primers annealing on the template (see example above). Notes ----- tm in the figure above is the melting temperature (tm) for each primer calculated according to SantaLucia 1998 [#]_. dbd is the tm calculation for enzymes with dsDNA binding domains like Pfu-Sso7d [#]_. See [#]_ for more information. References ---------- .. [#] J. SantaLucia, “A Unified View of Polymer, Dumbbell, and Oligonucleotide DNA Nearest-neighbor Thermodynamics,” Proceedings of the National Academy of Sciences 95, no. 4 (1998): 1460. .. [#] M. Nørholm, “A Mutant Pfu DNA Polymerprimerase Designed for Advanced Uracil-excision DNA Engineering,” BMC Biotechnology 10, no. 1 (2010): 21, doi:10.1186/1472-6750-10-21. .. [#] http://www.thermoscientificbio.com/webtools/tmc/ ''' f = ''' {sp1}5{faz}...{raz}3 {sp3}{rap} tm {tmr} (dbd) {tmr_dbd} {sp3}3{rp}5 5{fp}3 {fap:>{fplength}} tm {tmf} (dbd) {tmf_dbd} {sp2}3{fzc}...{rzc}5 '''.format( fp = self.forward_primer.seq, fap = "|"*len(self.forward_primer.footprint), fplength = len(self.forward_primer.seq), tmf = round(self.tmf,1), tmr = round(self.tmr,1), tmf_dbd = round(self.tmf_dbd,1), tmr_dbd = round(self.tmr_dbd,1), rp = self.reverse_primer.seq[::-1], rap = "|"*len(self.reverse_primer.footprint), rplength = len(self.reverse_primer.seq), faz = self.forward_primer.footprint, raz = self.reverse_primer.footprint.reverse_complement(), fzc = self.forward_primer.footprint.complement(), rzc = self.reverse_primer.footprint[::-1], sp1 = " "*(len(self.forward_primer.seq)-len(self.forward_primer.footprint)), sp2 = " "*(len(self.forward_primer.seq)-len(self.forward_primer.footprint)), sp3 = " "*(3+len(self.forward_primer.seq)) ) return pretty_str(textwrap.dedent(f).strip("\n"))
def url(self): return pretty_str("http://www.ncbi.nlm.nih.gov/nucleotide/"+self.acc)
def url(self): return pretty_str("http://www.ncbi.nlm.nih.gov/nucleotide/" + self.acc)
def test_reverse_complement(monkeypatch): from pydna._pretty import pretty_str from pydna.assembly import Assembly from pydna.dseqrecord import Dseqrecord a = Dseqrecord("acgatgctatactgtgCCNCCtgtgctgtgctcta") #12345678901234 b = Dseqrecord("tgtgctgtgctctaTTTTTTTtattctggctgtatc") #123456789012345 c = Dseqrecord("tattctggctgtatcGGGGGtacgatgctatactgtg") a.name = "aaa" #1234567890123456 b.name = "bbb" c.name = "ccc" asm = Assembly((a, b, c), limit=14) x = asm.assemble_circular()[0] y = x.rc() z = y.rc() assert x.figure() == z.figure() assert x.detailed_figure() == z.detailed_figure() xfig = '''\ -|aaa|14 | \\/ | /\\ | 14|bbb|15 | \\/ | /\\ | 15|ccc|16 | \\/ | /\\ | 16- | | ----------------------- '''.rstrip() xdfig = pretty_str('''\ |||||||||||||||| acgatgctatactgtgCCNCCtgtgctgtgctcta TGTGCTGTGCTCTA tgtgctgtgctctaTTTTTTTtattctggctgtatc TATTCTGGCTGTATC tattctggctgtatcGGGGGtacgatgctatactgtg ACGATGCTATACTGTG '''.rstrip() + "\n") assert x.figure() == xfig assert x.detailed_figure() == xdfig yfig = '''\ -|ccc_rc|15 | \\/ | /\\ | 15|bbb_rc|14 | \\/ | /\\ | 14|aaa_rc|16 | \\/ | /\\ | 16- | | -------------------------------- '''.rstrip() ydfig = '''\ |||||||||||||||| cacagtatagcatcgtaCCCCCgatacagccagaata GATACAGCCAGAATA gatacagccagaataAAAAAAAtagagcacagcaca TAGAGCACAGCACA tagagcacagcacaGGNGGcacagtatagcatcgt CACAGTATAGCATCGT '''.rstrip() + "\n" assert y.figure() == yfig assert y.detailed_figure() == ydfig