Chapter 15 Verify AFQ Analysis

Make directory to save figures:

mkdir -p /Volumes/bobo/data/ACAP/afq/figures/

15.1 Generate Figures

Open MATLAB and run the following code:

% Get home directory:
var = getenv('HOME');

% Add modules to MATLAB. Do not change the order of these programs:
SPM8Path = [var, '/apps/spm8'];
addpath(genpath(SPM8Path));
vistaPath = [var, '/apps/vistasoft'];
addpath(genpath(vistaPath));
AFQPath = [var, '/apps/afq'];
addpath(genpath(AFQPath));

pathDir = '/Volumes/bobo/data/ACAP/dtiInit/';
subjid = dir(pathDir);

% % Cingulum
for i = 1:length(subjid)
  if exist(fullfile([pathDir, subjid(i).name, ...
  '/dt/fibers/MoriGroups_clean_D5_L4.mat']), 'file')

    subjid(i).name

    % Load Fiber Groups
    fg = dtiReadFibers(fullfile([pathDir, subjid(i).name, ...
    '/dt/fibers/MoriGroups_clean_D5_L4.mat']));
    dt = dtiLoadDt6(fullfile([pathDir, subjid(i).name, ...
      '/dt/dt6.mat']));
    t1 = readFileNifti(fullfile([pathDir, subjid(i).name, ...
      '/dt/bin/wmProb.nii.gz']));

    % Create Figure
    AFQ_RenderFibers(fg(5), 'numfibers', 250, ...
      'color', [1 0 0], 'camera', 'axial');
    AFQ_RenderFibers(fg(6), 'numfibers', 250, ...
      'color', [1 0 0], 'newfig', '0');
    AFQ_AddImageTo3dPlot(t1, [0, 0, 30], [], [], 0.50);

    % Format Figure
    set(gcf, 'Position', [100, 100, 535, 700]);
    set(gca, 'XTick', [], 'YTick', [], 'ZTick', [], ...
      'xlabel', [], 'ylabel', [], 'zlabel', []);
    set(gca, 'LooseInset', get(gca, 'TightInset'))

    % Save Figure
    saveas(gcf, ...
    fullfile([...
    '/Volumes/bobo/data/ACAP/afq/figures/', ...
      subjid(i).name, '-cingulum.png']));
    close all
  end
end

15.2 Verify Clean will Work

% Fiber
jj = 6;

% Subject Name
subjname = 'sub-ACAP1001';

cur_file = dir(['/Volumes/bobo/data/ACAP/afq/data/' subjname '/*.mat']);
load(fullfile(cur_file.folder, cur_file.name))
pathDir = '/Volumes/bobo/data/ACAP/dtiInit/';
fg = dtiReadFibers(fullfile([pathDir, subjname, '/dt/fibers/MoriGroups_clean_D5_L4.mat']));
dt = dtiLoadDt6(fullfile([pathDir, subjname, '/dt/dt6.mat']));

% Remove fibers more than maxDist standard deviations from the tract core
maxDist = 3;
% Remove fibers more than maxLen standard deviations above the mean length
maxLen = 4;
% Sample each fiber to numNodes points
numNodes = 100;
% Compute the tract core with the function M
M = 'median';
% Display the number of fibers removed in each iteration
count = 1;
% Maximum number of iterations
maxIter = 1;
show = 1;
[fg_clean keep] = AFQ_removeFiberOutliers(fg(jj), maxDist, maxLen, numNodes, ...
  M, count, maxIter, show);

% If you ever need to remove a fiber
% [m,n] = size(keep);
% keep = false(m,n);

% Remove fibers from unclipped group that do not survive the clipping
fg(jj).fibers =fg(jj).fibers(keep);

% Save cleaned fibers
cleanFgName = fullfile('/Volumes/bobo/data/ACAP/dtiInit/', ...
  subjname, '/dt/fibers/MoriGroups_clean_D5_L4.mat');
dtiWriteFiberGroup(fg, cleanFgName);

15.3 Sync

Then sync the data from the local computer to your remote computer.

rsync -rauv \
--exclude=".*" \
--no-links \
/Volumes/bobo/data/ACAP/dtiInit/ \
ashley.ware@arc.ucalgary.ca:/work/ashley.ware/data/ACAP/dtiInit/

15.4 Re-run AFQ

On the remote computer, submit batch script:

find /work/ashley.ware/data/ACAP/afq/ -type f -name "afq*" -exec rm {} \;
sh ~/scripts/ACAP/afqIndividual-batch.sh

15.5 Sync

Then sync the data from the remote computer to your local computer.

rsync -rauv \
--delete \
--exclude=".*" \
ashley.ware@arc.ucalgary.ca:/work/ashley.ware/data/ACAP/afq/ \
/Volumes/bobo/data/ACAP/afq/

You can then re-run your code to regenerate new figures (see above).