Skip to content

Commit

Permalink
Added draft (not tested yet!) starting code for flask migration.
Browse files Browse the repository at this point in the history
  • Loading branch information
omokshyna committed Mar 25, 2024
1 parent 1079e3b commit 265df58
Show file tree
Hide file tree
Showing 18 changed files with 109 additions and 861 deletions.
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/

52 changes: 52 additions & 0 deletions flask_app/app.py
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)
3 changes: 3 additions & 0 deletions flask_app/services/plot_spectra.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
'''
TODO Migrate here functionality to plot spectra
'''
3 changes: 3 additions & 0 deletions flask_app/templates/about.html
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."
22 changes: 22 additions & 0 deletions flask_app/templates/base.html
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.
11 changes: 11 additions & 0 deletions flask_app/templates/plot_spectrum.html
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"> -->
13 changes: 13 additions & 0 deletions flask_app/templates/preview.html
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 %}
4 changes: 4 additions & 0 deletions flask_app/templates/upload_data.html
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>
35 changes: 0 additions & 35 deletions library_spectra_validation/.gitignore

This file was deleted.

File renamed without changes.
72 changes: 0 additions & 72 deletions streamlit_app/FAIR_MS_Library_Editor.py

This file was deleted.

24 changes: 0 additions & 24 deletions streamlit_app/README.md

This file was deleted.

Empty file removed streamlit_app/assets/.empty
Empty file.
20 changes: 0 additions & 20 deletions streamlit_app/config.json

This file was deleted.

Loading

0 comments on commit 265df58

Please sign in to comment.