-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.py
More file actions
90 lines (70 loc) · 3.54 KB
/
app.py
File metadata and controls
90 lines (70 loc) · 3.54 KB
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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
from flask import Flask, Response, render_template, flash, redirect, request, url_for
from wtforms import Form, validators, TextField, BooleanField, SelectField
from func import diana_scrapper, mirdb_scrapper, targetscan_scrapper, list_intersection, sorter
from holder import holder
app = Flask(__name__)
app.secret_key = "super secret key"
data = holder()
class ReusableForm(Form):
name = TextField('miRNA Name:', validators=[validators.required()])
best20 = BooleanField('Only best 20 percent? ')
specy = SelectField('Species: ', choices = [('mouse','Mouse'),('human','Human')])
@app.route("/", methods=['GET', 'POST'])
def hello_world():
form = ReusableForm(request.form)
if request.method == 'POST':
name=request.form['name']
try:
best20=request.form['best20']
best20 = "1"
except:
best20 = "0"
specy=request.form['specy']
if form.validate():
return redirect(url_for('diana', name=name, best20=best20, specy=specy))
else:
flash('enter a miRNA name')
return render_template('hello.html', form=form)
@app.route('/diana/<name>/<specy>/<best20>')
def diana(name, specy, best20):
try:
data.diana_list = diana_scrapper(name, best20, specy)
if data.diana_list=="error":
return render_template("error.html", error="diana threw an error, please check your miRNA name")
print("in diana, diana list:",len(data.diana_list))
return render_template('dianasearchdone.html', name=name, best20=best20, specy=specy, data=data.diana_list)
except:
return render_template("error.html", error="there is a server error")
@app.route('/mirdb/<name>/<specy>/<best20>')
def mirdb(name, specy, best20):
try:
data.mirdb_list = mirdb_scrapper(name, best20, specy)
if data.mirdb_list=="error":
return render_template("error.html", error="mirdb threw an error, please check your miRNA name")
print("in mirdb, diana list:",len(data.diana_list),"mirdb list:",len(data.mirdb_list))
return render_template('mirdbsearchdone.html', name=name, best20=best20, specy=specy, data=data.mirdb_list)
except:
return render_template("error.html", error="there is a server error")
@app.route('/targetscan/<name>/<specy>/<best20>')
def targetscan(name, specy, best20):
try:
print("in target, diana list:",len(data.diana_list),"mirdb list:",len(data.mirdb_list))
data.targetscan_list = targetscan_scrapper(name, best20, specy)
if data.targetscan_list=="error":
return render_template("error.html", error="targetscan threw an error, please check your miRNA name")
print("in target, diana list:",len(data.diana_list),"mirdb list:",len(data.mirdb_list),"target list:",len(data.targetscan_list))
return render_template('targetscansearchdone.html', name=name, best20=best20, specy=specy, data=data.targetscan_list)
except:
return render_template("error.html", error="there is a server error")
@app.route('/results/<name>/<specy>/<best20>')
def results(name, specy, best20):
try:
print(len(data.diana_list),len(data.mirdb_list),len(data.targetscan_list))
data.final = list_intersection(data.diana_list, data.mirdb_list, data.targetscan_list)
data.final = sorter(data.final)
return render_template("dictprinter.html", data=data.final, lengthoflist=len(data.final))
except:
return render_template("error.html", error="there is a server error")
if __name__ == '__main__':
app.debug = True
app.run()