def function(seq, category, prefix, suffix, enzymes, with_intron): pcrs, seq = domesticate(seq, category, prefix, suffix, enzymes, with_intron) protocol = write_domestication_protocol(pcrs) response = HttpResponse(protocol, content_type='text/plain') response['Content-Disposition'] = 'attachment; filename="protocol.txt"' return response
def function(seq, category, prefix, suffix, enzymes, with_intron): seq = domesticate(seq, category, prefix, suffix, enzymes, with_intron)[1] response = HttpResponse(convert_to_sbol(seq), content_type='text/xml') response['Content-Disposition'] = 'attachment; ' response['Content-Disposition'] += 'filename="{0}.xml"'.format(seq.id) return response
def function(seq, category, prefix, suffix, enzymes, with_intron): seq = domesticate(seq, category, prefix, suffix, enzymes, with_intron)[1] response = HttpResponse(seq.format('genbank'), content_type='text/plain') response['Content-Disposition'] = 'attachment; ' response['Content-Disposition'] += 'filename="{0}.gb"'.format(seq.id) return response
def xtest_daniels_promoter(self): fasta_path = os.path.join(TEST_DATA, 'prVvbHLH35v2.fa') seqrec = SeqIO.read(fasta_path, 'fasta') dom_seq = domesticate(seqrec, '01-02-03-11-12 (PROM+UTR+ATG)', 'GGAG', 'AATG')[1] print len(dom_seq), seqrec.seq.upper() print len(dom_seq), dom_seq.seq assert ('GGAG', 'AATG') == get_prefix_and_suffix(dom_seq.seq, 'BsaI')
def domestication_view_add(request): context = RequestContext(request) context.update(csrf(request)) request_data = request.POST # request_data seq = request_data['seq'] category = request_data['category'] prefix = request_data['prefix'] suffix = request_data['suffix'] seq_name = request_data['seq_name'] name = request_data['name'] with_intron = bool(int(request_data['with_intron'])) if category == 'None': category_name = 'Other' else: category_name = CATEGORIES[category][0] seq = SeqRecord(Seq(seq), id=seq_name, name=seq_name) seq = domesticate(seq, category, prefix, suffix, with_intron)[1] temp_fhand = NamedTemporaryFile(prefix='{0}.'.format(seq.id), suffix='.gb') temp_fhand.write(seq.format('gb')) temp_fhand.flush() temp_fhand.seek(0) props = {'Description': [request_data['description']], 'Reference': [request_data['reference']]} try: feature = add_feature(name=name, type_name=category_name, vector=DOMESTICATED_VECTOR, genbank=temp_fhand, props=props, owner=request.user, is_public=False) except IntegrityError as error: print error if 'feature already in db' in str(error): # TODO choose a template return render_to_response('feature_exists.html', {}, context_instance=RequestContext(request)) else: return HttpResponseServerError() except Exception as error: print error return HttpResponseServerError() # if everithing os fine we show the just added feature return redirect(feature.url)
def test_get_prefix_and_suffix(self): 'it tests get a suffix and prefix test' gb_path = os.path.join(TEST_DATA, 'pAn11_uniq.gb') seq = SeqIO.read(gb_path, 'gb') seq = seq.seq assert ('AATG', 'GCTT') == get_prefix_and_suffix(seq, 'BsaI') fasta_path = os.path.join(TEST_DATA, 'seq.fasta') seq = SeqIO.read(fasta_path, 'fasta') seq = seq.seq assert ('TGGA', 'AATG') == get_prefix_and_suffix(seq, 'BsaI') # no rec_sites fasta_path = os.path.join(TEST_DATA, 'seq2.fasta') seq = SeqIO.read(fasta_path, 'fasta') seq = seq.seq assert (None, None) == get_prefix_and_suffix(seq, 'BsaI') # no rec_sites fasta_path = os.path.join(TEST_DATA, 'seq_with_intron.fasta') seqrec = SeqIO.read(fasta_path, 'fasta') dom_seq = domesticate(seqrec, None, 'CCAT', 'AATG')[1] assert ('CCAT', 'AATG') == get_prefix_and_suffix(dom_seq.seq, 'BsaI')
def _domestication_view(request, kind): context = RequestContext(request) context.update(csrf(request)) if request.method == 'POST': request_data = request.POST elif request.method == 'GET': request_data = request.GET else: request_data = None if request_data: form = DomesticationForm(request_data, request.FILES) # do domestication if form.is_valid(): seq = form.cleaned_data['seq'] if seq is None: seq = form.cleaned_data['residues'] category = form.cleaned_data.get('category', None) enzymes = form.cleaned_data.get('enzymes', None) if category is None: prefix = form.cleaned_data.get('prefix') suffix = form.cleaned_data.get('suffix') else: try: prefix = CATEGORIES[category][1] suffix = CATEGORIES[category][2] except KeyError: prefix = CRYSPER_CATEGORIES[category][1] suffix = CRYSPER_CATEGORIES[category][2] with_intron = form.cleaned_data['with_intron'] with_intron_str = '1' if with_intron else '0' if kind == 'domestication': try: pcr = domesticate(seq, category, prefix, suffix, enzymes, with_intron)[0] except RuntimeError as error: return render_to_response('goldenbraid_info.html', {'title': 'Can not domesticate sequence', 'info': error}, context_instance=RequestContext(request)) return render_to_response('domestication_result.html', {'category': category, 'prefix': prefix, 'suffix': suffix, 'pcrs': pcr, 'seq': str(seq.seq), 'seq_name': seq.name, 'enzymes': enzymes, 'with_intron': with_intron_str}, context_instance=RequestContext(request)) elif kind == 'synthesis': try: seq_for_syn, prepared_seq = domesticate_for_synthesis(seq, category, prefix, suffix, enzymes, with_intron) except RuntimeError as error: return render_to_response('goldenbraid_info.html', {'title': 'Can not domesticate sequence', 'info': error}, context_instance=RequestContext(request)) return render_to_response('synthesis_result.html', {'category': category, 'prefix': prefix, 'suffix': suffix, 'seq_syn': seq_for_syn, 'seq': str(seq.seq), 'seq_name': prepared_seq.name, 'enzymes': enzymes, 'with_intron': with_intron_str}, context_instance=RequestContext(request)) else: form = DomesticationForm() context['form'] = form context['kind'] = kind template = 'domestication_template.html' content_type = None return render_to_response(template, context, content_type=content_type)