Skip to content

Commit 828f157

Browse files
authored
Merge pull request #730 from Remi-Gau/lesion_merge
[ENH] use inputs from several datasets for lesion abnormality detection
2 parents ceed798 + 13d37ac commit 828f157

File tree

7 files changed

+76
-34
lines changed

7 files changed

+76
-34
lines changed

CITATION.cff

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ cff-version: 1.2.0
22

33
title: "CPP SPM"
44

5-
version: 2.1.0
5+
version: 2.1.0dev
66

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

cli.py renamed to WIP/cli.py

File renamed without changes.
File renamed without changes.
Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,33 @@
1-
function opt = lesion_get_option()
2-
%
3-
% Returns a structure that contains the options chosen by the user to run the source processing
4-
% batch workflow
5-
%
6-
% USAGE::
7-
%
8-
% opt = lesion_get_option()
9-
%
10-
% :returns: - :opt: (struct)
1+
function [opt, opt2] = lesion_get_option()
112
%
123
% (C) Copyright 2021 CPP_SPM developers
134

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

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

2012
opt.query.modality = 'anat';
2113

2214
opt.pipeline.type = 'preproc';
2315

24-
% opt.toolbox.ALI.unified_segmentation.step1thr_size = 0.6;
2516
opt.toolbox.ALI.unified_segmentation.step1fwhm = 6;
2617
opt.toolbox.ALI.unified_segmentation.step1niti = 3;
18+
% Voxel sizes (in mm)
19+
opt.toolbox.ALI.unified_segmentation.step1vox = 1;
2720

2821
%% DO NOT TOUCH
2922
opt = checkOptions(opt);
3023
saveOptions(opt);
3124

25+
%%
26+
opt2.subjects = {'ctrl01'};
27+
opt2.dir.derivatives = '/home/remi/gin/Christine/olfaction_blind/derivatives/lesion/derivatives/';
28+
opt2.dir.preproc = fullfile(opt2.dir.derivatives, 'cpp_spm-preproc');
29+
opt2.query.run = '';
30+
opt2.query.acq = '';
31+
opt2.toolbox.ALI.unified_segmentation.step1fwhm = 6;
32+
opt2 = checkOptions(opt2);
3233
end

demos/lesion_detection/run_lesion.m

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,18 +15,18 @@
1515
cpp_spm();
1616

1717
%% Set options
18-
opt = lesion_get_option();
18+
[opt, opt2] = lesion_get_option();
1919

2020
%% Run batches
21-
% reportBIDS(opt);
22-
23-
bidsCopyInputFolder(opt);
21+
% bidsCopyInputFolder(opt);
22+
% bidsCopyInputFolder(opt2);
2423

2524
%% Step 1: segmentation
26-
bidsLesionSegmentation(opt);
25+
% bidsLesionSegmentation(opt);
26+
% bidsLesionSegmentation(opt2);
2727

2828
%% Step 2: lesion abnormalities
29-
bidsLesionAbnormalitiesDetection(opt);
29+
bidsLesionAbnormalitiesDetection(opt, opt2);
3030

3131
% % Step 3: overlap map
3232
% bidsLesionOverlapMap(opt)

src/workflows/lesion/bidsLesionAbnormalitiesDetection.m

Lines changed: 54 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
function bidsLesionAbnormalitiesDetection(opt)
1+
function bidsLesionAbnormalitiesDetection(opt, extraOptions)
22
%
33
% Use the ALI toolbox to detect lesion abnormalities in anatomical image
44
% after segmentation of the image.
@@ -9,41 +9,87 @@ function bidsLesionAbnormalitiesDetection(opt)
99
%
1010
% bidsLesionAbnormalitiesDetection(opt)
1111
%
12-
% :type opt: structure
1312
% :param opt: Options chosen for the analysis.
1413
% See also: checkOptions
1514
% ``checkOptions()`` and ``loadAndCheckOptions()``.
1615
% :type opt: structure
1716
%
17+
% :param extraOptions: Options chosen for analysis of another dataset
18+
% in case they need to be merged.
19+
% See also: checkOptions
20+
% ``checkOptions()`` and ``loadAndCheckOptions()``.
21+
% :type extraOptions: structure
22+
%
1823
% Lesion abnormalities detection will be performed using the information provided
1924
% from the lesion segmentation output in BIDS format.
2025
%
2126
%
2227
% (C) Copyright 2021 CPP_SPM developers
2328

