-
Notifications
You must be signed in to change notification settings - Fork 0
/
hello.template
162 lines (134 loc) · 5.63 KB
/
hello.template
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
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
from flask import Flask, render_template, redirect, url_for, abort, request, jsonify, send_from_directory
import glob
import os
import sys
import subprocess
import atexit
from flask_wtf import FlaskForm
from flask_wtf.csrf import CSRFProtect
from wtforms import StringField, SubmitField
import context_processors as cp
from bokeh.embed import server_document
import nameProcessing as np
# Configure flask stuff
app = Flask(__name__)
app.config['SECRET_KEY']='la'
app.url_map.strict_slashes = False
csrf = CSRFProtect(app)
cp.setup(app)
# Start bokeh servers
bokeh_process1 = subprocess.Popen(
['bokeh', 'serve', '--allow-websocket-origin={{dnprefix}}', 'lolliplotServer.py'], stdout=subprocess.PIPE)
bokeh_process2 = subprocess.Popen(
['bokeh', 'serve', '--allow-websocket-origin={{dnprefix}}', '--port=5007', 'lolliplotServerDetail.py'], stdout=subprocess.PIPE)
@atexit.register
def kill_server():
bokeh_process1.kill()
bokeh_process2.kill()
# Functions/classes needed for index page
@app.route('/autocomplete', methods=['GET'])
def autocomplete():
search = request.args.get('q').upper()
filelist = glob.glob(os.path.expanduser('~/data/*.ssw11.hhr'))
orflist = []
for f in filelist:
name = os.path.basename(f).split('.')[0].upper()
if np.is_systematic_name(name): # Accept only ORF's in the standard list
orflist.append( np.display_name(name) )
filteredlist = [orf for orf in sorted(orflist) if search in orf]
return jsonify(matching_results=filteredlist)
class IndexForm(FlaskForm):
filename = StringField('autocomplete')
display = SubmitField(label='Display plot')
download = SubmitField(label='Download file')
# Index page
@app.route('/', methods=['POST','GET'])
def index():
form = IndexForm()
if form.validate_on_submit():
filename = form.filename.data
name = filename.split('/')[-1]
if form.display.data:
url = url_for( 'load_name',filename=(np.single_name(name)) )
return redirect(url)
else:
return send_from_directory(os.path.expanduser('~/data'),np.systematic_name(name)+'.0.ssw11.hhr',as_attachment=True)
return render_template('index.html',form=form)
# Custom error handlers
@app.errorhandler(406)
def wrong_case_url(e):
url = ''
input_list = e.description.split(' ')
if len(input_list)==1:
url = url_for('load_name', filename=input_list[0].upper())
elif len(input_list)==2:
url = url_for('load_detail', filename=input_list[0].upper(), db=input_list[1].lower())
return redirect(url)
@app.errorhandler(410)
def syst_name_in_url(e):
url = ''
input_list = e.description.split(' ')
if len(input_list)==1:
url = url_for( 'load_name', filename=np.standard_name(input_list[0].upper()) )
elif len(input_list)==2:
url = url_for('load_detail', filename=np.standard_name(input_list[0].upper()), db=input_list[1].lower())
return redirect(url)
# Summary page
@app.route('/<filename>', methods=['POST','GET'])
def load_name(filename):
if filename!=filename.upper():
abort(406, filename)
if np.is_systematic_name(filename) and not np.is_hypothetical_protein(filename) :
abort(410, filename)
if np.is_unknown_protein(filename): # Accept only ORF's in the standard list
return render_template(
'error.html',
msg=filename+" is not a valid ORF. Please choose a different one.")
filepath = os.path.join(os.path.expanduser('~/data'),np.systematic_name(filename)+'.0.ssw11.hhr')
prob = request.args.get('prob', default=0.5, type=float)
ov_min = request.args.get('ovm', default=10, type=int)
ov_min_r = request.args.get('ovm1', default=0.1, type=float)
if os.path.isfile(filepath):
bokeh_script = server_document(
url='http://{{dnprefix}}:5006/lolliplotServer',
arguments=dict(filename=filepath, prob=prob, ov_min=ov_min, ov_min_r=ov_min_r))
return render_template(
'plot.html',
plot_script=bokeh_script,
name=filename,
prob=prob,
ov_min=ov_min,
ov_min_r=ov_min_r)
else:
return render_template(
'error.html',
msg="Data for "+filename+" does not exist. Please choose a different ORF.")
# Detail page
@app.route('/<filename>/<db>', methods=['POST','GET'])
def load_detail(filename, db):
if filename!=filename.upper() or db!=db.lower():
abort(406, filename+" "+db)
if np.is_systematic_name(filename) and not np.is_hypothetical_protein(filename) :
abort(410, filename+" "+db)
if np.is_unknown_protein(filename): # Accept only ORF's in the standard list
return render_template(
'error.html',
msg=filename+" is not a valid ORF. Please choose a different one.")
filepath = os.path.join(os.path.expanduser('~/data'),np.systematic_name(filename)+'.0.ssw11.hhr')
if db in ['pdb', 'pfam', 'yeast']:
if os.path.isfile(filepath):
bokeh_script = server_document(
url='http://{{dnprefix}}:5007/lolliplotServerDetail', arguments=dict(filename=filepath, db=db))
return render_template(
'detail.html',
plot_script=bokeh_script,
name=filename,
db=db )
else:
return render_template(
'error.html',
msg="Data for "+filename+" does not exist. Please choose a different ORF.")
else:
return render_template(
'error.html',
msg="Data for database "+db+" does not exist. Please choose between pdb, pfam or yeast.")