Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[ENH] Add API response examples and code to generate them #32

Merged
merged 3 commits into from
Aug 22, 2024
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
14 changes: 14 additions & 0 deletions api-responses/fapi_query_fail_207.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
"errors": [
{
"node_name": "2 OpenNeuro Datasets",
"error": "Request failed due to a network error or because the node API could not be reached: [Errno -3] Temporary failure in name resolution"
},
{
"node_name": "BIDS Synthetic",
"error": "Request failed due to a network error or because the node API could not be reached: [Errno -2] Name or service not known"
}
],
"responses": [],
"nodes_response_status": "fail"
}
41 changes: 41 additions & 0 deletions api-responses/fapi_query_partial_success_207.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
{
"errors": [
{
"node_name": "BIDS Synthetic",
"error": "Request failed due to a network error or because the node API could not be reached: [Errno -2] Name or service not known"
}
],
"responses": [
{
"node_name": "2 OpenNeuro Datasets",
"dataset_uuid": "http://neurobagel.org/vocab/1c9a29d8-9ce7-4bb6-9c44-f33ac504bcb4",
"dataset_name": "Balloon Analog Risk-taking Task",
"dataset_portal_uri": "https://github.com/OpenNeuroDatasets-JSONLD/ds000001.git",
"dataset_total_subjects": 16,
"records_protected": true,
"num_matching_subjects": 10,
"subject_data": "protected",
"image_modals": [
"http://purl.org/nidash/nidm#T2Weighted",
"http://purl.org/nidash/nidm#T1Weighted",
"http://purl.org/nidash/nidm#FlowWeighted"
]
},
{
"node_name": "2 OpenNeuro Datasets",
"dataset_uuid": "http://neurobagel.org/vocab/c7bb6a5b-4066-4a59-b56c-3c6fe4d44b90",
"dataset_name": "Classification learning",
"dataset_portal_uri": "https://github.com/OpenNeuroDatasets-JSONLD/ds000002.git",
"dataset_total_subjects": 17,
"records_protected": true,
"num_matching_subjects": 10,
"subject_data": "protected",
"image_modals": [
"http://purl.org/nidash/nidm#T2Weighted",
"http://purl.org/nidash/nidm#T1Weighted",
"http://purl.org/nidash/nidm#FlowWeighted"
]
}
],
"nodes_response_status": "partial success"
}
218 changes: 218 additions & 0 deletions api-responses/fapi_query_success_200.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,218 @@
{
"errors": [],
"responses": [
{
"node_name": "2 OpenNeuro Datasets",
"dataset_uuid": "http://neurobagel.org/vocab/1c9a29d8-9ce7-4bb6-9c44-f33ac504bcb4",
"dataset_name": "Balloon Analog Risk-taking Task",
"dataset_portal_uri": "https://github.com/OpenNeuroDatasets-JSONLD/ds000001.git",
"dataset_total_subjects": 16,
"records_protected": true,
"num_matching_subjects": 10,
"subject_data": "protected",
"image_modals": [
"http://purl.org/nidash/nidm#T2Weighted",
"http://purl.org/nidash/nidm#T1Weighted",
"http://purl.org/nidash/nidm#FlowWeighted"
]
},
{
"node_name": "2 OpenNeuro Datasets",
"dataset_uuid": "http://neurobagel.org/vocab/c7bb6a5b-4066-4a59-b56c-3c6fe4d44b90",
"dataset_name": "Classification learning",
"dataset_portal_uri": "https://github.com/OpenNeuroDatasets-JSONLD/ds000002.git",
"dataset_total_subjects": 17,
"records_protected": true,
"num_matching_subjects": 10,
"subject_data": "protected",
"image_modals": [
"http://purl.org/nidash/nidm#T2Weighted",
"http://purl.org/nidash/nidm#T1Weighted",
"http://purl.org/nidash/nidm#FlowWeighted"
]
},
{
"node_name": "BIDS Synthetic",
"dataset_uuid": "http://neurobagel.org/vocab/e0c7d08c-edcc-4c2a-816a-306878ed7be2",
"dataset_name": "BIDS synthetic",
"dataset_portal_uri": "https://github.com/bids-standard/bids-examples",
"dataset_total_subjects": 5,
"records_protected": false,
"num_matching_subjects": 2,
"subject_data": [
{
"sub_id": "sub-01",
"session_id": "ses-01",
"num_matching_phenotypic_sessions": 2,
"num_matching_imaging_sessions": 2,
"session_type": "http://neurobagel.org/vocab/ImagingSession",
"age": null,
"sex": null,
"diagnosis": [
null
],
"subject_group": null,
"assessment": [
null
],
"image_modal": [
"http://purl.org/nidash/nidm#T1Weighted",
"http://purl.org/nidash/nidm#FlowWeighted"
],
"session_file_path": "/data/neurobagel/bagel-cli/bids-examples/synthetic/sub-01/ses-01"
},
{
"sub_id": "sub-01",
"session_id": "ses-01",
"num_matching_phenotypic_sessions": 2,
"num_matching_imaging_sessions": 2,
"session_type": "http://neurobagel.org/vocab/PhenotypicSession",
"age": 34.1,
"sex": "http://purl.bioontology.org/ontology/SNOMEDCT/248152002",
"diagnosis": [
null
],
"subject_group": "http://ncicb.nci.nih.gov/xml/owl/EVS/Thesaurus.owl#C94342",
"assessment": [
"https://www.cognitiveatlas.org/task/id/trm_57964b8a66aed",
"https://www.cognitiveatlas.org/task/id/tsk_4a57abb949ece"
],
"image_modal": [
null
],
"session_file_path": null
},
{
"sub_id": "sub-01",
"session_id": "ses-02",
"num_matching_phenotypic_sessions": 2,
"num_matching_imaging_sessions": 2,
"session_type": "http://neurobagel.org/vocab/ImagingSession",
"age": null,
"sex": null,
"diagnosis": [
null
],
"subject_group": null,
"assessment": [
null
],
"image_modal": [
"http://purl.org/nidash/nidm#T1Weighted",
"http://purl.org/nidash/nidm#FlowWeighted"
],
"session_file_path": "/data/neurobagel/bagel-cli/bids-examples/synthetic/sub-01/ses-02"
},
{
"sub_id": "sub-01",
"session_id": "ses-02",
"num_matching_phenotypic_sessions": 2,
"num_matching_imaging_sessions": 2,
"session_type": "http://neurobagel.org/vocab/PhenotypicSession",
"age": 35.3,
"sex": "http://purl.bioontology.org/ontology/SNOMEDCT/248152002",
"diagnosis": [
null
],
"subject_group": "http://ncicb.nci.nih.gov/xml/owl/EVS/Thesaurus.owl#C94342",
"assessment": [
"https://www.cognitiveatlas.org/task/id/trm_57964b8a66aed",
"https://www.cognitiveatlas.org/task/id/tsk_4a57abb949ece"
],
"image_modal": [
null
],
"session_file_path": null
},
{
"sub_id": "sub-04",
"session_id": "ses-01",
"num_matching_phenotypic_sessions": 2,
"num_matching_imaging_sessions": 2,
"session_type": "http://neurobagel.org/vocab/ImagingSession",
"age": null,
"sex": null,
"diagnosis": [
null
],
"subject_group": null,
"assessment": [
null
],
"image_modal": [
"http://purl.org/nidash/nidm#T1Weighted",
"http://purl.org/nidash/nidm#FlowWeighted"
],
"session_file_path": "/data/neurobagel/bagel-cli/bids-examples/synthetic/sub-04/ses-01"
},
{
"sub_id": "sub-04",
"session_id": "ses-01",
"num_matching_phenotypic_sessions": 2,
"num_matching_imaging_sessions": 2,
"session_type": "http://neurobagel.org/vocab/PhenotypicSession",
"age": 21.1,
"sex": "http://purl.bioontology.org/ontology/SNOMEDCT/248152002",
"diagnosis": [
null
],
"subject_group": "http://ncicb.nci.nih.gov/xml/owl/EVS/Thesaurus.owl#C94342",
"assessment": [
"https://www.cognitiveatlas.org/task/id/tsk_4a57abb949ece"
],
"image_modal": [
null
],
"session_file_path": null
},
{
"sub_id": "sub-04",
"session_id": "ses-02",
"num_matching_phenotypic_sessions": 2,
"num_matching_imaging_sessions": 2,
"session_type": "http://neurobagel.org/vocab/ImagingSession",
"age": null,
"sex": null,
"diagnosis": [
null
],
"subject_group": null,
"assessment": [
null
],
"image_modal": [
"http://purl.org/nidash/nidm#T1Weighted",
"http://purl.org/nidash/nidm#FlowWeighted"
],
"session_file_path": "/data/neurobagel/bagel-cli/bids-examples/synthetic/sub-04/ses-02"
},
{
"sub_id": "sub-04",
"session_id": "ses-02",
"num_matching_phenotypic_sessions": 2,
"num_matching_imaging_sessions": 2,
"session_type": "http://neurobagel.org/vocab/PhenotypicSession",
"age": 22.3,
"sex": "http://purl.bioontology.org/ontology/SNOMEDCT/248152002",
"diagnosis": [
null
],
"subject_group": "http://ncicb.nci.nih.gov/xml/owl/EVS/Thesaurus.owl#C94342",
"assessment": [
"https://www.cognitiveatlas.org/task/id/trm_57964b8a66aed",
"https://www.cognitiveatlas.org/task/id/tsk_4a57abb949ece"
],
"image_modal": [
null
],
"session_file_path": null
}
],
"image_modals": [
"http://purl.org/nidash/nidm#T1Weighted",
"http://purl.org/nidash/nidm#FlowWeighted"
]
}
],
"nodes_response_status": "success"
}
66 changes: 66 additions & 0 deletions api-responses/make_api_responses.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
# The following script sets up two test nodes,
# Test node 1: 2 OpenNeuro datasets, in the aggregate results mode
# Test node 2: the (default) BIDS Synthetic dataset, in the unaggregated results mode
#
# A full_stack deployment recipe will be used for Test node 1 to provide local federation.

