def update_paper_molecule(): paper_id = request.form['paper_id'] id = request.form['id'] smi = request.form['smi'] name = request.form['name'] paper_query = Paper.objects(id=paper_id).select_related() if len(paper_query) != 0: paper = paper_query[0] if check_permission.check_paper_permission(current_user.id, paper): act_mol = ActivityMol.objects(id=id)[0] if smi != act_mol.smi: try: mol = Chem.MolFromSmiles(smi) svg = moltosvg(mol) except: svg = "" act_mol.svg = svg act_mol.smi = smi act_mol.name = name act_mol.save() result = {'status': 'success', 'msg': 'Molecule saved', 'issues': []} return jsonify(result=result) result = {'status': 'danger', 'msg': 'Could not delete molecule', 'issues': []} return jsonify(result=result)
def duplicate_paper_molecule(): id = request.form['id'] paper_id = request.form['paper_id'] paper_query = Paper.objects(id=paper_id).select_related() if len(paper_query) != 0: paper = paper_query[0] if check_permission.check_paper_permission(current_user.id, paper): mols = ActivityMol.objects(db.Q(id=id)) if len(mols) != 0: mol = mols[0] num_paper_mols = ActivityMol.objects(paper=paper).count() new_mol = ActivityMol(name=f"{num_paper_mols+1}", smi=mol.smi, svg=mol.svg, paper=paper) new_mol.save() mol_list = [(new_mol.name, new_mol.smi, new_mol.svg, str(new_mol.id))] result = {'status': 'success', 'msg': 'Molecule deleted', 'issues': [], 'mol_list': mol_list} return jsonify(result=result) result = {'status': 'danger', 'msg': 'Could not delete molecule', 'issues': []} return jsonify(result=result)
def submission_main_page(paper_id): user = user_datastore.get_user(current_user.id) paper_query = Paper.objects(id=paper_id).select_related() if len(paper_query) == 0: flash('Paper has not been added yet, please add to the database first', 'fail') return redirect(url_for("biocatdb.launch_add_paper")) paper = paper_query[0] if not check_permission.check_paper_permission(current_user.id, paper): flash('No access to edit this entry', 'fail') return redirect(url_for("biocatdb.launch_add_paper")) paper_data = get_paper_data(paper, user) activity_data = get_activity_data(paper) reactions = list(Reaction.objects().distinct('name')) enzyme_names = list(Sequence.objects(papers=paper).distinct('enzyme_name')) enzyme_types = list(EnzymeType.objects().distinct('enzyme_type')) enzyme_data = sequence_table.get_enzyme_data(db.Q(papers=paper)) enzyme_types_in_paper = list(Sequence.objects(papers=paper).distinct('enzyme_type')) reactions_in_paper = list(Reaction.objects(enzyme_types__in=enzyme_types_in_paper).distinct('name')) reactions_in_activity = list(Activity.objects(paper=paper).distinct('reaction')) status_dict = get_status(paper, user) comments = get_comments(paper, user) paper_molecules = get_paper_molecules(paper) admin_panel = False admin_dict = {} if current_user.has_role('admin'): admin_panel = True admin_dict = get_admin_dict(paper) reactions_ordered = reactions_in_activity + [r for r in reactions_in_paper if r not in reactions_in_activity] reactions_ordered += [r for r in reactions_in_paper if r not in reactions_ordered] reactions_ordered += [r for r in reactions if r not in reactions_ordered] return render_template('data_submission/submission_main_page.html', paper=paper_data, activity_data=activity_data, seq_data=enzyme_data, seq_button_columns=['edit', 'remove', 'papers'], status=status_dict, seq_table_height='60vh', enzyme_types=enzyme_types, show_header_filters=False, include_owner=True, lock_enz_type='false', reactions=reactions_ordered, enzyme_names=enzyme_names+['Chemical'], doi=paper.doi, comments=comments, paper_molecules=paper_molecules, admin_panel=admin_panel, admin_dict=admin_dict, enzyme_reactions=reactions_in_paper)
def save_paper(): user = user_datastore.get_user(current_user.id) paper = Paper.objects(id=request.form['paper_id'])[0] if not check_permission.check_paper_permission(current_user.id, paper): result = { 'status': 'danger', 'msg': 'No access to edit this paper', 'issues': [], 'redirect': url_for("biocatdb.launch_add_paper") } return jsonify(result=result) paper.short_citation = request.form['short_cit'] paper.doi = request.form['doi'].replace(' ', '') paper.html = 'https://doi.org/' + request.form['doi'] if request.form['date'] != "": paper.date = request.form['date'] paper.title = request.form['title'] paper.journal = request.form['journal'] paper.authors = request.form['authors'].split(', ') paper.tags = request.form['tags'].split(', ') if user not in paper.edits_by: paper.edits_by.append(user) if (paper.owner == user) and (request.form['self_assign'] == 'false'): paper.owner = None paper.save() unassign_seqs_in_paper(user, paper) if not current_user.has_role('super_contributor'): result = { 'status': 'warning', 'msg': 'Paper no longer assigned to you', 'issues': [], 'redirect': url_for("biocatdb.launch_add_paper") } return jsonify(result=result) elif request.form['self_assign'] == 'true': paper.owner = user paper.save() papers_functions.tag_paper_with_enzyme_types(paper) result = { 'status': 'success', 'msg': 'Paper information updated', 'issues': [] } return jsonify(result=result)
def reorder_paper_molecules(): paper_id = request.form['paper_id'] paper_query = Paper.objects(id=paper_id).select_related() if len(paper_query) != 0: paper = paper_query[0] if check_permission.check_paper_permission(current_user.id, paper): paper_mols = list(ActivityMol.objects(paper=paper)) paper_mols = natsorted(paper_mols, key=lambda x: x.name) for i, mol in enumerate(list(paper_mols)): mol.name = str(i+1) mol.save() result = {'status': 'success', 'msg': 'Molecules reordered', 'issues': []} return jsonify(result=result) result = {'status': 'danger', 'msg': 'Could not delete molecule', 'issues': []} return jsonify(result=result)
def delete_paper(): user = user_datastore.get_user(current_user.id) paper = Paper.objects(id=request.form['paper_id'])[0] if not check_permission.check_paper_permission(current_user.id, paper): result = { 'status': 'danger', 'msg': 'You are not the owner of this paper', 'issues': ['Assign this paper to yourself in order to delete it'] } return jsonify(result=result) elif len(Sequence.objects(papers=paper)) != 0: result = { 'status': 'danger', 'msg': 'Paper still contains sequences', 'issues': ['Please remove any sequences from paper before deleting'] } return jsonify(result=result) elif len(Activity.objects(paper=paper)) != 0: result = { 'status': 'danger', 'msg': 'Paper still contains activity data', 'issues': ['Please remove any activity data from paper before deleting'] } return jsonify(result=result) else: paper.delete() result = {'status': 'success', 'msg': 'Paper deleted', 'issues': []} return jsonify(result=result)
def delete_paper_molecule(): id = request.form['id'] paper_id = request.form['paper_id'] paper_query = Paper.objects(id=paper_id).select_related() if len(paper_query) != 0: paper = paper_query[0] if check_permission.check_paper_permission(current_user.id, paper): mols = ActivityMol.objects(db.Q(id=id)) if len(mols) != 0: mol = mols[0] mol.delete() result = {'status': 'success', 'msg': 'Molecule deleted', 'issues': []} return jsonify(result=result) result = {'status': 'danger', 'msg': 'Could not delete molecule', 'issues': []} return jsonify(result=result)