Skip to content

Commit

Permalink
Update PreCompMotionCorrection.m
Browse files Browse the repository at this point in the history
  • Loading branch information
mnoergaard committed Oct 6, 2023
1 parent 6bbe55e commit d687c12
Showing 1 changed file with 21 additions and 17 deletions.
38 changes: 21 additions & 17 deletions functions/PreCompMotionCorrection.m
Original file line number Diff line number Diff line change
Expand Up @@ -8,37 +8,41 @@
for idx = 1:numel(BIDS.subjects)
subj = BIDS.subjects(idx).name;
ses = BIDS.subjects(idx).session;

if ~isempty(BIDS.subjects(idx).pet)
file = fullfile(BIDS.subjects(idx).path, 'pet', BIDS.subjects(idx).pet(1).filename);

output_name = fullfile(output_dir, subj, ses, ...
'pet', [subj '_' ses '_desc-mc_pet.nii.gz']);

output_json = fullfile(output_dir, subj, ses, ...
'pet', [subj '_' ses '_desc-mc_pet.json']);

output_confounds = fullfile(output_dir, subj, ses, ...
'pet', [subj '_' ses '_desc-confounds_timeseries.tsv']);

mc_dir = dir([BIDS.pth '/derivatives/hmc_workflow/*' erase(ses,'ses-') '*' strrep(BIDS.subjects(idx).name(end-2:end),'-','_') ]);
mc_file = fullfile(mc_dir.folder, mc_dir.name, 'concat_frames/mc.nii.gz');
movement = fullfile(mc_dir.folder, mc_dir.name, 'plot_motion/movement.png');
rotation = fullfile(mc_dir.folder, mc_dir.name, 'plot_motion/rotation.png');
translation = fullfile(mc_dir.folder, mc_dir.name, 'plot_motion/translation.png');
confounds = fullfile(mc_dir.folder, mc_dir.name, 'hmc_movement_output/hmc_confounds.tsv');


mc_file = fullfile([BIDS.pth '/derivatives/petprep_hmc/' subj '/' ses '/' subj '_' ses '_desc-mc_pet.nii.gz']);
mc_json = fullfile([BIDS.pth '/derivatives/petprep_hmc/' subj '/' ses '/' subj '_' ses '_desc-mc_pet.json']);
movement = fullfile([BIDS.pth '/derivatives/petprep_hmc/' subj '/' ses '/' subj '_' ses '_movement.png']);
rotation = fullfile([BIDS.pth '/derivatives/petprep_hmc/' subj '/' ses '/' subj '_' ses '_rotation.png']);
translation = fullfile([BIDS.pth '/derivatives/petprep_hmc/' subj '/' ses '/' subj '_' ses '_translation.png']);
confounds = fullfile([BIDS.pth '/derivatives/petprep_hmc/' subj '/' ses '/' subj '_' ses '_desc-confounds_timeseries.tsv']);
nmc_plot = fullfile([BIDS.pth '/derivatives/petprep_hmc/' subj '/' ses '/' subj '_' ses '_desc-without_motion_correction.gif']);
mc_plot = fullfile([BIDS.pth '/derivatives/petprep_hmc/' subj '/' ses '/' subj '_' ses '_desc-with_motion_correction.gif']);

if exist(mc_file,"file")
mkdir(fullfile(output_dir, 'logs', subj))
copyfile(mc_file, output_name);
copyfile(mc_json, output_json);
copyfile(confounds, output_confounds);
copyfile(movement, fullfile(output_dir, 'logs', subj, [subj '_' ses '_movement.png']))
copyfile(rotation, fullfile(output_dir, 'logs', subj, [subj '_' ses '_rotation.png']))
copyfile(translation, fullfile(output_dir, 'logs', subj, [subj '_' ses '_translation.png']))
copyfile(nmc_plot, fullfile(output_dir, 'logs', subj, [subj '_' ses '_desc-without_motion_correction.gif']))
copyfile(mc_plot, fullfile(output_dir, 'logs', subj, [subj '_' ses '_desc-with_motion_correction.gif']))

mc = struct;
mc.Description = 'Motion-corrected PET file';
mc.Sources = erase(file,pwd);
mc.ReferenceImage = 'Robust template using mri_robust_register';
mc.CostFunction = 'ROB';
mc.QC = '';
mc.SoftwareName = 'PETPrep HMC workflow';
mc.SoftwareVersion = 'v. 0.0.1';
bids.util.jsonwrite(fullfile(output_dir, subj, ses, ...
'pet', [subj '_' ses '_desc-mc_pet.json']),mc);
end
end
end

0 comments on commit d687c12

Please sign in to comment.