bids-standard / bids-matlab

MATLAB / Octave tools for BIDS datasets
https://bids-matlab.readthedocs.io
MIT License
52 stars 32 forks source link

[ENH]: Retrieval of modality by bids.File #638

Closed nbeliy closed 7 months ago

nbeliy commented 12 months ago

Is there an existing issue for this?

New feature

So far, the modality is the only field which is not retrieved by bids.File, which can cause difficulties in file names manipulations, for ex. when I want to cite a source file in derived one:

p = bids.File(source_file);
sources = {fullfile(p.bids_path, p.filename)}

sources =

  1x1 cell array

    {'sub-KTA011/sub-KTA011_recording-manual_blood.csv'}

the modality is missing and must be set manually.

As the way to retrieve modality, it can be done by analyzing p.path:

[path, ~, ~] = fileparts(p.path);
[path, modality, ~] = fileparts(path); % Modality is just one level above the file
[path, entity, ~] = fileparts(path); % entity (sub or ses) is just above the modality

We can just check if entity matches with ses (or sub, if there no session), and if it is, then modality is found. If not, the file in question is not inside the BIDS dataset.

Remi-Gau commented 12 months ago

We can just check if entity matches with ses (or sub, if there no session), and if it is, then modality is found. If not, the file in question is not inside the BIDS dataset.

that sounds like a reasonable assumption to make

I would also potentially add an extra check when 'use_schema', true is used to check that the found modality matches one of those allowed in bids

Remi-Gau commented 12 months ago

feel free to open a PR if you have the bandwidth

nbeliy commented 12 months ago

Will do)