Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions demos/MoAE/moae_03_create_roi_extract_data.m
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@
% from the mask created by the contrast estimation in the previous step
ffxDir = getFFXdir(subLabel, opt);
maskImage = spm_select('FPList', ffxDir, '^.*_mask.nii$');
p = bids.internal.parse_filename(spm_file(maskImage, 'filename'));
conImage = spm_select('FPList', ffxDir, ['^con_' p.entities.label '.nii$']);
bf = bids.File(spm_file(maskImage, 'filename'));
conImage = spm_select('FPList', ffxDir, ['^con_' bf.entities.label '.nii$']);

%% Create ROI right auditory cortex
saveROI = true;
Expand Down
6 changes: 3 additions & 3 deletions demos/MoAE/moae_04_slice_display.m
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@
% we get the con image to extract data
ffxDir = getFFXdir(subLabel, opt);
maskImage = spm_select('FPList', ffxDir, '^.*_mask.nii$');
p = bids.internal.parse_filename(spm_file(maskImage, 'filename'));
conImage = spm_select('FPList', ffxDir, ['^con_' p.entities.label '.nii$']);
bf = bids.File(spm_file(maskImage, 'filename'));
conImage = spm_select('FPList', ffxDir, ['^con_' bf.entities.label '.nii$']);

%% Layers to put on the figure
layers = sd_config_layers('init', {'truecolor', 'dual', 'contour', 'contour'});
Expand Down Expand Up @@ -57,7 +57,7 @@
%
% - t-statistics opacity-coded

spmTImage = spm_select('FPList', ffxDir, ['^spmT_' p.entities.label '.nii$']);
spmTImage = spm_select('FPList', ffxDir, ['^spmT_' bf.entities.label '.nii$']);
layers(2).opacity.file = spmTImage;

layers(2).opacity.range = [2 3];
Expand Down
16 changes: 12 additions & 4 deletions demos/MoAE/moae_bids_app.m
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,22 @@

output_dir = fullfile(bids_dir, '..', '..', 'outputs', 'derivatives');

cpp_spm(bids_dir, output_dir, 'participant', ...
cpp_spm(bids_dir, output_dir, 'subject', ...
'action', 'preprocess', ...
'task', {'auditory'});
'task', {'auditory'}, ...
'ignore', {'unwarp'}, ...
'space', {'IXI549Space'});

%% STATS
addpath(fullfile(pwd, '..', '..'));

bids_dir = fullfile(fileparts(mfilename('fullpath')), 'inputs', 'raw');

output_dir = fullfile(bids_dir, '..', '..', 'outputs', 'derivatives');

preproc_dir = fullfile(output_dir, 'cpp_spm-preproc');

model_file = fullfile(this_dir, 'models', 'model-MoAE_smdl.json');
model_file = fullfile(pwd, 'models', 'model-MoAE_smdl.json');

opt.result.Nodes(1).Level = 'subject';
opt.result.Nodes(1).Contrasts(1).Name = 'listening_1';
Expand All @@ -28,7 +36,7 @@
opt.result.Nodes(1).Output.montage.slices = -4:2:16;
opt.result.Nodes(1).Output.NIDM_results = true();

