Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Loading FSL data #42

Open
wants to merge 9 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
32 changes: 32 additions & 0 deletions +rsa/+fsl/getDataFromFSL.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
function [betas,residuals] = getDataFromFSL(userOptions,subjectName)

%load mask
curmaskPath=rsa.util.replaceWildcards(userOptions.maskPath, ...
'[[subjectName]]',subjectName, ...
'[[maskName]]',userOptions.maskNames{1});
mask=load_nii(curmaskPath);

%load copes
betas=[];
residuals=[];
for r = userOptions.run_names
curfeatsPath=rsa.util.replaceWildcards(userOptions.featsPath, ...
'[[subjectName]]',subjectName, ...
'[[featPrefix]]',userOptions.featsPrefix, ...
'[[runName]]',r{1}, ...
'[[featSuffix]]',userOptions.featsSuffix);
for c = userOptions.copes
beta=load_nii(fullfile(curfeatsPath,'stats',['cope' int2str(c{1})' '.nii.gz']));
betas=cat(2,betas,beta.img(boolean(mask.img)));
end

res=load_nii(fullfile(curfeatsPath,'stats','res4d.nii.gz'));
res1=res.img(repmat(boolean(mask.img),[1 1 1 size(res.img,4)]));
residuals=cat(2,residuals,reshape(res1,[length(res1)/size(res.img,4) size(res.img,4)]));
%ress=cat(2,ress,res.img(boolean(mask.img)));
end

residuals=residuals';
betas=betas';

end
17 changes: 17 additions & 0 deletions +rsa/+fsl/noiseNormalizeBetaFSL.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
function [u_hat] = noiseNormalizeBetaFSL(Beta,Res,Partition)

[T,P] = size(Res);
[Q,P] = size(Beta);

Nrun= max(Partition);
partT = kron(1:Nrun,ones(1,T/Nrun))';
partQ = Partition;

for i=1:Nrun
idxT=partT==i;
idxQ=partQ==i;
Sw_hat(:,:,i)=rsa.stat.covdiag(Res(idxT,:)); %%% regularize Sw_hat through optimal shrinkage
u_hat(idxQ,:)=Beta(idxQ,:)*Sw_hat(:,:,i)^(-1/2); %%% multivariate noise normalization
end;

end
3 changes: 3 additions & 0 deletions Demos/FSLData/Readme.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# Download instructions
Downlad FSLData From:https://www.dropbox.com/s/usjjz31tf3q5kwx/FSLData.zip?dl=0
and extract here
2 changes: 1 addition & 1 deletion Demos/defineUserOptions.m
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
% a new name, so all will not be lost if you don't do this).
%
% For a guide to how to fill out the fields in this file, consult
% the documentation folder (particularly the userOptions_guide.m)
% the docu mentation folder (particularly the userOptions_guide.m)
%
% Cai Wingfield 11-2009
%__________________________________________________________________________
Expand Down
17 changes: 17 additions & 0 deletions Demos/fsl_demo.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
function distance=fsl_demo()

userOptions=projectOptions_fsl_demo;

[betas,residuals]=rsa.fsl.getDataFromFSL(userOptions,'T05');

partQ = kron(1:length(userOptions.run_names),ones(1,length(userOptions.copes)))'; %runNumber (partition)
partK = repmat(1:length(userOptions.copes),[1 length(userOptions.run_names)])'; %condNumber (CondVec)

u_hat = rsa.fsl.noiseNormalizeBetaFSL(betas,residuals,partQ); % Get noise normalised betas
distance = rsa.distanceLDC(u_hat,partQ,partK);

figure; imagesc(squareform(distance));



end
78 changes: 78 additions & 0 deletions Demos/projectOptions_fsl_demo.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
function userOptions = projectOptions_fsl_demo()
% projectOptions_fsl_demo is an options file for the FSL demo tutorial
%
% Roni Maimon 9-2017
%__________________________________________________________________________
% Copyright (C)

%% Project details
%Current folder
curFolder=fileparts(which('projectOptions_fsl_demo.m'));

% This name identifies a collection of files which all belong to the same run of a project.
userOptions.analysisName = 'DEMO_FSL'; % this is renamed in the code for demos 3-4.

% This is the root directory of the project.
userOptions.rootPath = [curFolder,filesep,'DEMO_FSL'];


%%%%%%%%%%%%%%%%%%%%%%%%
%% EXPERIMENTAL SETUP %%
%%%%%%%%%%%%%%%%%%%%%%%%


% The list of subjects to be included in the study.
userOptions.subjectNames = { ...
'T05', ...
'T06', ...
};

%% FSL Specific parameters
userOptions.run_names = { ...
'A1b','A2b','A3b','A4b' ...
};
userOptions.featsPrefix = '5_';
userOptions.featsSuffix = '';
userOptions.featsPath = [curFolder,filesep,'FSLData',filesep,'[[subjectName]]',...
filesep,'models',filesep,'glm',filesep,'fingers', ...
filesep, '[[featPrefix]]','[[runName]]','[[featSuffix]]','.feat'];

userOptions.copes = { ...
1,2,3,4,5 ...
};

%% End of FSL specific parameters

%%%%%%%%%%%%%%%%%%%%%%%%%%
%% ANALYSIS PREFERENCES %%
%%%%%%%%%%%%%%%%%%%%%%%%%%

%% First-order analysis
% Text lables which may be attached to the conditions for MDS plots.
userOptions.conditionLabels = { ...
'F1', ...
'F2', ...
'F3', ...
'F4', ...
'F5'
};

userOptions.useAlternativeConditionLabels = false;
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% FEATUERS OF INTEREST SELECTION OPTIONS %%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

%% %% %% %% %%
%% fMRI %% Use these next three options if you're working in fMRI native space:
%% %% %% %% %%

% The path to a stereotypical mask data file is stored (not including subject-specific identifiers).
% "[[subjectName]]" should be used as a placeholder to denote an entry in userOptions.subjectNames
% "[[maskName]]" should be used as a placeholder to denote an entry in userOptions.maskNames
userOptions.maskPath = [curFolder,filesep,'FSLData',filesep,'[[subjectName]]',filesep,'models',filesep,'masks',filesep,'[[maskName]].nii.gz'];

% The list of mask filenames (minus .hdr extension) to be used.
userOptions.maskNames = { ...
'S1_handknob_alldigits'...
};
end%function