mkdir test_node1 test_node2 api-responses

# SETUP FOR TEST NODE 1
git clone https://github.com/neurobagel/recipes.git test_node1/recipes

# Get the data
git clone https://github.com/neurobagel/openneuro-annotations.git test_node1/openneuro-annotations
mkdir test_node1/openneuro_mini_data
cp test_node1/openneuro-annotations/ds000001.jsonld test_node1/recipes/ds000002.jsonld test_node1/openneuro_mini_data

cd test_node1/recipes
cp template.env .env

sed -i 's/^LOCAL_GRAPH_DATA=.*/LOCAL_GRAPH_DATA=../openneuro_mini_data/' .env
sed -i 's/^NB_FEDERATE_REMOTE_PUBLIC_NODES=.*/NB_FEDERATE_REMOTE_PUBLIC_NODES=False/' .env
sed -i 's/^NB_API_QUERY_URL=.*/NB_API_QUERY_URL=http://localhost:8080/' .env
sed -i 's/^COMPOSE_PROFILES=.*/COMPOSE_PROFILES=full_stack/' .env

# Use full container names to avoid conflicts
echo '[{"NodeName": "2 OpenNeuro Datasets", "ApiURL": "http://neurobagel_node-api-1:8000"},{"NodeName": "BIDS Synthetic", "ApiURL": "http://neurobagel_node2-api-1:8000"}]' > local_nb_nodes.json
alyssadai marked this conversation as resolved.
Show resolved Hide resolved

