Skip to content

Commit

Permalink
Merge pull request #192 from FZJ-INM1-BDA/bugfix_cellsGenes
Browse files Browse the repository at this point in the history
bugfix: cortical cell distribution name/feat: add structure attr to gene exp
  • Loading branch information
xgui3783 authored May 25, 2022
2 parents 6352654 + 7700da3 commit d474e11
Show file tree
Hide file tree
Showing 6 changed files with 62 additions and 14 deletions.
13 changes: 5 additions & 8 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,14 +1,11 @@
numpy
requests
nibabel
anytree
nibabel
appdirs
scikit-image
click
neuroglancer-scripts
requests
memoization
neuroglancer-scripts
nilearn
simple-term-menu
pandas
importlib-resources; python_version < "3.7"
typing-extensions; python_version < "3.8"
pydantic==1.8.2
fpdf
1 change: 1 addition & 0 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ def find_version():
"neuroglancer-scripts",
"nilearn",
'importlib-resources; python_version < "3.7"',
'typing-extensions; python_version < "3.8"',
"pydantic==1.8.2",
],
)
4 changes: 4 additions & 0 deletions siibra/features/cells.py
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,10 @@ def imgdecoder(b):
break
return result

@property
def name(self):
return f"Cortical cell distribution for {self.info.get('brain_area')}"

@property
def info(self):
return self._info_loader.data
Expand Down
37 changes: 31 additions & 6 deletions siibra/features/genes.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
# See the License for the specific language governing permissions and
# limitations under the License.

from typing import Dict, List
from .feature import SpatialFeature
from .query import FeatureQuery

Expand All @@ -25,10 +26,28 @@
import numpy as np
import json
import siibra
try:
# python 3.8+
from typing import TypedDict
except ImportError:
# python 3.7 and below
from typing_extensions import TypedDict


BASE_URL = "http://api.brain-map.org/api/v2/data"

class DonorDict(TypedDict):
id: int
name: str
race: str
age: int
gender: str

class SampleStructure(TypedDict):
id: int
name: str
abbreviation: str
color: str

class GeneExpression(SpatialFeature):
"""
Expand All @@ -37,13 +56,15 @@ class GeneExpression(SpatialFeature):

def __init__(
self,
gene,
gene: str,
location: Point,
expression_levels,
z_scores,
probe_ids,
donor_info,
mri_coord=None,
expression_levels: List[float],
z_scores: List[float],
probe_ids: List[int],
donor_info: DonorDict,
mri_coord: List[int]=None,
structure: SampleStructure=None,
top_level_structure: SampleStructure=None,
):
"""
Construct the spatial feature for gene expressions measured in a sample.
Expand Down Expand Up @@ -72,6 +93,8 @@ def __init__(
self.gene = gene
self.probe_ids = probe_ids
self.mri_coord = mri_coord
self.structure = structure
self.top_level_structure = top_level_structure

def __repr__(self):
return " ".join(
Expand Down Expand Up @@ -263,6 +286,8 @@ def _retrieve_microarray(self, donor_id, probe_ids):
probe_ids=[p["id"] for p in probes],
donor_info={**self.factors[donor["id"]], **donor},
mri_coord=sample["sample"]["mri"],
structure=sample['structure'],
top_level_structure=sample['top_level_structure'],
)
)

Expand Down
1 change: 1 addition & 0 deletions test/features/test_cells.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ def test_to_model(self):
feature = features[0]
model = feature.to_model(detail=False)
assert isinstance(model, CorticalCellDistributionModel)
assert getattr(model.metadata, 'short_name') is not None and model.metadata.short_name != ""


if __name__ == "__main__":
Expand Down
20 changes: 20 additions & 0 deletions test/features/test_genes.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import pytest
import siibra
from siibra.features.genes import GeneExpression

test_params = [
("hoc1 left", "MAOA")
]

@pytest.mark.parametrize("region_spec,gene", test_params)
def test_genes(region_spec:str, gene: str):
parc = siibra.parcellations['2.9']
region = parc.decode_region(region_spec)
features = siibra.get_features(region, "gene", gene=gene)
assert len(features) > 0, f"expecting at least 1 gene feature"
assert all([
isinstance(f, GeneExpression) for f in features
]), f"expecting all features to be of type GeneExpression"
assert all([
hasattr(f, 'structure') and hasattr(f, "top_level_structure") for f in features
]), f"expecting all features to have structure and top_level_structure attributes"

0 comments on commit d474e11

Please sign in to comment.