Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion demos/tSNR/tsnr_01_preproc.m
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
bidsCopyInputFolder(opt);

acq = {'2pt0', '2pt5', '3pt0'};
for i = 1:numel(acq)
for i = numel(acq)
opt.query.acq = acq{i};
bidsSpatialPrepro(opt);
end
43 changes: 43 additions & 0 deletions demos/tSNR/tsnr_03_compute.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
% (C) Copyright 2019 Remi Gau

clear;

opt = tsnr_get_option();

opt = checkOptions(opt);

[BIDS, opt] = getData(opt, opt.dir.preproc);

opt.dir.roi = fullfile(opt.dir.preproc, '..', 'cpp_spm-roi');
opt = rmfield(opt, 'taskName');
[BIDSroi, opt] = getData(opt, opt.dir.roi);

% TODO ideally loop over subjects

boldImage = bids.query(BIDS, 'data', 'sub', 'CTL05', 'suffix', 'bold', 'desc', 'preproc');
referenceImg = bids.query(BIDS, 'data', 'sub', 'CTL05', 'suffix', 'bold', 'desc', 'mean');
roi = bids.query(BIDSroi, 'data', 'sub', 'CTL05');

% TODO reslice for each acquisition resolution

matlabbatch = {};
matlabbatch = setBatchReslice(matlabbatch, opt, referenceImg, roi);
spm_jobman('run', matlabbatch);

opt.dir.preproc = opt.dir.roi;
opt.query.modality = 'roi';
opt = set_spm_2_bids_defaults(opt);
name_spec.entities = struct('acq', 'xxx');
opt.spm_2_bids = opt.spm_2_bids.add_mapping('prefix', 'r', ...
'name_spec', name_spec);
opt.spm_2_bids = opt.spm_2_bids.flatten_mapping();

bidsRename(opt);

[tsnrImage, volTsnr] = computeTsnr(boldImage);

[BIDSroi, opt] = getData(opt, opt.dir.roi);
roi = bids.query(BIDSroi, 'data', 'sub', 'CTL05', 'acq', 'xxx');

% TODO loop over ROIs
value = computeMeanValueInMask(tsnrImage, roi{1});
159 changes: 117 additions & 42 deletions initCppSpm.m
Original file line number Diff line number Diff line change
@@ -1,51 +1,126 @@
function initCppSpm()
%
% Adds the relevant folders to the path for a given session.
% Has to be run to be able to use CPP_SPM.
%
% USAGE::
%
% initCppSpm()
%
% (C) Copyright 2021 CPP_SPM developers

opt.verbosity = 1;

global CPP_SPM_INITIALIZED

if isempty(CPP_SPM_INITIALIZED)

thisDirectory = fileparts(mfilename('fullpath'));

addpath(genpath(fullfile(thisDirectory, 'src')));
addpath(genpath(fullfile(thisDirectory, 'lib', 'spmup')));
addpath(genpath(fullfile(thisDirectory, 'lib', 'spm_2_bids')));

libList = { ...
'mancoreg', ...
'NiftiTools', ...
'bids-matlab', ...
'slice_display', ...
'panel-2.14', ...
'utils'};

for i = 1:numel(libList)
addpath(fullfile(thisDirectory, 'lib', libList{i}));
end
%
% Adds the relevant folders to the path for a given session.
% Has to be run to be able to use CPP_SPM.
%
% USAGE::
%
% initCppSpm()
%
% (C) Copyright 2021 CPP_SPM developers

opt.verbosity = 1;

octaveVersion = '4.0.3';
matlabVersion = '8.6.0';

installlist = {'io', 'statistics', 'image'};

global CPP_SPM_INITIALIZED

if isempty(CPP_SPM_INITIALIZED)

thisDirectory = fileparts(mfilename('fullpath'));

addpath(genpath(fullfile(thisDirectory, 'src')));
addpath(genpath(fullfile(thisDirectory, 'lib', 'spmup')));
addpath(genpath(fullfile(thisDirectory, 'lib', 'spm_2_bids')));

