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
15 changes: 8 additions & 7 deletions backend/sbs_server/app/downloadTemplates.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ def sbh_download_template(files):

params_from_request = json.loads(params_file.read())

required_params = ['template_type', 'sbh_url', 'sbh_token', 'collection_url']
required_params = ['template_type', 'sbh_url', 'sbh_prefix', 'sbh_token', 'collection_url']
for param in required_params:
if param not in params_from_request:
return jsonify({"error": f"Parameter {param} not found in request"}), 400
Expand All @@ -93,6 +93,7 @@ def sbh_download_template(files):
return jsonify({"error": "No SBH credentials provided"}), 400

sbh_url = params_from_request['sbh_url']
sbh_prefix = params_from_request.get('sbh_prefix')
sbh_collection_url = params_from_request['collection_url']
sbh_token = params_from_request['sbh_token']
parts = sbh_collection_url.split("/")
Expand All @@ -114,44 +115,44 @@ def sbh_download_template(files):
wb = load_workbook(BytesIO(template_bytes), keep_vba=True)

if template_type == "synbio.object-type.strains":
search_result = sbh_get_subCollection_uris(sbh_url,sbh_token,usergraph,sbh_collection_url,"http://identifiers.org/ncit/NCIT:C14419")
search_result = sbh_get_subCollection_uris(sbh_url,sbh_prefix,sbh_token,usergraph,sbh_collection_url,"http://identifiers.org/ncit/NCIT:C14419")
new_rows = []
for binding in search_result["results"]["bindings"]:
uri = binding["s"]["value"]
id = binding["id"]["value"]
new_rows.append([id, uri])
expand_table_in_xlsm(wb,sheet_name="SBH_chassis_collections",table_name="SBH_chassis_collections",new_rows=new_rows)
search_result = sbh_get_subCollection_uris(sbh_url,sbh_token,usergraph,sbh_collection_url,"http://identifiers.org/so/SO:0000637")
search_result = sbh_get_subCollection_uris(sbh_url,sbh_prefix,sbh_token,usergraph,sbh_collection_url,"http://identifiers.org/so/SO:0000637")
new_rows = []
for binding in search_result["results"]["bindings"]:
uri = binding["s"]["value"]
id = binding["id"]["value"]
new_rows.append([id, uri])
expand_table_in_xlsm(wb,sheet_name="SBH_plasmids_collections",table_name="SBH_plasmids_collections",new_rows=new_rows)
elif template_type == "synbio.object-type.sample-designs":
search_result = sbh_get_subCollection_uris(sbh_url,sbh_token,usergraph,sbh_collection_url,"http://identifiers.org/ncit/NCIT:C48164")
search_result = sbh_get_subCollection_uris(sbh_url,sbh_prefix,sbh_token,usergraph,sbh_collection_url,"http://identifiers.org/ncit/NCIT:C48164")
new_rows = []
for binding in search_result["results"]["bindings"]:
uri = binding["s"]["value"]
id = binding["id"]["value"]
new_rows.append([id, uri])
expand_table_in_xlsm(wb,sheet_name="SBH_media_collection",table_name="SBH_media_collection",new_rows=new_rows)
search_result = sbh_get_subCollection_uris(sbh_url,sbh_token,usergraph,sbh_collection_url,type="http://www.biopax.org/release/biopax-level3.owl#SmallMolecule")
search_result = sbh_get_subCollection_uris(sbh_url,sbh_prefix,sbh_token,usergraph,sbh_collection_url,type="http://www.biopax.org/release/biopax-level3.owl#SmallMolecule")
new_rows = []
for binding in search_result["results"]["bindings"]:
uri = binding["s"]["value"]
id = binding["id"]["value"]
new_rows.append([id, uri])
expand_table_in_xlsm(wb,sheet_name="SBH_chemicals_collection",table_name="SBH_chemicals_collection",new_rows=new_rows)
search_result = sbh_get_subCollection_uris(sbh_url,sbh_token,usergraph,sbh_collection_url,"http://purl.obolibrary.org/obo/NCIT_C97158")
search_result = sbh_get_subCollection_uris(sbh_url,sbh_prefix,sbh_token,usergraph,sbh_collection_url,"http://purl.obolibrary.org/obo/NCIT_C97158")
new_rows = []
for binding in search_result["results"]["bindings"]:
uri = binding["s"]["value"]
id = binding["id"]["value"]
new_rows.append([id, uri])
expand_table_in_xlsm(wb,sheet_name="SBH_strains_collection",table_name="SBH_strains_collection",new_rows=new_rows)
elif template_type == "synbio.object-type.study-data":
search_result = sbh_get_subCollection_uris(sbh_url,sbh_token,usergraph,sbh_collection_url,"https://wiki.synbiohub.org/wiki/Terms/SynBioSuite#SampleDesign")
search_result = sbh_get_subCollection_uris(sbh_url,sbh_prefix,sbh_token,usergraph,sbh_collection_url,"https://wiki.synbiohub.org/wiki/Terms/SynBioSuite#SampleDesign")
new_rows = []
for binding in search_result["results"]["bindings"]:
uri = binding["s"]["value"]
Expand Down
2 changes: 1 addition & 1 deletion backend/sbs_server/app/synbiohubUpload.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ def upload_to_sbh(doc, sbh_url, sbh_prefix, sbh_token, usergraph, sbh_collection
subCollection = sbol2.Collection(importType)
parts = sbh_collection_url.split("/")
subCollection_url = "/".join(parts[:6]) + "/" + importType + "/1"
search_result = sbh_get_subCollection_uris(sbh_url, sbh_token, usergraph, subCollection_url)
search_result = sbh_get_subCollection_uris(sbh_url, sbh_prefix, sbh_token, usergraph, subCollection_url, recursiveMembers=False)
for binding in search_result["results"]["bindings"]:
uri = binding["s"]["value"]
subCollection.members = subCollection.members + [ uri ]
Expand Down
37 changes: 28 additions & 9 deletions backend/sbs_server/app/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,16 +69,35 @@ def sparql_query(sbh_url, sbh_token, query):
'''
Helper function to perform SPARQL queries to fetch URIs from SynBioHub
'''
def sbh_get_subCollection_uris(sbh_url, sbh_token, usergraph, collectionUri, role = None, type = None):
if role is None and type is None:
query = f'PREFIX sbol: <http://sbols.org/v2#> SELECT ?s ?id FROM <{usergraph}> WHERE {{ <{collectionUri}> sbol:member ?s . ?s sbol:displayId ?id }}'
elif type is None:
query = f'PREFIX sbol: <http://sbols.org/v2#> SELECT ?s ?id FROM <{usergraph}> WHERE {{ ?s sbol:role <{role}> . <{collectionUri}> sbol:member ?s . ?s sbol:displayId ?id }}'
elif role is None:
query = f'PREFIX sbol: <http://sbols.org/v2#> SELECT ?s ?id FROM <{usergraph}> WHERE {{ ?s sbol:type <{type}> . <{collectionUri}> sbol:member ?s . ?s sbol:displayId ?id }}'
def sbh_get_subCollection_uris(sbh_url, sbh_prefix, sbh_token, usergraph, collectionUri,
role = None, type = None, recursiveMembers = True):
conditions = []
publicgraph = sbh_prefix + '/public'
if role is not None:
conditions.append(f'?s sbol:role <{role}> .')
if type is not None:
conditions.append(f'?s sbol:type <{type}> .')

if recursiveMembers:
where_parts = [
f'<{collectionUri}> sbol:member* ?s .',
'FILTER(?s != <' + collectionUri + '>)',
'?s sbol:displayId ?id .'
]
else:
query = f'PREFIX sbol: <http://sbols.org/v2#> SELECT ?s ?id FROM <{usergraph}> WHERE {{ ?s sbol:type <{type}> . ?s sbol:role <{role}> . <{collectionUri}> sbol:member ?s . ?s sbol:displayId ?id }}'

where_parts = [
f'<{collectionUri}> sbol:member ?s .',
'FILTER(?s != <' + collectionUri + '>)',
'?s sbol:displayId ?id .'
]
where_parts.extend(conditions)

query = (
f'PREFIX sbol: <http://sbols.org/v2#> '
f'SELECT DISTINCT ?s ?id FROM <{usergraph}> FROM <{publicgraph}> WHERE {{ '
f'{" ".join(where_parts)}'
f' }}'
)
return sparql_query(sbh_url, sbh_token, query)

def sbh_get_attachment_uri(sbh_url, sbh_token, usergraph, collectionUri, attachmentName):
Expand Down
2 changes: 2 additions & 0 deletions frontend/src/API.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ function capitalizeFirst(str) {

export async function download_template(
sbh_url,
sbh_prefix,
sbh_token,
collectionUrl,
templateType) {
Expand All @@ -21,6 +22,7 @@ export async function download_template(

const paramsObj = {
sbh_url: sbh_url,
sbh_prefix: sbh_prefix,
sbh_token: sbh_token,
collection_url: collectionUrl,
template_type: templateType
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,14 +60,15 @@ export default function DownloadMetadata({ objectType }) {
const selectedRepo = jsonData.registryURL;
const authToken = modalResult.authToken
const registryAPI = dataSBH.find((repo) => repo.registryURL === selectedRepo)?.registryAPI || selectedRepo

const registryPrefix = dataSBH.find((repo) => repo.registryURL === selectedRepo)?.registryPrefix || selectedRepo

if (!collectionUrl || !selectedRepo || !authToken) {
showErrorNotification("Download aborted", "Missing repository, credentials, or collection selection.")
return
}

try {
const response = await download_template(registryAPI,authToken,collectionUrl,objectType?.id);
const response = await download_template(registryAPI,registryPrefix,authToken,collectionUrl,objectType?.id);
const blob = new Blob([response.data], {
type: "application/vnd.ms-excel.sheet.macroEnabled.12"
});
Expand Down
Loading