diff --git a/bluepyemodel/access_point/forge_access_point.py b/bluepyemodel/access_point/forge_access_point.py index f0e5875b..ff26f790 100644 --- a/bluepyemodel/access_point/forge_access_point.py +++ b/bluepyemodel/access_point/forge_access_point.py @@ -895,14 +895,16 @@ def filter_resources(self, resources, filter): ) -def ontology_forge_access_point(access_token=None, forge_path=None): +def ontology_forge_access_point( + access_token=None, forge_path=None, endpoint="https://bbp.epfl.ch/nexus/v1" +): """Returns an access point targeting the project containing the ontology for the species and brain regions""" access_point = NexusForgeAccessPoint( project="datamodels", organisation="neurosciencegraph", - endpoint="https://bbp.epfl.ch/nexus/v1", + endpoint=endpoint, forge_path=forge_path, access_token=access_token, ) @@ -955,7 +957,14 @@ def raise_not_found_exception(base_text, label, access_point, filter, limit=30): raise AccessPointException(base_text) -def check_resource(label, category, access_point=None, access_token=None, forge_path=None): +def check_resource( + label, + category, + access_point=None, + access_token=None, + forge_path=None, + endpoint="https://bbp.epfl.ch/nexus/v1", +): """Checks that resource is present on nexus and is part of the provided category Arguments: @@ -963,13 +972,14 @@ def check_resource(label, category, access_point=None, access_token=None, forge_ category (str): can be "etype", "mtype" or "ttype" access_point (str): ontology_forge_access_point(access_token) forge_path (str): path to a .yml used as configuration by nexus-forge. + endpoint (str): nexus endpoint """ allowed_categories = ["etype", "mtype", "ttype"] if category not in allowed_categories: raise AccessPointException(f"Category is {category}, but should be in {allowed_categories}") if access_point is None: - access_point = ontology_forge_access_point(access_token, forge_path) + access_point = ontology_forge_access_point(access_token, forge_path, endpoint) resource = access_point.resolve(label, strategy="exact") # raise Exception if resource was not found @@ -1017,7 +1027,9 @@ def get_available_traces(species=None, brain_region=None, access_token=None, for return resources -def get_brain_region(brain_region, access_token=None, forge_path=None): +def get_brain_region( + brain_region, access_token=None, forge_path=None, endpoint="https://bbp.epfl.ch/nexus/v1" +): """Returns the resource corresponding to the brain region If the brain region name is not present in nexus, @@ -1027,10 +1039,11 @@ def get_brain_region(brain_region, access_token=None, forge_path=None): brain_region (str): name of the brain region to search for access_token (str): nexus connection token forge_path (str): path to a .yml used as configuration by nexus-forge. + endpoint (str): nexus endpoint """ filter = "brain_region" - access_point = ontology_forge_access_point(access_token, forge_path) + access_point = ontology_forge_access_point(access_token, forge_path, endpoint) if brain_region in ["SSCX", "sscx"]: brain_region = "somatosensory areas" @@ -1062,20 +1075,23 @@ def get_brain_region(brain_region, access_token=None, forge_path=None): return resource -def get_brain_region_dict(brain_region, access_token=None, forge_path=None): +def get_brain_region_dict( + brain_region, access_token=None, forge_path=None, endpoint="https://bbp.epfl.ch/nexus/v1" +): """Returns a dict with id and label of the resource corresponding to the brain region Arguments: brain_region (str): name of the brain region to search for access_token (str): nexus connection token forge_path (str): path to a .yml used as configuration by nexus-forge. + endpoint (str): nexus endpoint Returns: dict: the id and label of the nexus resource of the brain region """ - br_resource = get_brain_region(brain_region, access_token, forge_path) + br_resource = get_brain_region(brain_region, access_token, forge_path, endpoint) - access_point = ontology_forge_access_point(access_token, forge_path) + access_point = ontology_forge_access_point(access_token, forge_path, endpoint) # if no exception was raised, filter to get id and label and return them brain_region_dict = access_point.forge.as_json(br_resource) @@ -1085,25 +1101,29 @@ def get_brain_region_dict(brain_region, access_token=None, forge_path=None): } -def get_brain_region_notation(brain_region, access_token=None, forge_path=None): +def get_brain_region_notation( + brain_region, access_token=None, forge_path=None, endpoint="https://bbp.epfl.ch/nexus/v1" +): """Get the ontology of the brain location.""" if brain_region is None: return None brain_region_resource = get_brain_region( - brain_region, access_token=access_token, forge_path=forge_path + brain_region, access_token=access_token, forge_path=forge_path, endpoint=endpoint ) return brain_region_resource.notation -def get_nexus_brain_region(brain_region, access_token=None, forge_path=None): +def get_nexus_brain_region( + brain_region, access_token=None, forge_path=None, endpoint="https://bbp.epfl.ch/nexus/v1" +): """Get the ontology of the brain location.""" if brain_region is None: return None brain_region_from_nexus = get_brain_region_dict( - brain_region, access_token=access_token, forge_path=forge_path + brain_region, access_token=access_token, forge_path=forge_path, endpoint=endpoint ) return { @@ -1112,8 +1132,8 @@ def get_nexus_brain_region(brain_region, access_token=None, forge_path=None): } -def get_all_species(access_token=None, forge_path=None): - access_point = ontology_forge_access_point(access_token, forge_path) +def get_all_species(access_token=None, forge_path=None, endpoint="https://bbp.epfl.ch/nexus/v1"): + access_point = ontology_forge_access_point(access_token, forge_path, endpoint) resources = access_point.forge.search({"subClassOf": "nsg:Species"}, limit=100) diff --git a/bluepyemodel/access_point/nexus.py b/bluepyemodel/access_point/nexus.py index d184ec55..b5494aeb 100755 --- a/bluepyemodel/access_point/nexus.py +++ b/bluepyemodel/access_point/nexus.py @@ -129,6 +129,7 @@ def __init__( self.emodel_metadata.brain_region, self.access_point.access_token, self.forge_ontology_path, + self.access_point.endpoint, ) self.pipeline_settings = self.get_pipeline_settings(strict=False) @@ -145,7 +146,7 @@ def download_directory(self): def check_mettypes(self): """Check that etype, mtype and ttype are present on nexus""" ontology_access_point = ontology_forge_access_point( - self.access_point.access_token, self.forge_ontology_path + self.access_point.access_token, self.forge_ontology_path, self.access_point.endpoint ) logger.info("Checking if etype %s is present on nexus...", self.emodel_metadata.etype) @@ -155,6 +156,7 @@ def check_mettypes(self): access_point=ontology_access_point, access_token=self.access_point.access_token, forge_path=self.forge_ontology_path, + endpoint=self.access_point.endpoint, ) logger.info("Etype checked") @@ -169,6 +171,7 @@ def check_mettypes(self): access_point=ontology_access_point, access_token=self.access_point.access_token, forge_path=self.forge_ontology_path, + endpoint=self.access_point.endpoint, ) logger.info("Mtype checked") else: @@ -185,6 +188,7 @@ def check_mettypes(self): access_point=ontology_access_point, access_token=self.access_point.access_token, forge_path=self.forge_ontology_path, + endpoint=self.access_point.endpoint, ) logger.info("Ttype checked") else: @@ -228,6 +232,7 @@ def build_ontology_based_metadata(self): self.emodel_metadata.brain_region, self.access_point.access_token, self.forge_ontology_path, + self.access_point.endpoint, ) def get_nexus_subject(self, species): @@ -573,7 +578,7 @@ def store_model_configuration(self, configuration, path=None): # set id to mechanisms by filtering with brain region, temperature, species, ljp correction ontology_access_point = ontology_forge_access_point( - self.access_point.access_token, self.forge_ontology_path + self.access_point.access_token, self.forge_ontology_path, self.access_point.endpoint ) for mechanism in configuration.mechanisms: if mechanism.name in NEURON_BUILTIN_MECHANISMS: @@ -891,7 +896,7 @@ def download_mechanisms(self, mechanisms, any_downloaded=False): mechanisms_directory = self.get_mechanisms_directory() ontology_access_point = ontology_forge_access_point( - self.access_point.access_token, self.forge_ontology_path + self.access_point.access_token, self.forge_ontology_path, self.access_point.endpoint ) for mechanism in mechanisms: diff --git a/tests/unit_tests/test_nexus_access_point.py b/tests/unit_tests/test_nexus_access_point.py index ab525154..e70cdded 100644 --- a/tests/unit_tests/test_nexus_access_point.py +++ b/tests/unit_tests/test_nexus_access_point.py @@ -159,7 +159,8 @@ def test_check_mettypes(mock_nexus_access_point, mock_available_etypes, mock_ava mock_ontology_forge.assert_called_once_with( mock_nexus_access_point.access_point.access_token, - mock_nexus_access_point.forge_ontology_path + mock_nexus_access_point.forge_ontology_path, + mock_nexus_access_point.access_point.endpoint, ) mock_check_resource.assert_any_call( @@ -167,7 +168,8 @@ def test_check_mettypes(mock_nexus_access_point, mock_available_etypes, mock_ava "etype", access_point=mock_ontology_forge.return_value, access_token=mock_nexus_access_point.access_point.access_token, - forge_path=mock_nexus_access_point.forge_ontology_path + forge_path=mock_nexus_access_point.forge_ontology_path, + endpoint=mock_nexus_access_point.access_point.endpoint, )