def creg_index(request): if request.method == 'POST': smiles = request.POST.get("smiles", None) inchi = request.POST.get("inchi", False) inchi_check = True if inchi == 'on' else False if not smiles: return render(request, 'cmpd_reg/cmpd-reg.html', {}) try: result_compound, is_new = get_or_create_compound( smiles, clean=True, inchi_standard=inchi_check) except Exception, e: print str(e) return render( request, 'cmpd_reg/cmpd-reg.html', { 'smiles_error': "Error! Could not convert SMILES '{}' to molecule object". format(smiles), }) searched_image = create_compound_image(smiles, smiles=True) if searched_image: img_tag = create_image_tag(searched_image) return render( request, 'cmpd_reg/cmpd-reg.html', { 'searched_smiles': smiles, 'searched_compound_image': img_tag, 'returned_compound': str(result_compound.id), 'is_new': str(is_new), }) else: return render( request, 'cmpd_reg/cmpd-reg.html', { 'smiles_error': "Error! Could not convert SMILES '{}' to image".format( smiles), })
def creg_index(request): if request.method == 'POST': smiles = request.POST.get("smiles", None) inchi = request.POST.get("inchi", False) inchi_check = True if inchi == 'on' else False if not smiles: return render(request, 'cmpd_reg/cmpd-reg.html', {}) try: result_compound, is_new = get_or_create_compound(smiles, clean=True, inchi_standard=inchi_check) except Exception, e: print str(e) return render(request, 'cmpd_reg/cmpd-reg.html', { 'smiles_error': "Error! Could not convert SMILES '{}' to molecule object".format(smiles), }) searched_image = create_compound_image(smiles, smiles=True) if searched_image: img_tag = create_image_tag(searched_image) return render(request, 'cmpd_reg/cmpd-reg.html', { 'searched_smiles': smiles, 'searched_compound_image': img_tag, 'returned_compound': str(result_compound.id), 'is_new': str(is_new), }) else: return render(request, 'cmpd_reg/cmpd-reg.html', { 'smiles_error': "Error! Could not convert SMILES '{}' to image".format(smiles), })
def bulk_loader(request): if request.method == "POST": inchi = request.POST.get("inchi", False) inchi_check = True if inchi == 'on' else False output_stats = {'new':0,'existing':0,'errors':{'count':0,'report':[]}} reader = csv.DictReader(request.FILES['file']) row_count = 1 for row in reader: row_count += 1 if 'SMILES' not in row.keys(): return render(request, 'cmpd_reg/bulk_loader.html', { 'load_error': "Error! CSV must contain a column header named 'SMILES'" }) try: _, is_new = get_or_create_compound(row['SMILES'], clean=True, inchi_standard=inchi_check) if is_new: output_stats['new'] += 1 else: output_stats['existing'] += 1 except Exception, e: print str(e) output_stats['errors']['count'] += 1 output_stats['errors']['report'].append({'smiles':row['SMILES'],'msg':str(e),'row':str(row_count)}) return render(request, 'cmpd_reg/bulk_loader.html', { 'load_results': output_stats })
def bulk_loader(request): if request.method == "POST": inchi = request.POST.get("inchi", False) inchi_check = True if inchi == 'on' else False output_stats = { 'new': 0, 'existing': 0, 'errors': { 'count': 0, 'report': [] } } reader = csv.DictReader(request.FILES['file']) row_count = 1 for row in reader: row_count += 1 if 'SMILES' not in row.keys(): return render( request, 'cmpd_reg/bulk_loader.html', { 'load_error': "Error! CSV must contain a column header named 'SMILES'" }) try: _, is_new = get_or_create_compound(row['SMILES'], clean=True, inchi_standard=inchi_check) if is_new: output_stats['new'] += 1 else: output_stats['existing'] += 1 except Exception, e: print str(e) output_stats['errors']['count'] += 1 output_stats['errors']['report'].append({ 'smiles': row['SMILES'], 'msg': str(e), 'row': str(row_count) }) return render(request, 'cmpd_reg/bulk_loader.html', {'load_results': output_stats})