29+
% TODO: do not use extraOptions but instead either opt(1) and opt(2) or
30+
31+
if nargin < 2
32+
extraOptions = [];
33+
end
34+
35+
% create a structure to collect image names
36+
labels = {'GM', 'WM'};
37+
for i = 1:numel(labels)
38+
images(i, 1) = struct('controls', [], 'patients', []);
39+
end
40+
2441
opt.dir.input = opt.dir.preproc;
2542

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

30-
[BIDS, opt] = setUpWorkflow(opt, 'abnormalities detection');
47+
images = collectImagesFromDataset(opt, images, labels);
3148

32-
labels = {'GM', 'WM'};
49+
if ~isempty(extraOptions)
50+
if checkToolbox('ALI', 'verbose', extraOptions.verbosity > 0)
51+
extraOptions = setFields(extraOptions, ALI_my_defaults());
52+
end
53+
extraOptions.dir.input = extraOptions.dir.preproc;
54+
images = collectImagesFromDataset(extraOptions, images, labels);
55+
end
3356

34-
% create a structure to collect image names
35-
for i = 1:numel(labels)
36-
images(i, 1) = struct('controls', [], 'patients', []);
57+
%%
58+
controlsImages = cat(1, images.controls);
59+
patientsImages = cat(1, images.patients);
60+
61+
if isempty(controlsImages) || ...
62+
isempty(patientsImages) || ...
63+
any(cellfun('isempty', controlsImages)) || ...
64+
any(cellfun('isempty', patientsImages))
65+
msg = sprintf('Must have segmentation output from patients AND control');
66+
id = 'missingImages';
67+
errorHandling(mfilename(), id, msg, false);
3768
end
3869

70+
matlabbatch = {};
71+
matlabbatch = setBatchLesionAbnormalitiesDetection(matlabbatch, opt, images);
72+
73+
saveAndRunWorkflow(matlabbatch, 'LesionAbnormalitiesDetection', opt);
74+
75+
end
76+
77+
function images = collectImagesFromDataset(opt, images, labels)
78+
79+
[BIDS, opt] = setUpWorkflow(opt, 'abnormalities detection');
80+
3981
for iSub = 1:numel(opt.subjects)
4082

4183
subLabel = opt.subjects{iSub};
4284

4385
printProcessingSubject(iSub, subLabel, opt);
4486

4587
idx = strcmp(BIDS.participants.content.participant_id, ['sub-' subLabel]);
46-
participantsGroup = BIDS.participants.content.group(idx);
88+
if isfield(BIDS.participants.content, 'group')
89+
participantsGroup = BIDS.participants.content.group(idx);
90+
elseif isfield(BIDS.participants.content, 'Group')
91+
participantsGroup = BIDS.participants.content.Group(idx);
92+
end
4793

4894
anatImage = getAnatFilename(BIDS, opt, subLabel);
4995
anatImage = bids.File(anatImage);
@@ -79,9 +125,4 @@ function bidsLesionAbnormalitiesDetection(opt)
79125

80126
end
81127

82-
matlabbatch = {};
83-
matlabbatch = setBatchLesionAbnormalitiesDetection(matlabbatch, opt, images);
84-
85-
saveAndRunWorkflow(matlabbatch, 'LesionAbnormalitiesDetection', opt);
86-
87128
end

version.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
v2.1.0
1+
v2.1.0dev

0 commit comments

Comments
 (0)