cpp_spm(bids_dir, output_dir, 'participant', ...
cpp_spm(bids_dir, output_dir, 'subject', ...
'action', 'stats', ...
'preproc_dir', preproc_dir, ...
'model_file', model_file, ...
Expand Down
6 changes: 3 additions & 3 deletions demos/face_repetition/face_rep_resolution.m
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,9 @@
content = spm_jsonread(opt.model.file);
content.Name = [content.Name, ' resolution - ', num2str(iResolution)];

p = bids.internal.parse_filename(modelFile);
p.entities.model = [p.entities.model, ' resolution', num2str(iResolution)];
bf = bids.File(p);
bf = bids.File(modelFile);
bf.entities.model = [bf.entities.model, ' resolution', num2str(iResolution)];

newModel = spm_file(opt.model.file, 'filename', bf.filename);
opt.model.file = newModel;

Expand Down
12 changes: 6 additions & 6 deletions src/IO/getData.m
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,15 @@
%
% (C) Copyright 2020 CPP_SPM developers

p = inputParser;
args = inputParser;

addRequired(p, 'opt', @isstruct);
addRequired(p, 'bidsDir', @isdir);
addRequired(args, 'opt', @isstruct);
addRequired(args, 'bidsDir', @isdir);

parse(p, varargin{:});
parse(args, varargin{:});

opt = p.Results.opt;
bidsDir = p.Results.bidsDir;
opt = args.Results.opt;
bidsDir = args.Results.bidsDir;

if isfield(opt, 'taskName')
msg = sprintf('\nFOR TASK(s): %s\n', strjoin(opt.taskName, ' '));
Expand Down
10 changes: 5 additions & 5 deletions src/IO/onsetsMatToTsv.m
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,12 @@
%
% (C) Copyright 2022 CPP_SPM developers

p = inputParser;
args = inputParser;
isFile = @(x) exist(x, 'file') == 2;
addRequired(p, 'onsetsMatFile', isFile);
parse(p, varargin{:});
addRequired(args, 'onsetsMatFile', isFile);
parse(args, varargin{:});

load(p.Results.onsetsMatFile, 'names', 'onsets', 'durations');
load(args.Results.onsetsMatFile, 'names', 'onsets', 'durations');

tsvContent = struct('onset', [], 'duration', [], 'trial_type', {{}});

Expand All @@ -42,7 +42,7 @@
tsvContent.trial_type = tsvContent.trial_type(idx);
tsvContent.duration = tsvContent.duration(idx);

onsetsTsvFile = spm_file(p.Results.onsetsMatFile, 'ext', '.tsv');
onsetsTsvFile = spm_file(args.Results.onsetsMatFile, 'ext', '.tsv');

bids.util.tsvwrite(onsetsTsvFile, tsvContent);

Expand Down
10 changes: 5 additions & 5 deletions src/IO/regressorsMatToTsv.m
Original file line number Diff line number Diff line change
Expand Up @@ -15,20 +15,20 @@
%
% (C) Copyright 2022 CPP_SPM developers

p = inputParser;
args = inputParser;
isFile = @(x) exist(x, 'file') == 2;
addRequired(p, 'regressorsMatFile', isFile);
parse(p, varargin{:});
addRequired(args, 'regressorsMatFile', isFile);
parse(args, varargin{:});

load(p.Results.regressorsMatFile, 'names', 'R');
load(args.Results.regressorsMatFile, 'names', 'R');

tsvContent = struct();

for iReg = 1:numel(names) %#ok<*USENS>
tsvContent.(names{iReg}) = R(:, iReg); %#ok<*NODEF>
end

regressorsTsvFile = spm_file(p.Results.regressorsMatFile, 'ext', '.tsv');
regressorsTsvFile = spm_file(args.Results.regressorsMatFile, 'ext', '.tsv');

bids.util.tsvwrite(regressorsTsvFile, tsvContent);

Expand Down
12 changes: 5 additions & 7 deletions src/IO/renameSegmentParameter.m
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,13 @@ function renameSegmentParameter(BIDS, subLabel, opt)
spm_file(anatImage, 'basename'), ...
'_seg8.mat$']);

p = bids.internal.parse_filename(anatImage);
p.entities.label = p.suffix;
bf = bids.File(anatImage);
bf.entities.label = bf.suffix;

p.suffix = 'segparam';
p.ext = '.mat';
bf.suffix = 'segparam';
bf.extension = '.mat';

bidsFile = bids.File(p);

newName = spm_file(segmentParam, 'filename', bidsFile.filename);
newName = spm_file(segmentParam, 'filename', bf.filename);

if ~isempty(segmentParam)
movefile(segmentParam, newName);
Expand Down
10 changes: 5 additions & 5 deletions src/IO/renameUnwarpParameter.m
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,12 @@ function renameUnwarpParameter(BIDS, subLabel, opt)

inputFilename = strrep(unwarpParam(iFile, :), '_uw.', '.');

p = bids.internal.parse_filename(inputFilename);
p.entities.label = p.suffix;
p.suffix = 'unwarpparam';
p.ext = '.mat';
bf = bids.File(inputFilename);
bf.entities.label = bf.suffix;
bf.suffix = 'unwarpparam';
bf.extension = '.mat';

bidsFile = bids.File(p);
bidsFile = bids.File(bf);

newName = spm_file(unwarpParam(iFile, :), 'filename', bidsFile.filename);

Expand Down
18 changes: 9 additions & 9 deletions src/IO/saveSpmScript.m
Original file line number Diff line number Diff line change
Expand Up @@ -17,30 +17,30 @@

% TODO add header to output .m file

p = inputParser;
args = inputParser;

defaultOutputFilename = '';

isCellOrMatFile = @(x) iscell(x) || ...
(exist(x, 'file') == 2 && ...
strcmp(spm_file(x, 'ext'), 'mat'));

addRequired(p, 'input', isCellOrMatFile);
addOptional(p, 'outputFilename', defaultOutputFilename, @ischar);
addRequired(args, 'input', isCellOrMatFile);
addOptional(args, 'outputFilename', defaultOutputFilename, @ischar);

parse(p, varargin{:});
parse(args, varargin{:});

outputFilename = p.Results.outputFilename;
outputFilename = args.Results.outputFilename;

if iscell(p.Results.input)
matlabbatch = p.Results.input;
if iscell(args.Results.input)
matlabbatch = args.Results.input;

else
% assumes the job was saved in a matlabbatch variable
load(p.Results.input, 'matlabbatch');
load(args.Results.input, 'matlabbatch');

if strcmp(outputFilename, '')
outputFilename = spm_file(p.Results.input, 'ext', '.m');
outputFilename = spm_file(args.Results.input, 'ext', '.m');
end

end
Expand Down
20 changes: 10 additions & 10 deletions src/QA/anatomicalQA.m
Original file line number Diff line number Diff line change
Expand Up @@ -54,19 +54,19 @@ function anatomicalQA(opt)
outputDir = fullfile(anatDataDir, '..', 'reports');
spm_mkdir(outputDir);

