From b631503d1da5ebb1406976d51b833821f540955d Mon Sep 17 00:00:00 2001 From: "Robert C. Welsh" Date: Fri, 23 Mar 2012 14:19:28 -0400 Subject: [PATCH 01/29] Fixed some stupid bugs. Thanks Mike for finding them! And also deprecated SOM_read_nii_img and added SOM_readNII.m --- som/SOM_CheckDataStructure.m | 12 +++++----- som/SOM_PreProcessData.m | 17 ++++++++++---- som/SOM_PrepData.m | 7 +++--- som/SOM_ReadNII.m | 44 ++++++++++++++++++++++++++++++++++++ som/SOM_ReadNII.m~ | 44 ++++++++++++++++++++++++++++++++++++ 5 files changed, 111 insertions(+), 13 deletions(-) create mode 100644 som/SOM_ReadNII.m create mode 100644 som/SOM_ReadNII.m~ diff --git a/som/SOM_CheckDataStructure.m b/som/SOM_CheckDataStructure.m index 24d7572a..3350d65d 100644 --- a/som/SOM_CheckDataStructure.m +++ b/som/SOM_CheckDataStructure.m @@ -94,13 +94,13 @@ if exist(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'); diff --git a/som/SOM_PreProcessData.m b/som/SOM_PreProcessData.m index cba01449..73fa68d6 100644 --- a/som/SOM_PreProcessData.m +++ b/som/SOM_PreProcessData.m @@ -555,7 +555,7 @@ enTIME = []; for iRUN = length(parameters.data.run) - if exist(parmaters.data.run(iRUN),'censorVector') + if isfield(paramaters.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.'); @@ -567,11 +567,20 @@ end end -% Now calculate the new length. +% Now calculate the new length, that is if we need to. -cenTIME = cumsum(enTIME); +if length(enTIME) > 0 + cenTIME = cumsum(enTIME); + 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 + +% 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. 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_ReadNII.m~ b/som/SOM_ReadNII.m~ new file mode 100644 index 00000000..6a7e400c --- /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 +% \ No newline at end of file From e304fe7f63a43a1030e5d35c1bf0ccce60e6fe2d Mon Sep 17 00:00:00 2001 From: Mike Angstadt Date: Fri, 9 Mar 2012 18:17:59 -0500 Subject: [PATCH 02/29] initial skeleton of som_batch matlab wrapper --- som/som_batch_mc_template.m | 123 ++++++++++++++++++++++++++++++++++++ 1 file changed, 123 insertions(+) create mode 100644 som/som_batch_mc_template.m diff --git a/som/som_batch_mc_template.m b/som/som_batch_mc_template.m new file mode 100644 index 00000000..60c871e0 --- /dev/null +++ b/som/som_batch_mc_template.m @@ -0,0 +1,123 @@ +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +%%% GENERAL OPTIONS +%%% These options are shared among many of our scripts +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% + +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +%%% The path to SPM on your system +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +spmpath = '/net/dysthymia/spm8'; + +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +%%% 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/'; + 'run_02/'; +}; + +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +%%% The list of subjects to process +%%% The format is 'subjectfolder',subject number in masterfile,[runs to include] +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +SubjDir = { + '5034/Tx2',50342,[1], 0, 0; + '5035/Tx1',50351,[1 2], 0, 0; + '5035/Tx2',50352,[1 2], 0, 0; + '5036/Tx1',50361,[1], 0, 0; + '5036/Tx2',50362,[1], 0, 0; + '5037/Tx1',50371,[1], 0, 0; + '5037/Tx2',50372,[1], 0, 0; + '5038/Tx1',50381,[1], 0, 0; + '5038/Tx2',50382,[1], 0, 0; + '5039/Tx1',50391,[1], 0, 0; + '5039/Tx2',50392,[1], 0, 0; + }; + +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +%%% The TR your data was collected at +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +TR = 2; + +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +%%% Prefixes for slicetiming, realignment, normalization, and smoothing (spm8 only) +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +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 = 'run'; + +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +%%% 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 180]; + + +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +%%% CONNECTIVITY OPTIONS +%%% These options are only used for Connectivity +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% + +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +%% Paths to your anatomical images +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +GrayMatterTemplate = '[Exp]/Subjects/[Subject]/anatomy/'; +WhiteMatterTemplate = '[Exp]/Subjects/[Subject]/anatomy/'; +CSFTemplate = '[Exp]/Subjects/[Subject]/anatomy/'; + +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +%%% The voxel size to reslice your images to after normalization +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +vox_size = [3 3 3]; + +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +%%% Where to output the data +%%% OutputDir is constructed by /Exp/OutputLevel1/subjDir/OutputLevel2/OutputLevel3/ +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +OutputTemplate = '[Exp]/FirstLevel/[Subject]/[OutputName]/'; + +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +%%% Path and name of explicit mask to use at first level. +%%% Leave this blank ('') to turn off explicit masking +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +explicitmask = ''; From 5670cef690a7ea00828facffc2d201c232e72351 Mon Sep 17 00:00:00 2001 From: Mike Angstadt Date: Mon, 12 Mar 2012 19:00:05 -0400 Subject: [PATCH 03/29] added initial testing skeleton of som_batch_mc_central -- very preliminary --- som/som_batch_mc_central.m | 90 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 90 insertions(+) create mode 100644 som/som_batch_mc_central.m diff --git a/som/som_batch_mc_central.m b/som/som_batch_mc_central.m new file mode 100644 index 00000000..6a5e8ccc --- /dev/null +++ b/som/som_batch_mc_central.m @@ -0,0 +1,90 @@ +iRun = 1; + +GreyPath = mc_GenPath(GreyMatterTemplate); +WhitePath = mc_GenPath(WhiteMatterTemplate); +CSFPath = mc_GenPath(CSFTemplate); +BrainPath = mc_GenPath(BrainMaskTemplate); +OutputPath = mc_GenPath(OutputTemplate); +ImagePath = mc_GenPath(ImageTemplate); +ImageFiles = spm_select('FPList',ImagePath, ['^' Pswra basefile '*.' imagetype]); +RealignmentParametersFile = mc_GenPath(RealignmentParametersTemplate); + +parameters.grey.File = GreyPath; +parameters.grey.MaskFLAG = MaskGrey; +parameters.grey.ImgThreshold = GreyThreshold; + +parameters.white.File = WhitePath; +parameters.white.MaskFLAG = RegressWhite; + +parameters.csf.File = CSFPath; +parameters.csf.MaskFLAG = RegressCSF; + +parameters.epi.File = BrainPath; +parameters.epi.MaskFLAG = MaskBrain; + +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.RegressFLAGS.prinComp = PrincipalComponents; +parameters.RegressFLAGS.global = RegressGlobal; +parameters.RegressFLAGS.csf = RegressCSF; +parameters.RegressFLAGS.white = RegressWhite; +parameters.RegressFLAGS.motion = RegressMotion; +parameters.RegressFLAGS.order = ProcessOrder; + +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; + +parameters.rois.files = ; + +%-OR- + +parameters.rois.mni.coordinates = []; +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,:); + +parameters.rois.mask.File = BrainPath; +parameters.rois.mask.MaskFLAG = BrainMask; + +parameters.Output.correlation = 'images'; %or maps +parameters.Output.description = 'description of output'; +parameters.Output.directory = OutputPath; +parameters.Output.name = 'result file name'; + + + +global SOM +SOM.silent = 1; +SOM_LOG('STATUS : 01'); + + + + + + +[D0 parameters] = SOM_PreProcessData(parameters); +if D0 == -1 + SOM_LOG('FATAL ERROR : No data returned'); +else + results = SOM_CalculateCorrelations(D0,parameters); + if isnumeric(results) + SOM_LOG('FATAL ERROR : '); + end +end + From 76d6140c72ab6582718b73e5264657cde32515f0 Mon Sep 17 00:00:00 2001 From: Mike Angstadt Date: Tue, 13 Mar 2012 17:41:46 -0400 Subject: [PATCH 04/29] incremental updates to both template and central -- still very preliminary --- som/som_batch_mc_central.m | 28 +++++++++--------- som/som_batch_mc_template.m | 57 +++++++++++++++++++++++++++---------- 2 files changed, 56 insertions(+), 29 deletions(-) diff --git a/som/som_batch_mc_central.m b/som/som_batch_mc_central.m index 6a5e8ccc..f4755a5c 100644 --- a/som/som_batch_mc_central.m +++ b/som/som_batch_mc_central.m @@ -22,14 +22,14 @@ parameters.epi.File = BrainPath; parameters.epi.MaskFLAG = MaskBrain; -parameters.data.run[iRun].P = ImageFiles; +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.run(iRun).MotionParameters = [RealignmentParameters RealignmentParametersDerivR]; +parameters.data.run(iRun).nTIME = NumScan(iRun); parameters.data.MaskFLAG = MaskBrain; parameters.RegressFLAGS.prinComp = PrincipalComponents; @@ -39,17 +39,17 @@ parameters.RegressFLAGS.motion = RegressMotion; parameters.RegressFLAGS.order = ProcessOrder; -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; - -parameters.rois.files = ; +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; + +parameters.rois.files = ''; %-OR- diff --git a/som/som_batch_mc_template.m b/som/som_batch_mc_template.m index 60c871e0..13356447 100644 --- a/som/som_batch_mc_template.m +++ b/som/som_batch_mc_template.m @@ -34,7 +34,6 @@ %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% RunDir = { 'run_01/'; - 'run_02/'; }; %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% @@ -42,17 +41,17 @@ %%% The format is 'subjectfolder',subject number in masterfile,[runs to include] %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% SubjDir = { - '5034/Tx2',50342,[1], 0, 0; - '5035/Tx1',50351,[1 2], 0, 0; - '5035/Tx2',50352,[1 2], 0, 0; - '5036/Tx1',50361,[1], 0, 0; - '5036/Tx2',50362,[1], 0, 0; - '5037/Tx1',50371,[1], 0, 0; - '5037/Tx2',50372,[1], 0, 0; - '5038/Tx1',50381,[1], 0, 0; - '5038/Tx2',50382,[1], 0, 0; - '5039/Tx1',50391,[1], 0, 0; - '5039/Tx2',50392,[1], 0, 0; + '5034/Tx2',50342,[1]; +% '5035/Tx1',50351,[1]; +% '5035/Tx2',50352,[1]; +% '5036/Tx1',50361,[1]; +% '5036/Tx2',50362,[1]; +% '5037/Tx1',50371,[1]; +% '5037/Tx2',50372,[1]; +% '5038/Tx1',50381,[1]; +% '5038/Tx2',50382,[1]; +% '5039/Tx1',50391,[1]; +% '5039/Tx2',50392,[1]; }; %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% @@ -90,7 +89,7 @@ %%% Number of Functional scans per run %%% (if you have more than 1 run, there should be more than 1 value here) %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -NumScan = [180 180]; +NumScan = [180]; %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% @@ -101,7 +100,7 @@ %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %% Paths to your anatomical images %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -GrayMatterTemplate = '[Exp]/Subjects/[Subject]/anatomy/'; +GreyMatterTemplate = '[Exp]/Subjects/[Subject]/anatomy/'; WhiteMatterTemplate = '[Exp]/Subjects/[Subject]/anatomy/'; CSFTemplate = '[Exp]/Subjects/[Subject]/anatomy/'; @@ -115,9 +114,37 @@ %%% OutputDir is constructed by /Exp/OutputLevel1/subjDir/OutputLevel2/OutputLevel3/ %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% OutputTemplate = '[Exp]/FirstLevel/[Subject]/[OutputName]/'; +OutputName = 'TEST'; %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %%% Path and name of explicit mask to use at first level. %%% Leave this blank ('') to turn off explicit masking %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -explicitmask = ''; +BrainMaskTemplate = ''; + +RealignmentParametersTemplate = '[Exp]/Subjects/[Subject]/TASK/func/[Run]/rp_arun_*'; + + + +MaskGrey = 0; +GreyThreshold = 0.75; +RegressWhite = 1; +RegressCSF = 1; +MaskBrain = 1; +RegressMotion = 1; +PrincipalComponents = 5; +RegressGlobal = 0; +ProcessOrder = 'DCWMB'; + +DoBandpassFilter = 1; +DoLinearDetrend = 1; +LowFrequency = 0.01; +HighFrequency = 0.1; +Gentle = 1; +Padding = 10; + +BandpassFilter = 1; +Fraction = 1; + +addpath /net/dysthymia/mangstad/repos/MethodsCore/som +som_batch_mc_central \ No newline at end of file From 36d6c23bd115c8abf1b97c6897f8803b8fa3631c Mon Sep 17 00:00:00 2001 From: Mike Angstadt Date: Mon, 26 Mar 2012 17:21:59 -0400 Subject: [PATCH 05/29] updated mc_central and mc_template --- som/som_batch_mc_central.m | 31 ++++++++++++++++++------------- som/som_batch_mc_template.m | 15 +++++++++++---- 2 files changed, 29 insertions(+), 17 deletions(-) diff --git a/som/som_batch_mc_central.m b/som/som_batch_mc_central.m index f4755a5c..fc2b5dc4 100644 --- a/som/som_batch_mc_central.m +++ b/som/som_batch_mc_central.m @@ -4,9 +4,14 @@ WhitePath = mc_GenPath(WhiteMatterTemplate); CSFPath = mc_GenPath(CSFTemplate); BrainPath = mc_GenPath(BrainMaskTemplate); -OutputPath = mc_GenPath(OutputTemplate); + +output.Template = OutputTemplate; +output.type = 1; +output.mode = 'makedir'; + +OutputPath = mc_GenPath(output); ImagePath = mc_GenPath(ImageTemplate); -ImageFiles = spm_select('FPList',ImagePath, ['^' Pswra basefile '*.' imagetype]); +ImageFiles = spm_select('FPList',ImagePath, ['^' Pswra basefile '.*.' imagetype]); RealignmentParametersFile = mc_GenPath(RealignmentParametersTemplate); parameters.grey.File = GreyPath; @@ -53,14 +58,14 @@ %-OR- -parameters.rois.mni.coordinates = []; +parameters.rois.mni.coordinates = [0 0 0]; 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,:); parameters.rois.mask.File = BrainPath; -parameters.rois.mask.MaskFLAG = BrainMask; +parameters.rois.mask.MaskFLAG = MaskBrain; parameters.Output.correlation = 'images'; %or maps parameters.Output.description = 'description of output'; @@ -69,7 +74,7 @@ -global SOM +global SOM; SOM.silent = 1; SOM_LOG('STATUS : 01'); @@ -79,12 +84,12 @@ [D0 parameters] = SOM_PreProcessData(parameters); -if D0 == -1 - SOM_LOG('FATAL ERROR : No data returned'); -else - results = SOM_CalculateCorrelations(D0,parameters); - if isnumeric(results) - SOM_LOG('FATAL ERROR : '); - end -end +%if D0 == -1 +% SOM_LOG('FATAL ERROR : No data returned'); +%else +% results = SOM_CalculateCorrelations(D0,parameters); +% if isnumeric(results) +% SOM_LOG('FATAL ERROR : '); +% end +%end diff --git a/som/som_batch_mc_template.m b/som/som_batch_mc_template.m index 13356447..33f64d0c 100644 --- a/som/som_batch_mc_template.m +++ b/som/som_batch_mc_template.m @@ -100,9 +100,9 @@ %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %% Paths to your anatomical images %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -GreyMatterTemplate = '[Exp]/Subjects/[Subject]/anatomy/'; -WhiteMatterTemplate = '[Exp]/Subjects/[Subject]/anatomy/'; -CSFTemplate = '[Exp]/Subjects/[Subject]/anatomy/'; +GreyMatterTemplate = '[Exp]/Subjects/[Subject]/anatomy/rgrey.img'; +WhiteMatterTemplate = '[Exp]/Subjects/[Subject]/anatomy/rwhite.img'; +CSFTemplate = '[Exp]/Subjects/[Subject]/anatomy/rcsf.img'; %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %%% The voxel size to reslice your images to after normalization @@ -130,7 +130,7 @@ GreyThreshold = 0.75; RegressWhite = 1; RegressCSF = 1; -MaskBrain = 1; +MaskBrain = 0; RegressMotion = 1; PrincipalComponents = 5; RegressGlobal = 0; @@ -146,5 +146,12 @@ BandpassFilter = 1; Fraction = 1; +ROISize = 2; + +addpath /net/dysthymia/mangstad/repos/MethodsCore/matlabScripts addpath /net/dysthymia/mangstad/repos/MethodsCore/som +addpath /net/dysthymia/spm8 +Subject = SubjDir{1,1}; +Run = RunDir{1}; +Pswra = 'swra'; som_batch_mc_central \ No newline at end of file From 071aba3992ade5f9a5c672dab81149e1cf368756 Mon Sep 17 00:00:00 2001 From: Mike Angstadt Date: Tue, 27 Mar 2012 16:04:01 -0400 Subject: [PATCH 06/29] fixed commenting --- som/som_batch_mc_template.m | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/som/som_batch_mc_template.m b/som/som_batch_mc_template.m index 33f64d0c..f614fd34 100644 --- a/som/som_batch_mc_template.m +++ b/som/som_batch_mc_template.m @@ -14,18 +14,18 @@ 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]/' +%%% 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]/'; From 50a3638bdd7f5a935db56bfee284e7ac2005ded0 Mon Sep 17 00:00:00 2001 From: "Robert C. Welsh" Date: Thu, 29 Mar 2012 09:32:23 -0400 Subject: [PATCH 07/29] Fixed small bug in writing of zmaps to local directory instead of parameters.Output.directory, noted by Mike A. --- som/SOM_CalculateCorrelationImages.m | 2 +- som/SOM_ParseFileParam.m | 8 +++++--- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/som/SOM_CalculateCorrelationImages.m b/som/SOM_CalculateCorrelationImages.m index a16bd64c..15c4b310 100755 --- a/som/SOM_CalculateCorrelationImages.m +++ b/som/SOM_CalculateCorrelationImages.m @@ -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_%03d.nii',parameters.Output.name,iROI)); Vo.mat = Vi.mat; Vo.dim = Vi.dim; Vo.dt = [16 0]; diff --git a/som/SOM_ParseFileParam.m b/som/SOM_ParseFileParam.m index 6ff97b02..7c41e035 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,8 +36,8 @@ 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 @@ -49,7 +51,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 From 54677ed01e9f94ec32083d0eda4e2f44262484ac Mon Sep 17 00:00:00 2001 From: Mike Angstadt Date: Tue, 27 Mar 2012 17:19:59 -0400 Subject: [PATCH 08/29] fixed some typos/bugs --- som/SOM_CheckDataStructure.m | 2 +- som/SOM_PreProcessData.m | 9 +++++---- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/som/SOM_CheckDataStructure.m b/som/SOM_CheckDataStructure.m index 3350d65d..b663bf11 100644 --- a/som/SOM_CheckDataStructure.m +++ b/som/SOM_CheckDataStructure.m @@ -92,7 +92,7 @@ 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 does not match %d'),iRUN,data.run(iRUN).nTIME) return diff --git a/som/SOM_PreProcessData.m b/som/SOM_PreProcessData.m index 73fa68d6..ff64011b 100644 --- a/som/SOM_PreProcessData.m +++ b/som/SOM_PreProcessData.m @@ -555,13 +555,13 @@ enTIME = []; for iRUN = length(parameters.data.run) - if isfield(paramaters.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))); + 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)]; end end @@ -573,7 +573,7 @@ cenTIME = cumsum(enTIME); SOM_LOG(sprintf('STATUS : Edited data to : %d space by total %d time-points',nSPACE(1),cenTIME(end))); else - enTIME=nTIME; + cenTIME=nTIME; SOM_LOG(sprintf('STATUS : No editing of data : %d space by total % time-points',nSPACE(1),cnTIME(end))); end @@ -584,8 +584,9 @@ % Now contactenate the data. -D0 = zeros(nSPACE(1),sum(enTIME)); +D0 = zeros(nSPACE(1),sum(cenTIME)); +cenTIME = [0 cenTIME]; for iRUN = 1:length(parameters.data.run) D0(:,cenTIME(iRUN)+1:cenTIME(iRUN+1)) = D0RUN(iRUN).D0; end From 4e392f91451efdddb8811ca2b7a0e14853bee701 Mon Sep 17 00:00:00 2001 From: Mike Angstadt Date: Wed, 28 Mar 2012 18:01:58 -0400 Subject: [PATCH 09/29] updated SOM_CreateMask to work with .nii images and SPM8 --- som/SOM_CreateMask.m | 171 ++++++++++++++++++++++++++++--------------- 1 file changed, 111 insertions(+), 60 deletions(-) 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; From b2f9c82157a5e1ce68226e3dec753189c3d425a1 Mon Sep 17 00:00:00 2001 From: Mike Angstadt Date: Wed, 28 Mar 2012 18:02:35 -0400 Subject: [PATCH 10/29] bugfixes on SOM functions --- som/SOM_CalculateCorrelationImages.m | 4 ++-- som/SOM_CheckROIParameters.m | 2 +- som/SOM_PreProcessData.m | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/som/SOM_CalculateCorrelationImages.m b/som/SOM_CalculateCorrelationImages.m index a16bd64c..dc2fb99f 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 for iROI = 1 : parameters.rois.nroisRequested @@ -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_%03d.nii',parameters.Output.name,iROI)); Vo.mat = Vi.mat; Vo.dim = Vi.dim; Vo.dt = [16 0]; diff --git a/som/SOM_CheckROIParameters.m b/som/SOM_CheckROIParameters.m index 2de056d3..63516cd0 100644 --- a/som/SOM_CheckROIParameters.m +++ b/som/SOM_CheckROIParameters.m @@ -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_PreProcessData.m b/som/SOM_PreProcessData.m index ff64011b..6c7494f4 100644 --- a/som/SOM_PreProcessData.m +++ b/som/SOM_PreProcessData.m @@ -282,7 +282,7 @@ if parameters.data.MaskFLAG == 1 if parameters.epi.MaskFLAG == 0 - fprint('Calculating subject specific epi mask'); + 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 From b81a2e885e99555cf175c851e7ec045234a766cf Mon Sep 17 00:00:00 2001 From: Mike Angstadt Date: Wed, 28 Mar 2012 18:03:37 -0400 Subject: [PATCH 11/29] updated mc_central/mc_template - still just testing versions --- som/som_batch_mc_central.m | 14 ++++++++++++-- som/som_batch_mc_template.m | 4 ++-- 2 files changed, 14 insertions(+), 4 deletions(-) diff --git a/som/som_batch_mc_central.m b/som/som_batch_mc_central.m index fc2b5dc4..0304c8c6 100644 --- a/som/som_batch_mc_central.m +++ b/som/som_batch_mc_central.m @@ -12,6 +12,7 @@ OutputPath = mc_GenPath(output); ImagePath = mc_GenPath(ImageTemplate); ImageFiles = spm_select('FPList',ImagePath, ['^' Pswra basefile '.*.' imagetype]); +SOM_Mask = fullfile(ImagePath,'som_mask.img'); RealignmentParametersFile = mc_GenPath(RealignmentParametersTemplate); parameters.grey.File = GreyPath; @@ -25,7 +26,12 @@ parameters.csf.MaskFLAG = RegressCSF; parameters.epi.File = BrainPath; -parameters.epi.MaskFLAG = MaskBrain; +if (isempty(BrainMaskTemplate)) + parameters.epi.MaskFLAG = 0; +else + paramters.epi.MaskFLAG = 1; +end + parameters.data.run(iRun).P = ImageFiles; @@ -64,7 +70,11 @@ parameters.rois.mni.size.YROI = XYZ(2,:); parameters.rois.mni.size.ZROI = XYZ(3,:); -parameters.rois.mask.File = BrainPath; +if (isempty(BrainMaskTemplate)) + parameters.rois.mask.File = SOM_Mask; +else + parameters.rois.mask.File = BrainPath; +end parameters.rois.mask.MaskFLAG = MaskBrain; parameters.Output.correlation = 'images'; %or maps diff --git a/som/som_batch_mc_template.m b/som/som_batch_mc_template.m index f614fd34..f0c72afc 100644 --- a/som/som_batch_mc_template.m +++ b/som/som_batch_mc_template.m @@ -98,7 +98,7 @@ %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -%% Paths to your anatomical images +%%% Paths to your anatomical images %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% GreyMatterTemplate = '[Exp]/Subjects/[Subject]/anatomy/rgrey.img'; WhiteMatterTemplate = '[Exp]/Subjects/[Subject]/anatomy/rwhite.img'; @@ -130,7 +130,7 @@ GreyThreshold = 0.75; RegressWhite = 1; RegressCSF = 1; -MaskBrain = 0; +MaskBrain = 1; RegressMotion = 1; PrincipalComponents = 5; RegressGlobal = 0; From 9afc9942d7c1a3431b4073e7a4ebd3807911246c Mon Sep 17 00:00:00 2001 From: Mike Angstadt Date: Thu, 29 Mar 2012 09:57:12 -0400 Subject: [PATCH 12/29] getting som_mc_central ready to test matrix --- som/som_batch_mc_central.m | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/som/som_batch_mc_central.m b/som/som_batch_mc_central.m index 0304c8c6..48bf2efe 100644 --- a/som/som_batch_mc_central.m +++ b/som/som_batch_mc_central.m @@ -64,12 +64,14 @@ %-OR- -parameters.rois.mni.coordinates = [0 0 0]; +parameters.rois.mni.coordinates = [0 0 0;20 20 20]; 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,:); + + if (isempty(BrainMaskTemplate)) parameters.rois.mask.File = SOM_Mask; else @@ -78,6 +80,7 @@ parameters.rois.mask.MaskFLAG = MaskBrain; parameters.Output.correlation = 'images'; %or maps +parameters.Output.correlation = 'maps'; parameters.Output.description = 'description of output'; parameters.Output.directory = OutputPath; parameters.Output.name = 'result file name'; From 53fa3b2db78da9d28bcb5b63bd75a52b743b55ad Mon Sep 17 00:00:00 2001 From: "Robert C. Welsh" Date: Thu, 29 Mar 2012 10:45:09 -0400 Subject: [PATCH 13/29] Fixed issues with SOM_PreProcessData that would have broken the concatentation of runs. --- som/SOM_PreProcessData.m | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/som/SOM_PreProcessData.m b/som/SOM_PreProcessData.m index 6c7494f4..7d2a394d 100644 --- a/som/SOM_PreProcessData.m +++ b/som/SOM_PreProcessData.m @@ -561,8 +561,8 @@ 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 @@ -570,13 +570,14 @@ % Now calculate the new length, that is if we need to. if length(enTIME) > 0 - cenTIME = cumsum(enTIME); SOM_LOG(sprintf('STATUS : Edited data to : %d space by total %d time-points',nSPACE(1),cenTIME(end))); else - cenTIME=nTIME; + 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)]; + % We can store all of this for posterity parameters.data.nTIME = nTIME; @@ -584,9 +585,8 @@ % Now contactenate the data. -D0 = zeros(nSPACE(1),sum(cenTIME)); +D0 = zeros(nSPACE(1),cenTIME(end))); -cenTIME = [0 cenTIME]; for iRUN = 1:length(parameters.data.run) D0(:,cenTIME(iRUN)+1:cenTIME(iRUN+1)) = D0RUN(iRUN).D0; end From eb76db851dffdb95b2768b5faa7bebc510fd46e7 Mon Sep 17 00:00:00 2001 From: "Robert C. Welsh" Date: Mon, 2 Apr 2012 22:01:54 -0400 Subject: [PATCH 14/29] Modification of the API, move .epi, .gray, .white, .csf into parameters.masks, also did a fix to the TIME structure replication. --- som/SOM_CalculateCorrelationImages.m | 2 +- som/SOM_CheckDataStructure.m | 4 +- som/SOM_CheckMasks.m | 92 +++++++++++ som/SOM_CheckMasks.m~ | 85 ++++++++++ som/SOM_CheckROIParameters.m | 2 +- som/SOM_CheckRegressFLAGS.m | 60 ++++--- som/SOM_CheckTimeParams.m | 5 +- som/SOM_MaskRead.m | 25 +++ som/SOM_ParseFileParam.m | 2 +- som/SOM_PreProcessData.m | 229 +++++++++++---------------- som/SOM_WriteNII.m | 15 +- 11 files changed, 343 insertions(+), 178 deletions(-) create mode 100644 som/SOM_CheckMasks.m create mode 100644 som/SOM_CheckMasks.m~ create mode 100644 som/SOM_MaskRead.m diff --git a/som/SOM_CalculateCorrelationImages.m b/som/SOM_CalculateCorrelationImages.m index dc2fb99f..00e28e62 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)); %this fails if user specified no masking +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 diff --git a/som/SOM_CheckDataStructure.m b/som/SOM_CheckDataStructure.m index b663bf11..dbb68182 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 @@ -104,7 +104,7 @@ 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 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_CheckMasks.m~ b/som/SOM_CheckMasks.m~ new file mode 100644 index 00000000..85adf1b1 --- /dev/null +++ b/som/SOM_CheckMasks.m~ @@ -0,0 +1,85 @@ +% - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +% +% 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 diff --git a/som/SOM_CheckROIParameters.m b/som/SOM_CheckROIParameters.m index 63516cd0..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 = []; diff --git a/som/SOM_CheckRegressFLAGS.m b/som/SOM_CheckRegressFLAGS.m index 510d47e3..b00cb529 100755 --- a/som/SOM_CheckRegressFLAGS.m +++ b/som/SOM_CheckRegressFLAGS.m @@ -41,9 +41,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 +81,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_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 7c41e035..457b4483 100755 --- a/som/SOM_ParseFileParam.m +++ b/som/SOM_ParseFileParam.m @@ -51,7 +51,7 @@ if exist(type.File,'file') == 0 type.OK = -1; - SOM_LOG(sprintf('FATAL Error : Masking file %s specified doesn''t exist',type.File); + 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 7d2a394d..dbc4eb98 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? - -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. +parameters.masks = SOM_CheckMasks(parameters); -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 + 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 % @@ -378,12 +337,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 +350,39 @@ 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 : CSF speficied but no CSF regression mask available.'); end parameters.stopCPU.run(iRUN).csf = cputime; @@ -440,39 +395,39 @@ 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 : WM speficied but no WM regression mask available.'); end parameters.stopCPU.run(iRUN).white = cputime; @@ -490,7 +445,7 @@ 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 : Motion speficied by motion regression internally turned off???'); end parameters.stopCPU.run(iRUN).motion = cputime; @@ -516,7 +471,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; @@ -585,7 +540,7 @@ % Now contactenate the data. -D0 = zeros(nSPACE(1),cenTIME(end))); +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_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; From 7acb4074aa5b5d839f6b5f7e6987ed7faacce562 Mon Sep 17 00:00:00 2001 From: "Robert C. Welsh" Date: Wed, 4 Apr 2012 11:28:41 -0400 Subject: [PATCH 15/29] Added SOM_MakeGrid and fixed some small comments and output messages --- som/SOM_CheckRegressFLAGS.m | 20 +++++----- som/SOM_MakeGrid.m | 76 +++++++++++++++++++++++++++++++++++++ som/SOM_MakeGrid.m~ | 0 som/SOM_PreProcessData.m | 18 +++++++-- 4 files changed, 99 insertions(+), 15 deletions(-) create mode 100644 som/SOM_MakeGrid.m create mode 100644 som/SOM_MakeGrid.m~ diff --git a/som/SOM_CheckRegressFLAGS.m b/som/SOM_CheckRegressFLAGS.m index b00cb529..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 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_MakeGrid.m~ b/som/SOM_MakeGrid.m~ new file mode 100644 index 00000000..e69de29b diff --git a/som/SOM_PreProcessData.m b/som/SOM_PreProcessData.m index dbc4eb98..1c0d0ca1 100644 --- a/som/SOM_PreProcessData.m +++ b/som/SOM_PreProcessData.m @@ -318,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 @@ -382,7 +383,9 @@ end else parameters.masks.csf.run(iRUN).regressors = []; - SOM_LOG('WARNING : CSF speficied but no CSF regression mask available.'); + 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; @@ -427,7 +430,9 @@ D0RUN(iRUN).D0 = SOM_RemoveMotion(D0RUN(iRUN).D0,parameters.masks.white.run(iRUN).regressors); else parameters.masks.white.run(iRUN).regressors = []; - SOM_LOG('WARNING : WM speficied but no WM regression mask available.'); + 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; @@ -445,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('WARNING : Motion speficied by motion regression internally turned off???'); + 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; @@ -492,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 From 20c8011e9691aa69f9dbb1f635110138427c5d68 Mon Sep 17 00:00:00 2001 From: "Robert C. Welsh" Date: Fri, 6 Apr 2012 14:13:42 -0400 Subject: [PATCH 16/29] Fixed small bug when a person specifies an empty array for a masking file, the internal flag was not being created and set to zero, that is now done --- som/SOM_ParseFileParam.m | 1 + 1 file changed, 1 insertion(+) diff --git a/som/SOM_ParseFileParam.m b/som/SOM_ParseFileParam.m index 457b4483..9c58fb8b 100755 --- a/som/SOM_ParseFileParam.m +++ b/som/SOM_ParseFileParam.m @@ -44,6 +44,7 @@ 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 From 66982ba935aa6d6624c47aa82fa2467624b517af Mon Sep 17 00:00:00 2001 From: Mike Angstadt Date: Thu, 5 Apr 2012 15:14:55 -0400 Subject: [PATCH 17/29] updated template --- som/som_batch_mc_template.m | 78 +++++++++++++++++++++++++++++++------ 1 file changed, 67 insertions(+), 11 deletions(-) diff --git a/som/som_batch_mc_template.m b/som/som_batch_mc_template.m index f0c72afc..0fd4fbb2 100644 --- a/som/som_batch_mc_template.m +++ b/som/som_batch_mc_template.m @@ -41,17 +41,73 @@ %%% The format is 'subjectfolder',subject number in masterfile,[runs to include] %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% SubjDir = { - '5034/Tx2',50342,[1]; -% '5035/Tx1',50351,[1]; -% '5035/Tx2',50352,[1]; -% '5036/Tx1',50361,[1]; -% '5036/Tx2',50362,[1]; -% '5037/Tx1',50371,[1]; -% '5037/Tx2',50372,[1]; -% '5038/Tx1',50381,[1]; -% '5038/Tx2',50382,[1]; -% '5039/Tx1',50391,[1]; -% '5039/Tx2',50392,[1]; +'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]; + + % '5034/Tx2',50342,[1]; }; %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% From 32b08125f13ee974cfd4b9c336379834909fb98b Mon Sep 17 00:00:00 2001 From: Mike Angstadt Date: Thu, 12 Apr 2012 12:03:58 -0400 Subject: [PATCH 18/29] updating template Conflicts: som/SOM_ParseFileParam.m som/som_batch_mc_central.m --- som/som_batch_mc_central.m | 265 +++++++++++++++++++++++------------ som/som_batch_mc_central.m~ | 181 ++++++++++++++++++++++++ som/som_batch_mc_template.m | 240 ++++++++++++++++++------------- som/som_batch_mc_template.m~ | 265 +++++++++++++++++++++++++++++++++++ 4 files changed, 764 insertions(+), 187 deletions(-) create mode 100644 som/som_batch_mc_central.m~ create mode 100644 som/som_batch_mc_template.m~ diff --git a/som/som_batch_mc_central.m b/som/som_batch_mc_central.m index 48bf2efe..ddabb6d6 100644 --- a/som/som_batch_mc_central.m +++ b/som/som_batch_mc_central.m @@ -1,108 +1,187 @@ -iRun = 1; - -GreyPath = mc_GenPath(GreyMatterTemplate); -WhitePath = mc_GenPath(WhiteMatterTemplate); -CSFPath = mc_GenPath(CSFTemplate); -BrainPath = mc_GenPath(BrainMaskTemplate); - -output.Template = OutputTemplate; -output.type = 1; -output.mode = 'makedir'; - -OutputPath = mc_GenPath(output); -ImagePath = mc_GenPath(ImageTemplate); -ImageFiles = spm_select('FPList',ImagePath, ['^' Pswra basefile '.*.' imagetype]); -SOM_Mask = fullfile(ImagePath,'som_mask.img'); -RealignmentParametersFile = mc_GenPath(RealignmentParametersTemplate); - -parameters.grey.File = GreyPath; -parameters.grey.MaskFLAG = MaskGrey; -parameters.grey.ImgThreshold = GreyThreshold; - -parameters.white.File = WhitePath; -parameters.white.MaskFLAG = RegressWhite; - -parameters.csf.File = CSFPath; -parameters.csf.MaskFLAG = RegressCSF; - -parameters.epi.File = BrainPath; -if (isempty(BrainMaskTemplate)) - parameters.epi.MaskFLAG = 0; -else - paramters.epi.MaskFLAG = 1; +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +%%% 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 -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.RegressFLAGS.prinComp = PrincipalComponents; -parameters.RegressFLAGS.global = RegressGlobal; -parameters.RegressFLAGS.csf = RegressCSF; -parameters.RegressFLAGS.white = RegressWhite; -parameters.RegressFLAGS.motion = RegressMotion; -parameters.RegressFLAGS.order = ProcessOrder; - -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; - -parameters.rois.files = ''; - -%-OR- - -parameters.rois.mni.coordinates = [0 0 0;20 20 20]; -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,:); - - - -if (isempty(BrainMaskTemplate)) - parameters.rois.mask.File = SOM_Mask; +RunMode = [0 0]; +if (strcmpi(Mode,'full')) + RunMode = [1 1]; else - parameters.rois.mask.File = BrainPath; + RunMode(1) = strcmpi(Mode,'parameters'); + RunMode(2) = strcmpi(Mode,'som'); end -parameters.rois.mask.MaskFLAG = MaskBrain; - -parameters.Output.correlation = 'images'; %or maps -parameters.Output.correlation = 'maps'; -parameters.Output.description = 'description of output'; -parameters.Output.directory = OutputPath; -parameters.Output.name = 'result file name'; +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 -global SOM; -SOM.silent = 1; -SOM_LOG('STATUS : 01'); +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')); + + parameters.RegressFLAGS.prinComp = PrincipalComponents; + parameters.RegressFLAGS.global = RegressGlobal; + parameters.RegressFLAGS.csf = RegressCSF; + parameters.RegressFLAGS.white = RegressWhite; + parameters.RegressFLAGS.motion = RegressMotion; + parameters.RegressFLAGS.order = RegressOrder; + + + for iSubject = 1:size(SubjDir,1) + 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,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 + parameters.rois.files = ''; + + %-OR- + + parameters.rois.mni.coordinates = [0 0 0;20 20 20]; + 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,:); + + + parameters.Output.correlation = 'images'; %or maps + parameters.Output.correlation = 'maps'; + parameters.Output.description = 'description of output'; + parameters.Output.directory = OutputPath; + parameters.Output.name = 'result file name'; + + ParameterPath = mc_GenPath(fullfile(OutputPath,ParameterFilename)); + save(ParameterFilename,'parameters'); + + end +end +if (RunMode(2)) + for iSubject = 1:size(SubjDir,1) + Subject=SubjDir{iSubject,1}; + %load existing parameter file + OutputPath = mc_GenPath(OutputTemplate); + if (~RunMode(1)) + load(fullfile(OutputPath,ParameterFilename)); + end + 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 -[D0 parameters] = SOM_PreProcessData(parameters); -%if D0 == -1 -% SOM_LOG('FATAL ERROR : No data returned'); -%else -% results = SOM_CalculateCorrelations(D0,parameters); -% if isnumeric(results) -% SOM_LOG('FATAL ERROR : '); -% end -%end diff --git a/som/som_batch_mc_central.m~ b/som/som_batch_mc_central.m~ new file mode 100644 index 00000000..439c44e5 --- /dev/null +++ b/som/som_batch_mc_central.m~ @@ -0,0 +1,181 @@ +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +%%% 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')); + + parameters.RegressFLAGS.prinComp = PrincipalComponents; + parameters.RegressFLAGS.global = RegressGlobal; + parameters.RegressFLAGS.csf = RegressCSF; + parameters.RegressFLAGS.white = RegressWhite; + parameters.RegressFLAGS.motion = RegressMotion; + parameters.RegressFLAGS.order = RegressOrder; + + + for iSubject = 1:size(SubjDir,1) + 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,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 + parameters.rois.files = ''; + + %-OR- + + parameters.rois.mni.coordinates = [0 0 0;20 20 20]; + 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,:); + + + parameters.Output.correlation = 'images'; %or maps + parameters.Output.correlation = 'maps'; + parameters.Output.description = 'description of output'; + parameters.Output.directory = OutputPath; + parameters.Output.name = 'result file name'; + + + end +end + +if (RunMode(2)) + for iSubject = 1:size(SubjDir,1) + %load existing parameter file + OutputPath = mc_GenPath(OutputTemplate) + parameters = load(fullfile(OutputTemplate,ParameterFilename)); + 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 index 0fd4fbb2..cb1735a0 100644 --- a/som/som_batch_mc_template.m +++ b/som/som_batch_mc_template.m @@ -3,15 +3,11 @@ %%% These options are shared among many of our scripts %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -%%% The path to SPM on your system -%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -spmpath = '/net/dysthymia/spm8'; - %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %%% The folder that contains your subject folders %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% Exp = '/net/data4/MAS/'; +Exp = '/dysthymia/sandbox/MAS/'; %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %%% Path where your images are located @@ -41,73 +37,74 @@ %%% 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]; - - % '5034/Tx2',50342,[1]; + + '5034/Tx2',50342,[1]; +% '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]; + }; %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% @@ -153,6 +150,28 @@ %%% 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 = 'som'; + +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +%%% The filename to use for saving/loading parameters +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +ParameterFilename = 'parameters'; + %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %%% Paths to your anatomical images %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% @@ -160,14 +179,10 @@ WhiteMatterTemplate = '[Exp]/Subjects/[Subject]/anatomy/rwhite.img'; CSFTemplate = '[Exp]/Subjects/[Subject]/anatomy/rcsf.img'; -%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -%%% The voxel size to reslice your images to after normalization -%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -vox_size = [3 3 3]; + %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %%% Where to output the data -%%% OutputDir is constructed by /Exp/OutputLevel1/subjDir/OutputLevel2/OutputLevel3/ %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% OutputTemplate = '[Exp]/FirstLevel/[Subject]/[OutputName]/'; OutputName = 'TEST'; @@ -178,36 +193,73 @@ %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% BrainMaskTemplate = ''; +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +%%% Path Template for realignment parameters file +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% RealignmentParametersTemplate = '[Exp]/Subjects/[Subject]/TASK/func/[Run]/rp_arun_*'; +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +%%% 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 = []; -MaskGrey = 0; -GreyThreshold = 0.75; -RegressWhite = 1; -RegressCSF = 1; -MaskBrain = 1; -RegressMotion = 1; +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +%%% 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; -RegressGlobal = 0; -ProcessOrder = 'DCWMB'; -DoBandpassFilter = 1; -DoLinearDetrend = 1; +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +%%% 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; +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +%%% Radius (in mm) of ROI spheres. +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% ROISize = 2; -addpath /net/dysthymia/mangstad/repos/MethodsCore/matlabScripts -addpath /net/dysthymia/mangstad/repos/MethodsCore/som -addpath /net/dysthymia/spm8 -Subject = SubjDir{1,1}; -Run = RunDir{1}; -Pswra = 'swra'; + + +%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 diff --git a/som/som_batch_mc_template.m~ b/som/som_batch_mc_template.m~ new file mode 100644 index 00000000..f56b00f3 --- /dev/null +++ b/som/som_batch_mc_template.m~ @@ -0,0 +1,265 @@ +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +%%% GENERAL OPTIONS +%%% These options are shared among many of our scripts +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% + +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +%%% The folder that contains your subject folders +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +Exp = '/net/data4/MAS/'; +Exp = '/dysthymia/sandbox/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 = { + + '5034/Tx2',50342,[1]; +'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 (spm8 only) +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +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 = 'run'; + +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +%%% 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 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 +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +Mode = 'test'; + +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +%%% The filename to use for saving/loading parameters +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +ParameterFilename = 'my_parameters'; + +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +%%% Paths to your anatomical images +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +GreyMatterTemplate = '[Exp]/Subjects/[Subject]/anatomy/rgrey.img'; +WhiteMatterTemplate = '[Exp]/Subjects/[Subject]/anatomy/rwhite.img'; +CSFTemplate = '[Exp]/Subjects/[Subject]/anatomy/rcsf.img'; + +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +%%% The voxel size to reslice your images to after normalization +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +vox_size = [3 3 3]; + +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +%%% Where to output the data +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +OutputTemplate = '[Exp]/FirstLevel/[Subject]/[OutputName]/'; +OutputName = 'TEST'; + +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +%%% Path and name of explicit mask to use at first level. +%%% Leave this blank ('') to turn off explicit masking +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +BrainMaskTemplate = ''; + +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +%%% Path Template for realignment parameters file +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +RealignmentParametersTemplate = '[Exp]/Subjects/[Subject]/TASK/func/[Run]/rp_arun_*'; + +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +%%% 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; + +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +%%% Radius (in mm) of ROI spheres. +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +ROISize = 2; + + + +%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 From 7602c2b3ed433e46cf600c4d9b1d40dc431271cd Mon Sep 17 00:00:00 2001 From: Mike Angstadt Date: Thu, 12 Apr 2012 16:45:48 -0400 Subject: [PATCH 19/29] fixed typos in PreprocessFirstLevel_central --- FirstLevel/PreprocessFirstLevel_central.m | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) 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; From 6b1190f1af5ef080e6363ec760a61c2966d79d4f Mon Sep 17 00:00:00 2001 From: Mike Angstadt Date: Tue, 17 Apr 2012 11:57:25 -0400 Subject: [PATCH 20/29] some more tweaks to template/central for som_batch --- som/som_batch_mc_central.m | 5 ++--- som/som_batch_mc_template.m | 34 +++++++++++++++++++++++++++------- 2 files changed, 29 insertions(+), 10 deletions(-) diff --git a/som/som_batch_mc_central.m b/som/som_batch_mc_central.m index ddabb6d6..6d89a7fb 100644 --- a/som/som_batch_mc_central.m +++ b/som/som_batch_mc_central.m @@ -135,15 +135,14 @@ %-OR- - parameters.rois.mni.coordinates = [0 0 0;20 20 20]; + parameters.rois.mni.coordinates = ROICenters; 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,:); - parameters.Output.correlation = 'images'; %or maps - parameters.Output.correlation = 'maps'; + parameters.Output.correlation = ROIOutput; parameters.Output.description = 'description of output'; parameters.Output.directory = OutputPath; parameters.Output.name = 'result file name'; diff --git a/som/som_batch_mc_template.m b/som/som_batch_mc_template.m index cb1735a0..17ba0179 100644 --- a/som/som_batch_mc_template.m +++ b/som/som_batch_mc_template.m @@ -7,7 +7,7 @@ %%% The folder that contains your subject folders %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% Exp = '/net/data4/MAS/'; -Exp = '/dysthymia/sandbox/MAS/'; +%Exp = '/dysthymia/sandbox/MAS/'; %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %%% Path where your images are located @@ -131,7 +131,7 @@ %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %%% The prefix of each functional file %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -basefile = 'run'; +basefile = 'restrun'; %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %%% Image Type should be either 'nii' or 'img' @@ -165,7 +165,7 @@ %%% will be loaded from the already existing parameter file for each %%% subject. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -Mode = 'som'; +Mode = 'test'; %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %%% The filename to use for saving/loading parameters @@ -176,8 +176,8 @@ %%% Paths to your anatomical images %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% GreyMatterTemplate = '[Exp]/Subjects/[Subject]/anatomy/rgrey.img'; -WhiteMatterTemplate = '[Exp]/Subjects/[Subject]/anatomy/rwhite.img'; -CSFTemplate = '[Exp]/Subjects/[Subject]/anatomy/rcsf.img'; +WhiteMatterTemplate = '[Exp]/Subjects/[Subject]/anatomy/wm_mask.nii'; +CSFTemplate = '[Exp]/Subjects/[Subject]/anatomy/csf_mask.nii'; @@ -191,12 +191,12 @@ %%% Path and name of explicit mask to use at first level. %%% Leave this blank ('') to turn off explicit masking %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -BrainMaskTemplate = ''; +BrainMaskTemplate = '[Exp]/ROIS/rEPI_MASK_NOEYES.img'; %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %%% Path Template for realignment parameters file %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -RealignmentParametersTemplate = '[Exp]/Subjects/[Subject]/TASK/func/[Run]/rp_arun_*'; +RealignmentParametersTemplate = '[Exp]/Subjects/[Subject]/TASK/func/[Run]/rp_arestrun_*'; %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %%% Constrain results to only regions in GreyMatterTemplate (1=yes, 0=no) @@ -245,12 +245,32 @@ BandpassFilter = 1; Fraction = 1; +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +%%% Centers of ROI spheres (in mm) +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +ROICenters = [ + 0 0 0; + 10 10 10; + 20 20 20; + ]; + %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %%% Radius (in mm) of ROI spheres. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% ROISize = 2; +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +%%% 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' +ROITemplate = '[Exp]/ROIS'; +ROIImages = { + 'image1.nii'; + 'image2.nii'; + }; %DEVSTART mcRoot = fullfile(fileparts(mfilename('fullpath')),'../../MethodsCore'); From f067827b027f93e60cadc0561d8be6a503d9f7e6 Mon Sep 17 00:00:00 2001 From: Mike Angstadt Date: Tue, 17 Apr 2012 18:01:04 -0400 Subject: [PATCH 21/29] first release candidate of som_batch template and central --- som/som_batch_mc_central.m | 52 ++++++---- som/som_batch_mc_template.m | 190 ++++++++++++++++++++---------------- 2 files changed, 143 insertions(+), 99 deletions(-) diff --git a/som/som_batch_mc_central.m b/som/som_batch_mc_central.m index 6d89a7fb..58f20555 100644 --- a/som/som_batch_mc_central.m +++ b/som/som_batch_mc_central.m @@ -131,36 +131,56 @@ else OutputPath = mc_GenPath(OutputTemplate); end - parameters.rois.files = ''; - - %-OR- - - parameters.rois.mni.coordinates = ROICenters; - 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,:); - + + 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; + 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,:); + case 'grid' + ROIGridMask = mc_Genpath(ROIGridMaskTemplate); + ROIGridMaskHdr = spm_vol(ROIGridMask); + ROIGridBB = mc_GetBoundingBox(ROIGridMaskHdr); + grid_coord_cand = SOM_MakeGrid(ROIGridSpacing,ROIGridBB); + inOut = SOM_roiPointsInMask(ROIGridMask,grid_coord_cand); + inOutIDX = find(inOut); + grid_coord = grid_coord_cand(inOutIDX,:); + parameters.rois.mni.coordinates = grid_coord; + XYZ = SOM_MakeSphereROI(ROIGridRadius); + parameters.rois.mni.size.XROI = XYZ(1,:); + parameters.rois.mni.size.YROI = XYZ(2,:); + parameters.rois.mni.size.ZROI = XYZ(2,:); + end parameters.Output.correlation = ROIOutput; - parameters.Output.description = 'description of output'; + %parameters.Output.description = 'description of output'; parameters.Output.directory = OutputPath; - parameters.Output.name = 'result file name'; + parameters.Output.name = OutputName; ParameterPath = mc_GenPath(fullfile(OutputPath,ParameterFilename)); - save(ParameterFilename,'parameters'); + 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); - if (~RunMode(1)) + %if (~RunMode(1)) load(fullfile(OutputPath,ParameterFilename)); - end + %end global SOM; SOM.silent = 1; SOM_LOG('STATUS : 01'); @@ -182,5 +202,3 @@ - - diff --git a/som/som_batch_mc_template.m b/som/som_batch_mc_template.m index 17ba0179..4c44446b 100644 --- a/som/som_batch_mc_template.m +++ b/som/som_batch_mc_template.m @@ -3,6 +3,11 @@ %%% These options are shared among many of our scripts %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +%%% The version of SPM to use +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +spmversion = 'spm8'; + %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %%% The folder that contains your subject folders %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% @@ -38,72 +43,72 @@ %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% SubjDir = { - '5034/Tx2',50342,[1]; -% '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]; +% '5034/Tx2',50342,[1]; +'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]; }; @@ -165,12 +170,12 @@ %%% will be loaded from the already existing parameter file for each %%% subject. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -Mode = 'test'; +Mode = 'full'; %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %%% The filename to use for saving/loading parameters %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -ParameterFilename = 'parameters'; +ParameterFilename = '12mmGrid_parameters'; %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %%% Paths to your anatomical images @@ -185,7 +190,7 @@ %%% Where to output the data %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% OutputTemplate = '[Exp]/FirstLevel/[Subject]/[OutputName]/'; -OutputName = 'TEST'; +OutputName = '12mmGrid'; %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %%% Path and name of explicit mask to use at first level. @@ -246,31 +251,52 @@ Fraction = 1; %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -%%% Centers of ROI spheres (in mm) +%%% 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 = 'grid'; + +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +%%% If specifying ROI coordinates you need to provide a list of centers and +%%% a radius both in mm. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% ROICenters = [ - 0 0 0; - 10 10 10; - 20 20 20; + 0 -53 26; ]; +ROISize = 4; + +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +%%% 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'; + }; %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -%%% Radius (in mm) of ROI spheres. +%%% If specifying ROI gri you need to provide a spacing as well as a +%%% mask for point inclusion %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -ROISize = 2; +ROIGridSpacing = 12; +ROIGridRadius = 4; +ROIGridMaskTemplate = '[Exp]/ROIS/ravg_gm_mask.nii'; %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %%% 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' +ROIOutput = 'maps'; -ROITemplate = '[Exp]/ROIS'; -ROIImages = { - 'image1.nii'; - 'image2.nii'; - }; + +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +%%% Do not edit below this line +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %DEVSTART mcRoot = fullfile(fileparts(mfilename('fullpath')),'../../MethodsCore'); @@ -280,6 +306,6 @@ addpath(fullfile(mcRoot,'matlabScripts')); addpath(fullfile(mcRoot,'som')); -addpath(fullfile(mcRoot,'spm8')); +addpath(fullfile(mcRoot,spmversion)); som_batch_mc_central \ No newline at end of file From e85582aa3bf78d5afa3dd3d1dd381898051ebe3b Mon Sep 17 00:00:00 2001 From: Mike Angstadt Date: Tue, 17 Apr 2012 18:11:12 -0400 Subject: [PATCH 22/29] added a quick function to get the bounding box from an image, pulled from Ged Ridgway's code here: http://www.cs.ucl.ac.uk/staff/G.Ridgway/vbm/resize_img.m --- matlabScripts/mc_GetBoundingBox.m | 21 +++ som/som_batch_mc_central.m~ | 181 -------------------- som/som_batch_mc_template.m~ | 265 ------------------------------ 3 files changed, 21 insertions(+), 446 deletions(-) create mode 100644 matlabScripts/mc_GetBoundingBox.m delete mode 100644 som/som_batch_mc_central.m~ delete mode 100644 som/som_batch_mc_template.m~ 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_batch_mc_central.m~ b/som/som_batch_mc_central.m~ deleted file mode 100644 index 439c44e5..00000000 --- a/som/som_batch_mc_central.m~ +++ /dev/null @@ -1,181 +0,0 @@ -%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -%%% 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')); - - parameters.RegressFLAGS.prinComp = PrincipalComponents; - parameters.RegressFLAGS.global = RegressGlobal; - parameters.RegressFLAGS.csf = RegressCSF; - parameters.RegressFLAGS.white = RegressWhite; - parameters.RegressFLAGS.motion = RegressMotion; - parameters.RegressFLAGS.order = RegressOrder; - - - for iSubject = 1:size(SubjDir,1) - 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,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 - parameters.rois.files = ''; - - %-OR- - - parameters.rois.mni.coordinates = [0 0 0;20 20 20]; - 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,:); - - - parameters.Output.correlation = 'images'; %or maps - parameters.Output.correlation = 'maps'; - parameters.Output.description = 'description of output'; - parameters.Output.directory = OutputPath; - parameters.Output.name = 'result file name'; - - - end -end - -if (RunMode(2)) - for iSubject = 1:size(SubjDir,1) - %load existing parameter file - OutputPath = mc_GenPath(OutputTemplate) - parameters = load(fullfile(OutputTemplate,ParameterFilename)); - 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~ deleted file mode 100644 index f56b00f3..00000000 --- a/som/som_batch_mc_template.m~ +++ /dev/null @@ -1,265 +0,0 @@ -%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -%%% GENERAL OPTIONS -%%% These options are shared among many of our scripts -%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% - -%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -%%% The folder that contains your subject folders -%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -Exp = '/net/data4/MAS/'; -Exp = '/dysthymia/sandbox/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 = { - - '5034/Tx2',50342,[1]; -'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 (spm8 only) -%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -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 = 'run'; - -%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -%%% 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 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 -%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -Mode = 'test'; - -%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -%%% The filename to use for saving/loading parameters -%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -ParameterFilename = 'my_parameters'; - -%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -%%% Paths to your anatomical images -%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -GreyMatterTemplate = '[Exp]/Subjects/[Subject]/anatomy/rgrey.img'; -WhiteMatterTemplate = '[Exp]/Subjects/[Subject]/anatomy/rwhite.img'; -CSFTemplate = '[Exp]/Subjects/[Subject]/anatomy/rcsf.img'; - -%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -%%% The voxel size to reslice your images to after normalization -%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -vox_size = [3 3 3]; - -%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -%%% Where to output the data -%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -OutputTemplate = '[Exp]/FirstLevel/[Subject]/[OutputName]/'; -OutputName = 'TEST'; - -%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -%%% Path and name of explicit mask to use at first level. -%%% Leave this blank ('') to turn off explicit masking -%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -BrainMaskTemplate = ''; - -%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -%%% Path Template for realignment parameters file -%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -RealignmentParametersTemplate = '[Exp]/Subjects/[Subject]/TASK/func/[Run]/rp_arun_*'; - -%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -%%% 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; - -%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -%%% Radius (in mm) of ROI spheres. -%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -ROISize = 2; - - - -%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 From 6cf5888d3129ab49b39fc477a38f0beb8bdb22f5 Mon Sep 17 00:00:00 2001 From: Mike Angstadt Date: Mon, 23 Apr 2012 13:56:00 -0400 Subject: [PATCH 23/29] template / central in beta test state --- som/som_batch_mc_central.m | 34 ++++++++++++++---------- som/som_batch_mc_template.m | 53 ++++++++++++++++--------------------- 2 files changed, 43 insertions(+), 44 deletions(-) diff --git a/som/som_batch_mc_central.m b/som/som_batch_mc_central.m index 58f20555..394ec748 100644 --- a/som/som_batch_mc_central.m +++ b/som/som_batch_mc_central.m @@ -142,30 +142,37 @@ case 'coordinates' parameters.rois.mni.coordinates = ROICenters; - 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,:); + 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); - inOut = SOM_roiPointsInMask(ROIGridMask,grid_coord_cand); - inOutIDX = find(inOut); + inOutIDX = SOM_roiPointsInMask(ROIGridMask,grid_coord_cand); grid_coord = grid_coord_cand(inOutIDX,:); parameters.rois.mni.coordinates = grid_coord; - XYZ = SOM_MakeSphereROI(ROIGridRadius); - parameters.rois.mni.size.XROI = XYZ(1,:); - parameters.rois.mni.size.YROI = XYZ(2,:); - parameters.rois.mni.size.ZROI = XYZ(2,:); + 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'); @@ -178,9 +185,8 @@ Subject=SubjDir{iSubject,1}; %load existing parameter file OutputPath = mc_GenPath(OutputTemplate); - %if (~RunMode(1)) - load(fullfile(OutputPath,ParameterFilename)); - %end + load(fullfile(OutputPath,ParameterFilename)); + clear global SOM; global SOM; SOM.silent = 1; SOM_LOG('STATUS : 01'); diff --git a/som/som_batch_mc_template.m b/som/som_batch_mc_template.m index 4c44446b..37ab4716 100644 --- a/som/som_batch_mc_template.m +++ b/som/som_batch_mc_template.m @@ -3,16 +3,10 @@ %%% These options are shared among many of our scripts %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -%%% The version of SPM to use -%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -spmversion = 'spm8'; - %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %%% The folder that contains your subject folders %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% Exp = '/net/data4/MAS/'; -%Exp = '/dysthymia/sandbox/MAS/'; %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %%% Path where your images are located @@ -42,8 +36,6 @@ %%% The format is 'subjectfolder',subject number in masterfile,[runs to include] %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% SubjDir = { - -% '5034/Tx2',50342,[1]; '5001/Tx1',50011,[1]; '5002/Tx1',50021,[1]; '5003/Tx1',50031,[1]; @@ -109,7 +101,6 @@ '5040/Tx2',50402,[1]; '5041/Tx2',50412,[1]; '5042/Tx2',50422,[1]; - }; %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% @@ -118,7 +109,7 @@ TR = 2; %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -%%% Prefixes for slicetiming, realignment, normalization, and smoothing (spm8 only) +%%% Prefixes for slicetiming, realignment, normalization, and smoothing %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% stp = 'a'; rep = 'r'; @@ -172,11 +163,6 @@ %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% Mode = 'full'; -%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -%%% The filename to use for saving/loading parameters -%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -ParameterFilename = '12mmGrid_parameters'; - %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %%% Paths to your anatomical images %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% @@ -184,17 +170,16 @@ 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 = '12mmGrid'; +OutputName = 'PCC'; %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %%% Path and name of explicit mask to use at first level. -%%% Leave this blank ('') to turn off explicit masking +%%% 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'; @@ -257,16 +242,19 @@ %%% grid - make a grid based on provided spacing and masked %%% by provided mask %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -ROIInput = 'grid'; +ROIInput = 'coordinates'; %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -%%% If specifying ROI coordinates you need to provide a list of centers and -%%% a radius both in mm. +%%% 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; ]; -ROISize = 4; +ROISize = {19}; %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %%% If specifying ROI images you need to provide an ROI folder as well as a @@ -279,19 +267,24 @@ }; %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -%%% If specifying ROI gri you need to provide a spacing as well as a -%%% mask for point inclusion +%%% 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; -ROIGridRadius = 4; -ROIGridMaskTemplate = '[Exp]/ROIS/ravg_gm_mask.nii'; - +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 = 'maps'; +ROIOutput = 'images'; %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% @@ -306,6 +299,6 @@ addpath(fullfile(mcRoot,'matlabScripts')); addpath(fullfile(mcRoot,'som')); -addpath(fullfile(mcRoot,spmversion)); +addpath(fullfile(mcRoot,'spm8')); som_batch_mc_central \ No newline at end of file From 0d46680d5f4967848b3782fe76b379f8dded31ce Mon Sep 17 00:00:00 2001 From: Mike Angstadt Date: Tue, 24 Apr 2012 19:02:05 -0400 Subject: [PATCH 24/29] template update --- som/SOM_CheckMasks.m~ | 85 ------------------------------------- som/SOM_Detrend.m~ | 43 ------------------- som/SOM_MakeGrid.m~ | 0 som/SOM_ReadNII.m~ | 44 ------------------- som/som_batch_mc_template.m | 18 ++++++-- 5 files changed, 15 insertions(+), 175 deletions(-) delete mode 100644 som/SOM_CheckMasks.m~ delete mode 100644 som/SOM_Detrend.m~ delete mode 100644 som/SOM_MakeGrid.m~ delete mode 100644 som/SOM_ReadNII.m~ diff --git a/som/SOM_CheckMasks.m~ b/som/SOM_CheckMasks.m~ deleted file mode 100644 index 85adf1b1..00000000 --- a/som/SOM_CheckMasks.m~ +++ /dev/null @@ -1,85 +0,0 @@ -% - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -% -% 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 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~ deleted file mode 100644 index e69de29b..00000000 diff --git a/som/SOM_ReadNII.m~ b/som/SOM_ReadNII.m~ deleted file mode 100644 index 6a7e400c..00000000 --- a/som/SOM_ReadNII.m~ +++ /dev/null @@ -1,44 +0,0 @@ -% - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -% -% 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 -% \ No newline at end of file diff --git a/som/som_batch_mc_template.m b/som/som_batch_mc_template.m index 37ab4716..8053458b 100644 --- a/som/som_batch_mc_template.m +++ b/som/som_batch_mc_template.m @@ -174,7 +174,7 @@ %%% Where to output the data %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% OutputTemplate = '[Exp]/FirstLevel/[Subject]/[OutputName]/'; -OutputName = 'PCC'; +OutputName = 'Striatum'; %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %%% Path and name of explicit mask to use at first level. @@ -252,7 +252,19 @@ %%% need to specify the size as a cell (i.e. {19}) %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% ROICenters = [ - 0 -53 26; + %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}; @@ -278,7 +290,7 @@ ROIGridSpacing = 12; ROIGridSize = {19}; ROIGridMaskTemplate = '[Exp]/ROIS/ravg_gm_mask_and_EPI_mask.img'; -ROIGridMaskTemplate = '[Exp]/ROIS/rEPI_MASK_NOEYES.img'; +%ROIGridMaskTemplate = '[Exp]/ROIS/rEPI_MASK_NOEYES.img'; %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %%% Type of output %%% images - output R and Z images of correlation with each seed From b5b6694ee2be675fc85d741aadcea6584cef0f6b Mon Sep 17 00:00:00 2001 From: Mike Angstadt Date: Tue, 24 Apr 2012 19:04:13 -0400 Subject: [PATCH 25/29] quick format change for image output names --- som/SOM_CalculateCorrelationImages.m | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/som/SOM_CalculateCorrelationImages.m b/som/SOM_CalculateCorrelationImages.m index 00e28e62..652ff95c 100755 --- a/som/SOM_CalculateCorrelationImages.m +++ b/som/SOM_CalculateCorrelationImages.m @@ -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 = fullfile(parameters.Output.directory,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]; From e0eecd7a1b88cb26c428297cad23465ec50418d7 Mon Sep 17 00:00:00 2001 From: Mike Angstadt Date: Tue, 8 May 2012 15:15:49 -0400 Subject: [PATCH 26/29] fixed 124 in CheckDataStructure --- som/SOM_CheckDataStructure.m | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/som/SOM_CheckDataStructure.m b/som/SOM_CheckDataStructure.m index dbb68182..ef17c9b5 100644 --- a/som/SOM_CheckDataStructure.m +++ b/som/SOM_CheckDataStructure.m @@ -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,:)); if SOM_SpaceVerify(data.run(iRUN).hdr,thisHDR) ~= 1 SOM_LOG('FATAL ERROR : Error with consistent in-run image space definition.'); return From a93ecb5504d8004f74d0c6368e3b06a541d32648 Mon Sep 17 00:00:00 2001 From: Mike Angstadt Date: Thu, 17 May 2012 15:49:40 -0400 Subject: [PATCH 27/29] fixed clearing of parameters variable for each subject --- som/som_batch_mc_central.m | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/som/som_batch_mc_central.m b/som/som_batch_mc_central.m index 394ec748..1b97444f 100644 --- a/som/som_batch_mc_central.m +++ b/som/som_batch_mc_central.m @@ -39,7 +39,6 @@ MaskBrain = 1; - RegressGlobal = any(strfind(upper(RegressOrder),'G')); RegressWhite = any(strfind(upper(RegressOrder),'W')); RegressCSF = any(strfind(upper(RegressOrder),'C')); @@ -47,15 +46,17 @@ RegressMotion = any(strfind(upper(RegressOrder),'M')); DoLinearDetrend = any(strfind(upper(RegressOrder),'D')); - parameters.RegressFLAGS.prinComp = PrincipalComponents; - parameters.RegressFLAGS.global = RegressGlobal; - parameters.RegressFLAGS.csf = RegressCSF; - parameters.RegressFLAGS.white = RegressWhite; - parameters.RegressFLAGS.motion = RegressMotion; - parameters.RegressFLAGS.order = RegressOrder; - - 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}; From 41017c703b5fc0e982f46cf690935ab7576cbc2b Mon Sep 17 00:00:00 2001 From: "Robert C. Welsh" Date: Tue, 12 Jun 2012 14:26:36 -0400 Subject: [PATCH 28/29] Fixed small bug with reading a header in SOM_CheckDataStructure.m and changed to 4-digit numeric file name in SOM_CalculateCorrelationImages.m --- som/SOM_CalculateCorrelationImages.m | 6 +- som/SOM_CalculateCorrelationImagesSlow.m | 109 ----------------------- som/SOM_CheckDataStructure.m | 2 +- 3 files changed, 4 insertions(+), 113 deletions(-) delete mode 100755 som/SOM_CalculateCorrelationImagesSlow.m diff --git a/som/SOM_CalculateCorrelationImages.m b/som/SOM_CalculateCorrelationImages.m index 00e28e62..652ff95c 100755 --- a/som/SOM_CalculateCorrelationImages.m +++ b/som/SOM_CalculateCorrelationImages.m @@ -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 = fullfile(parameters.Output.directory,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 dbb68182..2b65083b 100644 --- a/som/SOM_CheckDataStructure.m +++ b/som/SOM_CheckDataStructure.m @@ -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 From e21aa55e7fb819a7dea7632dbd6ae302334cf19b Mon Sep 17 00:00:00 2001 From: Mike Angstadt Date: Tue, 3 Jul 2012 10:32:19 -0400 Subject: [PATCH 29/29] fixed bug in NumScan calculation for missing runs --- som/som_batch_mc_central.m | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/som/som_batch_mc_central.m b/som/som_batch_mc_central.m index 1b97444f..153e619c 100644 --- a/som/som_batch_mc_central.m +++ b/som/som_batch_mc_central.m @@ -69,7 +69,7 @@ clear RunDir; for iRun=1:NumRun RunDir{iRun,1}=RunNamesTotal{RunList(1,iRun)}; - NumScan=horzcat(NumScan,NumScanTotal(1,iRun)); + NumScan=horzcat(NumScan,NumScanTotal(1,RunList(1,iRun))); end NumRun= size(NumScan,2); % number of runs