Skip to content

Commit

Permalink
Raise if allen api human microarray services down
Browse files Browse the repository at this point in the history
  • Loading branch information
AhmetNSimsek committed Dec 20, 2024
1 parent 645cbfe commit e233a8a
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 1 deletion.
7 changes: 6 additions & 1 deletion docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,17 @@
import sphinx_rtd_theme # this import must be kept to make sphinx_rtd_theme function
import sphinx_autopackagesummary # this import must be kept to make autopackagesummary function

print("sphinx-rtd-theme:", sphinx_rtd_theme.__version__)
print("sphinx-autopackagesummary", sphinx_autopackagesummary.__version__)

os.environ['SIIBRA_LOG_LEVEL'] = "ERROR"
sys.path.insert(0, os.path.abspath(".."))
print("Path:", sys.path)


def is_allen_api_microarray_service_available():
import requests

# see https://community.brain-map.org/t/human-brain-atlas-api/2876
microarray_test_url = "http://api.brain-map.org/api/v2/data/query.json?criteria= service::human_microarray_expression[probes$eq1023146,1023147][donors$eq15496][structures$eq9148]"
try:
Expand All @@ -31,6 +35,7 @@ def is_allen_api_microarray_service_available():
return False
return response["success"]


# -- Project information -----------------------------------------------------

project = "siibra-python"
Expand Down
7 changes: 7 additions & 0 deletions examples/03_data_features/000_matchings.py
Original file line number Diff line number Diff line change
Expand Up @@ -138,5 +138,12 @@
# For example, the gene expressions retrieved from the Allen atlas are linked by the coordinate
# For example, the gene expressions retrieved from the Allen atlas are linked by the coordinate
# of their tissue probes in MNI space. If a coordinate is inside the selected brain regions, it is an exact match.
#
# .. warning::
# The service "web API of the Allen Brain Atlas for the human microarray expression"
# is not available at the moment, therefore siibra is not able to fetch
# gene expression features. This is a known issue which we are investigating:
# https://github.com/FZJ-INM1-BDA/siibra-python/issues/636.
#
features = siibra.features.get(v1, siibra.features.molecular.GeneExpressions, gene="TAC1")
print(features[0].last_match_description)
6 changes: 6 additions & 0 deletions examples/03_data_features/004_gene_expressions.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,12 @@
Gene expressions
~~~~~~~~~~~~~~~~
.. warning::
The service "web API of the Allen Brain Atlas for the human microarray expression"
is not available at the moment, therefore siibra is not able to fetch
gene expression features. This is a known issue which we are investigating:
https://github.com/FZJ-INM1-BDA/siibra-python/issues/636.
``siibra`` can query gene expression data from the Allen brain atlas. The gene
expressions are linked to atlas regions by coordinates of their probes in MNI
space. When querying feature by a region, ``siibra`` automatically builds a
Expand Down
19 changes: 19 additions & 0 deletions siibra/livequeries/allen.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,18 @@
LOCATION_PRECISION_MM = 2. # the assumed spatial precision of the probe locations in MNI space


def is_allen_api_microarray_service_available():
import requests

# see https://community.brain-map.org/t/human-brain-atlas-api/2876
microarray_test_url = "http://api.brain-map.org/api/v2/data/query.json?criteria= service::human_microarray_expression[probes$eq1023146,1023147][donors$eq15496][structures$eq9148]"
try:
response = requests.get(microarray_test_url).json()
except requests.RequestException:
return False
return response["success"]


class InvalidAllenAPIResponseException(Exception):
pass

Expand Down Expand Up @@ -124,6 +136,13 @@ def parse_gene(spec):
self.genes = parse_gene(gene)

def query(self, concept: structure.BrainStructure) -> List[GeneExpressions]:
if not is_allen_api_microarray_service_available():
raise InvalidAllenAPIResponseException(
'The service "web API of the Allen Brain Atlas for the human microarray expression" '
'is not available at the moment, therefore siibra is not able to fetch '
'gene expression features. This is a known issue which we are investigating: '
'https://github.com/FZJ-INM1-BDA/siibra-python/issues/636.'
)

mnispace = _space.Space.registry().get('mni152')

Expand Down

0 comments on commit e233a8a

Please sign in to comment.