def multipartite_view_add(request): context = RequestContext(request) context.update(csrf(request)) request_data = request.POST if not request_data: return render_to_response('goldenbraid_info.html', {'info': "Not enougth data to add the feature"}, context_instance=RequestContext(request)) multi_type = request_data['category'] allowed_categories = PARTS_TO_ASSEMBLE.keys() + ['free'] if multi_type is None or multi_type not in allowed_categories: return render_to_response('goldenbraid_info.html', {'info': "Not enougth data to add the feature"}, context_instance=RequestContext(request)) if multi_type == 'free': part_types = request_data['order'].split(':') else: part_types = [p[0] for p in PARTS_TO_ASSEMBLE[multi_type]] multi_data = {'Vector': request_data['Vector']} for part_type in part_types: multi_data[part_type] = request_data[part_type] assembled_seq = assemble_parts(multi_data, part_types) name = request_data['name'] temp_fhand = NamedTemporaryFile(prefix='{0}.'.format(assembled_seq.id), suffix='.gb') temp_fhand.write(assembled_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=TU_TYPE_NAME, vector=request_data['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_add_feature(self): 'It tests the add_feature function' name = 'test_name' type_name = VECTOR_TYPE_NAME vector = None genbank = os.path.join(TEST_DATA, 'pANT1_uniq.gb') props = {ENZYME_IN_TYPE_NAME: ['BsaI'], ENZYME_OUT_TYPE_NAME: ['BsaI']} try: add_feature(name, type_name, vector, open(genbank), props, 'test_user') self.fail() except RuntimeError as error: if 'the given user does not exist' in str(error): pass else: raise User.objects.create_user(username='******', email='*****@*****.**', password='******') add_feature(name, type_name, vector, open(genbank), props, 'admin') feat = Feature.objects.get(uniquename='pANT1_uniq') assert FeatureRelationship.objects.filter(object=feat).count() == 0 assert feat.uniquename == "pANT1_uniq" os.remove(os.path.join(proj_settings.MEDIA_ROOT, feat.genbank_file.name)) # add relationships to feature # first we need to add derives from to db as it is not in the fixtures name = 'GB_UA_17A' vector = 'pDGB1_alpha1' type_name = TU_TYPE_NAME genbank = os.path.join(TEST_DATA, 'GB_UA_17A.gb') props = {ENZYME_IN_TYPE_NAME: ['BsaI'], ENZYME_OUT_TYPE_NAME: ['BsaI']} # add_feature(name, type_name, vector, open(genbank), props, 'admin') feat = Feature.objects.get(uniquename='GB_UA_17A') assert FeatureRelationship.objects.filter(object=feat).count() == 2
def crispr_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'] if category == 'None': category_name = 'Other' else: category_name = CRYSPER_CATEGORIES[category][0] print 'seq', seq seq = SeqRecord(Seq(seq, DNAAlphabet()), id=seq_name, name=seq_name) print 'seq', seq 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=None, genbank=temp_fhand, props=props, owner=request.user, is_public=False, prefix=prefix, suffix=suffix) 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: raise print error return HttpResponseServerError(error) # if everithing os fine we show the just added feature return redirect(feature.url)
def bipartite_view_add(request): context = RequestContext(request) context.update(csrf(request)) request_data = request.POST if not request_data: return render_to_response('goldenbraid_info.html', {'info': "Not enougth data to add the feature"}, context_instance=RequestContext(request)) name = request_data['name'] vector_name = request_data['Vector'] used_parts = {'Vector': vector_name, 'part_1': request_data['part_1'], 'part_2': request_data['part_2']} seq = assemble_parts(used_parts, ['part_1', 'part_2']) props = {'Description': [request_data['description']], 'Reference': [request_data['reference']]} temp_fhand = NamedTemporaryFile(prefix='{0}.'.format(seq.id), suffix='.gb') temp_fhand.write(seq.format('gb')) temp_fhand.flush() temp_fhand.seek(0) try: feature = add_feature(name=name, type_name=MODULE_TYPE_NAME, vector=vector_name, 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(error) # if everithing os fine we show the just added feature return redirect(feature.url)