-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.py
65 lines (42 loc) · 1.57 KB
/
app.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
from flask import Flask, url_for, render_template, redirect, request, send_file, flash
from utils import data_dir
from HBB import HBB
import zipfile
import io
import os
app = Flask(__name__)
app.secret_key = os.environ['SECRET_KEY']
@app.route('/')
def index():
return render_template('index.j2')
@app.route('/results')
def results():
if not os.path.exists(f'{data_dir}/clustalo_input.fasta'):
return redirect(url_for('index'))
return render_template('results.j2')
@app.route('/upload', methods=['POST'])
def upload():
basic_file = request.files['basic_file']
related_file = request.files['related_file']
if not basic_file or not related_file:
flash('Must upload both basic and related dataset.')
return redirect(url_for('index'))
basic_dataset = basic_file.stream.read().decode('utf-8')
related_dataset = related_file.stream.read().decode('utf-8')
hbb = HBB(basic_dataset, related_dataset)
return redirect(url_for('results'))
@app.route('/download')
def download():
files = ['basic_dataset_training.fasta', 'basic_dataset_testing.fasta',
'related_dataset_training.fasta', 'related_dataset_testing.fasta']
data = io.BytesIO()
with zipfile.ZipFile(data, mode='w') as z:
for file in files:
z.write(f'{data_dir}/{file}', file)
data.seek(0)
return send_file(data, mimetype='application/zip', as_attachment=True, download_name='output.zip')
@app.route('/favicon.ico')
def send_favicon():
return send_file('favicon.ico')
if __name__ == '__main__':
app.run(debug=True)