Science Score: 44.0%
This score indicates how likely this project is to be science-related based on various indicators:
-
✓CITATION.cff file
Found CITATION.cff file -
✓codemeta.json file
Found codemeta.json file -
✓.zenodo.json file
Found .zenodo.json file -
○DOI references
-
○Academic publication links
-
○Academic email domains
-
○Institutional organization owner
-
○JOSS paper metadata
-
○Scientific vocabulary similarity
Low similarity (12.7%) to scientific vocabulary
Repository
Basic Info
- Host: GitHub
- Owner: neurobagel
- License: mit
- Language: Python
- Default Branch: main
- Homepage: https://api.neurobagel.org/
- Size: 868 KB
Statistics
- Stars: 4
- Watchers: 3
- Forks: 5
- Open Issues: 18
- Releases: 17
Metadata Files
README.md
The Neurobagel API is a REST API, developed in Python using FastAPI and Pydantic.
Please refer to our official documentation for more information on how to use the API.
Quickstart
The API is hosted at https://api.neurobagel.org/ and interfaces with Neurobagel's graph database. Queries of the graph can be run using the /query route.
Example: I want to query for only female participants in the graph.
The URL for such a query would be https://api.neurobagel.org/query?sex=snomed:248152002, where snomed:248152002 is a controlled term from the SNOMED CT database corresponding to female sex.
Interactive documentation for the API is available at https://api.neurobagel.org/docs.
Local installation
The below instructions assume that you have a local instance of or access to a remotely hosted graph database to be queried. If this is not the case and you need to first build a graph from data, refer to our documentation for getting started locally with a graph backend.
Clone the repo
bash
git clone https://github.com/neurobagel/api.git
Set the environment variables
Create a file called .env in the root of the repository to store the environment variables used by the app.
See the Neurobagel recipes repo for a template .env file you can copy and edit.
To run API requests against a graph, at least two environment variables must be set: NB_GRAPH_USERNAME and NB_GRAPH_PASSWORD.
See our official documentation for all the possible Neurobagel environment variables that you can set in .env, and to check which variables are relevant for your specific installation and setup.
:warning: Important: - Variables set in the shell environment where the API is launched should not be used as a replacement for the
.envfile to configure options for the API or graph server software. - To avoid conflicts related to Docker's environment variable precedence, also ensure that any variables defined in your.envare not already set in your current shell environment with different values.
The below instructions for Docker and Python assume that you have at least set NB_GRAPH_USERNAME and NB_GRAPH_PASSWORD in your .env.
Docker
First, install Docker.
You can then run a Docker container for the API in one of three ways:
Option 1 (RECOMMENDED): Use the Neurobagel Docker Compose recipe
Follow the instructions in our official documentation for using the template configuration files provided in our recipes repository to spin up a local Neurobagel API and graph backend using Docker Compose.
TIP: Double check that Neurobagel environment variables are resolved with your expected values using the command docker compose config.
Option 2: Use the latest image from Docker Hub
bash
docker pull neurobagel/api
docker run -d --name=api -p 8000:8000 --env-file=.env neurobagel/api
NOTE: The above docker run command uses recommended default values for NBI_API_PORT_HOST and NB_API_PORT in the -p flag.
If you wish to set different port numbers, modify your .env file accordingly and run the below commands instead:
bash
export $(cat .env | xargs) # export your .env file to expose your set port numbers to the -p flag of docker run
docker run -d --name=api -p ${NB_API_PORT_HOST}:${NB_API_PORT} --env-file=.env neurobagel/api
:warning: IMPORTANT: If using the above command, do not wrap any values for variables in the
.envfile in quotation marks, as they will be interpreted literally and may lead to issues.
Option 3: Build the image using the Dockerfile
After cloning the current repository, build the Docker image locally:
bash
docker build -t neurobagel/api .
docker run -d --name=api -p 8000:8000 --env-file=.env neurobagel/api
NOTE: The above docker run command uses recommended default values for NBI_API_PORT_HOST and NB_API_PORT in the -p flag.
If you wish to set different port numbers, modify your .env file accordingly and run the below commands instead:
bash
docker build -t neurobagel/api .
export $(cat .env | xargs) # export your .env file to expose your set port numbers to the -p flag of docker run
docker run -d --name=api -p ${NB_API_PORT_HOST}:${NB_API_PORT} --env-file=.env neurobagel/api
:warning: IMPORTANT: If using the above command, do not wrap any values for variables in the
.envfile in quotation marks, as they will be interpreted literally and may lead to issues.
Send a test query to the API
By default, after running the above steps, the API should be served at localhost, http://127.0.0.1:8000/query, on the machine where you launched the Dockerized app. To check that the API is running and can access the knowledge graph as expected, you can navigate to the interactive API docs in your local browser (http://127.0.0.1:8000/docs) and enter a sample query, or send an HTTP request in your terminal using curl:
``` bash
example: query for female subjects in graph
curl http://127.0.0.1:8000/query?sex=snomed:248152002 ``` The response should be a list of dictionaries containing info about datasets with participants matching the query.
Python
Install dependencies
After cloning the repository, install the dependencies outlined in the requirements.txt file. For convenience, you can use Python's venv package to install dependencies in a virtual environment. You can find the instructions on creating and activating a virtual environment in the official documentation. After setting up and activating your environment, you can install the dependencies by running the following command in your terminal:
bash
$ pip install -r requirements.txt
Launch the API
To launch the API make sure you're in repository's main directory and in your environment where the dependencies are installed and environment variables are set.
Export the variables defined in your .env file:
bash
export $(cat .env | xargs)
You can then launch the API by running the following command in your terminal:
bash
$ python -m app.main
bash
INFO: Will watch for changes in these directories: ['home/usr/directory/']
INFO: Uvicorn running on http://127.0.0.1:8000 (Press CTRL+C to quit)
INFO: Started reloader process [12683] using StatReload
INFO: Started server process [12685]
INFO: Waiting for application startup.
INFO: Application startup complete.
...
You can verify the API is running once you receive info messages similar to the above in your terminal.
Troubleshooting
If you get a 401 response to your API request with an "Unauthorized: " error message, your NB_GRAPH_USERNAME and NB_GRAPH_PASSWORD pair may be incorrect. Verify that these environment variables have been exported and/or have the correct values.
Testing
Neurobagel API utilizes Pytest framework for testing.
To run the tests, first ensure you're in the repository's root directory and in the environment where the dependencies are installed.
Install the submodules used by the tests:
bash
git submodule init
git submodule update
You can then run the tests by executing the following command in your terminal:
bash
pytest tests
To run the integration tests of SPARQL queries (skipped by default), also launch the test graph store:
bash
docker compose up -d test_graph
NOTE: Don't have a .env file in the root directory as it will conflict with the environment variable configuration of the docker compose file,
since docker compose will try to use .env by default.
Then, run all tests using: ```bash pytest -m "integration or not integration"
OR
pytest -m "" ```
Or, to run only the integration tests:
bash
pytest -m "integration"
Once you are done with testing, you can stop and remove the test graph container:
bash
docker compose stop test_graph
docker compose rm -f test_graph
The default Neurobagel SPARQL query
docs/default_neurobagel_query.rq contains a sample default SPARQL query sent by the Neurobagel API to a graph database to retrieve all available phenotypic and imaging data.
This file is mainly intended for reference because in normal operations,
the API will always talk to the graph on behalf of the user.
(For developers) To regenerate this sample query when the API query template is updated, run the following commands from the repository root in an interactive Python terminal:
```python from app.api.utility import create_query
with open("docs/defaultneurobagelquery.rq", "w") as file: file.write(createquery(returnagg=False)) ```
License
Neurobagel API is released under the terms of the MIT License
Owner
- Name: Neurobagel
- Login: neurobagel
- Kind: organization
- Repositories: 7
- Profile: https://github.com/neurobagel
Citation (CITATION.cff)
# doc: https://citation-file-format.github.io/
# schema: https://github.com/citation-file-format/citation-file-format/blob/main/schema-guide.md
cff-version: 1.2.0
title: "neurobagel_api"
version: 0.2.0
abstract: "The Neurobagel API is a REST API, developed in [Python](https://www.python.org/) using [FastAPI](https://fastapi.tiangolo.com/) and [pydantic](https://docs.pydantic.dev/)."
message: "If you use this software, please cite it as below."
repository-code: "https://github.com/neurobagel/api.git"
contact:
- affiliation: "ORIGAMI lab, McGill University, Montréal, Canada"
family-names: Urchs
given-names: Sebastian
authors:
- affiliation: "ORIGAMI lab, McGill University, Montréal, Canada"
family-names: Urchs
given-names: Sebastian
orcid: "https://orcid.org/0000-0001-5504-8579"
- affiliation: "ORIGAMI lab, McGill University, Montréal, Canada"
family-names: Dai
given-names: Alyssa
orcid: "https://orcid.org/0000-0003-0174-6800"
- affiliation: "ORIGAMI lab, McGill University, Montréal, Canada"
family-names: Armoza
given-names: Jonathan
orcid: "https://orcid.org/0000-0002-7193-9344"
- affiliation: "ORIGAMI lab, McGill University, Montréal, Canada"
family-names: Jahanpour
given-names: Arman
- affiliation: "ORIGAMI lab, McGill University, Montréal, Canada"
email: nikhil.bhagwat@mcgill.ca
family-names: Bhagwat
given-names: Nikhil
orcid: "https://orcid.org/0000-0001-6073-7141"
- affiliation: "ORIGAMI lab, McGill University, Montréal, Canada"
family-names: Poline
given-names: Jean-Baptiste
orcid: "https://orcid.org/0000-0002-9794-749X"
license: MIT
GitHub Events
Total
- Create event: 87
- Release event: 10
- Issues event: 33
- Delete event: 70
- Issue comment event: 180
- Push event: 172
- Pull request review comment event: 86
- Pull request event: 156
- Pull request review event: 140
- Fork event: 2
Last Year
- Create event: 87
- Release event: 10
- Issues event: 33
- Delete event: 70
- Issue comment event: 180
- Push event: 172
- Pull request review comment event: 86
- Pull request event: 156
- Pull request review event: 140
- Fork event: 2
Issues and Pull Requests
Last synced: 6 months ago
All Time
- Total issues: 56
- Total pull requests: 145
- Average time to close issues: about 2 months
- Average time to close pull requests: 6 days
- Total issue authors: 4
- Total pull request authors: 8
- Average comments per issue: 0.64
- Average comments per pull request: 1.04
- Merged pull requests: 109
- Bot issues: 1
- Bot pull requests: 77
Past Year
- Issues: 20
- Pull requests: 86
- Average time to close issues: 11 days
- Average time to close pull requests: 4 days
- Issue authors: 4
- Pull request authors: 7
- Average comments per issue: 0.3
- Average comments per pull request: 1.03
- Merged pull requests: 61
- Bot issues: 1
- Bot pull requests: 58
Top Authors
Issue Authors
- alyssadai (42)
- rmanaem (7)
- surchs (6)
- dependabot[bot] (1)
Pull Request Authors
- dependabot[bot] (50)
- alyssadai (38)
- surchs (24)
- pre-commit-ci[bot] (19)
- neurobagel-bot[bot] (9)
- rmanaem (6)
- samadpls (4)
- KhushiRajurkar (1)