-
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: bootstrap sample functional connectivity pipe
- Loading branch information
1 parent
0e207bb
commit 21a498b
Showing
4 changed files
with
228 additions
and
0 deletions.
There are no files selected for viewing
44 changes: 44 additions & 0 deletions
44
src/matlab/builders/configurations/BuildFunctionalConnectivityConfiguration.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,44 @@ | ||
function [config] = BuildFunctionalConnectivityConfiguration() | ||
%BUILDFUNCTIONALCONNECTIVITYCONFIGURATION Builds configuration for a pipeline. | ||
% Builds a configuration for a pipeline that performs segmentation. | ||
% | ||
% 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'); | ||
% for intermediary pipelines, send output to the transfer folder | ||
pathToOutput = fullfile(pathToDataFolder, 'transfer'); | ||
|
||
%% pipeline: segmentation | ||
% common configuration | ||
config.verbose = true; | ||
config.clobber = true; | ||
config.pathToWorkspace = pathToWorkspace; | ||
config.pathToDataset = pathToDataset; | ||
config.pathToOutput = pathToOutput; | ||
% helps debug by not running all subjects | ||
config.numSubjects = 1; | ||
config.parallel = false; | ||
|
||
% sequence level configurations | ||
config.sequence.startStep = 1; | ||
config.sequence.noCleanUp = true; | ||
|
||
% step 1: reorient to standard | ||
config.step1.optional = false; | ||
config.step1.skip = false; | ||
config.step1.clobber = config.clobber; | ||
config.step1.verbose = config.verbose; | ||
|
||
|
||
end | ||
|
111 changes: 111 additions & 0 deletions
111
src/matlab/builders/pipelines/BuildFunctionalConnectivityPipeline.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,111 @@ | ||
function [pipeline] = BuildFunctionalConnectivityPipeline(pathToWorkspace, ... | ||
pathToDataset, ... | ||
pathToIntermediaryOutputs, ... | ||
pathToOutput, ... | ||
numSubjects, ... | ||
config) | ||
%BUILDFUNCTIONALCONNECTIVITYPIPELINE Example of a pipeline builder. | ||
% This builder creates a pipeline with one sequence per run 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 | ||
pathToWorkspace char = '.' | ||
pathToDataset char = '.' | ||
pathToIntermediaryOutputs char = '.' | ||
pathToOutput char = '.' | ||
numSubjects int8 {mustBeNonnegative} = 0 | ||
config = struct() | ||
end | ||
|
||
% names of inputs needed to start the sequence | ||
inputs = { ... | ||
fullfile(pathToIntermediaryOutputs, ... | ||
'{subject}/{subject}_T1w_brain_mul.nii.gz'), ... | ||
fullfile(pathToIntermediaryOutputs, ... | ||
'{subject}/{subject}_T1w_brain_mask_filled.nii.gz'), ... | ||
fullfile(pathToDataset, ... | ||
'{subject}/func/{subject}_task-convers_{run}_bold.nii.gz'), ... | ||
}; | ||
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 | ||
|
||
% there are four runs per subject | ||
runs = { 'run-01', 'run-02', 'run-03', 'run-04' }; | ||
numRuns = length(runs); | ||
sequences = cell(1, numSubjects * numRuns); | ||
|
||
% 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 subject | ||
subjectInputs = cell(1, numInputs); | ||
for j = 1 : numInputs | ||
input = inputs{j}; | ||
|
||
% replace subject name | ||
subjectInputs{j} = strrep(input, '{subject}', subjectName); | ||
end | ||
|
||
% now prepare a sequence for each of the subject's runs | ||
for k = 1 : numRuns | ||
run = runs{k}; | ||
|
||
% sequence index | ||
sequenceIdx = (i - 1) * numRuns + k; | ||
|
||
% create an input array for each run sequence | ||
runInputs = cell(1, numInputs); | ||
for l = 1 : numInputs | ||
subjectInput = subjectInputs{l}; | ||
|
||
% replace subject name | ||
runInputs{l} = strrep(subjectInput, '{run}', run); | ||
end | ||
|
||
pathToRunWorkspace = fullfile(pathToWorkspace, subjectName, run); | ||
pathToRunOutput = fullfile(pathToOutput, subjectName, run); | ||
|
||
% add to sequences at the right index | ||
sequences{sequenceIdx} = BuildFunctionalConnectivitySequence(runInputs, ... | ||
subjectName, ... | ||
run, ... | ||
pathToRunWorkspace, ... | ||
pathToRunOutput, ... | ||
config); | ||
|
||
end | ||
end | ||
|
||
% create a pipeline with the sequences | ||
parallel = config.parallel; | ||
pipeline = Pipeline(sequences, parallel); | ||
|
||
end |
54 changes: 54 additions & 0 deletions
54
src/matlab/builders/sequences/BuildFunctionalConnectivitySequence.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,54 @@ | ||
function [sequence] = BuildFunctionalConnectivitySequence(inputs, ... | ||
subjectName, ... | ||
run, ... | ||
pathToWorkspace, ... | ||
pathToOutput, ... | ||
config) | ||
%BUILDFUNCTIONALCONNECTIVITYSEQUENCE Example of a sequence builder. | ||
% This builder creates the typical sequence to generate functional | ||
% connectomes. | ||
% | ||
% Input: | ||
% - inputs: Inputs that will be copied into the workspace. | ||
% - pathToWorkspace: Path to the sequence's workspace. | ||
% - pathToOutput: Path to where we will output the data. | ||
% | ||
% Output: | ||
% - sequence: Built sequence. | ||
|
||
%% step 1 | ||
% reorient to standard | ||
step1Params = struct(); | ||
step1Config = config.step1; | ||
step1Params.inputVolume = sprintf('%s_task-convers_%s_bold.nii.gz', ... | ||
subjectName, ... | ||
run); | ||
step1Params.outputVolume = sprintf('%s_task-convers_%s_bold_std.nii.gz', ... | ||
subjectName, ... | ||
run); | ||
deps1 = { step1Params.inputVolume }; | ||
outputs1 = { step1Params.outputVolume }; | ||
step1 = Step(@ReorientToStandard, ... | ||
step1Params, ... | ||
deps1, ... | ||
step1Config, ... | ||
outputs1); | ||
|
||
|
||
|
||
%% prepare the sequence | ||
% set up steps in order | ||
steps = { step1 }; | ||
|
||
% these files will be copied from the workspace to the output path | ||
outputs = { step1Params.outputVolume }; | ||
|
||
sequence = Sequence(steps, ... | ||
inputs, ... | ||
outputs, ... | ||
pathToWorkspace, ... | ||
pathToOutput, ... | ||
config.sequence); | ||
|
||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
% ensure variables are cleared | ||
clearvars; | ||
|
||
% ensure src/matlab and subfolders are in the path | ||
filePath = fileparts(which(mfilename)); | ||
addpath(genpath(fullfile(filePath, '../../matlab'))); | ||
|
||
% build configuration | ||
config = BuildFunctionalConnectivityConfiguration(); | ||
|
||
pipeline = BuildFunctionalConnectivityPipeline(config.pathToWorkspace, ... | ||
config.pathToDataset, ... | ||
config.pathToOutput, ... | ||
config.pathToOutput, ... | ||
config.numSubjects, ... | ||
config); | ||
|
||
pipelineExecution = pipeline.run(); | ||
|