-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: split register parcellation into two pipelines
- Loading branch information
1 parent
12f4e94
commit 2afb919
Showing
9 changed files
with
449 additions
and
109 deletions.
There are no files selected for viewing
79 changes: 79 additions & 0 deletions
79
src/matlab/builders/configurations/BuildRegisterToStandardConfiguration.m
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
function [config] = BuildRegisterToStandardConfiguration() | ||
%BUILDREGISTERTOSTANDARDCONFIGURATION Builds configuration for pipeline. | ||
% Builds a configuration for a pipeline that registers volumes to a standard. | ||
% | ||
% Input: | ||
% - ... | ||
% | ||
% Output: | ||
% - config: Configuration. | ||
|
||
config = struct(); | ||
|
||
% get data folder relative to this file | ||
filePath = fileparts(which(mfilename)); | ||
pathToDataFolder = fullfile(filePath, '../../../../../neurochi/data/'); | ||
pathToWorkspace = fullfile(pathToDataFolder, 'w1'); | ||
pathToDataset = fullfile(pathToDataFolder, 'input'); | ||
pathToParcellations = fullfile(pathToDataFolder, 'parcs'); | ||
% for intermediary pipelines, send output to the transfer folder | ||
pathToOutput = fullfile(pathToDataFolder, 'transfer'); | ||
|
||
%% pipeline: register to standard | ||
% common configuration | ||
config.verbose = true; | ||
config.clobber = true; | ||
config.pathToWorkspace = pathToWorkspace; | ||
config.pathToDataset = pathToDataset; | ||
config.pathToParcellations = pathToParcellations; | ||
config.pathToOutput = pathToOutput; | ||
% helps debug by not running all subjects | ||
config.numSubjects = 1; | ||
|
||
|
||
% step 1 | ||
config.step1.dof = 6; | ||
config.step1.interp = 'spline'; | ||
config.step1.optional = false; | ||
config.step1.clobber = config.clobber; | ||
config.step1.verbose = config.verbose; | ||
% step 2: flirt | ||
config.step2.dof = 6; | ||
config.step2.applyxfm = true; | ||
config.step2.nosearch = true; | ||
config.step2.interp = 'spline'; | ||
config.step2.optional = false; | ||
config.step2.clobber = config.clobber; | ||
config.step2.verbose = config.verbose; | ||
% step 3 | ||
config.step3.optional = false; | ||
config.step3.clobber = config.clobber; | ||
config.step3.verbose = config.verbose; | ||
% step 4 | ||
config.step4.dof = 12; | ||
config.step4.interp = 'spline'; | ||
config.step4.optional = false; | ||
config.step4.clobber = config.clobber; | ||
config.step4.verbose = config.verbose; | ||
% step 5 | ||
config.step5.dof = 12; | ||
config.step5.applyxfm = true; | ||
config.step5.nosearch = true; | ||
config.step5.interp = 'spline'; | ||
config.step5.optional = false; | ||
config.step5.clobber = config.clobber; | ||
config.step5.verbose = config.verbose; | ||
% step 6 | ||
config.step6.optional = false; | ||
config.step6.clobber = config.clobber; | ||
config.step6.verbose = config.verbose; | ||
% step 7 | ||
config.step7.optional = false; | ||
config.step7.clobber = config.clobber; | ||
config.step7.verbose = config.verbose; | ||
% step 8 | ||
config.step8.optional = false; | ||
config.step8.clobber = config.clobber; | ||
config.step8.verbose = config.verbose; | ||
|
||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
62 changes: 62 additions & 0 deletions
62
src/matlab/builders/configurations/BuildTransformParcellationConfiguration.m
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
function [config] = BuildTransformParcellationConfiguration() | ||
%BUILDTRANSFORMPARCELLATIONCONFIGURATION Builds configuration for pipeline. | ||
% Builds a configuration for a pipeline that transforms a parcellation. | ||
% | ||
% Input: | ||
% - ... | ||
% | ||
% Output: | ||
% - config: Configuration. | ||
|
||
config = struct(); | ||
|
||
% get data folder relative to this file | ||
filePath = fileparts(which(mfilename)); | ||
pathToDataFolder = fullfile(filePath, '../../../../../neurochi/data/'); | ||
pathToWorkspace = fullfile(pathToDataFolder, 'w1'); | ||
pathToDataset = fullfile(pathToDataFolder, 'input'); | ||
pathToParcellations = fullfile(pathToDataFolder, 'parcs'); | ||
% for intermediary pipelines, send output to the transfer folder | ||
pathToOutput = fullfile(pathToDataFolder, 'transfer'); | ||
|
||
%% pipeline: transform parcellation | ||
% common configuration | ||
config.verbose = true; | ||
config.clobber = true; | ||
config.pathToWorkspace = pathToWorkspace; | ||
config.pathToDataset = pathToDataset; | ||
config.pathToParcellations = pathToParcellations; | ||
config.pathToOutput = pathToOutput; | ||
% helps debug by not running all subjects | ||
config.numSubjects = 1; | ||
% select the parcellation to transform | ||
% (must be present in `pathToParcellations`) | ||
config.parcellation = 'mask_ventricles_MNIch2.nii.gz'; | ||
|
||
% step 1 | ||
config.step1.numDilations = 0; | ||
config.step1.clobber = config.clobber; | ||
config.step1.verbose = config.verbose; | ||
% step 2 | ||
config.step2.interp = 'nn'; | ||
config.step2.clobber = config.clobber; | ||
config.step2.verbose = config.verbose; | ||
% step 3 | ||
config.step3.interp = 'nearestneighbour'; | ||
config.step3.applyxfm = true; | ||
config.step3.nosearch = true; | ||
config.step3.optional = true; | ||
config.step3.clobber = config.clobber; | ||
config.step3.verbose = config.verbose; | ||
|
||
% step 4 | ||
config.step4.interp = 'nearestneighbour'; | ||
config.step4.applyxfm = true; | ||
config.step4.nosearch = true; | ||
config.step4.optional = true; | ||
config.step4.clobber = config.clobber; | ||
config.step4.verbose = config.verbose; | ||
|
||
|
||
end | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
95 changes: 95 additions & 0 deletions
95
src/matlab/builders/pipelines/BuildTransformParcellationPipeline.m
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,95 @@ | ||
function [pipeline] = BuildTransformParcellationPipeline(parcellation, ... | ||
pathToWorkspace, ... | ||
pathToDataset, ... | ||
pathToParcellations, ... | ||
pathToIntermediaryOutputs, ... | ||
pathToOutput, ... | ||
numSubjects, ... | ||
config) | ||
%BUILDSAMPLEPIPELINE Example of a pipeline builder. | ||
% This builder creates a pipeline with one sequence per subject, based | ||
% on the format of a BIDS dataset's participants.tsv file. | ||
% | ||
% Input: | ||
% - pathToWorkspace: Path to the workspace. | ||
% - pathToDataset: Path to input the root of the BIDS dataset. | ||
% - pathToOutput: Path to where we will output the data. | ||
% | ||
% Output: | ||
% - pipeline: Built pipeline. | ||
|
||
arguments | ||
parcellation char | ||
pathToWorkspace char = '.' | ||
pathToDataset char = '.' | ||
pathToParcellations char = '.' | ||
pathToIntermediaryOutputs char = '.' | ||
pathToOutput char = '.' | ||
numSubjects int8 {mustBeNonnegative} = 0 | ||
config = {} | ||
end | ||
|
||
% names of inputs needed to start the sequence | ||
inputs = { ... | ||
fullfile(pathToDataset, '%s/anat/%s_T1w.nii.gz'), ... | ||
fullfile(pathToIntermediaryOutputs, '%s/%s_T1w_brain_mul.nii.gz'), ... | ||
fullfile(pathToIntermediaryOutputs, '%s/%s_MNI2T1w_dof6.mat'), ... | ||
fullfile(pathToIntermediaryOutputs, '%s/%s_MNI2T1w_dof12.mat'), ... | ||
fullfile(pathToIntermediaryOutputs, '%s/%s_MNI2T1w_warp.nii.gz'), ... | ||
fullfile(pathToIntermediaryOutputs, '%s/%s_T1w_brain_dof6.nii.gz'), ... | ||
fullfile(pathToIntermediaryOutputs, '%s/%s_T1w_brain_dof12.nii.gz'), ... | ||
fullfile(pathToParcellations, parcellation) }; | ||
numInputs = length(inputs); | ||
|
||
% get information about participants | ||
subjects = readtable(fullfile(pathToDataset, 'participants.tsv'), ... | ||
'Delimiter', ... | ||
'\t', ... | ||
'FileType', ... | ||
'delimitedtext', ... | ||
'PreserveVariableNames', ... | ||
true); | ||
|
||
tableHeight = height(subjects); | ||
if ~numSubjects | ||
numSubjects = tableHeight; | ||
else | ||
numSubjects = min(numSubjects, tableHeight); | ||
end | ||
|
||
sequences = cell(1, numSubjects); | ||
|
||
% create a sequence for each subject | ||
for i = 1 : numSubjects | ||
% get data for one participant | ||
subject = subjects(i, :); | ||
|
||
% participant_id is the column name and it's a cell | ||
subjectName = subject.participant_id{1}; | ||
|
||
% create an input array for each sequence | ||
subjectInputs = cell(1, numInputs); | ||
for j = 1 : numInputs | ||
input = inputs{j}; | ||
% get number of times subject name is needed | ||
subjectNameOccurences = count(input, '%s'); | ||
[subjectNameArray{1:subjectNameOccurences}] = deal(subjectName); | ||
subjectInputs{j} = sprintf(input, subjectNameArray{:}); | ||
end | ||
|
||
pathToSubjectWorkspace = fullfile(pathToWorkspace, subjectName); | ||
pathToSubjectOutput = fullfile(pathToOutput, subjectName); | ||
sequences{i} = BuildTransformParcellationSequence(subjectInputs, ... | ||
parcellation, ... | ||
subjectName, ... | ||
pathToSubjectWorkspace, ... | ||
pathToSubjectOutput, ... | ||
config); | ||
end | ||
|
||
% create a pipeline with the sequences | ||
parallel = false; | ||
pipeline = Pipeline(sequences, parallel); | ||
|
||
end | ||
|
Oops, something went wrong.