Skip to content

Commit 35e41e6

Browse files
committed
Auth Tokens
1 parent cfb3a6a commit 35e41e6

6 files changed

Lines changed: 21 additions & 15 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: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ def Sankey_Run():
5252
size = data['size']
5353
rdf_type = data['type']
5454
shallow_sbol = data['shallow_sbol']
55+
token = data['token']
5556

5657
url = complete_sbol.replace('/sbol','')
5758

@@ -62,13 +63,13 @@ def Sankey_Run():
6263
#top_level_url = 'https://dev.synbiohub.org/public/igem/BBa_B0012/1'
6364

6465
#retrieve information about the poi
65-
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)
6667

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+
df_sankey = sankey(url, top_level_url, title, instance_url, token)
7273
sankey_title = "Parts Co-Located with "+ title + " (a "+role_link+")"
7374

7475
#create a temporary directory
@@ -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>'

input_data.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
import requests
33
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
@@ -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: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
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: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
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)

sankey.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
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
@@ -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)