forked from JMante1/jet-plugin
-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.py
184 lines (131 loc) · 5.63 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
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
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
#FLASK_APP=app.py flask run
from flask import Flask, request, abort
from input_data import input_data
from find_role_name import find_role_name
from sankey import sankey
from sankey_graph import sankey_graph
from retrieve_html import retrieve_html
from most_used_bar import most_used_bar
from bar_plot import bar_plot
from most_used_by_type_bar import most_used_by_type_bar
from toggle_bars import toggle_bars
import tempfile, os, shutil
app = Flask(__name__)
#flask run --host=0.0.0.0
@app.route("/sankey/status")
def Sankey_Status():
return("The sankey plugin is up and running")
@app.route("/sankey/evaluate", methods=["POST"])
def Sankey_Evaluate():
data = request.get_json(force=True)
rdf_type = data['type']
########## REPLACE THIS SECTION WITH OWN RUN CODE #################
#uses rdf types
accepted_types = {'Component'}
acceptable = rdf_type in accepted_types
# #to ensure it shows up on all pages
# acceptable = True
################## END SECTION ####################################
if acceptable:
return f'The type sent ({rdf_type}) is an accepted type', 200
else:
return f'The type sent ({rdf_type}) is NOT an accepted type', 415
@app.route("/sankey/run", methods=["POST"])
def Sankey_Run():
data = request.get_json(force=True)
top_level_url = data['top_level']
complete_sbol = data['complete_sbol']
instance_url = data['instanceUrl']
size = data['size']
rdf_type = data['type']
shallow_sbol = data['shallow_sbol']
url = complete_sbol.replace('/sbol','')
try:
#instance_ur = 'https://synbiohub.org/'
#url = 'https://synbiohub.org/public/igem/BBa_B0012/1'
#top_level_url = 'https://dev.synbiohub.org/public/igem/BBa_B0012/1'
#retrieve information about the poi
self_df, display_id, title, role, count = input_data(top_level_url, instance_url)
#print("Find role name")
#Find the role name in the ontology of the part of interest
role_link = find_role_name(role, plural = False)
#create data for the sankey diagram and format it correctly
df_sankey = sankey(url, top_level_url, title, instance_url)
sankey_title = "Parts Co-Located with "+ title + " (a "+role_link+")"
#create a temporary directory
temp_dir = tempfile.TemporaryDirectory()
#name file
filename = os.path.join(temp_dir.name, "Sankey.html")
#create the sankey diagram
sankey_graph(filename, df_sankey, 'Node, Label',
'Link', 'Color', 'Source','Target', 'Value',
'Link Color', sankey_title, url_not_name=False)
#obtain the html from the sankey diagram
result = retrieve_html(filename)
return result
except Exception as e:
print(e)
abort(400)
#flask run --host=0.0.0.0
@app.route("/bar/status")
def Bar_Status():
return("The bar plugin is up and running")
@app.route("/bar/evaluate", methods=["POST"])
def Bar_Evaluate():
data = request.get_json(force=True)
rdf_type = data['type']
########## REPLACE THIS SECTION WITH OWN RUN CODE #################
#uses rdf types
accepted_types = {'Component'}
acceptable = rdf_type in accepted_types
# #to ensure it shows up on all pages
# acceptable = True
################## END SECTION ####################################
if acceptable:
return f'The type sent ({rdf_type}) is an accepted type', 200
else:
return f'The type sent ({rdf_type}) is NOT an accepted type', 415
@app.route("/bar/run", methods=["POST"])
def Bar_Run():
data = request.get_json(force=True)
top_level_url = data['top_level']
complete_sbol = data['complete_sbol']
instance_url = data['instanceUrl']
size = data['size']
rdf_type = data['type']
shallow_sbol = data['shallow_sbol']
url = complete_sbol.replace('/sbol','')
try:
#create input data
self_df, display_id, title, role, count = input_data(top_level_url, instance_url)
#create and format data for the most_used barchart
bar_df = most_used_bar(top_level_url, instance_url, display_id, title, role,
count)
#graph title for most used barchart
graph_title = f'Top Ten Parts by Number of Uses Compared to <a href="{url}" target="_blank">{title}</a>'
#create a temporary directory
temp_dir = tempfile.TemporaryDirectory()
#name file
filename1 = os.path.join(temp_dir.name, "Most_Used.html")
#create the most used barchart
bar_plot('title','count','color',bar_df, graph_title, filename1, 'deff')
#retrieve html
most_used = retrieve_html(filename1)
#find poi role ontology link
role_link = find_role_name(role, plural = False)
bar_df = most_used_by_type_bar(top_level_url,instance_url, display_id, title,
role, count)
#graph title for most used barchart
graph_title = f'Top Ten {role_link} by Number of Uses Compared to <a href="{url}" target="_blank">{title}</a>'
#name file
filename2 = os.path.join(temp_dir.name, "Most_Used_Type.html")
#create the most used barchart
bar_plot('title','count','color',bar_df, graph_title, filename2, 'deff')
#retrieve html
by_role = retrieve_html(filename2)
#create bar toggle html
toggle_display = toggle_bars(most_used,by_role)
return toggle_display
except Exception as e:
print(e)
abort(400)