<SYSTEM_TASK:>
Given the following text description, write Python code to implement the functionality described below step by step
<END_TASK>
<USER_TASK:>
Description:
 Golden gate cloning simulation using pydna
The objective is to assemble three 50 bp sequences into one circular sequence.
We will use the assembly_fragments function and the Assembly class.
Step1:  The sequences below were generated here.
Step2:  We make a list of amplicons (sequences with pairs of primers from the Dseqrecords)
Step3:  We need a list of golden gate linkers, these could be generated automatically in some other way.
Step4:  we zip together the golden gate linkers and sequences to a flat list.
Step5:  The optional settings below are important. Sequences with a size equal to or shorter than maxlink will be incorporated in the primers.
overlap controls the overlap between the sequences in the assembly.
Step6:  We get only three sequences, since the golden gate linkers are incorporated in the primers.
Lets give them nicer names
Step7:  We can assemble these by setting the limit to 4 and only_terminal_overlaps to True. 
With such short homology limit, we need to consider only terminal overlaps, otherwise 
we would get many irrelevant results.
Step8:  We got three circular products. The second one should be the same as the theoretical one below
Step9:  The candidate and the correct sequence has the same cseguid, so they represent the same circular sequence.
We need to add the BsaI restriction enzyme recognition sequence (plus one nucleotide to get the cut right) to the primers
<ASSISTANT_TASK:>
Python Code:
from pydna.all import *
Explanation: Golden gate cloning simulation using pydna
The objective is to assemble three 50 bp sequences into one circular sequence.
We will use the assembly_fragments function and the Assembly class.
End of explanation
frags = parse('''
>1|random sequence|A: 0.25|C: 0.25|G: 0.25|T: 0.25|length: 50 bp
ccagaatacagtgccttagatctacggatcgtatctgcgatttggccgat
>2|random sequence|A: 0.25|C: 0.25|G: 0.25|T: 0.25|length: 50 bp
gccctgcttggtagatcaggcgagccaataacattctatagtgtagcctt
>3|random sequence|A: 0.25|C: 0.25|G: 0.25|T: 0.25|length: 50 bp
gagagcgctcctgtttcaatgcttgcaaactctagcagctatactgtagg ''' )
frags
Explanation: The sequences below were generated here.
End of explanation
amplicons = [primer_design(f) for f in frags]
Explanation: We make a list of amplicons (sequences with pairs of primers from the Dseqrecords)
End of explanation
golden_gate_linkers = [Dseqrecord(lnk) for lnk in "GAAT GATC AATT GAAT".split()]
golden_gate_linkers
from itertools import chain, zip_longest
Explanation: We need a list of golden gate linkers, these could be generated automatically in some other way.
End of explanation
seqlist = list( chain.from_iterable( zip_longest(golden_gate_linkers, amplicons)))[:-1]
seqlist
Explanation: we zip together the golden gate linkers and sequences to a flat list.
End of explanation
a,b,c = assembly_fragments( seqlist, maxlink=4, overlap=4 )
Explanation: The optional settings below are important. Sequences with a size equal to or shorter than maxlink will be incorporated in the primers.
overlap controls the overlap between the sequences in the assembly.
End of explanation
a.locus, b.locus, c.locus = "sequenceA", "sequenceB", "sequenceC"
a.figure()
b.figure()
c.figure()
Explanation: We get only three sequences, since the golden gate linkers are incorporated in the primers.
Lets give them nicer names:
End of explanation
from pydna.assembly import terminal_overlap
asm = Assembly((a,b,c), limit=4, algorithm=terminal_overlap)
asm
Explanation: We can assemble these by setting the limit to 4 and only_terminal_overlaps to True. 
With such short homology limit, we need to consider only terminal overlaps, otherwise 
we would get many irrelevant results.
End of explanation
correct = Dseqrecord("")
for s in seqlist[1:]:
    correct += s
correct = correct.looped()
correct.cseguid()
candidate = asm.assemble_circular()[1]
candidate.cseguid()
Explanation: We got three circular products. The second one should be the same as the theoretical one below:
End of explanation
from Bio.Restriction import BsaI
BsaI.site
for f in (a,b,c):
    f.forward_primer = BsaI.site + "a" + f.forward_primer
    f.reverse_primer = BsaI.site + "a" + f.reverse_primer
    print(f.name)
    print(f.forward_primer.format("tab"))
    print(f.reverse_primer.format("tab"))
    print(f.figure())
first_prod = pcr(a.forward_primer, a.reverse_primer, a.template)
first_prod.figure()
first_prod.cut(BsaI)
first_prod.cut(BsaI)[1].seq
Explanation: The candidate and the correct sequence has the same cseguid, so they represent the same circular sequence.
We need to add the BsaI restriction enzyme recognition sequence (plus one nucleotide to get the cut right) to the primers:
End of explanation
<END_TASK>