forked from gkaguirrelab/MRklar
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMASTER.m
More file actions
120 lines (119 loc) · 4.83 KB
/
Copy pathMASTER.m
File metadata and controls
120 lines (119 loc) · 4.83 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
%% Template script for preprocessing MRI data using MRklar
%
% Required software:
% Freesurfer, FSL
% IMPORTANT:
% start matlab from terminal, so environmental variables,
% libraries are set correctly
% add $FREESURFER_HOME/matlab to your matlab path
%
% Directory structure:
% data_directory -> project directory -> subject directory ->
% session directory -> dicom directory
%
% e.g. ~/data/Retinotopy/ASB/10012014/DICOMS
%
% If physiological measures are collected, using the following
% directory structure:
%
% data_directory -> project directory -> subject directory ->
% session directory -> physio directory
%
% e.g. ~/data/Retinotopy/ASB/10012014/PulseOx
%
% I recommend creating a project specific master file in a separate
% directory. For example, copy this MASTER.m file to a project
% specific folder:
%
% /User/Shared/Matlab/<project_name>/<project_name>_MASTER.m
%
% Written by Andrew S Bock Dec 2014
%% Create shell scripts
% The entire MRklar pipeline can be run using shell scripts, which are
% created using the 'create_preprocessing_scripts' function
%
% Example:
% session_dir = '/some/session/dir';
% outDir = fullfile(session_dir,'preprocessing_scripts');
% if ~exist(outDir,'dir')
% mkdir(outDir);
% end
% numRuns = 6; % number of bold runs
% reconall = 1;
% slicetiming = 1; % correct slice timings
% refvol = 1; % motion correct to 1st TR
% filtType = 'detrend';
% lowHz = 0.01;
% highHz = 0.10;
% physio = 1;
% motion = 1;
% task = 0;
% localWM = 1;
% anat = 1;
% amem = 20;
% fmem = 50;
% create_preprocessing_scripts(session_dir,subject_name,outDir,logDir,...
% job_name,numRuns,reconall,slicetiming,refvol,filtType,lowHz,highHz,...
% physio,motion,task,localWM,anat,amem,fmem);
%% Define session and subject
session_dir = '~/data/Retinotopy/ASB/10012014/'; % session directory
subject_name = 'A102714B'; % Freesurfer subject name
%% Sort dicoms, convert to nifti
% Sort dicoms into series specific directories, converts dicoms to nifti
sort_nifti(session_dir);
%% Freesurfer Reconstruction
% If the subject has not been run through the Freesurfer recon-all
% pipeline, run this step. If the subject aleady exists, you can skip.
% Note: this will take 9-24 hours, depending on the CPU.
system(['recon-all -i ' fullfile(session_dir,'MPRAGE','001','ACPC',...
'MPRAGE.ACPC.nii.gz') ' -s ' subject_name ' -all']);
%% B0 fieldmap
% Creates a B0 field map, and brain extracts the magnitude image by
% registering that image to the freesurfer "brain.mgz" image. If a B0
% image was not acquired, you can skip.
make_fieldmap(session_dir,subject_name);
%% Brain extract T1 image
% Creates skull stripped file 'MPRAGE_brain.nii.gz' using FreeSurfer tools
skull_strip(session_dir,subject_name);
%% Segment freesurfer aseg.mgz volume
% Segments the freesurfer anatomical aseg.mgz volume into several ROIs in
% the session_dir, to be used later for noise removal.
segment_anat(session_dir,subject_name);
%% Cross-hemisphere and fsaverage_sym registration
% Checks that 'xhemireg' and 'surfreg' have been run for the specified
% freesurfer subject. If not, this function runs those commands.
xhemi_check(session_dir,subject_name);
%% Motion correction
% Motion correct functional runs. This script has several options, such as
% despikeing and slice timing correction.
motion_slice_correction(session_dir);
%% Register functional runs to anatomical image
% Registers the functional volumes from to the corresponding Freesurfer
% anatomical image for the bold directory specified by 'runNum'.
register_func(session_dir,subject_name,runNum);
%% Project anatomical ROIs to functional space
% Projects anatomical ROIs into functional space for the bold directory
% specified by 'runNum'.
project_anat2func(session_dir,runNum);
%% Create regressors for noise removal
% Creates a nuisance regressor text file for the bold directory
% specified by 'runNum', based on physiological noise and motion. If a
% task-design, an option exists to make the motion parameters orthogonal
% to the task.
create_regressors(session_dir,runNum);
%% Remove noise
% Removes physiological and other non-neuronal noise regressors for the
% bold directory specified by 'runNum'
remove_noise(session_dir,runNum);
%% Local White Matter
% Removes the average local white matter signal in the functional volume
% for the bold directory specified by 'runNum'
remove_localWM(session_dir,runNum);
%% Temporal filter
% Temporally filters the bold data, based on a specified filter (see help),
% for the bold directory specified by 'runNum'
temporal_filter(session_dir,runNum);
%% Spatially smooth functional data
% Spatially smooths the functional data in the volume and on the surface,
% using a Gaussian kernel (default = 5mm).
smooth_vol_surf(session_dir,runNum);