diff --git a/.deploy/DeploymentREADME b/.deploy/DeploymentREADME index 543678ba..f56e39eb 100644 --- a/.deploy/DeploymentREADME +++ b/.deploy/DeploymentREADME @@ -5,13 +5,36 @@ degree of localization, as they usually don't know where they've been cloned to. you'll find some scripts and hooks in this directory. Follow the following instructions to enable this support. -1. Copy post-checkout to .git/hooks -2. If this clone is an active deployment (i.e. you expect users to copy templates out of this -directory before doing work on them, and it's very unlikely that commits will ever occur from this -clone), then touch a regular file named .local/deployment. This will influence the behavior of -deploy.sh which is called from the post-checkout hook. +If this is a development repository, consider running +setup_developer.sh. At present, this will just copy the hook from +.deploy/src/post-checkout to .git/hooks/. -That's it! +If this is a deployment repository, run setup_deployment.sh + +This will +1. Add a remote called github/universe to point to the +UMPsychMethodsCore/MethodsCore repo on github +2. Copy the post-checkout hook up to where it will be active +3. Make a .local directory in your repo (this is ignored by a +.gitignore file) +4. Create a file called deployment in .local (this affects behavior of +the hook) +5. Generate a keypair for you in .local called deploy and deploy.pub +6. Create a file in .local called branch, and echo "public" into it + +After you run this, you need to + +1. Grab the content of .local/deploy.pub and add it as a deployment +key at Github. +2. Edit .local/branch to contain the content of the branch that you +want this repository to automatically update to +3. Run at regular intervals, or schedule with cron, the process +.deploy/src/self_update.sh which will automatically pull the latest +version of the file specified in .local/branch from universe, update +your working tree, and then run the hook to clean paths up for users. + + +###Here is what the hook does### Once you've done this, you'll get the following behavior everytime you perform a checkout. @@ -36,4 +59,4 @@ string "*_mc_template*". It will the loop over these files and do the following This tool might get fancier in the future (e.g. strip off any leading comment characters in lines that contain the search string described in 2 or 3 to give you more flexibility in your use of -wildcards, but for now this is all that is supported. \ No newline at end of file +wildcards, but for now this is all that is supported. diff --git a/.deploy/post-checkout b/.deploy/post-checkout deleted file mode 100755 index eb6cc2a8..00000000 --- a/.deploy/post-checkout +++ /dev/null @@ -1,11 +0,0 @@ -#!/bin/sh -# -# An example hook script that is called after a successful -# commit is made. -# -# To enable this hook, rename this file to "post-commit". - -#Run your deployment script -if [ -f .deploy/deploy.sh ]; then -source .deploy/deploy.sh -fi diff --git a/.deploy/setup_deployment.sh b/.deploy/setup_deployment.sh new file mode 100755 index 00000000..7e225cd2 --- /dev/null +++ b/.deploy/setup_deployment.sh @@ -0,0 +1,23 @@ +#!/bin/sh + +thisdir=`dirname $0` + + +# Add universe remote +git remote add github/universe git@github.com:UMPsychMethodsCore/MethodsCore + +# Copy hooks +cp $thisdir/src/post-checkout $thisdir/../.git/hooks + + +#Make .local directory if it doesn't exist, and add deployment +mkdir -p ${thisdir}/../.local + +#Mark this as a deployment +touch $thisdir/../.local/deployment + +#Add file to indicate which branch should be updated by self-checkout +echo public > $thisdir/../.local/branch + +#Make keyfiles +ssh-keygen -f $thisdir/../.local/deploy -N "" \ No newline at end of file diff --git a/.deploy/setup_developer.sh b/.deploy/setup_developer.sh new file mode 100755 index 00000000..f26a1501 --- /dev/null +++ b/.deploy/setup_developer.sh @@ -0,0 +1,6 @@ +#!/bin/sh + +thisdir=`dirname $0` + +#Copy hooks +cp $thisdir/src/post-checkout $thisdir/../.git/hooks \ No newline at end of file diff --git a/.deploy/deploy.sh b/.deploy/src/checkout.sh old mode 100644 new mode 100755 similarity index 94% rename from .deploy/deploy.sh rename to .deploy/src/checkout.sh index e002a31b..aa3a3e91 --- a/.deploy/deploy.sh +++ b/.deploy/src/checkout.sh @@ -3,7 +3,6 @@ #Grab Current Root mcRoot=`pwd` -#Make sure .local directory exists mkdir -p .local #Identify Current Version diff --git a/.deploy/src/git_ssh.sh b/.deploy/src/git_ssh.sh new file mode 100755 index 00000000..f1b0fc37 --- /dev/null +++ b/.deploy/src/git_ssh.sh @@ -0,0 +1,7 @@ +#!/bin/sh + +thisdir=`dirname $0` + +idfile=$thisdir/../../.local/deploy + +ssh -i ${idfile} $@ \ No newline at end of file diff --git a/.deploy/src/post-checkout b/.deploy/src/post-checkout new file mode 100755 index 00000000..05474cc7 --- /dev/null +++ b/.deploy/src/post-checkout @@ -0,0 +1,7 @@ +#!/bin/sh +# + +#Run your checkout script +if [ -f .deploy/src/checkout.sh ]; then +.deploy/src/checkout.sh +fi diff --git a/.deploy/src/self_update.sh b/.deploy/src/self_update.sh new file mode 100755 index 00000000..032e0049 --- /dev/null +++ b/.deploy/src/self_update.sh @@ -0,0 +1,21 @@ +#!/bin/sh + + + +thisdir=`dirname $0` + +origdir=`pwd` +cd $thisdir +harddir=`pwd` +cd $origdir + +export GIT_SSH=${harddir}/git_ssh.sh + +branch=`cat $thisdir/../../.local/branch` + +git reset HEAD --hard + +git pull github/universe $branch:$branch + +git checkout $branch + diff --git a/FirstLevel/PreprocessFirstLevel_central.m b/FirstLevel/PreprocessFirstLevel_central.m index fb5c0868..7129f8dd 100644 --- a/FirstLevel/PreprocessFirstLevel_central.m +++ b/FirstLevel/PreprocessFirstLevel_central.m @@ -535,7 +535,7 @@ end normsource = ['mean' b c]; - ImageDirCheck = struct('Template',ImageTmeplate,... + ImageDirCheck = struct('Template',ImageTemplate,... 'mode','check'); ImageDir=mc_GenPath(ImageDirCheck); @@ -559,7 +559,7 @@ %job{6}.spm.util.defs.comp{1}.def = {fullfile(subjdir,anatdir,['y_r' hires '.' imagetype])}; - [HiResPath HiResName]=fileparts(HiResTemplate); + [HiResPath HiResName]=fileparts(HiresTemplate); job{6}.spm.util.defs.comp{1}.def = {fullfile(HiResPath,['y_r' HiResName '.nii'])}; %%%Mike needs to check this job{6}.spm.util.defs.fnames = wscan; diff --git a/matlabScripts/mc_Error.m b/matlabScripts/mc_Error.m new file mode 100644 index 00000000..9c436b82 --- /dev/null +++ b/matlabScripts/mc_Error.m @@ -0,0 +1,45 @@ +function mc_Error(errorString,varargin) +% A utility function to make error handling and logging more compact +% A single call to mc_Error will log the error to the global mc_LogName, +% bring up an error dialog box with your error message, and actually throw +% an exception with the Matlab error function. +% +% FORMAT mc_Error(errorString,other variable arguments) +% +% errorString This is a string message that will be displayed +% to the user. This can either be a simple string, +% or it can take the format of an sprintf +% formatting string using % format specifiers (see +% sprintf documentation for more information about +% these format strings). +% +% other variables If you are using the sprintf format string, you +% need to pass in the other variables that need to +% appear in the formatted string. +% +% EXAMPLES +% mc_Error('File does not exist.'); +% mc_Error('File %s does not exist.',filename); +% mc_Error('File %s does not exist at path %s.',filename, folder); +% mc_Error('You specified %d images but I found %d.\nPlease double +% check subject %s folder %s for images.',NumScan(iRun), +% size(P,1),subjDir,RunDir{iRun}); + + if (~isempty(varargin)) + formatcount = size(strfind(errorString,'%'),2); + if (formatcount == size(varargin,2)) + errormsg = sprintf(errorString,varargin{:}); + else + mc_Error('Found %d format specifiers but %d other variables were provided.\n\nError String: %s\n',formatcount,size(varargin,2),errorString); + + end + else + errormsg = errorString; + end + + %add future code to call mc_Logger with loglevel Error + + errordlg(errormsg); + error(errormsg); + + \ No newline at end of file diff --git a/matlabScripts/mc_GetBoundingBox.m b/matlabScripts/mc_GetBoundingBox.m new file mode 100644 index 00000000..74829c4f --- /dev/null +++ b/matlabScripts/mc_GetBoundingBox.m @@ -0,0 +1,21 @@ +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +function bb = mc_GetBoundingBox(V) +% world-bb -- get bounding box in world (mm) coordinates + +d = V.dim(1:3); +% corners in voxel-space +c = [ 1 1 1 1 + 1 1 d(3) 1 + 1 d(2) 1 1 + 1 d(2) d(3) 1 + d(1) 1 1 1 + d(1) 1 d(3) 1 + d(1) d(2) 1 1 + d(1) d(2) d(3) 1 ]'; +% corners in world-space +tc = V.mat(1:3,1:4)*c; + +% bounding box (world) min and max +mn = min(tc,[],2)'; +mx = max(tc,[],2)'; +bb = [mn; mx]; \ No newline at end of file diff --git a/som/SOM_CalculateCorrelationImages.m b/som/SOM_CalculateCorrelationImages.m index a16bd64c..652ff95c 100755 --- a/som/SOM_CalculateCorrelationImages.m +++ b/som/SOM_CalculateCorrelationImages.m @@ -33,7 +33,7 @@ results = []; rMap = zeros(size(D0,1),1); -rMapVol = zeros(parameters.maskHdr.dim(1:3)); +rMapVol = zeros(parameters.maskHdr.dim(1:3)); %this fails if user specified no masking %% This should now be fixed with change in SOM_PreProcessData - 2012-03-29 - RCWelsh for iROI = 1 : parameters.rois.nroisRequested @@ -63,7 +63,7 @@ clear rMapHdr; - rMapHdr.fname = fullfile(parameters.Output.directory,sprintf('rmap_%s_%03d.nii',parameters.Output.name,iROI)); + rMapHdr.fname = fullfile(parameters.Output.directory,sprintf('rmap_%s_%04d.nii',parameters.Output.name,iROI)); rMapHdr.mat = parameters.maskHdr.mat; % Make sure we write out float32..... @@ -75,7 +75,7 @@ % Now the probability map. pMapHdr = rMapHdr; - pMapHdr.fname = fullfile(parameters.Output.directory,sprintf('pmap_%s_%03d.nii',parameters.Output.name,iROI)); + pMapHdr.fname = fullfile(parameters.Output.directory,sprintf('pmap_%s_%04d.nii',parameters.Output.name,iROI)); spm_write_vol(rMapHdr,rMapVol); spm_write_vol(pMapHdr,pMapVol); @@ -85,7 +85,7 @@ if exist(rMapHdr.fname) == 2 clear Vo Vi = spm_vol(rMapHdr.fname); - Vo.fname = sprintf('zmap_%s_%03d.nii',parameters.Output.name,iROI); + Vo.fname = fullfile(parameters.Output.directory,sprintf('zmap_%s_%04d.nii',parameters.Output.name,iROI)); Vo.mat = Vi.mat; Vo.dim = Vi.dim; Vo.dt = [16 0]; diff --git a/som/SOM_CalculateCorrelationImagesSlow.m b/som/SOM_CalculateCorrelationImagesSlow.m deleted file mode 100755 index d981bb81..00000000 --- a/som/SOM_CalculateCorrelationImagesSlow.m +++ /dev/null @@ -1,109 +0,0 @@ -% - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -% -% Robert C. Welsh -% Copyright 2011 -% -% Ann Arbor, MI -% -% Calculate correlation images. -% -% INPUT -% -% D0 -- see SOM_PreProcessData -% parameters -- see SOM_PreProcessData and SOM_CalculateCorrelations -% -% OUTPUT -% -% results = -1 error -% array of output written. -% -% -% function results = SOM_CalculateCorrelationImages(D0,parameters) -% -% - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -function results = SOM_CalculateCorrelationImagesSlow(D0,parameters) - -global SOM - -% -% Initialize the output matrix. -% - -results = []; - -rMap = zeros(size(D0,1),1); -rMapVol = zeros(parameters.maskHdr.dim(1:3)); - -for iROI = 1 : parameters.rois.nroisRequested - - if parameters.rois.ROIOK(iROI) - roiTC = mean(D0(parameters.rois.IDX{iROI},:),1); - - SOM_LOG('STATUS : Entering CorrCoeff Image Calculation'); - - rMap = 0*rMap; - pMap = 0*rMap; - - for iV = 1:size(D0,1); - [rMap(iV) pMap(iV)] = corr(D0(iV,:)',roiTC'); - end - - % Now turn into maps (r and p) and write out. - - rMapVol = 0*rMapVol; - pMapVol = ones(size(rMapVol)); - - rMapVol(parameters.maskInfo.iMask) = rMap; - pMapVol(parameters.maskInfo.iMask) = pMap; - - clear rMapHdr; - - rMapHdr.fname = fullfile(parameters.Output.directory,sprintf('rmap_%s_%03d.nii',parameters.Output.name,iROI)); - rMapHdr.mat = parameters.maskHdr.mat; - - % Make sure we write out float32..... - - rMapHdr.dim = parameters.maskHdr.dim(1:3); - rMapHdr.dt = [16 0]; - rMapHdr.descrip = sprintf('%s : %d',parameters.Output.description,iROI); - - % Now the probability map. - - pMapHdr = rMapHdr; - pMapHdr.fname = fullfile(parameters.Output.directory,sprintf('pmap_%s_%03d.nii',parameters.Output.name,iROI)); - - spm_write_vol(rMapHdr,rMapVol); - spm_write_vol(pMapHdr,pMapVol); - - % now transform the results to a z score. - - if exist(rMapHdr.fname) == 2 - Vi = spm_vol(rMapHdr.fname); - clear Vo - Vo.fname = sprintf('zmap_%s_%03d.nii',parameters.Output.name,iROI); - Vo.mat = Vi.mat; - Vo.dim = Vi.dim; - Vo.dt = [16 0]; - Vo.descrip = ['z-score for ' rMapHdr.descrip]; - spm_imcalc(Vi,Vo,'1/2*log((1+i1)./(1-i1))'); - else - SOM_LOG(sprintf('WARNING : I guess the corr didn''t work for ROI %d',iROI)); - end - end - results = strvcat(results,rMapHdr.fname); -end - -parameters.stopCPU = cputime; - -paraName = fullfile(parameters.Output.directory,[parameters.Output.name '_parameters']); - -save(paraName,'parameters','SOM'); - -results = strvcat(results,paraName); - -return - -% -% All done. -% \ No newline at end of file diff --git a/som/SOM_CheckDataStructure.m b/som/SOM_CheckDataStructure.m index 24d7572a..16b69e63 100644 --- a/som/SOM_CheckDataStructure.m +++ b/som/SOM_CheckDataStructure.m @@ -73,7 +73,7 @@ % Now check to see if the input files actually exist. if exist(data.run(iRUN).P(1,:),'file') == 0 - SOM_LOG(sprintf('FATAL ERROR : File %s does not exist'),data.run(iRUN).P(1,:)); + SOM_LOG(sprintf('FATAL ERROR : File %s does not exist',data.run(iRUN).P(1,:))); return end @@ -92,19 +92,19 @@ SOM_LOG(sprintf('STATUS : Determined that for run %d, there are %d time-points.',iRUN,nTIME)); end - if exist(data.run(iRUN),'censorVector') + if isfield(data.run(iRUN),'censorVector') if length(data.run(iRUN).censorVector) ~= data.run(iRUN).nTIME - SOM_LOG(sprintf('FATAL : Specified censorVector of length %d - %for - %run - %%d - %s + SOM_LOG(sprintf('FATAL : Specified censorVector of length %d for run %d does not match %d'),iRUN,data.run(iRUN).nTIME) + return + end + end + % Check to see if the motion parameters are there - + if isfield(data.run(iRUN),'MotionParameters') == 1 if size(data.run(iRUN).MotionParameters,1) ~= data.run(iRUN).nTIME SOM_LOG('WARNING : Motion parameters length does not match expected number of time points'); - if size(data.run(iRUN).MotionParameters,1) < data.run(iRUN).nTIME + if length(data.run(iRUN).MotionParameters) > 0 & size(data.run(iRUN).MotionParameters,1) < data.run(iRUN).nTIME SOM_LOG(sprintf('FATAL ERROR : Motion parameter array is too short for run %d',iRUN)); return end @@ -121,7 +121,7 @@ SOM_LOG(sprintf('FATAL ERROR : File %s does not exist'),data.run(iRUN).P(iFILE,:)); return else - thisHDR = spm_read_vol(data.run(iRUN).P(iFILE,:)); + thisHDR = spm_vol(data.run(iRUN).P(iFILE,:)); % fixed on 5/2/2012 if SOM_SpaceVerify(data.run(iRUN).hdr,thisHDR) ~= 1 SOM_LOG('FATAL ERROR : Error with consistent in-run image space definition.'); return @@ -167,4 +167,4 @@ - \ No newline at end of file + diff --git a/som/SOM_CheckMasks.m b/som/SOM_CheckMasks.m new file mode 100644 index 00000000..73a40c3f --- /dev/null +++ b/som/SOM_CheckMasks.m @@ -0,0 +1,92 @@ +% - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +% +% Robert C. Welsh +% Copyright 2011 +% +% Ann Arbor, MI +% +% A routine to loop on the different masks that are potentially +% used in the SOM code and to check them for correctness etc. +% +% function masks = SOM_CheckMasks(parameters) +% +% - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + +function masks = SOM_CheckMasks(parameters) + +global SOM + +% Does 'masks' field exist? + +if isfield(parameters,'masks') == 0 + SOM_LOG('WARNING : You have not specified a ".masks" structure. Using defaults'); + masks.epi = []; + masks.grey = []; + masks.csf = []; + masks.white = []; +else + masks = parameters.masks; +end + +% Default is error state + +masks.OK = -1; + +% Files needed for masking? + +if isfield(masks,'grey') == 0 + masks.grey = []; +end + +masks.grey = SOM_ParseFileParam(masks.grey); + +if masks.grey.OK == -1 + SOM_LOG('FATAL ERROR : You specified an grey mask that doesn''t exist'); + return +end + +% White Matter ROI for regression? + +if isfield(masks,'white') == 0 + masks.white = []; +end + +masks.white = SOM_ParseFileParam(masks.white); + +if masks.white.OK == -1 + SOM_LOG('FATAL ERROR : You specified an white mask that doesn''t exist'); + return +end + +% CSF ROI? + +if isfield(masks,'csf') == 0 + masks.csf = []; +end + +masks.csf = SOM_ParseFileParam(masks.csf); + +if masks.csf.OK == -1 + SOM_LOG('FATAL ERROR : You specified an csf mask that doesn''t exist'); + return +end + +% If no common epi mask then we will use one create on the fly. + +if isfield(masks,'epi') == 0 + masks.epi = []; +else + masks.epi = SOM_ParseFileParam(masks.epi); + if masks.epi.OK == -1 + SOM_LOG('FATAL ERROR : You specified an epi mask that doesn''t exist'); + return + end +end + +% Okay, we made it this far so all good. + +masks.OK = 1; + +% +% all done. +% \ No newline at end of file diff --git a/som/SOM_CheckROIParameters.m b/som/SOM_CheckROIParameters.m index 2de056d3..9f929fa1 100644 --- a/som/SOM_CheckROIParameters.m +++ b/som/SOM_CheckROIParameters.m @@ -103,7 +103,7 @@ % Now see if they specified a mask to constrain the ROI's % The rois will ALSO be constrained by the mask as defined in -% parameters.epi +% parameters.masks.epi if isfield(rois,'mask') == 0 rois.mask = []; @@ -124,7 +124,7 @@ if isempty(rois.mask.File) try PMask = parameters.data.run(1).P(1,:); - SOM_LOG(sprintf('STATUS : Using %s as a masking image',P(1,:))); + SOM_LOG(sprintf('STATUS : Using %s as a masking image',parameters.data.run(1).P(1,:))); catch SOM_LOG('FATAL ERROR : No time series data specified yet.'); return diff --git a/som/SOM_CheckRegressFLAGS.m b/som/SOM_CheckRegressFLAGS.m index 510d47e3..0a9349a3 100755 --- a/som/SOM_CheckRegressFLAGS.m +++ b/som/SOM_CheckRegressFLAGS.m @@ -13,21 +13,19 @@ % prinComp = 0 use average if available % # use [N] principle components specified % -% global = 0 no global regression -% 1 do global regression -% -% csf = 0 no CSF regression -% 1 CSF regression if 'csf' is filled -% above. -% -% white = 0 no white matter regresson -% 1 white matter regression if 'white' is filled -% above. -% % motion = 0 no motion regression % 1 motion regression (default if MotionParameters % are present) +% THIS IS AN INTERNAL FLAG % +% order = alphabetic order of signal processing. +% D = detrend +% G = global +% C = CSF +% W = white matter +% M = motion +% B = band pass +% % - - - - - - - - - - - - - - - - - - - - - - - - - - - - - % Modified Nov 8, 2011 to have nTIME be part of data.run @@ -41,9 +39,6 @@ SOM_LOG('WARNING : No regression flags specified, going to build defaults'); RegressFLAGS = []; RegressFLAGS.prinComp = SOM.defaults.RegressFLAGS.prinComp; - RegressFLAGS.global = SOM.defaults.RegressFLAGS.global; - RegressFLAGS.csf = parameters.csf.MaskFLAG; - RegressFLAGS.white = parameters.white.MaskFLAG; RegressFLAGS.motion = 1; for iRUN = 1:length(parameters.data.run) % @@ -84,41 +79,42 @@ RegressFLAGS.prinComp = SOM.defaults.RegressFLAGS.prinComp; end -if isfield(RegressFLAGS,'global') == 0 - SOM_LOG('WARNING : global FLAG no set, using default of 0'); - RegressFLAGS.global = SOM.defaults.RegressFLAGS.global; -end +%if isfield(RegressFLAGS,'global') == 0 +% SOM_LOG('WARNING : global FLAG no set, using default of 0'); +% RegressFLAGS.global = SOM.defaults.RegressFLAGS.global; +%end -if isfield(RegressFLAGS,'csf') == 0 - SOM_LOG('WARNING : csf FLAG no set, using default of parameters.csf.MaskFLAG'); - RegressFLAGS.csf = parameters.csf.MaskFLAG; -end +%if isfield(RegressFLAGS,'csf') == 0 +% SOM_LOG('WARNING : csf FLAG no set, using default of parameters.masks.csf.MaskFLAG'); +% RegressFLAGS.csf = parameters.masks.csf.MaskFLAG; +%end -if isfield(RegressFLAGS,'white') == 0 - SOM_LOG('WARNING : white FLAG no set, using default of parameters.white.MaskFLAG'); - RegressFLAGS.white = parameters.white.MaskFLAG; -end +%if isfield(RegressFLAGS,'white') == 0 +% SOM_LOG('WARNING : white FLAG no set, using default of parameters.masks.white.MaskFLAG'); +% RegressFLAGS.white = parameters.masks.white.MaskFLAG; +%end % Check the motion parameters for each run for iRUN = 1:length(parameters.data.run) - if isfield(parameters.data.run(iRUN),'MotionParameters') == 0 - SOM_LOG('WARNING : Motion parameters not specified'); - MotionParameters = []; - else - MotionParameters = parameters.data.run(iRUN).MotionParameters; - end - - if ~isnumeric(MotionParameters) | ... - parameters.data.run(iRUN).nTIME > size(MotionParameters,1) - SOM_LOG('FATAL ERROR : motion parameters missing, or mismatched, not using.'); - return - else - if isfield(RegressFLAGS,'motion') == 0 - SOM_LOG('WARNING : motion flag not there, but motion parameters present, setting flag to 1.'); - RegressFLAGS.motion = 1; + if isfield(parameters.data.run(iRUN),'MotionParameters') == 0 | length(parameters.data.run(iRUN).MotionParameters) < 1 + SOM_LOG('WARNING : Motion parameters not specified'); + MotionParameters = []; + RegressFLAGS.motion = 0; + else + MotionParameters = parameters.data.run(iRUN).MotionParameters; + + if ~isnumeric(MotionParameters) | ... + parameters.data.run(iRUN).nTIME > size(MotionParameters,1) + SOM_LOG('FATAL ERROR : motion parameters missing, or mismatched, not using.'); + return + else + if isfield(RegressFLAGS,'motion') == 0 + SOM_LOG('WARNING : motion flag not there, but motion parameters present, setting flag to 1.'); + RegressFLAGS.motion = 1; + end + end end - end end % The regression order. diff --git a/som/SOM_CheckTimeParams.m b/som/SOM_CheckTimeParams.m index 8adeac98..53cb9760 100755 --- a/som/SOM_CheckTimeParams.m +++ b/som/SOM_CheckTimeParams.m @@ -69,8 +69,9 @@ if length(TIME.run) == 1 & length(parameters.data.run) > 1 SOM_LOG('STATUS : Replicating timing parameters for all runs.\n'); % Make the passed the new defaults. - SOM.defaults.TIME = TIME.run; - TIME.run = []; + SOM.defaults.TIME = TIME.run(1); + TIME = rmfield(TIME,'run'); + %TIME.run = []; for iRUN = 1:length(parameters.data.run) TIME.run(iRUN) = SOM.defaults.TIME; end diff --git a/som/SOM_CreateMask.m b/som/SOM_CreateMask.m index 33bd36bb..cffb9dc9 100755 --- a/som/SOM_CreateMask.m +++ b/som/SOM_CreateMask.m @@ -37,27 +37,35 @@ [fPath fName fExt] = fileparts(P(1,:)); if strcmp(strtrim(lower(fExt)),'.img') - analyzeFMT=1 + analyzeFMT=1 else - analyzeFMT=0; + if (strcmp(strtrim(lower(fExt)),'.nii')) + analyzeFMT=2; + else + analyzeFMT=0; + end end if analyzeFMT == 1 - som_mask = spm_read_vols(spm_vol(P(1,:))); + som_mask = spm_read_vols(spm_vol(P(1,:))); else - tmpVol = load(P(1,:)); - fldNm = fieldnames(tmpVol); - if length(fldNm) ~= 1 - fprintf('\nError - the mat file has more than one variable.\n'); - fprintf('File : %s\n',P(1,:)); - hdr = []; - results = []; - analyzeFMT = []; - return - end - som_mask = getfield(tmpVol,fldNm{1}); + if analyzeFMT == 2 + mtx = spm_read_vols(spm_vol(P(1,:))); + som_mask = ones(size(mtx,1),size(mtx,2),size(mtx,3)); + else + tmpVol = load(P(1,:)); + fldNm = fieldnames(tmpVol); + if length(fldNm) ~= 1 + fprintf('\nError - the mat file has more than one variable.\n'); + fprintf('File : %s\n',P(1,:)); + hdr = []; + results = []; + analyzeFMT = []; + return + end + som_mask = getfield(tmpVol,fldNm{1}); + end end - volSIZE = size(som_mask); som_mask = ones(size(som_mask)); @@ -65,61 +73,104 @@ spm('defaults','fmri'); global defaults; -for iP = 1:size(P,1) - fprintf('\b\b\b%03d',iP) - if analyzeFMT == 1 - vol = spm_read_vols(spm_vol(P(iP,:))); - t(iP) = spm_global(spm_vol(P(iP,:))); - else - tmpVol = load(P(iP,:)); - fldNm = fieldnames(tmpVol); - if length(fldNm) ~= 1 - fprintf('\nError - the mat file has more than one variable.\n'); - fprintf('File : %s\n',P(iP,:)); - hdr = []; - results = []; - analyzeFMT = []; - return - end - vol = getfield(tmpVol,fldNm{1}); - mvol = mean(mean(mean(vol)))*SOM.maskThresh; % Just like SPM. - t(iP) = mean(vol(find(vol>mvol))); +if analyzeFMT == 2 + V = spm_vol(P(1,:)); + for iV = 1:size(V,1) + vol = spm_read_vols(V(iV)); + t(iV) = spm_global(V(iV)); + som_mask = som_mask.*(vol>(defaults.mask.thresh * t(iV))); + % + % Check to see if the volumes being read are all the same size. + % + if any(volSIZE - size(vol)) + fprintf('\nVolumes are of different size!.\n'); + fprintf('%s\n',P(iP,:)); + hdr = []; + results = []; + analyzeFMT= []; + return + end + clear vol; end - som_mask = som_mask.*(vol>(defaults.mask.thresh * t(iP))); - % - % Check to see if the volumes being read are all the same size. - % - if any(volSIZE - size(vol)) - fprintf('\nVolumes are of different size!.\n'); - fprintf('%s\n',P(iP,:)); - hdr = []; - results = []; - analyzeFMT= []; - return + +else + for iP = 1:size(P,1) + fprintf('\b\b\b%03d',iP) + if analyzeFMT == 1 + vol = spm_read_vols(spm_vol(P(iP,:))); + t(iP) = spm_global(spm_vol(P(iP,:))); + else + tmpVol = load(P(iP,:)); + fldNm = fieldnames(tmpVol); + if length(fldNm) ~= 1 + fprintf('\nError - the mat file has more than one variable.\n'); + fprintf('File : %s\n',P(iP,:)); + hdr = []; + results = []; + analyzeFMT = []; + return + end + vol = getfield(tmpVol,fldNm{1}); + mvol = mean(mean(mean(vol)))*SOM.maskThresh; % Just like SPM. + t(iP) = mean(vol(find(vol>mvol))); + + end + som_mask = som_mask.*(vol>(defaults.mask.thresh * t(iP))); + % + % Check to see if the volumes being read are all the same size. + % + if any(volSIZE - size(vol)) + fprintf('\nVolumes are of different size!.\n'); + fprintf('%s\n',P(iP,:)); + hdr = []; + results = []; + analyzeFMT= []; + return + end + clear vol; end - clear vol; end + fprintf('\b\b\bdone\n'); iMask = find(som_mask); if analyzeFMT == 1 - hdr = spm_vol(P(1,:)); - [pn fn] = fileparts(hdr.fname); - nhdr.fname = fullfile(pn,'som_mask.img'); - nhdr.dim(1:3) = hdr.dim(1:3); - nhdr.mat = hdr.mat; - nhdr.descrip = ['SOM Created Masked based on SPM:',spm('ver')]; - if strcmp(spm('ver'),'SPM5') - nhdr.dt = [4 0]; - else - nhdr.dim(4) = 4; - end - spm_write_vol(nhdr,som_mask); + hdr = spm_vol(P(1,:)); + [pn fn] = fileparts(hdr.fname); + nhdr.fname = fullfile(pn,'som_mask.img'); + nhdr.dim(1:3) = hdr.dim(1:3); + nhdr.mat = hdr.mat; + nhdr.descrip = ['SOM Created Masked based on SPM:',spm('ver')]; + if strcmp(spm('ver'),'SPM5') | strcmp(spm('ver'),'SPM8') + nhdr.dt = [4 0]; + else + nhdr.dim(4) = 4; + end + spm_write_vol(nhdr,som_mask); + hdr = nhdr; else - hdr = []; - save(fullfile(fPath,'som_mask'),'som_mask'); + if analyzeFMT == 2 + hdr = spm_vol(P(1,:)); + hdr = hdr(1); + [pn fn] = fileparts(hdr.fname); + nhdr.fname = fullfile(pn,'som_mask.img'); + nhdr.dim(1:3) = hdr.dim(1:3); + nhdr.mat = hdr.mat; + nhdr.descrip = ['SOM Created Masked based on SPM:',spm('ver')]; + if (strcmp(spm('ver'),'SPM5') | strcmp(spm('ver'),'SPM8')) + nhdr.dt = [4 0]; + else + nhdr.dim(4) = 4; + end + spm_write_vol(nhdr,som_mask); + hdr = nhdr; + else + + hdr = []; + save(fullfile(fPath,'som_mask'),'som_mask'); + end end results = som_mask; diff --git a/som/SOM_Detrend.m~ b/som/SOM_Detrend.m~ deleted file mode 100644 index cb3ae467..00000000 --- a/som/SOM_Detrend.m~ +++ /dev/null @@ -1,43 +0,0 @@ -% - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -% -% Robert C. Welsh -% Copyright 2011 -% -% Ann Arbor, MI -% -% -% newData = SOM_Detrend(data,polyorder); -% -% -% Input Parameters that we need for preparing the data -% -% polyorder = order of the polynomial, 0 is mean centered. -% -% data = data (space x time); -% -% This we operate on the 2nd dimension. -% -% - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -function results = SOM_Detrend(data,polyorder) - -% Check to see if they specified the polynomial order. - -if nargin == 1 - polyorder = 0; -end - -% -% If polyorder = 0 then we are just mean centering the data. -% - -if polyorder == 0 - results = bsxfun(@minus,data,mean(data,2)); - return -end - -% -% Okay the specified something -% - -X = zeros(size(data,2), \ No newline at end of file diff --git a/som/SOM_MakeGrid.m b/som/SOM_MakeGrid.m new file mode 100644 index 00000000..9064a0ad --- /dev/null +++ b/som/SOM_MakeGrid.m @@ -0,0 +1,76 @@ +% - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +% +% Robert C. Welsh +% Copyright 2011 +% +% Ann Arbor, MI +% +% Routine to make a grid of rois. +% +% function results = SOM_MakeGrid(gridSpacing,[BB]) +% +% gridSpacing = the grid spacing in mm +% +% BB = the bounding box, optional. +% X, Y, Z as in defaults.normalise.write.bb from SPM8 +% +% +% Typically you,d call SOM_MakeGrid and then after you get your list of +% candidate locations you can pass to "SOM_roiPointsInMask" if you want to +% mask for gray matter. +% +% The grid created will straddle the left-right hemispheric fissure, but +% will start at Y=0 and Z=0. +% +% - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + +function results = SOM_MakeGrid(gridSpacing,BB) + +% Make sure grid is > 0 + +if gridSpacing < 0 + SOM_LOG('FATAL : Grid spacing must be > 0'); + results = -1; + return +end + +% Did they define a bouding box> +if exist('BB') == 0 + BB = [-76, -112, -50; 76, 73, 84]; +end + +% Build the grid. +xvals1 = [gridSpacing/2:gridSpacing:BB(2,1)]; +xvals2 = [-gridSpacing/2:-gridSpacing:BB(1,1)]; +xvals = sort([xvals1 xvals2]); + +yvals1 = [0:gridSpacing:BB(2,2)]; +yvals2 = [-gridSpacing:-gridSpacing:BB(1,2)]; +yvals = sort([yvals1 yvals2]); + +zvals1 = [0:gridSpacing:BB(2,3)]; +zvals2 = [-gridSpacing:-gridSpacing:BB(1,3)]; +zvals = sort([zvals1 zvals2]); + +xgrid = repmat(xvals,[length(yvals) 1]); +ygrid = repmat(yvals',[1 length(xvals)]); + +mni_xcoords = zeros([size(xgrid) length(zvals)]); +mni_ycoords = zeros([size(xgrid) length(zvals)]); +mni_zcoords = zeros([size(xgrid) length(zvals)]); + +for iZ = 1:length(zvals) + mni_xcoords(:,:,iZ) = xgrid; + mni_ycoords(:,:,iZ) = ygrid; + mni_zcoords(:,:,iZ) = zvals(iZ); +end + +mni_coords_cand = [mni_xcoords(:) mni_ycoords(:) mni_zcoords(:) ]; + +results = mni_coords_cand; + +return + +% +% All done. +% \ No newline at end of file diff --git a/som/SOM_MaskRead.m b/som/SOM_MaskRead.m new file mode 100644 index 00000000..b6158c17 --- /dev/null +++ b/som/SOM_MaskRead.m @@ -0,0 +1,25 @@ +% - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +% +% Robert C. Welsh +% Copyright 2011 +% +% Ann Arbor, MI +% +% A routine to read mask information +% +% function maskName = SOM_ReadMasks(maskName) +% +% - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + +function maskName = SOM_MaskRead(maskName) + +maskName.ImgHDR = spm_vol(maskName.File); +maskName.ImgVol = spm_read_vols(spm_vol(maskName.File)); +maskName.ImgMask = maskName.ImgVol > maskName.ImgThreshold; +maskName.ROIIDX = find(maskName.ImgMask); + +return + +% +% all done. +% diff --git a/som/SOM_ParseFileParam.m b/som/SOM_ParseFileParam.m index 6ff97b02..9c58fb8b 100755 --- a/som/SOM_ParseFileParam.m +++ b/som/SOM_ParseFileParam.m @@ -8,6 +8,8 @@ % Validate the time parameters % pass for SOM_PreProcessData % +% In general you should just set the ".File" field and let the code +% determine the rest of the fields. % % function type = SOM_ParseFileParam(type) % @@ -34,14 +36,15 @@ if isfield(type,'File') == 0 SOM_LOG('WARNING : No file information, skipping.'); - type.File = []; - type.MaskFLAG = 0; + type.File = []; + type.MaskFLAG = 0; type.ImgThreshold = SOM.defaults.MaskImgThreshold; return end if isempty(type.File) SOM_LOG('WARNING : No file information, skipping.'); + type.MaskFLAG = 0; % Since the file name is empty, force the flag to be 0. return end @@ -49,7 +52,7 @@ if exist(type.File,'file') == 0 type.OK = -1; - SOM_LOG('FATAL Error : Masking file specified doesn''t exist'); + SOM_LOG(sprintf('FATAL Error : Masking file %s specified doesn''t exist',type.File)); return end diff --git a/som/SOM_PreProcessData.m b/som/SOM_PreProcessData.m index cba01449..1c0d0ca1 100644 --- a/som/SOM_PreProcessData.m +++ b/som/SOM_PreProcessData.m @@ -7,40 +7,44 @@ % % Pre-processing data for connectivity analysis. % -% results = SOM_PreProcessData(parameters) +% [D0 parameters] = SOM_PreProcessData(parameters) % % % Input Parameters that we need for preparing the data % -% Grey Matter mask and flag to use it. +% masks. % -% (the grey matter mask is intersected with the epi mask) +% Grey Matter mask and flag to use it. % -% grey. -% File = full directory path and name to file. -% MaskFLAG = 0 no masking, 1 = masking. -% ImgThreshold = 0.75 (default) +% (the grey matter mask is intersected with the epi mask) % -% -% White Matter mask and flags. -% -% white. -% File = full directory path and name to file. -% MaskFLAG = 0 no regression, 1 regression -% -% csf mask and flags. +% grey. +% File = full directory path and name to file. +% [ImgThreshold = 0.75 (default) ] % -% csf. -% File = full directory path and name to file. -% MaskFLAG = 0 no regression, 1 regression -% -% -% Brain matter mask % -% epi. -% File = full directory path and name to file. -% MaskFLAG = 0 no mask, 1 mask +% White Matter mask +% +% white. +% File = full directory path and name to file. +% [ImgThreshold = 0.75 (default) ] +% +% +% csf mask +% +% csf. +% File = full directory path and name to file. +% [ImgThreshold = 0.75 (default) ] +% +% +% +% Brain matter mask % +% epi. +% File = full directory path and name to file. +% [ImgThreshold = 0.75 (default) ] +% +% % data. % % run[iRun]. @@ -169,53 +173,11 @@ % Files needed for masking? -if isfield(parameters,'grey') == 0 - parameters.grey = []; -end - -parameters.grey = SOM_ParseFileParam(parameters.grey); - -if parameters.grey.OK == -1 - SOM_LOG('FATAL ERROR : You specified an grey mask that doesn''t exist'); - return -end - -% White Matter ROI for regression? +parameters.masks = SOM_CheckMasks(parameters); -if isfield(parameters,'white') == 0 - parameters.white = []; -end - -parameters.white = SOM_ParseFileParam(parameters.white); - -if parameters.white.OK == -1 - SOM_LOG('FATAL ERROR : You specified an white mask that doesn''t exist'); - return -end - -% CSF ROI? - -if isfield(parameters,'csf') == 0 - parameters.csf = []; -end - -parameters.csf = SOM_ParseFileParam(parameters.csf); - -if parameters.csf.OK == -1 - SOM_LOG('FATAL ERROR : You specified an csf mask that doesn''t exist'); - return -end - -% If no common epi mask then we will use one create on the fly. - -if isfield(parameters,'epi') == 0 - parameters.epi = []; -else - parameters.epi = SOM_ParseFileParam(parameters.epi); - if parameters.epi.OK == -1 - SOM_LOG('FATAL ERROR : You specified an epi mask that doesn''t exist'); - return - end +if parameters.masks.OK ~= 1 + SOM_LOG('FATAL ERROR : Something wrong with masks definitions.') + return end % Now prepare based on parameters. @@ -225,41 +187,35 @@ fileINDEXTemp = 0; filesToCheck = []; -if parameters.grey.MaskFLAG == 0 - parameters.grey.ImgMask = 1; +if parameters.masks.grey.MaskFLAG == 0 + parameters.masks.grey.ImgMask = 1; + parameters.masks.grey.ROIIDX = []; % Superflous but consistent. else - parameters.grey.ImgHDR = spm_vol(parameters.grey.File); - parameters.grey.ImgVol = spm_read_vols(spm_vol(parameters.grey.File)); - parameters.grey.ImgMask = parameters.grey.ImgVol > parameters.grey.ImgThreshold; - % store temp - fileINDEXTemp = fileINDEXTemp + 1; - filesToCheck(fileINDEXTemp).hdr = parameters.grey.ImgHDR; + parameters.masks.grey = SOM_MaskRead(parameters.masks.grey); + % store temp + fileINDEXTemp = fileINDEXTemp + 1; + filesToCheck(fileINDEXTemp).hdr = parameters.masks.grey.ImgHDR; end - -if parameters.white.MaskFLAG == 0 - parameters.white.ImgMask = 0; - parameters.white.ROIIDX = []; + +if parameters.masks.white.MaskFLAG == 0 + parameters.masks.white.ImgMask = 0; + parameters.masks.white.ROIIDX = []; else - parameters.white.ImgHDR = spm_vol(parameters.white.File); - parameters.white.ImgVol = spm_read_vols(spm_vol(parameters.white.File)); - parameters.white.ImgMask = parameters.white.ImgVol > parameters.white.ImgThreshold; - parameters.white.ROIIDX = find(parameters.white.ImgMask); - % store temp - fileINDEXTemp = fileINDEXTemp + 1; - filesToCheck(fileINDEXTemp).hdr = parameters.white.ImgHDR; + parameters.masks.white = SOM_MaskRead(parameters.masks.white); + % store temp + fileINDEXTemp = fileINDEXTemp + 1; + filesToCheck(fileINDEXTemp).hdr = parameters.masks.white.ImgHDR; end - -if parameters.csf.MaskFLAG == 0 - parameters.csf.ImgMask = 0; - parameters.csf.ROIIDX = []; + +if parameters.masks.csf.MaskFLAG == 0 + parameters.masks.csf.ImgMask = 0; + parameters.masks.csf.ROIIDX = []; else - parameters.csf.ImgHDR = spm_vol(parameters.csf.File); - parameters.csf.ImgVol = spm_read_vols(spm_vol(parameters.csf.File)); - parameters.csf.ImgMask = parameters.csf.ImgVol > parameters.csf.ImgThreshold; - parameters.csf.ROIIDX = find(parameters.csf.ImgMask); - % store temp - fileINDEXTemp = fileINDEXTemp + 1; - filesToCheck(fileINDEXTemp).hdr = parameters.csf.ImgHDR; + parameters.masks.csf = SOM_MaskRead(parameters.masks.csf); + + % store temp + fileINDEXTemp = fileINDEXTemp + 1; + filesToCheck(fileINDEXTemp).hdr = parameters.masks.csf.ImgHDR; end % Check the reression flags. @@ -281,18 +237,21 @@ % Make the mask file, masking out non-brain. Using a standard mask. if parameters.data.MaskFLAG == 1 - if parameters.epi.MaskFLAG == 0 - fprint('Calculating subject specific epi mask'); + if parameters.masks.epi.MaskFLAG == 0 + SOM_LOG('Calculating subject specific epi mask'); % Create the mask from the very first/only run. parameters.maskHdr = SOM_CreateMask(parameters.data.run(1).P); else - parameters.maskHdr = spm_vol(parameters.epi.File); + parameters.maskHdr = spm_vol(parameters.masks.epi.File); end % store temp fileINDEXTemp = fileINDEXTemp + 1; filesToCheck(fileINDEXTemp).hdr = parameters.maskHdr; else - parameters.maskHdr.fname = []; % If no name then SOM_PrepData can deal. + % changed this on 2012-03-29 (RCWelsh), this will force some sort of masking, but that is okay. + % This will prevent SOM_CalculateCorrelationImages from failing if no mask is indicated at all + parameters.maskHdr = SOM_CreateMask(parameters.data.run(1).P); + %parameters.maskHdr.fname = []; % If no name then SOM_PrepData can deal. end % @@ -359,6 +318,7 @@ % operator. This will also mean center the data. % + SOM_LOG('STATUS : Doing detrending.'); parameters.startCPU.run(iRUN).detrend = cputime; if parameters.TIME.run(iRUN).TrendFLAG > 0 @@ -378,12 +338,8 @@ parameters.TIME.run(iRUN).GS = SOM_GlobalCalc(D0RUN(iRUN).D0); - if parameters.RegressFLAGS.global ~= 0 - SOM_LOG('STATUS : Doing global regression'); - D0RUN(iRUN).D0 = SOM_RemoveConfound(D0RUN(iRUN).D0,parameters.TIME.run(iRUN).GS); - else - SOM_LOG('STATUS : NOT doing global regression'); - end + SOM_LOG('STATUS : Doing global regression'); + D0RUN(iRUN).D0 = SOM_RemoveConfound(D0RUN(iRUN).D0,parameters.TIME.run(iRUN).GS); parameters.stopCPU.run(iRUN).global = cputime; @@ -395,39 +351,41 @@ parameters.startCPU.run(iRUN).csf = cputime; - if parameters.csf.MaskFLAG > 0 & parameters.RegressFLAGS.csf > 0 + if parameters.masks.csf.MaskFLAG > 0 SOM_LOG('STATUS : CSF Regression'); - parameters.csf.IDX = []; + parameters.masks.csf.IDX = []; % Now convert the ROI indices to the indices in the mask. - parameters.csf.IDX = SOM_ROIIDXnMASK(parameters,parameters.csf.ROIIDX); + parameters.masks.csf.IDX = SOM_ROIIDXnMASK(parameters,parameters.masks.csf.ROIIDX); - if length(parameters.csf.IDX) < 1 + if length(parameters.masks.csf.IDX) < 1 SOM_LOG(sprintf('STATUS : Not enough voxels to determine CSF time course')) else - SOM_LOG(sprintf('STATUS : %d CSF Voxels in extracted data.',length(parameters.csf.IDX))); - parameters.csf.run(iRUN).PRINCOMP = []; + SOM_LOG(sprintf('STATUS : %d CSF Voxels in extracted data.',length(parameters.masks.csf.IDX))); + parameters.masks.csf.run(iRUN).PRINCOMP = []; % % Are we doing principle components are we taking the mean of the ROI? % if parameters.RegressFLAGS.prinComp > 0 - parameters.csf.run(iRUN).PRINCOMP = SOM_PrinComp(D0RUN(iRUN).D0(parameters.csf.IDX,:),parameters.TIME.run(iRUN).fraction); + parameters.masks.csf.run(iRUN).PRINCOMP = SOM_PrinComp(D0RUN(iRUN).D0(parameters.masks.csf.IDX,:),parameters.TIME.run(iRUN).fraction); % How many components are we to use? - parameters.csf.run(iRUN).nComp = min([parameters.RegressFLAGS.prinComp size(parameters.csf.run(iRUN).PRINCOMP.PCScore,2)]); - parameters.csf.run(iRUN).regressors = (parameters.csf.run(iRUN).PRINCOMP.PCScore(:,1:parameters.csf.run(iRUN).nComp)); + parameters.masks.csf.run(iRUN).nComp = min([parameters.RegressFLAGS.prinComp size(parameters.masks.csf.run(iRUN).PRINCOMP.PCScore,2)]); + parameters.masks.csf.run(iRUN).regressors = (parameters.masks.csf.run(iRUN).PRINCOMP.PCScore(:,1:parameters.masks.csf.run(iRUN).nComp)); else - parameters.csf.run(iRUN).regressors = mean(D0RUN(iRUN).D0(parameters.csf.IDX,:))'; + parameters.masks.csf.run(iRUN).regressors = mean(D0RUN(iRUN).D0(parameters.masks.csf.IDX,:))'; end % Now remove them. - D0RUN(iRUN).D0 = SOM_RemoveMotion(D0RUN(iRUN).D0,parameters.csf.run(iRUN).regressors); + D0RUN(iRUN).D0 = SOM_RemoveMotion(D0RUN(iRUN).D0,parameters.masks.csf.run(iRUN).regressors); end else - parameters.csf.run(iRUN).regressors = []; - SOM_LOG('STATUS : No CSF Regression'); + parameters.masks.csf.run(iRUN).regressors = []; + SOM_LOG('WARNING : * * * * * * * * * * * *'); + SOM_LOG('WARNING : CSF regression speficied but no CSF regression mask available.'); + SOM_LOG('WARNING : * * * * * * * * * * * *'); end parameters.stopCPU.run(iRUN).csf = cputime; @@ -440,39 +398,41 @@ parameters.startCPU.run(iRUN).white = cputime; - if parameters.white.MaskFLAG > 0 & parameters.RegressFLAGS.white > 0 + if parameters.masks.white.MaskFLAG > 0 SOM_LOG('STATUS : WM Regression'); - parameters.white.IDX = []; + parameters.masks.white.IDX = []; % Now convert the ROI indices to the indices in the mask. - parameters.white.IDX = SOM_ROIIDXnMASK(parameters,parameters.white.ROIIDX); + parameters.masks.white.IDX = SOM_ROIIDXnMASK(parameters,parameters.masks.white.ROIIDX); - SOM_LOG(sprintf('STATUS : %d WM Voxels in extracted data.',length(parameters.white.IDX))); + SOM_LOG(sprintf('STATUS : %d WM Voxels in extracted data.',length(parameters.masks.white.IDX))); % Are we regressing out the principle components or the mean. - parameters.white.run(iRUN).PRINCOMP = []; + parameters.masks.white.run(iRUN).PRINCOMP = []; % % Are we doing principle components are we taking the mean of the ROI? % if parameters.RegressFLAGS.prinComp > 0 - parameters.white.run(iRUN).PRINCOMP = SOM_PrinComp(D0RUN(iRUN).D0(parameters.white.IDX,:),parameters.TIME.run(iRUN).fraction); + parameters.masks.white.run(iRUN).PRINCOMP = SOM_PrinComp(D0RUN(iRUN).D0(parameters.masks.white.IDX,:),parameters.TIME.run(iRUN).fraction); % How many components are we to use? - parameters.white.run(iRUN).nComp = min([parameters.RegressFLAGS.prinComp size(parameters.white.run(iRUN).PRINCOMP.PCScore,2)]); - parameters.white.run(iRUN).regressors = (parameters.white.run(iRUN).PRINCOMP.PCScore(:,1:parameters.white.run(iRUN).nComp)); + parameters.masks.white.run(iRUN).nComp = min([parameters.RegressFLAGS.prinComp size(parameters.masks.white.run(iRUN).PRINCOMP.PCScore,2)]); + parameters.masks.white.run(iRUN).regressors = (parameters.masks.white.run(iRUN).PRINCOMP.PCScore(:,1:parameters.masks.white.run(iRUN).nComp)); else - parameters.white.run(iRUN).regressors = mean(D0RUN(iRUN).D0(parameters.white.IDX,:))'; + parameters.masks.white.run(iRUN).regressors = mean(D0RUN(iRUN).D0(parameters.masks.white.IDX,:))'; end % Now remove them. - D0RUN(iRUN).D0 = SOM_RemoveMotion(D0RUN(iRUN).D0,parameters.white.run(iRUN).regressors); + D0RUN(iRUN).D0 = SOM_RemoveMotion(D0RUN(iRUN).D0,parameters.masks.white.run(iRUN).regressors); else - parameters.white.run(iRUN).regressors = []; - SOM_LOG('STATUS : No WM Regression'); + parameters.masks.white.run(iRUN).regressors = []; + SOM_LOG('WARNING : * * * * * * * * * * * *'); + SOM_LOG('WARNING : WM reression speficied but no WM regression mask available.'); + SOM_LOG('WARNING : * * * * * * * * * * * *'); end parameters.stopCPU.run(iRUN).white = cputime; @@ -490,7 +450,9 @@ D0RUN(iRUN).D0 = SOM_RemoveMotion(D0RUN(iRUN).D0,parameters.data.run(iRUN).MotionParameters(1:parameters.data.run(iRUN).nTimeAnalyzed,:)); SOM_LOG('STATUS : Motion Correction Implemented'); else - SOM_LOG('STATUS : No Motion Regression.'); + SOM_LOG('WARNING : * * * * * * * * * * * *'); + SOM_LOG('WARNING : Motion regression speficied, but motion regression internally turned off???'); + SOM_LOG('WARNING : * * * * * * * * * * * *'); end parameters.stopCPU.run(iRUN).motion = cputime; @@ -516,7 +478,7 @@ SOM_LOG('STATUS : Band Pass Filter Implemented.'); else parameters.TIME.run(iRUN).b = []; - SOM_LOG('STATUS : No Band Pass Filter.'); + SOM_LOG(sprintf('WARNING : No Band Pass Filter Speficied for this run : %d.',iRUN)); end parameters.stopCPU.run(iRUN).band = cputime; @@ -537,7 +499,10 @@ if length(nSPACE>1) if any(diff(nSPACE)) - SOM_LOG(sprintf('FATAL : regression step not recongnized : %s',parameters.RegressFLAGS.order)); + SOM_LOG(sprintf('FATAL : Resulting number of voxels in each run is inconsistent')); + for iRUN=1:length(nSPACE) + SOM_LOG(sprintf('FATAL : Run %d has %d voxels',iRUN,nSPACE(iRUN))); + end return end end @@ -555,27 +520,37 @@ enTIME = []; for iRUN = length(parameters.data.run) - if exist(parmaters.data.run(iRUN),'censorVector') + if isfield(parameters.data.run(iRUN),'censorVector') D0RUN(iRUN).D0 = SOM_editTimeSeries(D0RUN(iRUN.D0),parameters.data.run(iRUN).censorVector); if D0RUN(iRUN).D0 == -1 SOM_LOG('FATAL : SOM_editTimeSeries failed.'); exit else - SOM_LOG(sprintf(['STATUS : Changed run %d from %d time-points to %d',iRUN,nTIME(iRUN),enTIME(iRUN))); enTIME = [enTIME size(D0RUN(iRUN).D0,2)]; + SOM_LOG(sprintf('STATUS : Changed run %d from %d time-points to %d',iRUN,nTIME(iRUN),enTIME(iRUN))); end end end -% Now calculate the new length. +% Now calculate the new length, that is if we need to. + +if length(enTIME) > 0 + SOM_LOG(sprintf('STATUS : Edited data to : %d space by total %d time-points',nSPACE(1),cenTIME(end))); +else + enTIME=nTIME; + SOM_LOG(sprintf('STATUS : No editing of data : %d space by total % time-points',nSPACE(1),cnTIME(end))); +end + +cenTIME = [0 cumsum(enTIME)]; -cenTIME = cumsum(enTIME); +% We can store all of this for posterity -SOM_LOG(sprintf('STATUS : Edited data to : %d space by %d time-points',nSPACE(1),cenTIME(end))); +parameters.data.nTIME = nTIME; +parameters.data.enTIME = enTIME; % Now contactenate the data. -D0 = zeros(nSPACE(1),sum(enTIME)); +D0 = zeros(nSPACE(1),cenTIME(end)); for iRUN = 1:length(parameters.data.run) D0(:,cenTIME(iRUN)+1:cenTIME(iRUN+1)) = D0RUN(iRUN).D0; diff --git a/som/SOM_PrepData.m b/som/SOM_PrepData.m index 59d0234c..fe5684fd 100755 --- a/som/SOM_PrepData.m +++ b/som/SOM_PrepData.m @@ -72,7 +72,7 @@ % If there is no mask then we will use the first image of the data. -if isempty(PMask) == 0 +if isempty(PMask) == 1 [mfPath mfName mfExt] = fileparts(P(1,:)); else [mfPath mfName mfExt] = fileparts(PMask); @@ -187,7 +187,7 @@ FASTCODEPRESENT=1; -FASTCODE={'SOM_read_nii_img','SOM_read_nii_hdr','SOM_img_endian'}; +FASTCODE={'nifti','SOM_read_nii_img','SOM_read_nii_hdr','SOM_img_endian'}; for iCODE = 1:length(FASTCODE) if exist(FASTCODE{iCODE}) ~= 2 @@ -197,7 +197,8 @@ if FASTCODEPRESENT & analyzeFMT == 2 tic; - theVols = SOM_read_nii_img(P); + %theVols = SOM_read_nii_img(P); % Depreceated on 2012-03-23 - RCWelsh and replaced with SOM_ReadNII which uses 'nifti' + theVols = SOM_ReadNII(P); results = (theVols(:,maskInfo.iMask))'; toctime = toc; SOM_LOG(sprintf('STATUS : Fast read code implemented, %s',toctime)); diff --git a/som/SOM_ReadNII.m b/som/SOM_ReadNII.m new file mode 100644 index 00000000..40442bb8 --- /dev/null +++ b/som/SOM_ReadNII.m @@ -0,0 +1,44 @@ +% - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +% +% Robert C. Welsh +% Copyright 2011 +% +% Ann Arbor, MI +% +% A routine to read the 4D file +% and shape to match the output of Luis' +% code +% +% function results = SOM_ReadNII(P); +% - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + +function results = SOM_ReadNII(P); + +results = -1; + +if exist(P) ~= 2 + SOM_LOG(sprintf('ERROR : File does not exist : %s',P)); + return +end + +try + DATA4D = nifti(P); +catch + SOM_LOG(sprintf('ERROR : Error reading file : %s',P)); + return +end + +if ndims(DATA4D.dat(:,:,:,:)) ~= 4 + SOM_LOG(sprintf('ERROR : %s does not appear to be time-series data',P)); + return +end + +results = reshape(DATA4D.dat(:,:,:,:),[prod(size(DATA4D.dat(:,:,:,1))) size(DATA4D.dat(:,:,:,:),4)])'; + +clear DATA4D; + +return + +% +% all done +% diff --git a/som/SOM_WriteNII.m b/som/SOM_WriteNII.m index 597ca69c..d4d7b547 100644 --- a/som/SOM_WriteNII.m +++ b/som/SOM_WriteNII.m @@ -29,7 +29,7 @@ results = -1; % First get the dimensions of what we want to write, and we need to -% pad with 1's for 3D to beome the propoer.0 +% pad with 1's for 3D to become the proper order. volDIM = size(Volume); @@ -50,14 +50,12 @@ end % data area. - niftiOutData = file_array; niftiOutData.fname = NewName; niftiOutData.dim = volDIM; % No error checking on that they pass in!!! - if exist('dtype') == 0 niftiOutData.dtype = niftiIn.dat.dtype; else @@ -75,14 +73,25 @@ niftiOut.descrip = [niftiIn.descrip ', SOM Create Nifti file']; niftiOut.timing = niftiIn.timing; +% Clear the hook to the template image. +clear niftiIn; + +% Put the data onto disk. niftiOut.dat = niftiOutData; +% create the file. create(niftiOut); +% Actually write the data now, first reserving some zeros. -- Not sure if we +% need to do this step. niftiOut.dat(:,:,:,:) = zeros(niftiOutData.dim); +% data to disk. niftiOut.dat(:,:,:,:) = Volume; +% Close our connection to the output file. +clear niftiOut + % All done results = NewName; diff --git a/som/som_batch_mc_central.m b/som/som_batch_mc_central.m new file mode 100644 index 00000000..153e619c --- /dev/null +++ b/som/som_batch_mc_central.m @@ -0,0 +1,211 @@ +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +%%% General calculations that apply to both Preprocessing and First Level +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +if (alreadydone(1)) + basefile = [stp basefile]; +end +if (alreadydone(2)) + basefile = [rep basefile]; +end +if (alreadydone(3)) + basefile = [nop basefile]; +end +if (alreadydone(4)) + basefile = [smp basefile]; +end + + +RunMode = [0 0]; +if (strcmpi(Mode,'full')) + RunMode = [1 1]; +else + RunMode(1) = strcmpi(Mode,'parameters'); + RunMode(2) = strcmpi(Mode,'som'); +end + +spm('defaults','fmri'); +global defaults +warning off all + +spmver = spm('Ver'); +if (strcmp(spmver,'SPM8')==1) + spm_jobman('initcfg'); + spm_get_defaults('cmdline',true); +end + +if (RunMode(1) | sum(RunMode) == 0) + RunNamesTotal = RunDir; + NumScanTotal = NumScan; + + MaskBrain = 1; + + RegressGlobal = any(strfind(upper(RegressOrder),'G')); + RegressWhite = any(strfind(upper(RegressOrder),'W')); + RegressCSF = any(strfind(upper(RegressOrder),'C')); + DoBandpassFilter = any(strfind(upper(RegressOrder),'B')); + RegressMotion = any(strfind(upper(RegressOrder),'M')); + DoLinearDetrend = any(strfind(upper(RegressOrder),'D')); + + for iSubject = 1:size(SubjDir,1) + clear parameters; + clear global SOM; + + parameters.RegressFLAGS.prinComp = PrincipalComponents; + parameters.RegressFLAGS.global = RegressGlobal; + parameters.RegressFLAGS.csf = RegressCSF; + parameters.RegressFLAGS.white = RegressWhite; + parameters.RegressFLAGS.motion = RegressMotion; + parameters.RegressFLAGS.order = RegressOrder; + + Subject=SubjDir{iSubject,1}; + RunList=SubjDir{iSubject,3}; + + NumRun = size(RunList,2); + + TotalNumRun = size(NumScanTotal,2); %%% number of image runs if every run were present + + %%%%% This code cuts RunDir and NumScan based which Image Runs are present + NumScan=[]; + clear RunDir; + for iRun=1:NumRun + RunDir{iRun,1}=RunNamesTotal{RunList(1,iRun)}; + NumScan=horzcat(NumScan,NumScanTotal(1,RunList(1,iRun))); + end + + NumRun= size(NumScan,2); % number of runs + ImageNumRun=size(RunDir,1); %number of image folders + + GreyPath = mc_GenPath(GreyMatterTemplate); + WhitePath = mc_GenPath(WhiteMatterTemplate); + CSFPath = mc_GenPath(CSFTemplate); + BrainPath = mc_GenPath(BrainMaskTemplate); + + parameters.grey.File = GreyPath; + parameters.grey.ImgThreshold = GreyThreshold; + parameters.masks.white.File = WhitePath; + parameters.masks.csf.File = CSFPath; + parameters.masks.epi.File = BrainPath; + parameters.rois.mask.MaskFLAG = MaskBrain; + + for iRun = 1:ImageNumRun + Run = RunDir{iRun}; + + ImagePath = mc_GenPath(ImageTemplate); + ImageFiles = spm_select('FPList',ImagePath, ['^' basefile '.*.' imagetype]); + RealignmentParametersFile = mc_GenPath(RealignmentParametersTemplate); + + parameters.data.run(iRun).P = ImageFiles; + + RealignmentParameters = load(RealignmentParametersFile); + RealignmentParametersDeriv = diff(RealignmentParameters); + RealignmentParametersDerivR = resample(RealignmentParametersDeriv,size(RealignmentParameters,1),size(RealignmentParametersDeriv,1)); + + parameters.data.run(iRun).MotionParameters = [RealignmentParameters RealignmentParametersDerivR]; + parameters.data.run(iRun).nTIME = NumScan(iRun); + parameters.data.MaskFLAG = MaskBrain; + + parameters.TIME.run(iRun).TR = TR; + parameters.TIME.run(iRun).BandFLAG = DoBandpassFilter; + parameters.TIME.run(iRun).TrendFLAG = DoLinearDetrend; + parameters.TIME.run(iRun).LowF = LowFrequency; + parameters.TIME.run(iRun).HiF = HighFrequency; + parameters.TIME.run(iRun).gentle = Gentle; + parameters.TIME.run(iRun).padding = Padding; + parameters.TIME.run(iRun).whichFilter = BandpassFilter; + parameters.TIME.run(iRun).fraction = Fraction; + end + + Run = RunDir{1}; + ImagePath = mc_GenPath(ImageTemplate); + SOM_Mask = mc_GenPath(fullfile(ImagePath,'som_mask.img')); + + if (isempty(BrainMaskTemplate)) + parameters.rois.mask.File = SOM_Mask; + else + parameters.rois.mask.File = BrainPath; + end + output.Template = OutputTemplate; + output.type = 1; + output.mode = 'makedir'; + if (RunMode(1)) + OutputPath = mc_GenPath(output); + else + OutputPath = mc_GenPath(OutputTemplate); + end + + switch (ROIInput) + case 'files' + ROIFolder = mc_GenPath(ROITemplate); + for iROIs = 1:size(ROIImages,1) + ROI{iROIs} = fullfile(ROIFolder,ROIImages{iROIs}); + end + parameters.rois.files = char(ROI); + + case 'coordinates' + parameters.rois.mni.coordinates = ROICenters; + if (iscell(ROISize)) + parameters.rois.mni.size = ROISize{1}; + else + XYZ = SOM_MakeSphereROI(ROISize); + parameters.rois.mni.size.XROI = XYZ(1,:); + parameters.rois.mni.size.YROI = XYZ(2,:); + parameters.rois.mni.size.ZROI = XYZ(3,:); + end + case 'grid' + ROIGridMask = mc_Genpath(ROIGridMaskTemplate); + ROIGridMaskHdr = spm_vol(ROIGridMask); + ROIGridBB = mc_GetBoundingBox(ROIGridMaskHdr); + grid_coord_cand = SOM_MakeGrid(ROIGridSpacing,ROIGridBB); + inOutIDX = SOM_roiPointsInMask(ROIGridMask,grid_coord_cand); + grid_coord = grid_coord_cand(inOutIDX,:); + parameters.rois.mni.coordinates = grid_coord; + if (iscell(ROIGridSize)) + parameters.rois.mni.size = ROIGridSize{1}; + else + XYZ = SOM_MakeSphereROI(ROIGridSize); + parameters.rois.mni.size.XROI = XYZ(1,:); + parameters.rois.mni.size.YROI = XYZ(2,:); + parameters.rois.mni.size.ZROI = XYZ(2,:); + end + end + + parameters.Output.correlation = ROIOutput; + %parameters.Output.description = 'description of output'; + parameters.Output.directory = OutputPath; + parameters.Output.name = OutputName; + ParameterFilename = [OutputName '_parameters']; + ParameterPath = mc_GenPath(fullfile(OutputPath,ParameterFilename)); + save(ParameterPath,'parameters'); + + end +end + +if (RunMode(2)) + for iSubject = 1:size(SubjDir,1) + clear D0 parameters results; + Subject=SubjDir{iSubject,1}; + %load existing parameter file + OutputPath = mc_GenPath(OutputTemplate); + load(fullfile(OutputPath,ParameterFilename)); + clear global SOM; + global SOM; + SOM.silent = 1; + SOM_LOG('STATUS : 01'); + + [D0 parameters] = SOM_PreProcessData(parameters); + if D0 == -1 + SOM_LOG('FATAL ERROR : No data returned'); + mc_Error('There is something wrong with your template or your data.\nNo data was returned from SOM_PreProcessData\n'); + else + results = SOM_CalculateCorrelations(D0,parameters); + if isnumeric(results) + SOM_LOG('FATAL ERROR : '); + mc_Error('There is something wrong with your template or your data.\nNo results were returned from SOM_CalculateCorrelations\n'); + end + end + end +end + + + + diff --git a/som/som_batch_mc_template.m b/som/som_batch_mc_template.m new file mode 100644 index 00000000..8053458b --- /dev/null +++ b/som/som_batch_mc_template.m @@ -0,0 +1,316 @@ +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +%%% GENERAL OPTIONS +%%% These options are shared among many of our scripts +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% + +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +%%% The folder that contains your subject folders +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +Exp = '/net/data4/MAS/'; + +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +%%% Path where your images are located +%%% +%%% Variables you can use in your template are: +%%% Exp = path to your experiment directory +%%% iSubject = index for subject +%%% Subject = name of subject from SubjDir (using iSubject as index of row) +%%% iRun = index of run (listed in Column 3 of SubjDir) +%%% Run = name of run from RunDir (using iRun as index of row) +%%% * = wildcard (can only be placed in final part of template) +%%% Examples: +%%% ImageTemplate = '[Exp]/Subjects/[Subject]/func/run_0[iRun]/'; +%%% ImageTemplate = '[Exp]/Subjects/[Subject]/TASK/func/[Run]/' +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +ImageTemplate = '[Exp]/Subjects/[Subject]/TASK/func/[Run]/'; + +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +%%% A list of run folders where the script can find functional images +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +RunDir = { + 'run_01/'; +}; + +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +%%% The list of subjects to process +%%% The format is 'subjectfolder',subject number in masterfile,[runs to include] +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +SubjDir = { +'5001/Tx1',50011,[1]; +'5002/Tx1',50021,[1]; +'5003/Tx1',50031,[1]; +'5004/Tx1',50041,[1]; +'5005/Tx1',50051,[1]; +'5010/Tx1',50101,[1]; +'5012/Tx1',50121,[1]; +'5014/Tx1',50141,[1]; +'5015/Tx1',50151,[1]; +'5016/Tx1',50161,[1]; +'5017/Tx1',50171,[1]; +'5018/Tx1',50181,[1]; +'5019/Tx1',50191,[1]; +'5020/Tx1',50201,[1]; +'5021/Tx1',50211,[1]; +'5023/Tx1',50231,[1]; +'5024/Tx1',50241,[1]; +'5025/Tx1',50251,[1]; +'5026/Tx1',50261,[1]; +'5028/Tx1',50281,[1]; +'5029/Tx1',50291,[1]; +'5031/Tx1',50311,[1]; +'5032/Tx1',50321,[1]; +'5034/Tx1',50341,[1]; +'5035/Tx1',50351,[1]; +'5036/Tx1',50361,[1]; +'5037/Tx1',50371,[1]; +'5038/Tx1',50381,[1]; +'5039/Tx1',50391,[1]; +'5040/Tx1',50401,[1]; +'5041/Tx1',50411,[1]; +'5042/Tx1',50421,[1]; + +'5001/Tx2',50012,[1]; +'5002/Tx2',50022,[1]; +'5003/Tx2',50032,[1]; +'5004/Tx2',50042,[1]; +'5005/Tx2',50052,[1]; +'5010/Tx2',50102,[1]; +'5012/Tx2',50122,[1]; +'5014/Tx2',50142,[1]; +'5015/Tx2',50152,[1]; +'5016/Tx2',50162,[1]; +'5017/Tx2',50172,[1]; +'5018/Tx2',50182,[1]; +'5019/Tx2',50192,[1]; +'5020/Tx2',50202,[1]; +'5021/Tx2',50212,[1]; +'5023/Tx2',50232,[1]; +'5024/Tx2',50242,[1]; +'5025/Tx2',50252,[1]; +'5026/Tx2',50262,[1]; +'5028/Tx2',50282,[1]; +'5029/Tx2',50292,[1]; +'5031/Tx2',50312,[1]; +'5032/Tx2',50322,[1]; +'5034/Tx2',50342,[1]; +'5035/Tx2',50352,[1]; +'5036/Tx2',50362,[1]; +'5037/Tx2',50372,[1]; +'5038/Tx2',50382,[1]; +'5039/Tx2',50392,[1]; +'5040/Tx2',50402,[1]; +'5041/Tx2',50412,[1]; +'5042/Tx2',50422,[1]; + }; + +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +%%% The TR your data was collected at +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +TR = 2; + +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +%%% Prefixes for slicetiming, realignment, normalization, and smoothing +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +stp = 'a'; +rep = 'r'; +nop = 'w'; +smp = 's'; + +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +%%% Preprocessing that has already been completed on images +%%% [slicetime realign normalize smooth] +%%% If you are only running First Level (i.e. Preprocessing is already done) +%%% setting these will add the appropriate prefix to the basefile +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +alreadydone = [1 1 1 1]; + +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +%%% The prefix of each functional file +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +basefile = 'restrun'; + +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +%%% Image Type should be either 'nii' or 'img' +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +imagetype = 'nii'; + +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +%%% Number of Functional scans per run +%%% (if you have more than 1 run, there should be more than 1 value here) +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +NumScan = [180]; + + +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +%%% CONNECTIVITY OPTIONS +%%% These options are only used for Connectivity +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% + + +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +%%% Mode to run som_batch_mc_central in +%%% 'test' = test script but do not save parameters or run any +%%% SOM code +%%% 'parameters' = run script and save parameters for each subject +%%% but do not run any SOM code +%%% 'som' = run SOM code on previously saved parameters +%%% 'full' = generate parameters and immediately run SOM code +%%% +%%% NOTE: If you choose mode 'som' then most variables except +%%% SubjDir and OutputTemplate/OutputName will be ignored as they +%%% will be loaded from the already existing parameter file for each +%%% subject. +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +Mode = 'full'; + +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +%%% Paths to your anatomical images +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +GreyMatterTemplate = '[Exp]/Subjects/[Subject]/anatomy/rgrey.img'; +WhiteMatterTemplate = '[Exp]/Subjects/[Subject]/anatomy/wm_mask.nii'; +CSFTemplate = '[Exp]/Subjects/[Subject]/anatomy/csf_mask.nii'; + +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +%%% Where to output the data +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +OutputTemplate = '[Exp]/FirstLevel/[Subject]/[OutputName]/'; +OutputName = 'Striatum'; + +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +%%% Path and name of explicit mask to use at first level. +%%% Leaving this blank ('') will use a subject-specific mask +%%% NOTE: Subject-specific masks are not recommended for grid usage below. +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +BrainMaskTemplate = '[Exp]/ROIS/rEPI_MASK_NOEYES.img'; + +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +%%% Path Template for realignment parameters file +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +RealignmentParametersTemplate = '[Exp]/Subjects/[Subject]/TASK/func/[Run]/rp_arestrun_*'; + +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +%%% Constrain results to only regions in GreyMatterTemplate (1=yes, 0=no) +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +MaskGrey = 0; + +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +%%% Value threshold to use for each mask. If left as [] use default 0.75 +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +GreyThreshold = []; +WhiteThreshold = []; +CSFThreshold = []; +EPIThreshold = []; + +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +%%% the order to perform the regressions etc +%%% D = detrend +%%% G = global +%%% W = white matter +%%% C = csf +%%% M = motion +%%% B = bandpass +%%% +%%% Suggested order is "D[G]CWMB" +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +RegressOrder = 'DCWMB'; + +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +%%% Use this many principle components for regression +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +PrincipalComponents = 5; + +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +%%% Bandpass Filter Settings +%%% LowFrequency - low frequency cutoff +%%% HighFrequency - high frequency cutoff +%%% Gentle - 0 = no rolling, 1 = rolling +%%% Padding - number of timepoints to pad on beginning/end +%%% BandpassFilter - 0 = Matlab filter, 1 = SOM_Filter_FFT +%%% Fraction - fraction of variance for principle components +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +LowFrequency = 0.01; +HighFrequency = 0.1; +Gentle = 1; +Padding = 10; +BandpassFilter = 1; +Fraction = 1; + +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +%%% Type of input +%%% coordinates - provide the center of each seed and a radius +%%% files - provide a list of ROI files +%%% grid - make a grid based on provided spacing and masked +%%% by provided mask +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +ROIInput = 'coordinates'; + +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +%%% If specifying ROI coordinates you need to provide a list of centers in +%%% MNI coordinates (mm) and a radius in voxels. +%%% NOTE: ROISize will be used as the radius of a sphere at each point. If +%%% you'd prefer to use the predefined 1,7,19, or 27 voxel sizes you will +%%% need to specify the size as a cell (i.e. {19}) +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +ROICenters = [ + %0 -53 26; %pcc seed + 9 9 -8; %VSi right + -9 9 -8; %VSi left + 10 15 0; %VSs right + -10 15 0; %VSs left + 13 15 9; %DC right + -13 15 9; %DC left + 28 1 3; %DCP right + -28 1 3; %DCP left + 25 8 6; %DRP right + -25 8 6; %DRP left + 20 12 -3; %VRP right + -20 12 -3; %VRP left + ]; +ROISize = {19}; + +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +%%% If specifying ROI images you need to provide an ROI folder as well as a +%%% cell array list of ROI images. +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +ROITemplate = '[Exp]/ROIS'; +ROIImages = { + 'image1.nii'; + 'image2.nii'; + }; + +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +%%% If specifying ROI grid you need to provide a spacing and ROI size as +%%% well as an optional mask for grid point inclusion (a mask is strongly +%%% encouraged as not using one will return coordinates from across the entire +%%% bounding box). +%%% NOTE: ROIGridSize will be used as the radius of a sphere at each grid +%%% point. If you'd prefer to use the predefined 1,7,19, or 27 voxel sizes +%%% you will need to specify the size as a cell (i.e. {19}) +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +ROIGridSpacing = 12; +ROIGridSize = {19}; +ROIGridMaskTemplate = '[Exp]/ROIS/ravg_gm_mask_and_EPI_mask.img'; +%ROIGridMaskTemplate = '[Exp]/ROIS/rEPI_MASK_NOEYES.img'; +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +%%% Type of output +%%% images - output R and Z images of correlation with each seed +%%% maps - output R and P matrix of correlations between seeds +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +ROIOutput = 'images'; + + +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +%%% Do not edit below this line +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% + +%DEVSTART +mcRoot = fullfile(fileparts(mfilename('fullpath')),'../../MethodsCore'); +%DEVSTOP + +%[DEVmcRootAssign] + +addpath(fullfile(mcRoot,'matlabScripts')); +addpath(fullfile(mcRoot,'som')); +addpath(fullfile(mcRoot,'spm8')); + +som_batch_mc_central \ No newline at end of file