diff --git a/+rsa/+fsl/getDataFromFSL.m b/+rsa/+fsl/getDataFromFSL.m new file mode 100644 index 0000000..b01a4e5 --- /dev/null +++ b/+rsa/+fsl/getDataFromFSL.m @@ -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 diff --git a/+rsa/+fsl/noiseNormalizeBetaFSL.m b/+rsa/+fsl/noiseNormalizeBetaFSL.m new file mode 100644 index 0000000..d790bf0 --- /dev/null +++ b/+rsa/+fsl/noiseNormalizeBetaFSL.m @@ -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 \ No newline at end of file diff --git a/Demos/FSLData/Readme.md b/Demos/FSLData/Readme.md new file mode 100644 index 0000000..c82d3b4 --- /dev/null +++ b/Demos/FSLData/Readme.md @@ -0,0 +1,3 @@ +# Download instructions +Downlad FSLData From:https://www.dropbox.com/s/usjjz31tf3q5kwx/FSLData.zip?dl=0 +and extract here \ No newline at end of file diff --git a/Demos/defineUserOptions.m b/Demos/defineUserOptions.m index 1882876..5f66448 100644 --- a/Demos/defineUserOptions.m +++ b/Demos/defineUserOptions.m @@ -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 %__________________________________________________________________________ diff --git a/Demos/fsl_demo.m b/Demos/fsl_demo.m new file mode 100644 index 0000000..89449e1 --- /dev/null +++ b/Demos/fsl_demo.m @@ -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 \ No newline at end of file diff --git a/Demos/projectOptions_fsl_demo.m b/Demos/projectOptions_fsl_demo.m new file mode 100644 index 0000000..c34a3b7 --- /dev/null +++ b/Demos/projectOptions_fsl_demo.m @@ -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