コード例 #1
0
def df_to_db(spec_df):
    #added_by_dict = make_added_by_user_dict()

    print('Saving biocatdb_2 excel to mongodb..')
    for i, row in spec_df.iterrows():
        html_doi = str(row['html_doi'])
        doi = str(row['html_doi'])
        added_by_string = str(row['added_by'])

        list_html_to_remove = [
            'https://doi.org/', 'http://doi.org/', 'http://dx.doi.org/'
        ]
        for to_remove in list_html_to_remove:
            if to_remove in doi:
                doi = html_doi.replace(to_remove, '')

        if len(Paper.objects(doi=doi)) == 0:
            paper = Paper(short_citation=str(row['short_citation']),
                          html=html_doi,
                          doi=doi)
            paper = paper.save()
            print(f"{row['short_citation']} added")
        else:
            paper = Paper.objects(doi=doi)[0]

        if row['enzyme_type'] is not None and row['enzyme_type'] != '' and type(
                row['enzyme_type']) == str:
            if len(EnzymeType.objects(enzyme_type=row['enzyme_type'])) == 0:
                enz_type = EnzymeType(enzyme_type=row['enzyme_type'],
                                      description='')
                enz_type.save()

        if row['enzyme_name'] is not None and row['enzyme_name'] != '' and type(
                row['enzyme_name']) == str:
            if len(Sequence.objects(enzyme_name=row['enzyme_name'])) == 0:
                seq = Sequence(enzyme_name=check_is_nan(row['enzyme_name']),
                               enzyme_type=check_is_nan(row['enzyme_type']),
                               papers=[paper])
                seq.save()
            else:
                seq = Sequence.objects(enzyme_name=row['enzyme_name'])[0]
                if paper not in seq.papers:
                    seq.papers.append(paper)
                    seq = seq.save()

        if row['binary'] == 1:
            binary = True
        else:
            binary = False

        if row['auto_generated'] == 1:
            auto_gen = True
        else:
            auto_gen = False

        activity = Activity(
            enzyme_type=check_is_nan(row['enzyme_type']),
            enzyme_name=check_is_nan(row['enzyme_name']),
            reaction=check_is_nan(row['reaction']),
            short_citation=check_is_nan(row['short_citation']),
            html_doi=check_is_nan(row['html_doi']),
            added_by_string=added_by_string,
            paper=paper,
            cascade_num=check_is_nan(row['cascade_num']),
            substrate_1_smiles=get_smile(row['substrate_1_smiles']),
            substrate_2_smiles=get_smile(row['substrate_2_smiles']),
            product_1_smiles=get_smile(row['product_1_smiles']),
            temperature=check_is_nan(row['temperature']),
            ph=check_is_nan(row['ph']),
            solvent=check_is_nan(row['solvent']),
            other_conditions=check_is_nan(row['other_conditions']),
            notes=check_is_nan(row['notes']),
            reaction_vol=check_is_nan(row['reaction_vol']),
            formulation=check_is_nan(row['formulation']),
            biocat_conc=check_is_nan(row['biocat_conc']),
            kcat=check_is_float(row['kcat']),
            km=check_is_float(row['km']),
            mw=check_is_float(row['mw']),
            substrate_1_conc=check_is_nan(row['substrate_1_conc']),
            substrate_2_conc=check_is_nan(row['substrate_2_conc']),
            specific_activity=check_is_float(row['specific_activity']),
            conversion=check_is_float(row['conversion']),
            conversion_time=check_is_float(row['conversion_time']),
            categorical=check_is_nan(row['categorical']),
            binary=binary,
            selectivity=check_is_nan(row['selectivity']),
            auto_generated=auto_gen)

        activity.save()
    print('..done')
コード例 #2
0
def create_paper():
    form = PaperInfo()

    if 'doi' in session:
        doi = session['doi']
    else:
        doi = ''

    if form.validate_on_submit() == False:
        user = User.objects(id=current_user.id)[0]
        papers = Paper.objects(doi__iexact=doi)
        if len(papers) != 0:

            paper = papers[0]
            if paper.owner == user or user.has_role('super_contributor'):
                flash("Paper already in the database", 'success')
                return redirect(
                    url_for("biocatdb.submission_main_page",
                            paper_id=paper.id))

            elif paper.owner == None:
                flash(
                    'Paper already in database, self-assign the paper to add data',
                    'warning')
                return redirect(url_for("biocatdb.papers_that_need_data"))

            elif paper.owner != user and not user.has_role(
                    'super_contributor'):
                flash(
                    "Paper already in the database and is assigned to another user",
                    'danger')

            else:
                flash("error", 'danger')
                return redirect(url_for("biocatdb.launch_add_paper"))

        else:
            title, authors_list, journal, date, cite_mini = papers_crossref.get_metadata_from_crossref(
                doi)
            if cite_mini == '':
                title, authors_list, journal, date, cite_mini = papers_functions.query_pubmed(
                    doi)
            form.title.data = title
            form.authors.data = papers_functions.list_to_string(authors_list)
            form.journal.data = journal
            form.date.data = date
            form.short_cit.data = cite_mini
            form.doi.data = doi.replace(' ', '').lower()

            can_self_assign = papers_functions.can_self_assign(user)

            if cite_mini == '':
                flash(
                    "Paper not found in crossref, pubmed or db, please add manually",
                    'fail')
            else:
                flash("Paper found, please check information", 'success')

            return render_template(
                'add_paper_workflow/edit_paper_information.html',
                form=form,
                can_self_assign=can_self_assign)

    else:
        user = User.objects(id=current_user.id)[0]
        session.pop('doi')
        if form.self_assign.data == True:
            owner = user
        else:
            owner = None

        new_paper = Paper(doi=form.doi.data.replace(' ', '').lower(),
                          short_citation=form.short_cit.data,
                          title=form.title.data,
                          html='https://doi.org/' + form.doi.data,
                          journal=form.journal.data,
                          date=form.date.data,
                          tags=form.tags.data.split(', '),
                          authors=form.authors.data.split(', '),
                          owner=owner,
                          added_by=user,
                          status='Data required')
        new_paper.save()
        flash("Paper saved", 'success')

        if owner == user:
            return redirect(
                url_for("biocatdb.submission_main_page",
                        paper_id=new_paper.id))

        else:
            return redirect(url_for("biocatdb.launch_add_paper"))