Is it possible to collect metadata and datasets from dandi using matlab? #57
-
What is the best way to access dandi metadata and datasets using matlab? Can it be done directly from matlab, or do I have to install python and dandi-cli and call python from matlab? |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
Thanks for the question, @ehennestad DANDI uses a REST API, which can be accessed using many different languages, including MATLAB. You can find documentation detailing the available commands here and here. I have drafted a tutorial with an example workflow below: %% Get all dandisets
dandisets = webread('https://api.dandiarchive.org/api/dandisets/?page_size=1000').results
%% Get identifers for NWB dandisets
nwb_identifier = 'RRID:SCR_015242';
nwb_dandiset_identifiers = {};
for i = 1:length({dandisets.identifier})
identifier = dandisets(i).identifier;
version_url = ['https://api.dandiarchive.org/api/dandisets/' identifier '/versions/draft'];
assetsSummary = webread(version_url).assetsSummary;
if isfield(assetsSummary, 'dataStandard') ...
&& isstruct(assetsSummary.dataStandard) ...
&& any(strcmp({assetsSummary.dataStandard.identifier}, nwb_identifier))
nwb_dandiset_identifiers(end+1) = {identifier};
end
end
%% Get asset data for a dandiset
identifier = '000003';
assets_request = ['https://api.dandiarchive.org/api/dandisets/' identifier '/versions/draft/assets/'];
assets = webread(assets_request).results
%% Get s3 url for specific NWB file
asset_request = ['https://api.dandiarchive.org/api/dandisets/' identifier '/versions/draft/assets/' assets(1).asset_id];
nwb_url = webread(asset_request).contentUrl{end} This is a bit quick-and-dirty. The API returns paginated results, and I handled this by requesting 1000 per page, which will not be the best way to handle this as the number of dandisets grows. We have a python tool, DandiApiClient, which handles these types of things, but we don't have anything like this in MATLAB. This would be a great project for someone to work on! |
Beta Was this translation helpful? Give feedback.
Thanks for the question, @ehennestad
DANDI uses a REST API, which can be accessed using many different languages, including MATLAB. You can find documentation detailing the available commands here and here. I have drafted a tutorial with an example workflow below: