Permalink
Cannot retrieve contributors at this time
Name already in use
A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
NMR_OPTIMA_BIDS/OPTIMA_convert_GE_BIDS_4.m
Go to fileThis commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
191 lines (174 sloc)
12.2 KB
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
function OPTIMA_convert_GE_BIDS_4(BIDS, biomax_table) | |
% | |
% performes dicom2niix and saves data in BIDS format | |
% | |
% Required fields of convert_GE_BIDS: | |
% | |
% BIDS - BIDS structure | |
% biomax_table - biomax_out information in table format | |
% | |
% | |
% file history: | |
% created M. Czisch & F. Binder 20.11.2017 | |
% adapted to inclue SIT1 M. Czisch 17.7.2019 | |
% last edited M. Czisch 15.10.2020 | |
test_flag = 0; % if test then 1 | |
% flags are introduced to mark already processed files | |
flag_RSN2 = 0; | |
flag_RSN3 = 0; | |
fprintf('converting GE files\n'); | |
cmd_str = sprintf('date >> %s/func/logfile_%s_%s_func_dcm2nii.txt',BIDS.output.dir, BIDS.input.data_dir(1).FamilyName{3}, BIDS.input.data_dir(1).GivenName{3}); | |
if ~test_flag system(cmd_str); end | |
cmd_str = sprintf('date >> %s/anat/logfile_%s_%s_anat_dcm2nii.txt',BIDS.output.dir, BIDS.input.data_dir(1).FamilyName{3}, BIDS.input.data_dir(1).GivenName{3}); | |
if ~test_flag system(cmd_str); end | |
cmd_str = sprintf('date >> %s/dwi/logfile_%s_%s_dwi_dcm2nii.txt',BIDS.output.dir, BIDS.input.data_dir(1).FamilyName{3}, BIDS.input.data_dir(1).GivenName{3}); | |
if ~test_flag system(cmd_str); end | |
cmd_str = sprintf('mkdir %s/dicom',BIDS.output.dir); system(cmd_str); | |
number_of_days = size(BIDS.input.data_dir,2); | |
for i = 1:number_of_days % loop over days | |
max = size(BIDS.input.data_dir(i).subdir,2); | |
if i == 1 | |
cd([BIDS.input.dir,'/',BIDS.input.data_dir(1).name]); | |
for j = 3:max %ignore '.' and '..' | |
if strcmp(BIDS.input.data_dir(i).SeriesDescription{j},'Sag FSPGR BRAVO 1x1x1mm') | |
if biomax_table{{'T1w'},{'Ser'}} | |
cmd_str = sprintf('dcm2niix -f sub-%s_%s_T1w -z y -o %s/anat %s >> %s/anat/logfile_%s_%s_anat_dcm2nii.txt',... | |
BIDS.input.data_dir(1).FamilyName{j}, BIDS.input.data_dir(1).GivenName{j}, BIDS.output.dir, ... | |
BIDS.input.data_dir(i).subdir{j}, BIDS.output.dir, BIDS.input.data_dir(1).FamilyName{j}, BIDS.input.data_dir(1).GivenName{j}); | |
fprintf('\n%s', cmd_str); | |
if ~test_flag | |
system(cmd_str); | |
cmd_str = sprintf('cp %s/*MRDC.1 %s/dicom/sub-%s_%s_T1w.dicom.1 >> %s/anat/logfile_%s_%s_anat_dcm2nii.txt', ... | |
BIDS.input.data_dir(i).subdir{j}, BIDS.output.dir, BIDS.input.data_dir(1).FamilyName{j}, BIDS.input.data_dir(1).GivenName{j}, ... | |
BIDS.output.dir, BIDS.input.data_dir(1).FamilyName{j}, BIDS.input.data_dir(1).GivenName{j}); | |
system(cmd_str); | |
end | |
end | |
end | |
if strcmp(BIDS.input.data_dir(i).SeriesDescription{j},'fMRI rest') | |
if biomax_table{{'rest1'},{'Ser'}} | |
cmd_str = sprintf('dcm2niix -f sub-%s_%s_task-rest_run-1_bold -z y -o %s/func %s >> %s/func/logfile_%s_%s_func_dcm2nii.txt',... | |
BIDS.input.data_dir(1).FamilyName{j}, BIDS.input.data_dir(1).GivenName{j}, ... | |
BIDS.output.dir, BIDS.input.data_dir(i).subdir{j}, ... | |
BIDS.output.dir, BIDS.input.data_dir(1).FamilyName{j}, BIDS.input.data_dir(1).GivenName{j}); | |
fprintf('\n%s', cmd_str); | |
if ~test_flag | |
system(cmd_str); | |
filename = sprintf('%s/func/sub-%s_%s_task-rest_run-1_bold.json',BIDS.output.dir,BIDS.input.data_dir(1).FamilyName{j}, BIDS.input.data_dir(1).GivenName{j}); | |
OPTIMA_dataset_func_description_BIDS_4(BIDS,filename, biomax_table{{'rest1'},:}); | |
cmd_str = sprintf('cp %s/*MRDC.1 %s/dicom/sub-%s_%s_task-rest_run-1_bold.dicom.1 >> %s/func/logfile_%s_%s_func_dcm2nii.txt', ... | |
BIDS.input.data_dir(i).subdir{j}, BIDS.output.dir, BIDS.input.data_dir(1).FamilyName{j}, BIDS.input.data_dir(1).GivenName{j}, ... | |
BIDS.output.dir, BIDS.input.data_dir(1).FamilyName{j}, BIDS.input.data_dir(1).GivenName{j}); | |
system(cmd_str); | |
cmd_str = sprintf('touch %s/func/sub-%s_%s_task-rest_run-1_bold_README.txt >> %s/func/logfile_%s_%s_func_dcm2nii.txt',... | |
BIDS.output.dir, BIDS.input.data_dir(1).FamilyName{j}, BIDS.input.data_dir(1).GivenName{j}, ... | |
BIDS.output.dir, BIDS.input.data_dir(1).FamilyName{j}, BIDS.input.data_dir(1).GivenName{j}); | |
fprintf('\n%s', cmd_str); | |
system(cmd_str); | |
end | |
end | |
end | |
if strcmp(BIDS.input.data_dir(i).SeriesDescription{j},'EPI segmentation T2w') | |
if biomax_table{{'EPI1'},{'Ser'}} | |
cmd_str = sprintf('dcm2niix -f sub-%s_%s_inplaneT2star_run-1 -z y -o %s/anat %s >> %s/anat/logfile_%s_%s_anat_dcm2nii.txt',... | |
BIDS.input.data_dir(1).FamilyName{j}, BIDS.input.data_dir(1).GivenName{j}, BIDS.output.dir, BIDS.input.data_dir(i).subdir{j}, ... | |
BIDS.output.dir, BIDS.input.data_dir(1).FamilyName{j}, BIDS.input.data_dir(1).GivenName{j}); | |
fprintf('\n%s', cmd_str); | |
if ~test_flag | |
system(cmd_str); | |
cmd_str = sprintf('cp %s/*MRDC.1 %s/dicom/sub-%s_%s_inplaneT2star_run-1.dicom.1 >> %s/anat/logfile_%s_%s_anat_dcm2nii.txt', ... | |
BIDS.input.data_dir(i).subdir{j}, BIDS.output.dir, BIDS.input.data_dir(1).FamilyName{j}, BIDS.input.data_dir(1).GivenName{j}, ... | |
BIDS.output.dir, BIDS.input.data_dir(1).FamilyName{j}, BIDS.input.data_dir(1).GivenName{j}); | |
system(cmd_str); | |
end | |
end | |
end | |
if strcmp(BIDS.input.data_dir(i).SeriesDescription{j},'Ax T2 FLAIR') | |
if biomax_table{{'FLAIR'},{'Ser'}} | |
cmd_str = sprintf('dcm2niix -f sub-%s_%s_FLAIR -z y -o %s/anat %s >> %s/anat/logfile_%s_%s_anat_dcm2nii.txt',... | |
BIDS.input.data_dir(1).FamilyName{j}, BIDS.input.data_dir(1).GivenName{j}, ... | |
BIDS.output.dir, BIDS.input.data_dir(i).subdir{j}, ... | |
BIDS.output.dir, BIDS.input.data_dir(1).FamilyName{j}, BIDS.input.data_dir(1).GivenName{j}); | |
fprintf('\n%s', cmd_str); | |
if ~test_flag | |
system(cmd_str); | |
cmd_str = sprintf('cp %s/*MRDC.1 %s/dicom/sub-%s_%s_FLAIR.dicom.1 >> %s/anat/logfile_%s_%s_anat_dcm2nii.txt', ... | |
BIDS.input.data_dir(i).subdir{j}, ... | |
BIDS.output.dir, BIDS.input.data_dir(1).FamilyName{j}, BIDS.input.data_dir(1).GivenName{j}, ... | |
BIDS.output.dir, BIDS.input.data_dir(1).FamilyName{j}, BIDS.input.data_dir(1).GivenName{j}); | |
system(cmd_str); | |
end | |
end | |
end | |
if logical(strfind(BIDS.input.data_dir(i).SeriesDescription{j},'fMRI SIT1')) | |
if biomax_table{{'SIT1'},{'Ser'}} | |
cmd_str = sprintf('dcm2niix -f sub-%s_%s_task-sit1_bold -z y -o %s/func %s >> %s/func/logfile_%s_%s_func_dcm2nii.txt',... | |
BIDS.input.data_dir(1).FamilyName{j}, BIDS.input.data_dir(1).GivenName{j}, ... | |
BIDS.output.dir, BIDS.input.data_dir(i).subdir{j}, ... | |
BIDS.output.dir, BIDS.input.data_dir(1).FamilyName{j}, BIDS.input.data_dir(1).GivenName{j}); | |
fprintf('\n%s', cmd_str); | |
if ~test_flag | |
system(cmd_str); | |
filename = sprintf('%s/func/sub-%s_%s_task-sit1_bold.json',BIDS.output.dir,BIDS.input.data_dir(1).FamilyName{j}, BIDS.input.data_dir(1).GivenName{j}); | |
OPTIMA_dataset_func_description_BIDS_5(BIDS,filename, biomax_table{{'SIT1'},:}); | |
cmd_str = sprintf('cp %s/*MRDC.1 %s/dicom/sub-%s_%s_task-sit1_bold.dicom.1 >> %s/func/logfile_%s_%s_func_dcm2nii.txt', ... | |
BIDS.input.data_dir(i).subdir{j}, ... | |
BIDS.output.dir, BIDS.input.data_dir(1).FamilyName{j}, BIDS.input.data_dir(1).GivenName{j}, ... | |
BIDS.output.dir, BIDS.input.data_dir(1).FamilyName{j}, BIDS.input.data_dir(1).GivenName{j}); | |
system(cmd_str); | |
cmd_str = sprintf('touch %s/func/sub-%s_%s_task-sit1_bold_README.txt >> %s/func/logfile_%s_%s_func_dcm2nii.txt',... | |
BIDS.output.dir, BIDS.input.data_dir(1).FamilyName{j}, BIDS.input.data_dir(1).GivenName{j}, ... | |
BIDS.output.dir, BIDS.input.data_dir(1).FamilyName{j}, BIDS.input.data_dir(1).GivenName{j}); | |
fprintf('\n%s', cmd_str); | |
system(cmd_str); | |
end | |
end | |
end | |
if strcmp(BIDS.input.data_dir(i).SeriesDescription{j},'DTI 2.0 DSE 66 Dir Nex1') | |
if biomax_table{{'DTI'},{'Ser'}} | |
cmd_str = sprintf('dcm2niix -f sub-%s_%s_run-1_dwi -z y -o %s/dwi %s >> %s/dwi/logfile_%s_%s_dwi_dcm2nii.txt',... | |
BIDS.input.data_dir(1).FamilyName{j}, BIDS.input.data_dir(1).GivenName{j}, ... | |
BIDS.output.dir, BIDS.input.data_dir(i).subdir{j}, ... | |
BIDS.output.dir, BIDS.input.data_dir(1).FamilyName{j}, BIDS.input.data_dir(1).GivenName{j}); | |
fprintf('\n%s', cmd_str); | |
if ~test_flag | |
system(cmd_str); | |
cmd_str = sprintf('cp %s/*MRDC.1 %s/dicom/sub-%s_%s_run-1_dwi.dicom.1 >> %s/dwi/logfile_%s_%s_dwi_dcm2nii.txt', ... | |
BIDS.input.data_dir(i).subdir{j}, ... | |
BIDS.output.dir, BIDS.input.data_dir(1).FamilyName{j}, BIDS.input.data_dir(1).GivenName{j}, ... | |
BIDS.output.dir, BIDS.input.data_dir(1).FamilyName{j}, BIDS.input.data_dir(1).GivenName{j}); | |
system(cmd_str); | |
end | |
end | |
end | |
if logical(strfind(BIDS.input.data_dir(i).SeriesDescription{j},'polar')) | |
if biomax_table{{'Pepolar'},{'Ser'}} | |
% check number of dicom slices | |
% and delete incomplete volumes | |
tmp_str = sprintf('%s/i*MRDC*', BIDS.input.data_dir(i).subdir{j}); | |
tmp = dir(tmp_str); | |
n_images = size(tmp,1); | |
full_images = fix(n_images/double(BIDS.input.data_dir(i).N_of_slices{j})); %adapt 60 | |
for b = (full_images*BIDS.input.data_dir(i).N_of_slices{j})+1:n_images | |
cmd_str = ['rm ', BIDS.input.data_dir(i).subdir{j},'/', tmp(b).name]; | |
system(cmd_str); | |
end | |
cmd_str = sprintf('dcm2niix -f sub-%s_%s_run-2_dwi -z y -o %s/dwi %s >> %s/dwi/logfile_%s_%s_dwi_dcm2nii.txt',... | |
BIDS.input.data_dir(1).FamilyName{j}, BIDS.input.data_dir(1).GivenName{j}, ... | |
BIDS.output.dir, BIDS.input.data_dir(i).subdir{j}, ... | |
BIDS.output.dir, BIDS.input.data_dir(1).FamilyName{j}, BIDS.input.data_dir(1).GivenName{j}); | |
fprintf('\n%s', cmd_str); | |
if ~test_flag | |
system(cmd_str); | |
cmd_str = sprintf('cp %s/*MRDC.1 %s/dicom/sub-%s_%s_run-2_dwi.dicom.1 >> %s/dwi/logfile_%s_%s_dwi_dcm2nii.txt', ... | |
BIDS.input.data_dir(i).subdir{j}, ... | |
BIDS.output.dir, BIDS.input.data_dir(1).FamilyName{j}, BIDS.input.data_dir(1).GivenName{j}, ... | |
BIDS.output.dir, BIDS.input.data_dir(1).FamilyName{j}, BIDS.input.data_dir(1).GivenName{j}); | |
system(cmd_str); | |
end | |
end | |
end | |
end | |
end | |
end | |
cd([BIDS.input.dir]); |