Beispiel #1
0
def clear_databases():
    EnzymeType.drop_collection()
    Sequence.drop_collection()
    Paper.drop_collection()
    Reaction.drop_collection()
    Activity.drop_collection()
    Molecule.drop_collection()
Beispiel #2
0
def init_db():
    form = InitDB()

    if form.validate_on_submit() == True:
        if form.rxns.data != None:
            rxns_data = form.rxns.data
            filename = secure_filename(rxns_data.filename)
            try:
                rxns_data.save(filename)
                yaml_dict = rxn_rules_to_db.load_yaml_dict(filename)
                Reaction.drop_collection()
                current_app.db_queue.enqueue(rxn_rules_to_db.load_into_mongo,
                                             yaml_dict)
                flash("Yaml loaded ok, reactions_to_db in queue", 'success')
            except:
                flash("Failed to load reactions", 'fail')
            os.remove(filename)

        if form.biocatdb.data != None:
            filename = secure_filename(form.biocatdb.data.filename)
            form.biocatdb.data.save(filename)
            try:
                df = biocatdb_excel_to_db.load_df(filename)

                Paper.drop_collection()
                Activity.drop_collection()
                Molecule.drop_collection()
                Sequence.drop_collection()
                current_app.db_queue.enqueue(biocatdb_excel_to_db.df_to_db, df)
                current_app.db_queue.enqueue(make_molecule_db.make_fp_db)
                flash("Biocatdb excel loaded ok, added to queue", "success")
            except:
                flash("Problem loading biocatdb_2 excel", "fail")
            os.remove(filename)

        if form.sequences.data != None:
            filename = secure_filename(form.sequences.data.filename)
            form.sequences.data.save(filename)
            try:

                if '.xlsx' in filename:
                    df = pd.read_excel(filename)
                elif '.csv' in filename:
                    df = pd.read_csv(filename)
                else:
                    df = None
                    Exception('File must be .csv or .xlsx')

                current_app.db_queue.enqueue(task_add_sequence_data, df)
                flash("Sequences excel loaded ok, added to queue", "success")
            except Exception as e:
                flash(f"Problem loading sequences excel - {e}", "fail")

            os.remove(filename)

        if form.mongo_dump.data != None:
            filename = secure_filename(form.mongo_dump.data.filename)
            form.mongo_dump.data.save(filename)

            try:
                if 'mongo_dump.gz' in filename:
                    execute_mongo_restore(filename)
                else:
                    Exception('File must be mongo_dump.gz')

                flash("mongo dump loaded ok", "success")
            except Exception as e:
                flash(f"Problem loading mongo dump - {e}", "fail")

    return render_template('init_db/init_db.html', form=form)