Skip to content

Commit 182a5f1

Browse files
authored
Merge pull request #1 from SynBioHub/library-updates
Plugins Updated
2 parents 52c2b88 + 35e41e6 commit 182a5f1

7 files changed

Lines changed: 39 additions & 31 deletions

File tree

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# INSTALL
22
## Docker
3-
Run `docker run --publish 8080:5000 --detach --name component-use-plug synbiohub/plugin-visual-component-use` Check it is up using localhost:8080/sankey/status
3+
Run `docker run --publish 8095:5000 --detach --name component-use-plug synbiohub/plugin-visual-component-use` Check it is up using localhost:8095/sankey/status
44

55
## Python
66
Using python run `pip install -r requirements.txt` to install the requirements.

app.py

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
from toggle_bars import toggle_bars
1313

1414
import tempfile, os, shutil
15+
import traceback
1516

1617
app = Flask(__name__)
1718

@@ -27,7 +28,7 @@ def Sankey_Evaluate():
2728

2829
########## REPLACE THIS SECTION WITH OWN RUN CODE #################
2930
#uses rdf types
30-
accepted_types = {'Component'}
31+
accepted_types = {'Component', 'ComponentDefinition'}
3132

3233
acceptable = rdf_type in accepted_types
3334

@@ -51,6 +52,7 @@ def Sankey_Run():
5152
size = data['size']
5253
rdf_type = data['type']
5354
shallow_sbol = data['shallow_sbol']
55+
token = data['token']
5456

5557
url = complete_sbol.replace('/sbol','')
5658

@@ -61,15 +63,13 @@ def Sankey_Run():
6163
#top_level_url = 'https://dev.synbiohub.org/public/igem/BBa_B0012/1'
6264

6365
#retrieve information about the poi
64-
self_df, display_id, title, role, count = input_data(top_level_url, instance_url)
66+
self_df, display_id, title, role, count = input_data(top_level_url, instance_url, token)
6567

66-
#print("Find role name")
6768
#Find the role name in the ontology of the part of interest
6869
role_link = find_role_name(role, plural = False)
6970

7071
#create data for the sankey diagram and format it correctly
71-
df_sankey = sankey(url, top_level_url, title, instance_url)
72-
72+
df_sankey = sankey(url, top_level_url, title, instance_url, token)
7373
sankey_title = "Parts Co-Located with "+ title + " (a "+role_link+")"
7474

7575
#create a temporary directory
@@ -90,7 +90,8 @@ def Sankey_Run():
9090

9191
return result
9292
except Exception as e:
93-
print(e)
93+
print(e, flush=True)
94+
print(traceback.format_exc(), flush=True)
9495
abort(400)
9596

9697
#flask run --host=0.0.0.0
@@ -106,7 +107,7 @@ def Bar_Evaluate():
106107

107108
########## REPLACE THIS SECTION WITH OWN RUN CODE #################
108109
#uses rdf types
109-
accepted_types = {'Component'}
110+
accepted_types = {'Component', 'ComponentDefinition'}
110111

111112
acceptable = rdf_type in accepted_types
112113

@@ -130,17 +131,18 @@ def Bar_Run():
130131
size = data['size']
131132
rdf_type = data['type']
132133
shallow_sbol = data['shallow_sbol']
134+
token = data['token']
133135

134136
url = complete_sbol.replace('/sbol','')
135137

136138
try:
137139

138140
#create input data
139-
self_df, display_id, title, role, count = input_data(top_level_url, instance_url)
141+
self_df, display_id, title, role, count = input_data(top_level_url, instance_url, token)
140142

141143
#create and format data for the most_used barchart
142144
bar_df = most_used_bar(top_level_url, instance_url, display_id, title, role,
143-
count)
145+
count, token)
144146

145147
#graph title for most used barchart
146148
graph_title = f'Top Ten Parts by Number of Uses Compared to <a href="{url}" target="_blank">{title}</a>'
@@ -161,7 +163,7 @@ def Bar_Run():
161163
role_link = find_role_name(role, plural = False)
162164

163165
bar_df = most_used_by_type_bar(top_level_url,instance_url, display_id, title,
164-
role, count)
166+
role, count, token)
165167

166168
#graph title for most used barchart
167169
graph_title = f'Top Ten {role_link} by Number of Uses Compared to <a href="{url}" target="_blank">{title}</a>'
@@ -180,5 +182,6 @@ def Bar_Run():
180182

181183
return toggle_display
182184
except Exception as e:
183-
print(e)
185+
print(e, flush=True)
186+
print(traceback.format_exc(), flush=True)
184187
abort(400)

input_data.py

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
11
import json
22
import requests
3-
from pandas.io.json import json_normalize
3+
from pandas import json_normalize
44