libList = { ...
'mancoreg', ...
'NiftiTools', ...
'bids-matlab', ...
'slice_display', ...
'panel-2.14', ...
'utils'};

for i = 1:numel(libList)
addpath(fullfile(thisDirectory, 'lib', libList{i}));
end

addpath(fullfile(thisDirectory, 'lib', 'brain_colours', 'code'));
addpath(fullfile(thisDirectory, 'lib', 'riksneurotools', 'GLM'));

checkDependencies(opt);
printCredits(opt);

run(fullfile(thisDirectory, 'lib', 'CPP_ROI', 'initCppRoi'));

%%
if isOctave

% Exit if min version is not satisfied
if ~compare_versions(OCTAVE_VERSION, octaveVersion, '>=')
error('Minimum required Octave version: %s', octaveVersion);
end

addpath(fullfile(thisDirectory, 'lib', 'brain_colours', 'code'));
addpath(fullfile(thisDirectory, 'lib', 'riksneurotools', 'GLM'));
for ii = 1:length(installlist)

checkDependencies(opt);
printCredits(opt);
packageName = installlist{ii};

run(fullfile(thisDirectory, 'lib', 'CPP_ROI', 'initCppRoi'));
try
% Try loading Octave packages
disp(['loading ' packageName]);
pkg('load', packageName);

CPP_SPM_INITIALIZED = true();
catch

else
printToScreen('\n\nCPP_SPM already initialized\n\n', opt);
tryInstallFromForge(packageName);

end
end
end

else % MATLAB ----------------------------

if verLessThan('matlab', matlabVersion)
error('Sorry, minimum required MATLAB version is R2015b. :(');
end


end

CPP_SPM_INITIALIZED = true();

else
printToScreen('\n\nCPP_SPM already initialized\n\n', opt);

end

% %-Detect SPM directory
% %--------------------------------------------------------------------------
% SPMdir = cellstr(which('spm.m','-ALL'));
% if isempty(SPMdir)
% fprintf('SPM is not in your %s path.\n',software);
% return;
% elseif numel(SPMdir) > 1
% fprintf('SPM seems to appear in several different folders:\n');
% for i=1:numel(SPMdir)
% fprintf(' * %s\n',SPMdir{i});
% end
% fprintf('Remove all but one with ''pathtool'' or ''spm_rmpath''.\n');
% return;
% else
% fprintf('SPM is installed in: %s\n',fileparts(SPMdir{1}));
% end
% SPMdir = fileparts(SPMdir{1});

end


function tryInstallFromForge(packageName)

errorcount = 1;
while errorcount % Attempt twice in case installation fails
try
pkg('install', '-forge', packageName);
pkg('load', packageName);
errorcount = 0;
catch err
errorcount = errorcount + 1;
if errorcount > 2
error(err.message);
end
end
end

end
2 changes: 1 addition & 1 deletion lib/bids-matlab
Submodule bids-matlab updated 413 files
2 changes: 2 additions & 0 deletions miss_hit.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ copyright_entity: "Olivier Collignon"
copyright_entity: "Mohamed Rezk"
copyright_entity: "Remi Gau"
copyright_entity: "CPP_SPM developers"
copyright_entity: "Stephan Heunis"


tab_width: 2

Expand Down
68 changes: 0 additions & 68 deletions src/QA/anatomicalQALesion.m

This file was deleted.

22 changes: 22 additions & 0 deletions src/utils/computeMeanValueInMask.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
function value = computeMeanValueInMask(image, mask)
%
% USAGE::
%
% value = computeMeanValueInMask(image, mask)
%
% image: image filename
% mask: mask filename
%
%
% (C) Copyright 2021 CPP_SPM developers

% TODO what is returned by this when image is a 4D time series?
% write test

hdr = spm_vol(mask);
vol = spm_read_vols(hdr);
[x, y, z] = ind2sub(size(vol), find(vol));
data = spm_get_data(image, [x, y, z]');
value = nanmean(data);

end
Loading