-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added table rendering for spectra. Modified templates.
- Loading branch information
Showing
12 changed files
with
916 additions
and
50 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,52 +1,71 @@ | ||
import os,sys | ||
|
||
sys.path.append('../') | ||
sys.path.append('../library_spectra_validation') | ||
|
||
from flask import Flask | ||
from flask import request, render_template | ||
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=['POST']) | ||
@app.route('/upload', methods=['GET','POST']) | ||
def upload(): | ||
uploaded_file = request.files['file'] | ||
uploaded_file.save(uploaded_file.filename) # Save the file | ||
xl = pd.ExcelFile(uploaded_file.filename) | ||
sheets = xl.sheet_names | ||
return render_template('preview.html', sheets=sheets) | ||
|
||
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(): | ||
cmp_selector = request.form['compound_name'] | ||
cmp_id = cmp_list.index(cmp_selector) | ||
cmp_smile = df_spectra.loc[cmp_id]["smiles"] | ||
# @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] | ||
|
||
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]) | ||
|
||
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") | ||
|
||
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]) | ||
|
||
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') | ||
|
||
# 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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
UPLOAD_FOLDER = 'resources' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
Oops, something went wrong.