-
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 draft (not tested yet!) starting code for flask migration.
- Loading branch information
Showing
18 changed files
with
109 additions
and
861 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
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,52 @@ | ||
from flask import Flask | ||
from flask import request, render_template | ||
|
||
import pandas as pd | ||
from matplotlib.figure import Figure | ||
|
||
app = Flask(__name__) | ||
|
||
@app.route('/') | ||
def index(): | ||
return render_template('index.html') | ||
|
||
@app.route('/upload', methods=['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) | ||
|
||
@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"] | ||
|
||
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') | ||
|
||
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,3 @@ | ||
''' | ||
TODO Migrate here functionality to plot spectra | ||
''' |
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,3 @@ | ||
|
||
|
||
"# This is the creation and curation wizard for FAIR MS Libraries." |
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,22 @@ | ||
<!DOCTYPE html> | ||
<html lang="en"> | ||
<head> | ||
<meta charset="UTF-8"> | ||
<meta name="viewport" content="width=device-width, initial-scale=1.0"> | ||
<title>{% block title %}Order Service App{% endblock %}</title> | ||
<link rel= "stylesheet" type= "text/css" href= "{{ url_for('static',filename='styles.css') }}"> | ||
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.6.2/jquery.min.js"></script> | ||
</head> | ||
<body> | ||
<nav> | ||
<ul> | ||
<li><a href="{{ url_for('index') }}">Home</a></li> | ||
<li><a href="https://github.com/mzmine/biohack23_p15">Get help</a></li> | ||
<li><a href="https://github.com/mzmine/biohack23_p15/issues/new/choose">Report bug</a></li> | ||
<li><a href="{{ url_for('about') }}">About</a></li> | ||
</ul> | ||
</nav> | ||
{% block content %} | ||
{% endblock %} | ||
</body> | ||
</html> |
File renamed without changes.
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,11 @@ | ||
<form action="/plot_spectrum" method="post"> | ||
<label for="compound_name">Select a compound name:</label> | ||
<select id="compound_name" name="compound_name"> | ||
{% for cmp in cmp_list %} | ||
<option value="{{ cmp }}">{{ cmp }}</option> | ||
{% endfor %} | ||
</select> | ||
<input type="submit" value="Plot Spectrum"> | ||
</form> | ||
|
||
<!-- <img src="{{ plot_path }}" alt="Spectrum Plot"> --> |
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,13 @@ | ||
{% if sheets %} | ||
<form action="/preview" method="post"> | ||
<select name="sheet"> | ||
{% for sheet in sheets %} | ||
<option value="{{ sheet }}">{{ sheet }}</option> | ||
{% endfor %} | ||
</select> | ||
<input type="submit" value="Preview"> | ||
</form> | ||
{% endif %} | ||
{% if df %} | ||
{{ df | safe }} | ||
{% endif %} |
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,4 @@ | ||
<form action="/upload" method="post" enctype="multipart/form-data"> | ||
<input type="file" name="file" accept=".xls,.xlsx"> | ||
<input type="submit" value="Upload"> | ||
</form> |
This file was deleted.
Oops, something went wrong.
File renamed without changes.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
Empty file.
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.