Skip to content

Commit

Permalink
Merge branch 'develop' into 'master'
Browse files Browse the repository at this point in the history
Including the outlier censoring.
  • Loading branch information
ericearl committed Jan 27, 2020
2 parents 906de13 + 14fd6e9 commit 7acefb5
Show file tree
Hide file tree
Showing 7 changed files with 102 additions and 7 deletions.
6 changes: 6 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
mccExcludedFiles.log
readme.txt
requiredMCRProducts.txt
bin/
templates/parcellations/
*.asv
*.nii
*.mat
._*
32 changes: 28 additions & 4 deletions matlab_code/analyses_v2.m
Original file line number Diff line number Diff line change
Expand Up @@ -101,17 +101,41 @@ function analyses_v2(config_path)

disp('subject_motion_numbers_TXT_parse_BIDS complete')

subject_power_2014_FD_only_parse_BIDS(FD_movement_files, skip_seconds, ...
epi_TR, expected_contiguous_frame_count, result_dir, taskname)
mat_file = subject_power_2014_FD_only_parse_BIDS(FD_movement_files, skip_seconds, ...
epi_TR, expected_contiguous_frame_count, result_dir, taskname);
subject_power_2014_motion_parse_opt_BIDS(FD_movement_files, ...
skip_seconds, epi_TR, expected_contiguous_frame_count, result_dir, taskname)
skip_seconds, epi_TR, expected_contiguous_frame_count, result_dir, taskname);
motion_summary_BIDS([result_dir filesep taskname '_motion_numbers.mat'], ...
[result_dir filesep taskname '_power_2014_FD_only.mat'], result_dir, taskname);

%% Make the outlier mat files
dtseries = dir(fullfile(path_ciftis, '*.dtseries.nii'));
if ~isempty(dtseries)
dtseries_files = {};
for i = 1:length(dtseries)
dtseries_files{i} = fullfile(dtseries(i).folder,dtseries(i).name);
end
n_dtseries = length(dtseries_files);
disp([num2str(n_dtseries) ...
' individual dtseries files were identified'])
for i=1:n_dtseries
try
filename = dtseries_files{i};
[~, name, ~] = fileparts(filename);

subject_outliers_parse_BIDS(path_wb_c, mat_file, dtseries, ...
result_dir, taskname)

catch
disp([name 'does not exist'])
end
end
end

%% Make the csv timecourses
dummy = dir(fullfile(path_ciftis, '*ptseries*'));
if ~isempty(dummy)
ptseries_files = {}
ptseries_files = {};
for i = 1:length(dummy)
ptseries_files{i} = fullfile(dummy(i).folder,dummy(i).name);
end
Expand Down
Binary file not shown.
Binary file not shown.
27 changes: 27 additions & 0 deletions matlab_code/framewise_displacement/outlier_censoring.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
function output_removal_vector = outlier_censoring(wb_command, dtseries, input_removal_vector)

outlier_removal_vector = zeros(size(input_removal_vector,1), size(input_removal_vector,2));

[status,cmdout] = system([wb_command ' -cifti-stats ' dtseries ' -reduce STDEV']);

if status ~= 0
return
end

% parse standard deviation values
stdevs = cell2mat(textscan(cmdout, '%f\n'));

% find the kept frames
input_idx = find(~input_removal_vector);

% find outliers
outlier_vector = isoutlier(stdevs(input_idx),'median');

% find indices of outliers within the kept frames
outlier_idx = find(outlier_vector);

% put the outlier flags into the outliers vector as ones (to censor)
outlier_removal_vector( input_idx(outlier_idx) ) = 1;

% convert outliers flags vector to a strict logical vector
output_removal_vector = logical(outlier_removal_vector);
37 changes: 37 additions & 0 deletions matlab_code/framewise_displacement/subject_outliers_parse_BIDS.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
function subject_outliers_parse_BIDS(wb_command,motion_data_file,dtseries,output_dir,output_prefix)
% FD parsing Nipype wrapper pulling in list of motion files
% Modified to read DVAR_pre_reg, DVAR_post_reg, and DVAR_post_all and store
% values appropriately in the 51x51x3 cell array of structs
%
% All variables (skips, TR, CurrentDirectory) set within Nipype
% Iterates over range of values from 0.1 to maximum of 0.5 FD threshold
% Outputs to .mat file
% FD_movement_files = {'motion_numbers0.txt', 'motion_numbers1.txt', 'motion_numbers2.txt'};
% FD_movement_files can be TXT or DAT files
% varargin (brain_radius_in_mm) only needs to be provided for DAT file inputs

load(motion_data_file);
FD_range_max = motion_data{length(motion_data)}.FD_threshold;
FD_range = 0:0.01:FD_range_max;

for i = 1:length(motion_data)

motion_data{i}.fd_removal = motion_data{i}.frame_removal;
motion_data{i}.outlier_removal = double(outlier_censoring(wb_command, dtseries, motion_data{i}.frame_removal));
motion_data{i}.combined_removal = double(motion_data{i}.fd_removal | motion_data{i}.outlier_removal);

motion_data{i}.fd_format_string = format_generator(motion_data{i}.fd_removal);
motion_data{i}.outlier_format_string = format_generator(motion_data{i}.outlier_removal);
motion_data{i}.combined_format_string = format_generator(motion_data{i}.combined_removal);

motion_data{i}.remaining_fd_count = motion_data{i}.total_frame_count - sum(motion_data{i}.fd_removal);
motion_data{i}.remaining_outlier_count = motion_data{i}.total_frame_count - sum(motion_data{i}.outlier_removal);
motion_data{i}.remaining_combined_count = motion_data{i}.total_frame_count - sum(motion_data{i}.combined_removal);

motion_data{i}.remaining_fd_seconds = motion_data{i}.remaining_fd_count * motion_data{i}.epi_TR;
motion_data{i}.remaining_outlier_seconds = motion_data{i}.remaining_outlier_count * motion_data{i}.epi_TR;
motion_data{i}.remaining_combined_seconds = motion_data{i}.remaining_combined_count * motion_data{i}.epi_TR;

end

save([output_dir filesep output_prefix '_outliers_power_2014_FD_only.mat'],'motion_data');
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
function subject_power_2014_FD_only_parse_BIDS(movement_files,skip_seconds,epi_TR,expected_contiguous_frame_count,output_dir,output_prefix)
function output_mat = subject_power_2014_FD_only_parse_BIDS(movement_files,skip_seconds,epi_TR,expected_contiguous_frame_count,output_dir,output_prefix)
% FD parsing Nipype wrapper pulling in list of motion files
% Modified to read DVAR_pre_reg, DVAR_post_reg, and DVAR_post_all and store
% values appropriately in the 51x51x3 cell array of structs
Expand All @@ -10,7 +10,7 @@ function subject_power_2014_FD_only_parse_BIDS(movement_files,skip_seconds,epi_T
% FD_movement_files can be TXT or DAT files
% varargin (brain_radius_in_mm) only needs to be provided for DAT file inputs

FD_range = 0:0.01:0.5;
FD_range = 0:0.01:1.0;
motion_data = cell(1,length(FD_range));
run_count = length(movement_files);

Expand Down Expand Up @@ -57,4 +57,5 @@ function subject_power_2014_FD_only_parse_BIDS(movement_files,skip_seconds,epi_T

end
%this_path=pwd;
save([output_dir filesep output_prefix '_power_2014_FD_only.mat'],'motion_data');
output_mat = [output_dir filesep output_prefix '_power_2014_FD_only.mat'];
save(output_mat,'motion_data');

0 comments on commit 7acefb5

Please sign in to comment.