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.m
Go to fileThis commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
302 lines (272 sloc)
20.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(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 | |
% last edited M. Czisch 27.3.2018 | |
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_func_dcm2nii.txt',BIDS.output.dir, BIDS.input.data_dir(1).PatientID{3}); | |
if ~test_flag system(cmd_str); end | |
cmd_str = sprintf('date >> %s/anat/logfile_%s_anat_dcm2nii.txt',BIDS.output.dir, BIDS.input.data_dir(1).PatientID{3}); | |
if ~test_flag system(cmd_str); end | |
cmd_str = sprintf('date >> %s/dwi/logfile_%s_dwi_dcm2nii.txt',BIDS.output.dir, BIDS.input.data_dir(1).PatientID{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_T1w -z y -o %s/anat %s >> %s/anat/logfile_%s_anat_dcm2nii.txt',... | |
BIDS.input.data_dir(i).PatientID{j}, BIDS.output.dir, BIDS.input.data_dir(i).subdir{j}, BIDS.output.dir, BIDS.input.data_dir(1).PatientID{3}); | |
fprintf('\n%s', cmd_str); | |
if ~test_flag | |
system(cmd_str); | |
cmd_str = sprintf('cp %s/*MRDC.1 %s/dicom/sub-%s_T1w.dicom.1 >> %s/anat/logfile_%s_anat_dcm2nii.txt', ... | |
BIDS.input.data_dir(i).subdir{j}, BIDS.output.dir, BIDS.input.data_dir(i).PatientID{j}, BIDS.output.dir, BIDS.input.data_dir(1).PatientID{3}); | |
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_task-rest_run-1_bold -z y -o %s/func %s >> %s/func/logfile_%s_func_dcm2nii.txt',... | |
BIDS.input.data_dir(i).PatientID{j}, BIDS.output.dir, BIDS.input.data_dir(i).subdir{j}, BIDS.output.dir, BIDS.input.data_dir(1).PatientID{3}); | |
fprintf('\n%s', cmd_str); | |
if ~test_flag | |
system(cmd_str); | |
filename = sprintf('%s/func/sub-%s_task-rest_run-1_bold.json',BIDS.output.dir,BIDS.input.data_dir(i).PatientID{j}); | |
dataset_func_description_BIDS(BIDS,filename, biomax_table{{'rest1'},:}); | |
cmd_str = sprintf('cp %s/*MRDC.1 %s/dicom/sub-%s_task-rest_run-1_bold.dicom.1 >> %s/func/logfile_%s_func_dcm2nii.txt', ... | |
BIDS.input.data_dir(i).subdir{j}, BIDS.output.dir, BIDS.input.data_dir(i).PatientID{j}, BIDS.output.dir, BIDS.input.data_dir(1).PatientID{3}); | |
system(cmd_str); | |
cmd_str = sprintf('touch %s/func/sub-%s_task-rest_run-1_bold_README.txt >> %s/func/logfile_%s_func_dcm2nii.txt',... | |
BIDS.output.dir, BIDS.input.data_dir(i).PatientID{j}, BIDS.output.dir, BIDS.input.data_dir(1).PatientID{3}); | |
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_inplaneT2star_run-1 -z y -o %s/anat %s >> %s/anat/logfile_%s_anat_dcm2nii.txt',... | |
BIDS.input.data_dir(i).PatientID{j}, BIDS.output.dir, BIDS.input.data_dir(i).subdir{j}, BIDS.output.dir, BIDS.input.data_dir(1).PatientID{3}); | |
fprintf('\n%s', cmd_str); | |
if ~test_flag | |
system(cmd_str); | |
cmd_str = sprintf('cp %s/*MRDC.1 %s/dicom/sub-%s_inplaneT2star_run-1.dicom.1 >> %s/anat/logfile_%s_anat_dcm2nii.txt', ... | |
BIDS.input.data_dir(i).subdir{j}, BIDS.output.dir, BIDS.input.data_dir(i).PatientID{j}, BIDS.output.dir, BIDS.input.data_dir(1).PatientID{3}); | |
system(cmd_str); | |
end; | |
end | |
end | |
if strcmp(BIDS.input.data_dir(i).SeriesDescription{j},'fMRI TET') | |
if biomax_table{{'TET'},{'Ser'}} | |
cmd_str = sprintf('dcm2niix -f sub-%s_task-tet_bold -z y -o %s/func %s >> %s/func/logfile_%s_func_dcm2nii.txt',... | |
BIDS.input.data_dir(i).PatientID{j}, BIDS.output.dir, BIDS.input.data_dir(i).subdir{j}, BIDS.output.dir, BIDS.input.data_dir(1).PatientID{3}); | |
fprintf('\n%s', cmd_str); | |
if ~test_flag | |
system(cmd_str); | |
filename = sprintf('%s/func/sub-%s_task-tet_bold.json',BIDS.output.dir,BIDS.input.data_dir(i).PatientID{j}); | |
dataset_func_description_BIDS(BIDS,filename, biomax_table{{'TET'},:}); | |
cmd_str = sprintf('cp %s/*MRDC.1 %s/dicom/sub-%s_task-tet_bold.dicom.1 >> %s/func/logfile_%s_func_dcm2nii.txt', ... | |
BIDS.input.data_dir(i).subdir{j}, BIDS.output.dir, BIDS.input.data_dir(i).PatientID{j}, BIDS.output.dir, BIDS.input.data_dir(1).PatientID{3}); | |
system(cmd_str); | |
cmd_str = sprintf('touch %s/func/sub-%s_task-tet_bold_README.txt >> %s/func/logfile_%s_func_dcm2nii.txt',... | |
BIDS.output.dir, BIDS.input.data_dir(i).PatientID{j}, BIDS.output.dir, BIDS.input.data_dir(1).PatientID{3}); | |
fprintf('\n%s', cmd_str); | |
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_FLAIR -z y -o %s/anat %s >> %s/anat/logfile_%s_anat_dcm2nii.txt',... | |
BIDS.input.data_dir(i).PatientID{j}, BIDS.output.dir, BIDS.input.data_dir(i).subdir{j}, BIDS.output.dir, BIDS.input.data_dir(1).PatientID{3}); | |
fprintf('\n%s', cmd_str); | |
if ~test_flag | |
system(cmd_str); | |
cmd_str = sprintf('cp %s/*MRDC.1 %s/dicom/sub-%s_FLAIR.dicom.1 >> %s/anat/logfile_%s_anat_dcm2nii.txt', ... | |
BIDS.input.data_dir(i).subdir{j}, BIDS.output.dir, BIDS.input.data_dir(i).PatientID{j}, BIDS.output.dir, BIDS.input.data_dir(1).PatientID{3}); | |
system(cmd_str); | |
end; | |
end | |
end | |
if strcmp(BIDS.input.data_dir(i).SeriesDescription{j},'fMRI reward') | |
if biomax_table{{'Reward'},{'Ser'}} | |
cmd_str = sprintf('dcm2niix -f sub-%s_task-reward_bold -z y -o %s/func %s >> %s/func/logfile_%s_func_dcm2nii.txt',... | |
BIDS.input.data_dir(i).PatientID{j}, BIDS.output.dir, BIDS.input.data_dir(i).subdir{j}, BIDS.output.dir, BIDS.input.data_dir(1).PatientID{3}); | |
fprintf('\n%s', cmd_str); | |
if ~test_flag | |
system(cmd_str); | |
filename = sprintf('%s/func/sub-%s_task-reward_bold.json',BIDS.output.dir,BIDS.input.data_dir(i).PatientID{j}); | |
dataset_func_description_BIDS(BIDS,filename, biomax_table{{'Reward'},:}); | |
cmd_str = sprintf('cp %s/*MRDC.1 %s/dicom/sub-%s_task-reward_bold.dicom.1 >> %s/func/logfile_%s_func_dcm2nii.txt', ... | |
BIDS.input.data_dir(i).subdir{j}, BIDS.output.dir, BIDS.input.data_dir(i).PatientID{j}, BIDS.output.dir, BIDS.input.data_dir(1).PatientID{3}); | |
system(cmd_str); | |
cmd_str = sprintf('touch %s/func/sub-%s_task-reward_bold_README.txt >> %s/func/logfile_%s_func_dcm2nii.txt',... | |
BIDS.output.dir, BIDS.input.data_dir(i).PatientID{j}, BIDS.output.dir, BIDS.input.data_dir(1).PatientID{3}); | |
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_run-1_dwi -z y -o %s/dwi %s >> %s/dwi/logfile_%s_dwi_dcm2nii.txt',... | |
BIDS.input.data_dir(i).PatientID{j}, BIDS.output.dir, BIDS.input.data_dir(i).subdir{j}, BIDS.output.dir, BIDS.input.data_dir(1).PatientID{3}); | |
fprintf('\n%s', cmd_str); | |
if ~test_flag | |
system(cmd_str); | |
cmd_str = sprintf('cp %s/*MRDC.1 %s/dicom/sub-%s_run-1_dwi.dicom.1 >> %s/dwi/logfile_%s_dwi_dcm2nii.txt', ... | |
BIDS.input.data_dir(i).subdir{j}, BIDS.output.dir, BIDS.input.data_dir(i).PatientID{j}, BIDS.output.dir, BIDS.input.data_dir(1).PatientID{3}); | |
system(cmd_str); | |
end; | |
end | |
end | |
if logical(strfind(BIDS.input.data_dir(i).SeriesDescription{j},'polar')) | |
if biomax_table{{'Pepolar'},{'Ser'}} | |
cmd_str = sprintf('dcm2niix -f sub-%s_run-2_dwi -z y -o %s/dwi %s >> %s/dwi/logfile_%s_dwi_dcm2nii.txt',... | |
BIDS.input.data_dir(i).PatientID{j}, BIDS.output.dir, BIDS.input.data_dir(i).subdir{j}, BIDS.output.dir, BIDS.input.data_dir(1).PatientID{3}); | |
fprintf('\n%s', cmd_str); | |
if ~test_flag | |
system(cmd_str); | |
cmd_str = sprintf('cp %s/*MRDC.1 %s/dicom/sub-%s_run-2_dwi.dicom.1 >> %s/dwi/logfile_%s_dwi_dcm2nii.txt', ... | |
BIDS.input.data_dir(i).subdir{j}, BIDS.output.dir, BIDS.input.data_dir(i).PatientID{j}, BIDS.output.dir, BIDS.input.data_dir(1).PatientID{3}); | |
system(cmd_str); | |
end; | |
end | |
end | |
if strcmp(BIDS.input.data_dir(i).SeriesDescription{j},'fMRI n-back') | |
if biomax_table{{'nback'},{'Ser'}} | |
cmd_str = sprintf('dcm2niix -f sub-%s_task-nback_bold -z y -o %s/func %s >> %s/func/logfile_%s_func_dcm2nii.txt',... | |
BIDS.input.data_dir(i).PatientID{j}, BIDS.output.dir, BIDS.input.data_dir(i).subdir{j}, BIDS.output.dir, BIDS.input.data_dir(1).PatientID{3}); | |
fprintf('\n%s', cmd_str); | |
if ~test_flag | |
system(cmd_str); | |
filename = sprintf('%s/func/sub-%s_task-nback_bold.json',BIDS.output.dir,BIDS.input.data_dir(i).PatientID{j}); | |
dataset_func_description_BIDS(BIDS,filename, biomax_table{{'nback'},:}); | |
cmd_str = sprintf('cp %s/*MRDC.1 %s/dicom/sub-%s_task-nback_bold.dicom.1 >> %s/func/logfile_%s_func_dcm2nii.txt', ... | |
BIDS.input.data_dir(i).subdir{j}, BIDS.output.dir, BIDS.input.data_dir(i).PatientID{j}, BIDS.output.dir, BIDS.input.data_dir(1).PatientID{3}); | |
system(cmd_str); | |
cmd_str = sprintf('touch %s/func/sub-%s_task-nback_bold_README.txt >> %s/func/logfile_%s_func_dcm2nii.txt',... | |
BIDS.output.dir, BIDS.input.data_dir(i).PatientID{j}, BIDS.output.dir, BIDS.input.data_dir(1).PatientID{3}); | |
fprintf('\n%s', cmd_str); | |
system(cmd_str); | |
end; | |
end | |
end | |
end | |
elseif i==2 | |
cd([BIDS.input.dir,'/',BIDS.input.data_dir(2).name]); | |
for j = 3:max %ignore '.' and '..' | |
if strcmp(BIDS.input.data_dir(i).SeriesDescription{j},'fMRI faces') | |
if biomax_table{{'faces'},{'Ser'}} | |
%check_slice_order(BIDS.input.data_dir(i).subdir{j}); | |
cmd_str = sprintf('dcm2niix -f sub-%s_task-hariri_bold -z y -o %s/func %s >> %s/func/logfile_%s_func_dcm2nii.txt',... | |
BIDS.input.data_dir(i).PatientID{j}, BIDS.output.dir, BIDS.input.data_dir(i).subdir{j}, BIDS.output.dir, BIDS.input.data_dir(1).PatientID{3}); | |
fprintf('\n%s', cmd_str); | |
if ~test_flag | |
system(cmd_str); | |
filename = sprintf('%s/func/sub-%s_task-hariri_bold.json',BIDS.output.dir,BIDS.input.data_dir(i).PatientID{j}); | |
dataset_func_description_BIDS(BIDS,filename, biomax_table{{'faces'},:}); | |
cmd_str = sprintf('cp %s/*MRDC.1 %s/dicom/sub-%s_task-hariri_bold.dicom.1 >> %s/func/logfile_%s_func_dcm2nii.txt', ... | |
BIDS.input.data_dir(i).subdir{j}, BIDS.output.dir, BIDS.input.data_dir(i).PatientID{j}, BIDS.output.dir, BIDS.input.data_dir(1).PatientID{3}); | |
system(cmd_str); | |
cmd_str = sprintf('touch %s/func/sub-%s_task-hariri_bold_README.txt >> %s/func/logfile_%s_func_dcm2nii.txt',... | |
BIDS.output.dir, BIDS.input.data_dir(i).PatientID{j}, BIDS.output.dir, BIDS.input.data_dir(1).PatientID{3}); | |
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{{'EPI2'},{'Ser'}} | |
cmd_str = sprintf('dcm2niix -f sub-%s_inplaneT2star_run-2 -z y -o %s/anat %s >> %s/anat/logfile_%s_anat_dcm2nii.txt',... | |
BIDS.input.data_dir(i).PatientID{j}, BIDS.output.dir, BIDS.input.data_dir(i).subdir{j}, BIDS.output.dir, BIDS.input.data_dir(1).PatientID{3}); | |
fprintf('\n%s', cmd_str); | |
if ~test_flag | |
system(cmd_str); | |
cmd_str = sprintf('cp %s/*MRDC.1 %s/dicom/sub-%s_inplaneT2star_run-2.dicom.1 >> %s/anat/logfile_%s_anat_dcm2nii.txt', ... | |
BIDS.input.data_dir(i).subdir{j}, BIDS.output.dir, BIDS.input.data_dir(i).PatientID{j}, BIDS.output.dir, BIDS.input.data_dir(1).PatientID{3}); | |
system(cmd_str); | |
end; | |
end | |
end | |
if strcmp(BIDS.input.data_dir(i).SeriesDescription{j},'fMRI rest') & ~flag_RSN2 | |
if biomax_table{{'rest2'},{'Ser'}} | |
cmd_str = sprintf('dcm2niix -f sub-%s_task-rest_run-2_bold -z y -o %s/func %s >> %s/func/logfile_%s_func_dcm2nii.txt',... | |
BIDS.input.data_dir(i).PatientID{j}, BIDS.output.dir, BIDS.input.data_dir(i).subdir{j}, BIDS.output.dir, BIDS.input.data_dir(1).PatientID{3}); | |
fprintf('\n%s', cmd_str); | |
if ~test_flag | |
system(cmd_str); | |
filename = sprintf('%s/func/sub-%s_task-rest_run-2_bold.json',BIDS.output.dir,BIDS.input.data_dir(i).PatientID{j}); | |
dataset_func_description_BIDS(BIDS,filename, biomax_table{{'rest2'},:}); | |
cmd_str = sprintf('cp %s/*MRDC.1 %s/dicom/sub-%s_task-rest_run-2_bold.dicom.1 >> %s/func/logfile_%s_func_dcm2nii.txt', ... | |
BIDS.input.data_dir(i).subdir{j}, BIDS.output.dir, BIDS.input.data_dir(i).PatientID{j}, BIDS.output.dir, BIDS.input.data_dir(1).PatientID{3}); | |
system(cmd_str); | |
cmd_str = sprintf('touch %s/func/sub-%s_task-rest_run-2_bold_README.txt >> %s/func/logfile_%s_func_dcm2nii.txt',... | |
BIDS.output.dir, BIDS.input.data_dir(i).PatientID{j}, BIDS.output.dir, BIDS.input.data_dir(1).PatientID{3}); | |
fprintf('\n%s', cmd_str); | |
system(cmd_str); | |
end; | |
flag_RSN2 = 1; | |
end | |
end | |
if strcmp(BIDS.input.data_dir(i).SeriesDescription{j},'fMRI IST TR2000, 40SL') | |
if biomax_table{{'IST'},{'Ser'}} | |
cmd_str = sprintf('dcm2niix -f sub-%s_task-ist_bold -z y -o %s/func %s >> %s/func/logfile_%s_func_dcm2nii.txt',... | |
BIDS.input.data_dir(i).PatientID{j}, BIDS.output.dir, BIDS.input.data_dir(i).subdir{j}, BIDS.output.dir, BIDS.input.data_dir(1).PatientID{3}); | |
fprintf('\n%s', cmd_str); | |
if ~test_flag | |
system(cmd_str); | |
filename = sprintf('%s/func/sub-%s_task-ist_bold.json',BIDS.output.dir,BIDS.input.data_dir(i).PatientID{j}); | |
dataset_func_description_BIDS(BIDS,filename, biomax_table{{'IST'},:}); | |
cmd_str = sprintf('cp %s/*MRDC.1 %s/dicom/sub-%s_task-ist_bold.dicom.1 >> %s/func/logfile_%s_func_dcm2nii.txt', ... | |
BIDS.input.data_dir(i).subdir{j}, BIDS.output.dir, BIDS.input.data_dir(i).PatientID{j}, BIDS.output.dir, BIDS.input.data_dir(1).PatientID{3}); | |
system(cmd_str); | |
cmd_str = sprintf('touch %s/func/sub-%s_task-ist_bold_README.txt >> %s/func/logfile_%s_func_dcm2nii.txt',... | |
BIDS.output.dir, BIDS.input.data_dir(i).PatientID{j}, BIDS.output.dir, BIDS.input.data_dir(1).PatientID{3}); | |
fprintf('\n%s', cmd_str); | |
system(cmd_str); | |
end; | |
end | |
end | |
if strcmp(BIDS.input.data_dir(i).SeriesDescription{j},'fMRI rest') & ~flag_RSN3 | |
if biomax_table{{'rest3'},{'Ser'}} | |
cmd_str = sprintf('dcm2niix -f sub-%s_task-rest_run-3_bold -z y -o %s/func %s >> %s/func/logfile_%s_func_dcm2nii.txt',... | |
BIDS.input.data_dir(i).PatientID{j}, BIDS.output.dir, BIDS.input.data_dir(i).subdir{j}, BIDS.output.dir, BIDS.input.data_dir(1).PatientID{3}); | |
fprintf('\n%s', cmd_str); | |
if ~test_flag | |
system(cmd_str); | |
filename = sprintf('%s/func/sub-%s_task-rest_run-3_bold.json',BIDS.output.dir,BIDS.input.data_dir(i).PatientID{j}); | |
dataset_func_description_BIDS(BIDS,filename, biomax_table{{'rest3'},:}); | |
cmd_str = sprintf('cp %s/*MRDC.1 %s/dicom/sub-%s_task-rest_run-3_bold.dicom.1 >> %s/func/logfile_%s_func_dcm2nii.txt', ... | |
BIDS.input.data_dir(i).subdir{j}, BIDS.output.dir, BIDS.input.data_dir(i).PatientID{j}, BIDS.output.dir, BIDS.input.data_dir(1).PatientID{3}); | |
system(cmd_str); | |
cmd_str = sprintf('touch %s/func/sub-%s_task-rest_run-3_bold_README.txt >> %s/func/logfile_%s_func_dcm2nii.txt',... | |
BIDS.output.dir, BIDS.input.data_dir(i).PatientID{j}, BIDS.output.dir, BIDS.input.data_dir(1).PatientID{3}); | |
fprintf('\n%s', cmd_str); | |
system(cmd_str); | |
end; | |
flag_RSN3 = 1; | |
end | |
end | |
end | |
end | |
end | |
cd([BIDS.input.dir]); |