diff --git a/api/common/data_handlers/compounds/download.py b/api/common/data_handlers/compounds/download.py index 088b9acd..51d0174a 100644 --- a/api/common/data_handlers/compounds/download.py +++ b/api/common/data_handlers/compounds/download.py @@ -64,7 +64,7 @@ def download_all(space_id: str, parcellation_id: str, region_id: str=None, featu try: path_to_feature_export = Path(SIIBRA_API_SHARED_DIR, f"export-{feature_id}.zip") if not path_to_feature_export.exists(): - feature = siibra.features.Feature.get_instance_by_id(feature_id) + feature = siibra.features.Feature._get_instance_by_id(feature_id) feature.export(path_to_feature_export) zipfile.write(path_to_feature_export, f"export-{feature_id}.zip") except Exception as e: diff --git a/api/common/data_handlers/features/types.py b/api/common/data_handlers/features/types.py index 5059a194..4d6e59d9 100644 --- a/api/common/data_handlers/features/types.py +++ b/api/common/data_handlers/features/types.py @@ -40,7 +40,7 @@ def get_single_feature_from_id(feature_id: str, **kwargs): import siibra from api.serialization.util import instance_to_model try: - feature = siibra.features.Feature.get_instance_by_id(feature_id) + feature = siibra.features.Feature._get_instance_by_id(feature_id) except Exception as e: raise NotFound(str(e)) else: @@ -53,7 +53,7 @@ def get_single_feature_plot_from_id(feature_id: str, template="plotly", **kwargs import json try: - feature = siibra.features.Feature.get_instance_by_id(feature_id) + feature = siibra.features.Feature._get_instance_by_id(feature_id) except Exception as e: raise NotFound from e @@ -79,7 +79,7 @@ def get_single_feature_download_zip_path(feature_id: str, **kwargs): return str(full_filename) import siibra try: - feat = siibra.features.Feature.get_instance_by_id(feature_id) + feat = siibra.features.Feature._get_instance_by_id(feature_id) except Exception as e: logger.error(f"Error finding single feature {feature_id=}, {str(e)}") raise NotFound from e diff --git a/api/models/features/_basetypes/feature.py b/api/models/features/_basetypes/feature.py index f6203210..a3848564 100644 --- a/api/models/features/_basetypes/feature.py +++ b/api/models/features/_basetypes/feature.py @@ -20,3 +20,8 @@ class _FeatureModel(ConfigBaseModel, ABC, type="feature"): class FeatureModel(_FeatureModel): """FeatureModel""" pass + + +class CompoundFeatureModel(_FeatureModel, type="compound_feature"): + """CompoundFeatureModel""" + subfeature_keys: List[str] diff --git a/api/serialization/features/_basetypes/feature.py b/api/serialization/features/_basetypes/feature.py index fcb5c082..1f5f7157 100644 --- a/api/serialization/features/_basetypes/feature.py +++ b/api/serialization/features/_basetypes/feature.py @@ -1,6 +1,9 @@ from api.serialization.util.siibra import Feature from api.serialization.util import serialize, instance_to_model from api.models.features._basetypes.feature import FeatureModel +from api.serialization.util.siibra import CompoundFeature +from api.models.features._basetypes.feature import CompoundFeatureModel + @serialize(Feature) def feature_to_model(feat: Feature, detail: bool=False, **kwargs) -> FeatureModel: @@ -22,3 +25,16 @@ def feature_to_model(feat: Feature, detail: bool=False, **kwargs) -> FeatureMode anchor=instance_to_model(feat.anchor, **kwargs) if detail else None, datasets=[instance_to_model(ds, **kwargs) for ds in feat.datasets] ) + + +@serialize(CompoundFeature, pass_super_model=True) +def serialize_cf( + cf: CompoundFeature, + detail=False, + super_model_dict={}, + **kwargs +) -> CompoundFeatureModel: + return CompoundFeatureModel( + **super_model_dict, + indices=cf.indices + ) diff --git a/api/serialization/util/siibra.py b/api/serialization/util/siibra.py index ca6a2c66..798a0de3 100644 --- a/api/serialization/util/siibra.py +++ b/api/serialization/util/siibra.py @@ -19,6 +19,7 @@ from siibra.retrieval.datasets import EbrainsBaseDataset, GenericDataset from siibra.features.feature import Feature +from siibra.features.feature import CompoundFeature from siibra.features.connectivity.regional_connectivity import RegionalConnectivity from siibra.features.tabular.cortical_profile import CorticalProfile from siibra.features.tabular.tabular import Tabular diff --git a/docs/develop.md b/docs/develop.md index 24ea3d5e..e3a2287b 100644 --- a/docs/develop.md +++ b/docs/develop.md @@ -21,6 +21,8 @@ uvicorn api.server:api --host 127.0.0.1 --port 5000 --reload ``` ## With docker-compose +0) Delete if there is a siibra-api docker image. +1) Change the siibra requirement by chosing the new tag or install from a branch git+https://github.com/FZJ-INM1-BDA/siibra-python.git@BranchName ```sh docker-compose -f ./docker-compose-dev.yml up ``` diff --git a/requirements/siibra.txt b/requirements/siibra.txt index 818126a8..a260f1ee 100644 --- a/requirements/siibra.txt +++ b/requirements/siibra.txt @@ -1,2 +1,2 @@ -siibra==0.4a74 +git+https://github.com/FZJ-INM1-BDA/siibra-python.git@feat_compoundFeat plotly