def load_into_mongo(yaml_dict):
    for rxn_name in yaml_dict:
        enzymes = []
        for enz in list(yaml_dict[rxn_name]['enzymes'].keys()):
            enzymes.append(enz)
            if len(EnzymeType.objects(enzyme_type=enz)) == 0:
                new_type = EnzymeType(enzyme_type=enz,
                                      description='')
                new_type.save()

        if len(Reaction.objects(name=rxn_name)) == 0:
            reaction = Reaction(name=rxn_name,
                                smarts=yaml_dict[rxn_name]['smarts'],
                                enzyme_types=enzymes,
                                cofactors=yaml_dict[rxn_name]['enzymes'],
                                positive_tests=yaml_dict[rxn_name]['positive_tests'],
                                negative_tests=yaml_dict[rxn_name]['negative_tests'],
                                type=yaml_dict[rxn_name]['type'])

            if 'experimental' in yaml_dict[rxn_name]:
                reaction.experimental = bool(yaml_dict[rxn_name]['experimental'])

            if 'two_step' in yaml_dict[rxn_name]:
                reaction.two_step = bool(yaml_dict[rxn_name]['two_step'])

            reaction.save()
Beispiel #2
0
def add_enzyme_type():
    form = EnzymeTypeForm()

    if form.validate_on_submit() == True:
        if form.description.data == '':
            form.description.data = None
        if form.other_abbreviations.data == '':
            other_abbreviations = None
        else:
            other_abbreviations = form.other_abbreviations.data.split(', ')

        enz_type = EnzymeType(enzyme_type=form.enzyme_type.data,
                              full_name=form.full_name.data,
                              other_abbreviations=other_abbreviations,
                              description=form.description.data)
        enz_type.save()

        flash("Data added successfully", 'success')
        return redirect(url_for('biocatdb.add_enzyme_type'))

    return render_template('enzyme_type/add_enzyme_type.html', form=form)
Beispiel #3
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')