Skip to content

Commit

Permalink
add option to truncate timeseries
Browse files Browse the repository at this point in the history
  • Loading branch information
koenhelwegen committed Mar 21, 2023
1 parent df3ade5 commit ccb2cba
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 12 deletions.
3 changes: 2 additions & 1 deletion src/functional_pipeline/config_functional_default.json
Expand Up @@ -56,7 +56,7 @@
"reconstructionMethod": "corr",
"connectivityMatrixFile": "OUTPUTDIR/SUBJECT_connectivity_METHOD_TEMPLATE.mat",
"timeSeriesFile": "OUTPUTDIR/SUBJECT_time_series_METHOD_TEMPLATE.mat",
"minRepetitionTime": 100,
"minRepetitionTime": 100,
"regression":{
"regressionMask": [24,2,41,251,252,253,254,255],
"globalMeanRegression": false
Expand All @@ -65,6 +65,7 @@
"filter": true,
"frequencies": [0.01, 0.1]
},
"truncateFrames": 5,
"scrubbing":{
"scrubbing": true,
"maxFD": 0.25,
Expand Down
Binary file modified src/functional_pipeline/functionalParameterProperties.xlsx
Binary file not shown.
39 changes: 28 additions & 11 deletions src/functional_pipeline/reconstruction_functional_network.m
Expand Up @@ -41,6 +41,9 @@ function reconstruction_functional_network(configParams)
minRepetitionTime = configParams.(methods{iMethod}).minRepetitionTime;
bandpass_filter = configParams.(methods{iMethod}).bandpass_filter;

% Truncation parameters
truncateFrames = configParams.(methods{iMethod}).truncateFrames;

% Scrubbing parameters
scrubbing = configParams.(methods{iMethod}).scrubbing;
motionMetricsFile = configParams.compute_motion_metrics.motionMetricsFile;
Expand Down Expand Up @@ -235,7 +238,7 @@ function reconstruction_functional_network(configParams)
% Frames with a number of indicators larger or equal to
% minViolations are labeled as frames with potential motion
% artifacts and are excluded from further analysis.
outlierFrames = sum(violations, 1) >= scrubbing.minViolations;
framesToRemove = sum(violations, 1) >= scrubbing.minViolations;

% To accommodate temporal smoothing of data, frames consecutive to
% frames with labeled motion artifacts are optionally excluded:
Expand All @@ -244,29 +247,43 @@ function reconstruction_functional_network(configParams)
% succeeding frames to be excluded from further analysis.

% This is a convolution, but for clarity let's use a for-loop
outlierFramesextended = zeros(size(outlierFrames));
for i = 1:length(outlierFrames)
if outlierFrames(i) > 0
outlierFramesextended(i-scrubbing.backwardNeighbors:i+scrubbing.forwardNeighbors) = 1;
framesToRemoveExtended = zeros(size(framesToRemove));
for i = 1:length(framesToRemove)
if framesToRemove(i) > 0
framesToRemoveExtended(i-scrubbing.backwardNeighbors:i+scrubbing.forwardNeighbors) = 1;
end
end
outlierFrames = outlierFramesextended;
framesToRemove = framesToRemoveExtended;

fprintf('- scrubbing: remove %i frames\n', ...
nnz(outlierFrames));
nnz(framesToRemove));

else
outlierFrames = zeros(1, nTimePoints);
framesToRemove = zeros(1, nTimePoints);
end

numberOfScrubbedVolumes = nnz(outlierFrames); %#ok
%% Truncation
% Truncation is advisable when using bandpass filtering as filtering
% can potentially introduce artefacts at the beginning and end of the
% timeseries.

if truncateFrames > 0
removedPrior = nnz(framesToRemove);
framesToRemove = framesToRemove | [true(1, truncateFrames), false(1, nTimePoints-2*truncateFrames), true(1, truncateFrames)];
fprintf('- truncating: remove additional %i frames\n', ...
nnz(framesToRemove) - removedPrior);
end

%% Apply scrubbing & truncation

numberOfScrubbedVolumes = nnz(framesToRemove); %#ok

% calculate average motion metric over remaining frames
selectedFrames = find(~outlierFrames);
selectedFrames = find(~framesToRemove);
motionMetrics = mean(motionMetrics(:, selectedFrames(2:end)), 2); %#ok

% Compose final filtered, regressed and scrubbed time series
selectedTimeSeries = signalIntensities(:, ~outlierFrames);
selectedTimeSeries = signalIntensities(:, ~framesToRemove);
clear signalIntensities

%% Correlate
Expand Down

0 comments on commit ccb2cba

Please sign in to comment.