Skip to content

Flask app #30

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -157,5 +157,5 @@ cython_debug/
# be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore
# and can be added to the global gitignore or merged into this file. For a more nuclear
# option (not recommended) you can uncomment the following to ignore the entire idea folder.
#.idea/
.idea/

71 changes: 71 additions & 0 deletions flask_app/app.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
import os,sys

sys.path.append('../')
sys.path.append('../library_spectra_validation')

from flask import Flask
from flask import request, render_template, redirect, url_for

import pandas as pd
import numpy as np
from matplotlib.figure import Figure

from library_spectra_validation.library_handler import LibraryHandler


app = Flask(__name__)
app.config.from_pyfile("config.py")

@app.route('/')
def index():
return render_template('index.html')

@app.route('/upload', methods=['GET','POST'])
def upload():
if request.method == 'POST':
file = request.files['file']
file.save(os.path.join(app.config['UPLOAD_FOLDER'], file.filename))
fpath = os.path.join(app.config['UPLOAD_FOLDER'], file.filename)
if file:
library_handler = LibraryHandler(fpath)
df_spectra = pd.DataFrame({"spectrum": library_handler.spectra}) #TODO
return render_template("preview.html", data=df_spectra.to_html())
return render_template('upload_data.html')

@app.route('/preview', methods=['POST'])
def preview():
sheet_name = request.form['sheet']
df = pd.read_excel(request.files['file'], sheet_name=sheet_name)
return render_template('preview.html', df=df.to_html(), sheet_name=sheet_name)

# @app.route('/plot_spectrum', methods=['POST'])
# def plot_spectrum():
# # TODO plotly??
# cmp_selector = request.form['compound_name']
# cmp_id = cmp_list.index(cmp_selector)
# cmp_smile = df_spectra.loc[cmp_id]["smiles"]

# plt_spectrum = spectra[cmp_id]

# fig, axs = plt.subplots(1, 2, figsize=(12.8, 4.2), gridspec_kw={'width_ratios': [2, 5]}, sharey=False)
# cmp_img = Chem.Draw.MolToImage(Chem.MolFromSmiles(cmp_smile), ax=axs[0])

# axs[0].grid(False)
# axs[0].tick_params(axis='both', bottom=False, labelbottom=False, left=False, labelleft=False)
# axs[0].set_title(cmp_smile)
# axs[0].imshow(cmp_img)
# axs[0].axis("off")

# plot_spectrum(plt_spectrum, axs[1])

# # Save the plot to a temporary file or convert it to a base64 string to embed in HTML
# # Example: plt.savefig('static/plot.png')
# # Pass the path or base64 string to the template
# return render_template('plot_spectrum.html', plot_path='static/plot.png')

@app.route('/about')
def about():
return render_template('about.html')

if __name__ == '__main__':
app.run(debug=True)
1 change: 1 addition & 0 deletions flask_app/config.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
UPLOAD_FOLDER = 'resources'
19 changes: 19 additions & 0 deletions flask_app/resources/Broken_records.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
I clean all the 12 mass spectra in the "test_case_correct.mgf", in terms of
--> adding inchikey
--> cleaning the inchi
--> adding formula

So all mass spectra in the "test_case_wrong.mgf" are missing formula and inchikey

mass spectrum 1: no change
mass spectrum 2: wrong adduct
mass spectrum 3: wrong pepmass (precursor)
mass spectrum 4: wrong smiles
mass spectrum 5: missing adduct
mass spectrum 6: no change (share the same compound name as mass spectrum 5, but different adduct)
mass spectrum 7: missing adduct
mass spectrum 8: missing adduct
mass spectrum 9: no change
mass spectrum 10: missing compound name and adduct
mass spectrum 11: no change
mass spectrum 12: wroing inchi
Loading
Loading