Skip to content

Commit

Permalink
adapt features for regions to v3
Browse files Browse the repository at this point in the history
  • Loading branch information
valentin-pinkau committed Dec 12, 2024
1 parent fadd852 commit 27bd7a5
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 69 deletions.
65 changes: 11 additions & 54 deletions +siibra/+internal/API.m
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@

function regionsJson = regions(parcellationId)
absoluteLink = siibra.internal.API.absoluteLinkV3("regions");
parameters = ["parcellation_id=" + parcellationId];
parameters = "parcellation_id=" + parcellationId;
regionsJson = siibra.internal.API.collectItemsAcrossPages( ...
absoluteLink, parameters);
end
Expand Down Expand Up @@ -124,60 +124,17 @@
absoluteLink = siibra.internal.API.absoluteLinkV3(relativeLink);
end

function absoluteLink = featuresPageForParcellation(atlasId, parcellationId, page, size)
relativeLink = "atlases/" + atlasId + ...
"/parcellations/" + parcellationId + ...
"/features?page=" + page + ...
"&size=" + size;
absoluteLink = siibra.internal.API.absoluteLinkV2(relativeLink);
end
function featureList = featuresForParcellation(atlasId, parcellationId)
featureList = {};
page = 1;
size = 100;
firstPage = siibra.internal.API.doWebreadWithLongTimeout( ...
siibra.internal.API.featuresPageForParcellation( ...
atlasId, ...
parcellationId, ...
page, ...
size)...
);
totalElements = firstPage.total;
featureList{1} = firstPage.items;
processedElements = numel(firstPage.items);
while processedElements < totalElements
page = page + 1;
nextPage = siibra.internal.API.doWebreadWithLongTimeout( ...
siibra.internal.API.featuresPageForParcellation( ...
atlasId, ...
parcellationId, ...
page, ...
size)...
);
featureList{page} = nextPage.items;
processedElements = processedElements + numel(nextPage.items);
end
featureList = cat(1, featureList{:});
end
function absoluteLink = parcellationFeature(atlasId, parcellationId, featureId)
% get specific feature by feature id.
relativeLink = "atlases/" + atlasId + ...
"/parcellations/" + parcellationId + ...
"/features/" + featureId;
absoluteLink = siibra.internal.API.absoluteLinkV2(relativeLink);
end
function absoluteLink = featuresForRegion(atlasId, parcellationId, regionName)
relativeLink = "atlases/" +atlasId + ...
"/parcellations/" + parcellationId + ...
"/regions/" + regionName + "/features";
absoluteLink = siibra.internal.API.absoluteLinkV2(relativeLink);
function features = featuresForRegion(region)
relativeLink = "regions/" + region.Name + "/features";
absoluteLink = siibra.internal.API.absoluteLinkV3(relativeLink);
parameters = "parcellation_id=" + region.Parcellation.Id;
features = siibra.internal.API.collectItemsAcrossPages(absoluteLink, parameters);
end
function absoluteLink = regionFeature(atlasId, parcellationId, regionName, featureId)
relativeLink = "atlases/" +atlasId + ...
"/parcellations/" + parcellationId + ...
"/regions/" + regionName + ...
"/features/" + featureId;
absoluteLink = siibra.internal.API.absoluteLinkV2(relativeLink);
function absoluteLink = tabularFeature(region, featureId)
relativeLink = "feature/Tabular/" + featureId + ...
"?parcellation_id=" + region.Parcellation.Id + ...
"&region_id=" + region.Name;
absoluteLink = siibra.internal.API.absoluteLinkV3(relativeLink);
end
end

Expand Down
14 changes: 5 additions & 9 deletions +siibra/+items/+features/ReceptorDensity.m
Original file line number Diff line number Diff line change
Expand Up @@ -7,27 +7,23 @@
Id string
Description string
Name string
DOI string
Fingerprint string
Unit string
end

methods
function obj = ReceptorDensity(region, receptorJson)
obj.Region = region;
obj.Id = receptorJson.x_id;
obj.Description = receptorJson.metadata.description;
obj.Name = receptorJson.metadata.fullName;
obj.DOI = "https://doi.org/" + receptorJson.urls.doi;
obj.Id = receptorJson.id;
obj.Description = receptorJson.description;
obj.Name = receptorJson.name;
obj.Unit = "fmol/mg";
end

function fingerprints = get.Fingerprint(obj)
fingerprintJson = siibra.internal.API.doWebreadWithLongTimeout( ...
siibra.internal.API.regionFeature( ...
obj.Region.Parcellation.Atlas.Id, ...
obj.Region.Parcellation.Id, ...
obj.Region.Name, ...
siibra.internal.API.tabularFeature( ...
obj.Region, ...
obj.Id));
fingerprintStruct = fingerprintJson.data.fingerprints;
receptors = fieldnames(fingerprintStruct);
Expand Down
1 change: 1 addition & 0 deletions +siibra/+items/Parcellation.m
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@
end

function features = getAllFeatures(obj)
error("API v3 has no features on parcellation level!");
cached_file_name = siibra.internal.cache(obj.Name + ".mat", "parcellation_features");
if ~isfile(cached_file_name)
features = siibra.internal.API.featuresForParcellation(obj.Atlas.Id, obj.Id);
Expand Down
9 changes: 3 additions & 6 deletions +siibra/+items/Region.m
Original file line number Diff line number Diff line change
Expand Up @@ -45,11 +45,7 @@
function features = getAllFeatures(obj)
cached_file_name = siibra.internal.cache(obj.NormalizedName + ".mat", "region_features");
if ~isfile(cached_file_name)
features = siibra.internal.API.doWebreadWithLongTimeout( ...
siibra.internal.API.featuresForRegion( ...
obj.Parcellation.Atlas.Id, ...
obj.Parcellation.Id, ...
obj.Name));
features = siibra.internal.API.featuresForRegion(obj);

% make sure to always return a cell array
if ~iscell(features)
Expand All @@ -64,7 +60,8 @@

function receptorDensities = getReceptorDensities(obj)
allFeatures = obj.getAllFeatures();
receptorIdx = cellfun(@(e) strcmp(e.x_type,'siibra/features/receptor'), allFeatures);
featureTypes = cellfun(@(e) e.x_type, allFeatures, "UniformOutput",false);
receptorIdx = strcmp(featureTypes, "siibra-0.4/feature/tabular/receptor_density_fp");
if ~any(receptorIdx)
receptorDensities = siibra.items.features.ReceptorDensity.empty;
return
Expand Down

0 comments on commit 27bd7a5

Please sign in to comment.