5-
def input_data(uri, instance):
5+
def input_data(uri, instance, token = None):
66
"""
77
Finds information about an SBOL part based on its uri
88
99
Requirements
1010
-------
1111
import json
1212
import requests
13-
from pandas.io.json import json_normalize
13+
from pandas import json_normalize
1414
Input_Query.txt
1515
1616
Parameters
@@ -55,7 +55,10 @@ def input_data(uri, instance):
5555

5656
status = 200
5757

58-
req = requests.get(instance)
58+
headers = {}
59+
if token is not None:
60+
headers['X-authorization'] = token
61+
req = requests.get(instance, headers=headers)
5962
if req.status_code != 200: #if synbiohub is offline return an error
6063
status = 424
6164
else:
@@ -66,7 +69,7 @@ def input_data(uri, instance):
6669
sparqlquery = sparqlquery.replace('https://synbiohub.org/public/igem/BBa_B0012/1',uri)
6770

6871
#accept repsonses
69-
r = requests.post(instance+"sparql", data = {"query":sparqlquery}, headers = {"Accept":"application/json"})
72+
r = requests.post(instance+"sparql", data = {"query":sparqlquery}, headers = {"Accept":"application/json", "X-authorization": token} if token is not None else {"Accept":"application/json"})
7073

7174
#format responses
7275
d = json.loads(r.text)

most_used_bar.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
import pandas as pd
22
import requests
33
import json
4-
from pandas.io.json import json_normalize
4+
from pandas import json_normalize
55
from uri_to_url import uri_to_url
66

7-
def most_used_bar(uri, instance, display_id, title, role, count):
7+
def most_used_bar(uri, instance, display_id, title, role, count, token):
88
"""
99
Uses a sparql query to obtain information about the most used parts and format the data in such a way
1010
that a graph can be made comparing the poi (part of interest) to the most used parts
@@ -76,9 +76,10 @@ def most_used_bar(uri, instance, display_id, title, role, count):
7676
fl = open("Most_Used_Query.txt", "r")
7777
sparqlquery = fl.read()
7878

79+
7980
#send the query
8081
r = requests.post(instance+"sparql", data = {"query":sparqlquery},
81-
headers = {"Accept":"application/json"})
82+
headers = {"Accept":"application/json", "X-authorization": token} if token is not None else {"Accept":"application/json"})
8283

8384
#format query results
8485
d = json.loads(r.text)

most_used_by_type_bar.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
import pandas as pd
22
import requests
33
import json
4-
from pandas.io.json import json_normalize
4+
from pandas import json_normalize
55
from uri_to_url import uri_to_url
66

7-
def most_used_by_type_bar(uri, instance, display_id, title, role, count):
7+
def most_used_by_type_bar(uri, instance, display_id, title, role, count, token):
88
"""
99
Uses a sparql query to obtain information about the most used parts (of the same type as the poi e.g. all terminators)
1010
and format the data in such a way that a graph can be made comparing the poi (part of interest) to the most used parts
@@ -81,7 +81,7 @@ def most_used_by_type_bar(uri, instance, display_id, title, role, count):
8181
sparql_query = sparql_query.replace("0000167", role)
8282

8383
#perform the query
84-
r = requests.post(instance+"sparql", data = {"query":sparql_query}, headers = {"Accept":"application/json"})
84+
r = requests.post(instance+"sparql", data = {"query":sparql_query}, headers = {"Accept":"application/json", "X-authorization": token} if token is not None else {"Accept":"application/json"})
8585

8686
#format the data
8787
d = json.loads(r.text)

requirements.txt

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
bs4==0.0.1
2-
Flask==2.0.1
2+
Flask==2.2.5
33
jsonschema==3.0.1
4-
pandas==0.24.2
4+
pandas==2.2.3
55
plotly==3.9.0
66
requests==2.21.0
7-
8-
7+
Werkzeug==2.2.3
8+
waitress
9+
lxml

sankey.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
import requests
22
import json
33
import pandas as pd
4-
from pandas.io.json import json_normalize
4+
from pandas import json_normalize
55
from uri_to_url import uri_to_url
66

7-
def sankey(url, uri, title, instance):
7+
def sankey(url, uri, title, instance, token):
88
"""
99
This function creates the table needed to make the sankey diagram
1010
to create the sankey diagram two linked tables are needed
@@ -16,7 +16,7 @@ def sankey(url, uri, title, instance):
1616
import requests
1717
import json
1818
import pandas as pd
19-
from pandas.io.json import json_normalize
19+
from pandas import json_normalize
2020
Preceding_Percent_Query.txt
2121
2222
@@ -58,7 +58,7 @@ def sankey(url, uri, title, instance):
5858

5959
#substitute in the name of the particular part
6060
sparqlquery = sparqlquery.replace('https://synbiohub.org/public/igem/BBa_E0040/1',uri)
61-
r = requests.post(instance+"sparql", data = {"query":sparqlquery}, headers = {"Accept":"application/json"})
61+
r = requests.post(instance+"sparql", data = {"query":sparqlquery}, headers = {"Accept":"application/json", "X-authorization": token} if token is not None else {"Accept":"application/json"})
6262

6363
#reformat query results
6464
d = json.loads(r.text)

0 commit comments

Comments
 (0)