p = bids.internal.parse_filename(anatImage);
p.entities.label = p.suffix;
bf = bids.File(anatImage);
bf.entities.label = bf.suffix;

p.suffix = 'qametrics';
p.ext = '.json';
bidsFile = bids.File(p);
bids.util.jsonwrite(fullfile(outputDir, bidsFile.filename), anatQA);
bf.suffix = 'qametrics';
bf.extension = '.json';

bids.util.jsonwrite(fullfile(outputDir, bf.filename), anatQA);

bf.suffix = 'qa';
bf.extension = '.png';

p.suffix = 'qa';
p.ext = '.png';
bidsFile = bids.File(p);
movefile(fullfile(pwd, 'spmup_QC-Brain Mask_001.png'), ...
fullfile(outputDir, bidsFile.filename));
fullfile(outputDir, bf.filename));

delete(fullfile(anatDataDir, [spm_file(anatImage, 'basename') '_anatQA.txt']));

Expand Down
42 changes: 21 additions & 21 deletions src/QA/functionalQA.m
Original file line number Diff line number Diff line change
Expand Up @@ -167,33 +167,33 @@ function functionalQA(opt)
outputDir = fullfile(subFuncDataDir, '..', 'reports');
spm_mkdir(outputDir);

p = bids.internal.parse_filename(funcImage);
p.entities.label = p.suffix;
p.prefix = '';
bf = bids.File(funcImage);
bf.entities.label = bf.suffix;
bf.prefix = '';

% TODO find an ouput format that is leaner than a 3 Gb json file!!!
p.suffix = 'qametrics';
p.ext = '.json';
bidsFile = bids.File(p);
bids.util.jsonwrite(fullfile(outputDir, bidsFile.filename), jsonContent);

p.suffix = 'qa';
p.ext = '.pdf';
bidsFile = bids.File(p);
bf.suffix = 'qametrics';
bf.extension = '.json';

bids.util.jsonwrite(fullfile(outputDir, bf.filename), jsonContent);

bf.suffix = 'qa';
bf.extension = '.pdf';

movefile(fullfile(subFuncDataDir, 'spmup_QC.ps'), ...
fullfile(outputDir, bidsFile.filename));
fullfile(outputDir, bf.filename));

p.entities.desc = 'confounds';
p.entities.label = '';
p.suffix = 'regressors';
p.ext = '.tsv';
bidsFile = bids.File(p);
bids.util.tsvwrite(spm_file(funcImage, 'filename', bidsFile.filename), tsvContent);
bf.entities.desc = 'confounds';
bf.entities.label = '';
bf.suffix = 'regressors';
bf.extension = '.tsv';

bids.util.tsvwrite(spm_file(funcImage, 'filename', bf.filename), tsvContent);

jsonContent = createDataDictionary(tsvContent);
p.ext = '.json';
bidsFile = bids.File(p);
bids.util.jsonwrite(spm_file(funcImage, 'filename', bidsFile.filename), jsonContent);
bf.extension = '.json';

bids.util.jsonwrite(spm_file(funcImage, 'filename', bf.filename), jsonContent);

delete(outputFiles.design);
delete(realignParamFile);
Expand Down
22 changes: 11 additions & 11 deletions src/QA/plotRoiTimeCourse.m
Original file line number Diff line number Diff line change
Expand Up @@ -28,34 +28,34 @@
%
% (C) Copyright 2022 CPP_SPM developers

p = inputParser;
args = inputParser;

isFile = @(x) exist(x, 'file') == 2;

addRequired(p, 'tsvFile', isFile);
addOptional(p, 'verbose', true, @islogical);
addParameter(p, 'colors', twelveClassesColorMap(), @isnumeric);
addParameter(p, 'roiName', '', @ischar);
addRequired(args, 'tsvFile', isFile);
addOptional(args, 'verbose', true, @islogical);
addParameter(args, 'colors', twelveClassesColorMap(), @isnumeric);
addParameter(args, 'roiName', '', @ischar);

parse(p, varargin{:});
parse(args, varargin{:});

tsvFile = p.Results.tsvFile;
tsvFile = args.Results.tsvFile;
timeCourse = bids.util.tsvread(tsvFile);
conditionNames = fieldnames(timeCourse);

visible = 'off';
if p.Results.verbose
if args.Results.verbose
visible = 'on';
end

if strcmp(p.Results.roiName, '')
if strcmp(args.Results.roiName, '')
bf = bids.File(tsvFile);
figName = ['ROI: ' bf.entities.label];
if isfield(bf.entities, 'hemi')
figName = [figName ' - ' bf.entities.hemi];
end
else
figName = ['ROI: ' p.Results.roiName];
figName = ['ROI: ' args.Results.roiName];
end

for i = 1:numel(conditionNames)
Expand All @@ -68,7 +68,7 @@

secs = [0:size(timeCourse, 1) - 1] * jsonContent.SamplingFrequency;

colors = p.Results.colors;
colors = args.Results.colors;
if size(timeCourse, 2) > size(colors, 1)
colors = repmat(colors, 2, 1);
end
Expand Down
Loading