# Generate a partial success result (since Test node 2 isn't up yet)
docker compose up -d

# WAIT FOR GRAPH TO FINISH BEING SET UP (?)
while ! curl --silent "localhost:7200/rest/repositories" -u "DBUSER:DBPASSWORD" | grep '\['; do
:
done

# Query for female sex in f-API
curl -s http://localhost:8080/query?sex=snomed:248152002 | jq . > api-responses/fapi_query_partial_success_207.json

# Generate a fail result (both nodes are not accessible)
docker stop neurobagel_node-api-1
curl -s http://localhost:8080/query?sex=snomed:248152002 | jq . > api-responses/fapi_query_fail_207.json

cd ../..

# SETUP FOR TEST NODE 2
git clone https://github.com/neurobagel/recipes.git test_node2/recipes
cd test_node2/recipes
cp template.env .env

sed -i 's/^COMPOSE_PROJECT_NAME=.*/COMPOSE_PROJECT_NAME=neurobagel_node2/' .env
sed -i 's/^NB_GRAPH_PORT_HOST=.*/NB_GRAPH_PORT_HOST=7201/' .env
sed -i 's/^NB_NAPI_PORT_HOST=.*/NB_NAPI_PORT_HOST=8001/' .env

# Generate a full success result (both nodes are running and accessible)
# First, restart n-API for test node 1
docker start neurobagel_node-api-1
docker compose up -d
# Add second n-API to the network of the first node, so that the f-API can access the second n-API by container name
docker network add neurobagel_node_default neurobagel_node2-api-1
curl -s http://localhost:8080/query?sex=snomed:248152002 | jq . > api-responses/fapi_query_success_207.json


# Generate query response where results are protected (test node 1)
curl -s http://localhost:8000/query?sex=snomed:248152002 | jq . > api-responses/napi_query_aggregated_results.json
# Generate query response where results are open (test node 2)
curl -s http://localhost:8001/query?sex=snomed:248152002 | jq . > api-responses/napi_query_unaggregated_results.json
30 changes: 30 additions & 0 deletions api-responses/napi_query_aggregated_results.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
[
{
"dataset_uuid": "http://neurobagel.org/vocab/1c9a29d8-9ce7-4bb6-9c44-f33ac504bcb4",
"dataset_name": "Balloon Analog Risk-taking Task",
"dataset_portal_uri": "https://github.com/OpenNeuroDatasets-JSONLD/ds000001.git",
"dataset_total_subjects": 16,
"records_protected": true,
"num_matching_subjects": 10,
"subject_data": "protected",
"image_modals": [
"http://purl.org/nidash/nidm#T2Weighted",
"http://purl.org/nidash/nidm#T1Weighted",
"http://purl.org/nidash/nidm#FlowWeighted"
]
},
{
"dataset_uuid": "http://neurobagel.org/vocab/c7bb6a5b-4066-4a59-b56c-3c6fe4d44b90",
"dataset_name": "Classification learning",
"dataset_portal_uri": "https://github.com/OpenNeuroDatasets-JSONLD/ds000002.git",
"dataset_total_subjects": 17,
"records_protected": true,
"num_matching_subjects": 10,
"subject_data": "protected",
"image_modals": [
"http://purl.org/nidash/nidm#T2Weighted",
"http://purl.org/nidash/nidm#T1Weighted",
"http://purl.org/nidash/nidm#FlowWeighted"
]
}
]
Loading