juancarlosfarah / apero

A preprocessing pipeline builder for neuroimaging data.
MIT License
4 stars 0 forks source link

MRIfspec and therefore MRIread require single quotes (character vector) #1

Open juancarlosfarah opened 3 years ago

juancarlosfarah commented 3 years ago

In MATLAB, there's a difference between the use of single quotes ' and double quotes " to represent strings.

https://ch.mathworks.com/matlabcentral/answers/485385-difference-between-single-quote-vs-double-quote

It seems that MRIread, which uses MRIfspec under the hood, only works with the older ' character vectors.

MRIfspec('sub-01/sub-01_T1w.nii.gz')
ans =
    'sub-01/sub-01_T1w.nii.gz'

MRIfspec("sub-01/sub-01_T1w.nii.gz")
ans =
     []

Although we are using ' by default, what happens is that in a Step, when we transform our Parameters and Configuration properties to pass them as name-value arguments to the Operation, we use namedargs2cell.

% need to convert struct to name-value paired arguments
params = namedargs2cell(obj.Parameters);
config = namedargs2cell(obj.Configuration);
output = obj.Operation(pathToWorkspace, ...
                                        params{:}, ...
                                        config{:});

At this point, params still have the ' format:

params =
  1×4 cell array
    {'inputFile'}    {'sub-01_T1w.nii.gz'}    {'outputFile'}    {'sub-01_T1w_denoised.nii'}

But for some reason, when they are accessed from within the Operation, they get transformed to the " string representation:

params = 
  struct with fields:
     inputFile: "sub-01_T1w.nii.gz"
    outputFile: "sub-01_T1w_denoised.nii"

This means that we need to do a conversion back to ' in some of our operations (e.g. DenoiseImage).

inputFile = params.inputFile{1};
outputFile = params.outputFile{1};
juancarlosfarah commented 3 years ago

Looks like pathToWorkspace is also being converted, so it's not exclusive to the params and config name-value pairs.

juancarlosfarah commented 3 years ago

So I figured out why the conversion was happening. We were defining string in the arguments instead of char.

In DenoiseImage, this block:

arguments
  pathToWorkspace string = '.'
  params.inputFile string
  params.outputFile string
  config.beta double = 1
  config.patchRadius int8 = 1
  config.searchRadius int8 = 1
  config.rician logical = false
  config.verbose logical = false
end

Should be edited to:

arguments
  pathToWorkspace char = '.'
  params.inputFile char
  params.outputFile char
  config.beta double = 1
  config.patchRadius int8 = 1
  config.searchRadius int8 = 1
  config.rician logical = false
  config.verbose logical = false
end