Skip to content

[ENH]: Incorporate json manipulation into bids.File class #596

@nbeliy

Description

@nbeliy

Is there an existing issue for this?

  • I have searched the existing issues

New feature

Playing with `bids-matlab`, I found that `bids.File` class is extremely useful even outside working with bids layouts, as it allows to quickly create/modify the filenames, especially useful when creating derivatives.

It would be nice that the same class could modify the sidecar json file, making easier to supplement derivative with it's json.

As an example, by using `spm_reorient`:
```matlab
% out_list is the list of reoriented images
for iFile = 1:numel(out_list)
  p = bids.File(out_list{iFile});
  p.load_json(); % Loads the existing sidecar json, or create empty structure
  p.entities.space = space; % Adding space entity

  p.update_json('Description', ['Reoriented to ' space], ...
                'Sources', out_list{iFile},...
                'SpatialReference', ref_img{1});

  outfile = fullfile(pth, p.filename);
  movefile(reoriented, outfile); % Renaming the reoriented file
  p.export_json(pth); % Saving modified json to the path
end

I already have these functions as standalone, integrating them into bids.File shouldn't take a lot of time.

If this interests you, I can create a PR.



### Unclear documentation

_No response_

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    Status

    Done

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions