def test_cut_feat(self): puc19 = read('PUC19_MarkBudde.gb') pf, pr = cloning_primers(puc19) pcrProd = pcr(pf, pr, puc19) self.assertEqual(23, len(pcrProd.features)) #print len(pcrProd.cut(EcoRI)[1].features) self.assertEqual(17, len(pcrProd.cut(EcoRI)[1].features)) def amplicon_to_dseqrecord(a): d = Dseqrecord(a.seq) d.features = a.features return d pcrProdDseqrecord = amplicon_to_dseqrecord(pcrProd) self.assertEqual(17, len(pcrProdDseqrecord.cut(EcoRI)[1].features))
def __init__(self, enzyme, data): fp_tail = "ttaaat" rp_tail = "taattaa" if enzyme == ZraI: fp = p577 rp = p342 desc_re = re.compile("pYPKa_Z_([^\d\W]\w{2,15})tp") self.letter = "Z" elif enzyme == AjiI: fp = p468 rp = p342 fp_tail = "aa" rp_tail = "" desc_re = re.compile("pYPKa_A_([^\d\W]\w{2,15})") self.letter = "A" elif enzyme == EcoRV: fp = p568 rp = p342 desc_re = re.compile("pYPKa_E_([^\d\W]\w{2,15})tp") self.letter = "E" else: raise Exception(u"Enzyme has to be ZraI, Ajii or EcoRV, but got {}".format(enzyme)) self.enzyme = enzyme self.insert_length = cloned(pYPKa, enzyme, data) if self.insert_length: m = desc_re.search(data.description) if not m: raise Exception(u"{} is a pYPKa_{} sequence but was not correctly named.".format(data.description, self.letter)) self.insert_description = m.group(1) self.name = m.group(0) self.code = "{} = read('{}.txt')".format({ "Z":"first", "A":"middle", "E":"last"}[self.letter], self.name) self.files = { "{}.txt".format(self.name) : data.format("gb").encode("utf-8"), "{}_plan.rst".format(self.name) : u"This vector was given!"} self.rec = data self.flag = True elif data.linear: self.insert_description = data.name # .id .description f,r = pydna.cloning_primers(data, minlength=pYPKa_clone.minlength, maxlength=pYPKa_clone.maxlength, fp_tail=fp_tail, rp_tail=rp_tail) self.insert = pydna.pcr(f, r, data) self.insert_length = len(self.insert) self.insert.description+= "_prd" self.name = u"pYPKa_{}_{}{}".format(self.letter, data.name.split("tp")[0], {ZraI : "tp", AjiI : "", EcoRV: "tp" }[enzyme]) code = pYPKa_clone.codetempl.format( enz = self.enzyme, tp = data.name, f = f.format("fasta"), r = r.format("fasta"), vn = self.name) self.rec = (pYPKa.linearize(self.enzyme) + self.insert).looped().synced("tcgcgcgtttcggtgatgacggtgaaaacctctg") self.rec_rv = (pYPKa.linearize(self.enzyme) + self.insert.rc()).looped().synced("tcgcgcgtttcggtgatgacggtgaaaacctctg") self.rec.id = self.name[:15] self.rec.description = self.name plan = pYPKa_clone.plantempl.format( template = u"{}_template".format(data.name), rec = self.name, fwd = self.insert.forward_primer.name, rev = self.insert.reverse_primer.name, figure = add_space(self.insert.figure()), program = add_space(self.insert.program()), pcr_product =self.insert_description, length = len(self.insert), enz=enzyme, name = self.name, line = "="*len(self.name), fp = fp.name, rp = rp.name, f = f.name, correct_products = ", ".join(str(f) for f in [len(p) for p in pydna.Anneal((fp,rp,f), self.rec).products]), reversed_products = ", ".join(str(f) for f in [len(p) for p in pydna.Anneal((fp,rp,f), self.rec_rv).products]), clone_empty = ", ".join(str(f) for f in [len(p) for p in pydna.Anneal((fp,rp,f), pYPKa).products])) self.files = { "{}_template.txt".format(data.name) : data.format("gb").decode("utf-8"), "{}.txt".format(self.insert_description) : self.insert.format("gb").decode("utf-8"), "{}.txt".format(self.name) : self.rec.format("gb").decode("utf-8"), "{}.py".format(self.name) : code, "{}_plan.rst".format(self.name) : plan} self.code = "from {0} import {0} as {1}".format(self.name, {ZraI : "first", AjiI : "middle", EcoRV: "last" }[enzyme]) self.flag = False else: raise Exception("{} has to be a linear DNA fragment or a pYPKa_{} clone!".format(data.description, self.letter))
def test_primer_Design_saving_to_text_file(): files_ = [dedent(x) for x in ('''\ >fw64 t-sequence atgactgctaacccttc >rv64 t-sequence catcgtaagtttcgaac''', '''\ >fw64 t-sequence atgactgctaacccttcN >rv64 t-sequence catcgtaagtttcgaacN''', '''\ >fw64 t-sequence atgactgctaacccttcN''', '''\ >fw64 t-sequence atgactgctaacccttcN >rv64 t-sequence catcgtaagtttcgaac''', '''\ >rv64 t-sequence catcgtaagtttcgaacN''', '''\ >rv64 t-sequence catcgtaagtttcgaacN >fw64 t-sequence atgactgctaacccttc''', '''\ >fw64 t-sequenceZ atgactgctaacccttc >rv64 t-sequenceZ catcgtaagtttcgaac''', '''\ >fw64 t-sequenceZ atgactgctaacccttc >rv64 t-sequenceZ catcgtaagtttcgaac >fw64 t-sequence atgactgctaacccttc >rv64 t-sequence catcgtaagtttcgaac''', '''\ >fw64x t-sequence atgactgctaacccttc >rv64x t-sequence catcgtaagtttcgaac''', '''\ >fw64x t-sequence atgactgctaacccttc >rv64x t-sequence catcgtaagtttcgaac >fw64 t-sequence atgactgctaacccttc >rv64 t-sequence catcgtaagtttcgaac''', )] templ=Dseqrecord("atgactgctaacccttccttggtgttgaacaagatcgacgacatttcgttcgaaacttacgatg") templ.accession = "t-sequence" try: os.remove("PRIMERS.TXT") except OSError: pass pf, pr = cloning_primers(templ, path="PRIMERS.TXT") assert os.path.isfile("PRIMERS.TXT") with open("PRIMERS.TXT", "r") as f: text=f.read().strip() assert text == files_[0] with open("PRIMERS.TXT", "w") as f: text=f.write(files_[1]) pf, pr = cloning_primers(templ, path="PRIMERS.TXT") with open("PRIMERS.TXT", "r") as f: text=f.read().strip() assert text == files_[1] with open("PRIMERS.TXT", "w") as f: text=f.write(files_[2]) pf, pr = cloning_primers(templ, path="PRIMERS.TXT") with open("PRIMERS.TXT", "r") as f: text=f.read().strip() assert text == files_[3] with open("PRIMERS.TXT", "w") as f: text=f.write(files_[4]) pf, pr = cloning_primers(templ, path="PRIMERS.TXT") with open("PRIMERS.TXT", "r") as f: text=f.read().strip() assert text == files_[5] with open("PRIMERS.TXT", "w") as f: text=f.write(files_[6]) pf, pr = cloning_primers(templ, path="PRIMERS.TXT") with open("PRIMERS.TXT", "r") as f: text=f.read().strip() assert text == files_[7] with open("PRIMERS.TXT", "w") as f: text=f.write(files_[8]) pf, pr = cloning_primers(templ, path="PRIMERS.TXT") with open("PRIMERS.TXT", "r") as f: text=f.read().strip() assert text == files_[9] with open("PRIMERS.TXT", "w") as f: text=f.write('') pf, pr = cloning_primers(templ, path="PRIMERS.TXT") f, r = parse("PRIMERS.TXT", ds=False) assert f.description == "fw64 t-sequence" assert r.description == "rv64 t-sequence"