Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# INSTALL
## Docker
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
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

## Python
Using python run `pip install -r requirements.txt` to install the requirements.
Expand Down
25 changes: 14 additions & 11 deletions app.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
from toggle_bars import toggle_bars

import tempfile, os, shutil
import traceback

app = Flask(__name__)

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

########## REPLACE THIS SECTION WITH OWN RUN CODE #################
#uses rdf types
accepted_types = {'Component'}
accepted_types = {'Component', 'ComponentDefinition'}

acceptable = rdf_type in accepted_types

Expand All @@ -51,6 +52,7 @@ def Sankey_Run():
size = data['size']
rdf_type = data['type']
shallow_sbol = data['shallow_sbol']
token = data['token']

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

Expand All @@ -61,15 +63,13 @@ def Sankey_Run():
#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)
self_df, display_id, title, role, count = input_data(top_level_url, instance_url, token)

#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)

df_sankey = sankey(url, top_level_url, title, instance_url, token)
sankey_title = "Parts Co-Located with "+ title + " (a "+role_link+")"

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

return result
except Exception as e:
print(e)
print(e, flush=True)
print(traceback.format_exc(), flush=True)
abort(400)

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

########## REPLACE THIS SECTION WITH OWN RUN CODE #################
#uses rdf types
accepted_types = {'Component'}
accepted_types = {'Component', 'ComponentDefinition'}

acceptable = rdf_type in accepted_types

Expand All @@ -130,17 +131,18 @@ def Bar_Run():
size = data['size']
rdf_type = data['type']
shallow_sbol = data['shallow_sbol']
token = data['token']

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

try:

#create input data
self_df, display_id, title, role, count = input_data(top_level_url, instance_url)
self_df, display_id, title, role, count = input_data(top_level_url, instance_url, token)

#create and format data for the most_used barchart
bar_df = most_used_bar(top_level_url, instance_url, display_id, title, role,
count)
count, token)

#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>'
Expand All @@ -161,7 +163,7 @@ def Bar_Run():
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)
role, count, token)

#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>'
Expand All @@ -180,5 +182,6 @@ def Bar_Run():

return toggle_display
except Exception as e:
print(e)
print(e, flush=True)
print(traceback.format_exc(), flush=True)
abort(400)
13 changes: 8 additions & 5 deletions input_data.py
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
import json
import requests
from pandas.io.json import json_normalize
from pandas import json_normalize

def input_data(uri, instance):
def input_data(uri, instance, token = None):
"""
Finds information about an SBOL part based on its uri

Requirements
-------
import json
import requests
from pandas.io.json import json_normalize
from pandas import json_normalize
Input_Query.txt

Parameters
Expand Down Expand Up @@ -55,7 +55,10 @@ def input_data(uri, instance):

status = 200

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

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

#format responses
d = json.loads(r.text)
Expand Down
7 changes: 4 additions & 3 deletions most_used_bar.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import pandas as pd
import requests
import json
from pandas.io.json import json_normalize
from pandas import json_normalize
from uri_to_url import uri_to_url

def most_used_bar(uri, instance, display_id, title, role, count):
def most_used_bar(uri, instance, display_id, title, role, count, token):
"""
Uses a sparql query to obtain information about the most used parts 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
Expand Down Expand Up @@ -76,9 +76,10 @@ def most_used_bar(uri, instance, display_id, title, role, count):
fl = open("Most_Used_Query.txt", "r")
sparqlquery = fl.read()


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

#format query results
d = json.loads(r.text)
Expand Down
6 changes: 3 additions & 3 deletions most_used_by_type_bar.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import pandas as pd
import requests
import json
from pandas.io.json import json_normalize
from pandas import json_normalize
from uri_to_url import uri_to_url

def most_used_by_type_bar(uri, instance, display_id, title, role, count):
def most_used_by_type_bar(uri, instance, display_id, title, role, count, token):
"""
Uses a sparql query to obtain information about the most used parts (of the same type as the poi e.g. all terminators)
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
Expand Down Expand Up @@ -81,7 +81,7 @@ def most_used_by_type_bar(uri, instance, display_id, title, role, count):
sparql_query = sparql_query.replace("0000167", role)

#perform the query
r = requests.post(instance+"sparql", data = {"query":sparql_query}, headers = {"Accept":"application/json"})
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"})

#format the data
d = json.loads(r.text)
Expand Down
9 changes: 5 additions & 4 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
bs4==0.0.1
Flask==2.0.1
Flask==2.2.5
jsonschema==3.0.1
pandas==0.24.2
pandas==2.2.3
plotly==3.9.0
requests==2.21.0


Werkzeug==2.2.3
waitress
lxml
8 changes: 4 additions & 4 deletions sankey.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import requests
import json
import pandas as pd
from pandas.io.json import json_normalize
from pandas import json_normalize
from uri_to_url import uri_to_url

def sankey(url, uri, title, instance):
def sankey(url, uri, title, instance, token):
"""
This function creates the table needed to make the sankey diagram
to create the sankey diagram two linked tables are needed
Expand All @@ -16,7 +16,7 @@ def sankey(url, uri, title, instance):
import requests
import json
import pandas as pd
from pandas.io.json import json_normalize
from pandas import json_normalize
Preceding_Percent_Query.txt


Expand Down Expand Up @@ -58,7 +58,7 @@ def sankey(url, uri, title, instance):

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

#reformat query results
d = json.loads(r.text)
Expand Down