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
2 changes: 1 addition & 1 deletion CITATION.cff
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ cff-version: 1.2.0

title: "CPP SPM"

version: 2.1.0
version: 2.1.0dev

abstract: CPP_SPM is a set pipelines and tools for Octave/MATLAB to process and analyze BIDS data sets using SPM.

Expand Down
File renamed without changes.
File renamed without changes.
27 changes: 14 additions & 13 deletions demos/lesion_detection/lesion_get_option.m
Original file line number Diff line number Diff line change
@@ -1,32 +1,33 @@
function opt = lesion_get_option()
%
% Returns a structure that contains the options chosen by the user to run the source processing
% batch workflow
%
% USAGE::
%
% opt = lesion_get_option()
%
% :returns: - :opt: (struct)
function [opt, opt2] = lesion_get_option()
%
% (C) Copyright 2021 CPP_SPM developers

% The directory where the data are located
opt.dir.raw = 'C:\Users\michm\Data\myphdproject\MRI\CVI-DataLad\data';
opt.dir.raw = '/home/remi/gin/Michele/CVI-raw';

opt.dir.raw = '/home/remi/gin/Michele/CVI-raw';
opt.dir.derivatives = fullfile(opt.dir.raw, '..', 'derivatives');
opt.subjects = {'HH02', 'CTL25'};
opt.query.run = '02';

opt.query.modality = 'anat';

opt.pipeline.type = 'preproc';

% opt.toolbox.ALI.unified_segmentation.step1thr_size = 0.6;
opt.toolbox.ALI.unified_segmentation.step1fwhm = 6;
opt.toolbox.ALI.unified_segmentation.step1niti = 3;
% Voxel sizes (in mm)
opt.toolbox.ALI.unified_segmentation.step1vox = 1;

%% DO NOT TOUCH
opt = checkOptions(opt);
saveOptions(opt);

%%
opt2.subjects = {'ctrl01'};
opt2.dir.derivatives = '/home/remi/gin/Christine/olfaction_blind/derivatives/lesion/derivatives/';
opt2.dir.preproc = fullfile(opt2.dir.derivatives, 'cpp_spm-preproc');
opt2.query.run = '';
opt2.query.acq = '';
opt2.toolbox.ALI.unified_segmentation.step1fwhm = 6;
opt2 = checkOptions(opt2);
end
12 changes: 6 additions & 6 deletions demos/lesion_detection/run_lesion.m
Original file line number Diff line number Diff line change
Expand Up @@ -15,18 +15,18 @@
cpp_spm();

%% Set options
opt = lesion_get_option();
[opt, opt2] = lesion_get_option();

%% Run batches
% reportBIDS(opt);

bidsCopyInputFolder(opt);
% bidsCopyInputFolder(opt);
% bidsCopyInputFolder(opt2);

%% Step 1: segmentation
bidsLesionSegmentation(opt);
% bidsLesionSegmentation(opt);
% bidsLesionSegmentation(opt2);

%% Step 2: lesion abnormalities
bidsLesionAbnormalitiesDetection(opt);
bidsLesionAbnormalitiesDetection(opt, opt2);

% % Step 3: overlap map
% bidsLesionOverlapMap(opt)
67 changes: 54 additions & 13 deletions src/workflows/lesion/bidsLesionAbnormalitiesDetection.m
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
function bidsLesionAbnormalitiesDetection(opt)
function bidsLesionAbnormalitiesDetection(opt, extraOptions)
%
% Use the ALI toolbox to detect lesion abnormalities in anatomical image
% after segmentation of the image.
Expand All @@ -9,41 +9,87 @@ function bidsLesionAbnormalitiesDetection(opt)
%
% bidsLesionAbnormalitiesDetection(opt)
%
% :type opt: structure
% :param opt: Options chosen for the analysis.
% See also: checkOptions
% ``checkOptions()`` and ``loadAndCheckOptions()``.
% :type opt: structure
%
% :param extraOptions: Options chosen for analysis of another dataset
% in case they need to be merged.
% See also: checkOptions
% ``checkOptions()`` and ``loadAndCheckOptions()``.
% :type extraOptions: structure
%
% Lesion abnormalities detection will be performed using the information provided
% from the lesion segmentation output in BIDS format.
%
%
% (C) Copyright 2021 CPP_SPM developers

% TODO: do not use extraOptions but instead either opt(1) and opt(2) or

if nargin < 2
extraOptions = [];
end

% create a structure to collect image names
labels = {'GM', 'WM'};
for i = 1:numel(labels)
images(i, 1) = struct('controls', [], 'patients', []);
end

opt.dir.input = opt.dir.preproc;

if checkToolbox('ALI', 'verbose', opt.verbosity > 0)
opt = setFields(opt, ALI_my_defaults());
end

[BIDS, opt] = setUpWorkflow(opt, 'abnormalities detection');
images = collectImagesFromDataset(opt, images, labels);

labels = {'GM', 'WM'};
if ~isempty(extraOptions)
if checkToolbox('ALI', 'verbose', extraOptions.verbosity > 0)
extraOptions = setFields(extraOptions, ALI_my_defaults());
end
extraOptions.dir.input = extraOptions.dir.preproc;
images = collectImagesFromDataset(extraOptions, images, labels);
end

% create a structure to collect image names
for i = 1:numel(labels)
images(i, 1) = struct('controls', [], 'patients', []);
%%
controlsImages = cat(1, images.controls);
patientsImages = cat(1, images.patients);

if isempty(controlsImages) || ...
isempty(patientsImages) || ...
any(cellfun('isempty', controlsImages)) || ...
any(cellfun('isempty', patientsImages))
msg = sprintf('Must have segmentation output from patients AND control');
id = 'missingImages';
errorHandling(mfilename(), id, msg, false);
end

matlabbatch = {};
matlabbatch = setBatchLesionAbnormalitiesDetection(matlabbatch, opt, images);

saveAndRunWorkflow(matlabbatch, 'LesionAbnormalitiesDetection', opt);

end

function images = collectImagesFromDataset(opt, images, labels)

[BIDS, opt] = setUpWorkflow(opt, 'abnormalities detection');

for iSub = 1:numel(opt.subjects)

subLabel = opt.subjects{iSub};

printProcessingSubject(iSub, subLabel, opt);

idx = strcmp(BIDS.participants.content.participant_id, ['sub-' subLabel]);
participantsGroup = BIDS.participants.content.group(idx);
if isfield(BIDS.participants.content, 'group')
participantsGroup = BIDS.participants.content.group(idx);
elseif isfield(BIDS.participants.content, 'Group')
participantsGroup = BIDS.participants.content.Group(idx);
end

anatImage = getAnatFilename(BIDS, opt, subLabel);
anatImage = bids.File(anatImage);
Expand Down Expand Up @@ -79,9 +125,4 @@ function bidsLesionAbnormalitiesDetection(opt)

end

matlabbatch = {};
matlabbatch = setBatchLesionAbnormalitiesDetection(matlabbatch, opt, images);

saveAndRunWorkflow(matlabbatch, 'LesionAbnormalitiesDetection', opt);

end
2 changes: 1 addition & 1 deletion version.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
v2.1.0
v2.1.0dev