diff --git a/QualityChecks/CheckSpike/MC_CheckSpike_Template.m b/QualityChecks/CheckSpike/MC_CheckSpike_Template.m new file mode 100644 index 00000000..fee9d2a1 --- /dev/null +++ b/QualityChecks/CheckSpike/MC_CheckSpike_Template.m @@ -0,0 +1,19 @@ +%{ + Options has the following structure: + + struct Options { + MasterDir - Directory path that contains subject directories + Subjects - a cell array of the subject folders + SubRun - possible directory below run directory + }; +%} + +Options.MasterDir = '/oracle7/Researchers/heffjos/Mock_Data/fMRI/MYDATA/'; + +Options.Subjects = { + 'subject'; +}; + +Options.SubRun = 'SubRun'; + +UMBatchDetectSpike(Options); \ No newline at end of file diff --git a/QualityChecks/CheckSpike/QC_calcSliceVariance.m b/QualityChecks/CheckSpike/QC_calcSliceVariance.m new file mode 100644 index 00000000..dc953bf2 --- /dev/null +++ b/QualityChecks/CheckSpike/QC_calcSliceVariance.m @@ -0,0 +1,106 @@ +%- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +% QC_calcSlicerVariance +% +% A routine for calculating some statistical properties for slices in a +% time series +% +% Call as : +% +% function results = QC_calcSliceVariance(inputData,options) +% +% To Make this work you need to provide the following input: +% +% inputData = Either a 4D matrix or file name% +% options = polynomial order used in spm_detrend (OPTIONAL) +% +% Output +% +% results +% = -1 if failure +% OR +% = struct { +% globalMean - scalar mean of whole volume +% sliceMean - nSlice x 1 array mean of each slice over time +% sliceSTD - nSlice x 1 array std of each slice over time +% sliceVariance - nSlice x nTime array mean slice intensity at +% given timepoint / std (slice) +% } +% +% - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +function results = QC_calcSliceVariance(inputData,options) + +results = -1; + +if ischar(inputData) + inputData = strtrim(inputData); + % Check if file exists + if exist(inputData,'file') ~= 2 + fprintf('Input data "%s"\n does not exist.\n',inputData); + fprintf(' * * * A B O R T I N G * * *\n\n'); + return + end + P = nifti(inputData); + inputData = P.dat(:,:,:,:); +end + +% support only 4D arrays for now +if ndims(inputData) ~= 4 + fprintf('Expected 4D time series\n'); + fprintf(' * * * A B O R T I N G * * *\n\n'); + return +end + +if nargin < 2 + options = []; +end + +[xDim yDim nSlice scans] = size(inputData); + +% Remove whole mean +globalMean = mean(inputData(:)); +inputData = inputData - globalMean; + +% detrend time series +if ~isempty(options) + voxelsPerPlane = xDim*yDim; + for z=1:nSlice + slice = squeeze(inputData(:,:,z,:)); + optSlice = reshape(slice,voxelsPerPlane,scans)'; + if options ~= 0 + detrendSlice = spm_detrend(optSlice,options); + else + for t=1:scans + optSlice(:,t) = optSlice(:,t) - mean(optSlice(:,t)); + end + detrendSlice = optSlice; + end + inputData(:,:,z,:) = reshape(detrendSlice',xDim,yDim,1,scans); + end +end + +% calculate mean of slice and std of slice over time +sliceMean = zeros(nSlice,1); +sliceSTD = zeros(nSlice,1); +for z=1:nSlice + slice = inputData(:,:,z,:); + + sliceMean(z) = mean(slice(:)); + sliceSTD(z) = std(slice(:)); +end + +sliceSTD(sliceSTD==0) = 1; + +% calculate array of the mean slice intensity at a given time point/std +sliceVariance = zeros(nSlice,scans); +for t=1:scans + for z=1:nSlice + slice = inputData(:,:,z,t); + sliceVariance(z,t) = (mean(slice(:)) - sliceMean(z))/sliceSTD(z); + end +end + +results = struct('sliceMean',sliceMean,... + 'sliceSTD',sliceSTD,... + 'globalMean',globalMean,... + 'sliceVariance',sliceVariance); +return \ No newline at end of file diff --git a/QualityChecks/CheckSpike/UMBatchDetectSpike.m b/QualityChecks/CheckSpike/UMBatchDetectSpike.m new file mode 100644 index 00000000..b0740b82 --- /dev/null +++ b/QualityChecks/CheckSpike/UMBatchDetectSpike.m @@ -0,0 +1,85 @@ +% - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +% UMBatchDetectSpike +% +% A function that performs a batch detect spike upon several subjects. +% +% Call as : +% +% function results = UMBatchDetectSpike(Images,OutputFile,Subject,Run) +% +% To Make this work you need to provide the following input: +% +% Images = char array of images to text +% OutputFile = file to write detected spikes +% ImagePath = full directory path to Images +% +% Output +% +% results = -1 if failure +% 1 if success +% - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +function results = UMBatchDetectSpike(Images,OutputFile,ImagePath) + detOpt = 1; + Thres = 10; + results = -1; + + fid = fopen(OutputFile,'w'); + if fid == -1 + fprintf('Cannot open file: %s\n',Outputfile); + fprintf(' * * * A B O R T I N G * * *\n'); + return; + end + + % + % Build 4D array + % + if size(Images,1) > 1 + firstImage = nifti( strtrim(Images(1,:)) ); + data = zeros( [firstImage.dat.dim(1:3) size(Images,1)] ); + clear firstImage + + for i=1:size(Images,1) + dumImage = nifti( strtim(Images(i,:)) ); + data(:,:,:,i) = dumImage.dat(:,:,:,i); + clear dumImage + end + else + dumImage = nifti( strtim(Images) ); + data = dumImage.dat(:,:,:,:); + clear dumImage + end + + % + % Detect spikes here + % + [success results] = dSpike(data,detOpt); + if success == -1 + return; + end + + % + % Write output to text file + % + [nSlice nTime] = size(results); + + % Common header first + fprintf(fid,'%s\n\n',ImagePath); + fprintf(fid,'Slices:%s\n',nSlice); + fprintf(fid,'nTime :%s\n\n',nTime); + + % Write detected spikes now + [Slice Timepoint] = find(results > Thres); + if isempty(Slice) + fprintf(fid,'Status : No spikes found\n'); + else + fprintf(fid,'Status : %d spikes found\n',size(Slice,1)); + + for i=1:size(Slice,1) + fprintf(fid,'Slice:%d,Timepoint:%d,AJKZ:%f\n',Slice(i),Timepoint(i),results( Slice(i), Timepoint(i) ) ); + end + end + + fclose(fid); + results = 1; +end + diff --git a/QualityChecks/CheckSpike/dSpike.m b/QualityChecks/CheckSpike/dSpike.m new file mode 100644 index 00000000..fd2924ce --- /dev/null +++ b/QualityChecks/CheckSpike/dSpike.m @@ -0,0 +1,109 @@ +%- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +% dSpike +% +% A routine that implements the spike detection algorithm from "Automatic +% Spike Detection for fMRI" by Greve et al. +% +% Call as : +% +% function results = dSpike(inputData,options) +% +% To Make this work you need to provide the following input: +% +% inputData = Either a 4D matrix or file name +% detOpt = polynomial order used in spm_detrend (OPTIONAL) +% +% Output +% +% success = seconds for operation if no errors; otherwise, -1 +% results = nSlice x nTime array of the absolute measure of the +% jackknife z-score for each slice in each timepoint (AJKZ) +% +% Comments +% +% Obvious spikes will be obvious in the output. The paper classifies +% any AJKZ > 25 as a spike. It seems reasonable. Figure 1 in paper +% was not exactly reproduced. The distrubution of AJKZ was shifted +% further left. +% +% - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +function [success results]= dSpike(inputData,detOpt) + +success = -1; +results = []; +tic; + +if ischar(inputData) + inputData = strtrim(inputData); + % Check if file exists + if exist(inputData,'file') ~= 2 + fprintf('Input data "%s"\n does not exist.\n',inputData); + fprintf(' * * * A B O R T I N G * * *\n\n'); + return + end + P = nifti(inputData); + inputData = P.dat(:,:,:,:); +end + +% support only 4D arrays for now +if ndims(inputData) ~= 4 + fprintf('Expected 4D time series\n'); + fprintf(' * * * A B O R T I N G * * *\n\n'); + return +end + +if nargin < 2 + detOpt = []; +end + +[xDim yDim nSlice nTime] = size(inputData); + +% Remove mean per slice per time +for z=1:nSlice + slice = inputData(:,:,z,:); + mu_slice = mean( slice(:) ); + inputData(:,:,z,:) = slice - mu_slice; +end + +% Remove temporal trend, then compute temporal Z-score for each voxel +for z=1:nSlice + slice = squeeze(inputData(:,:,z,:)); + reSlice = reshape(slice,xDim*yDim,nTime)'; + % detrend + if ~isempty(detOpt) + if detOpt ~= 0 + reSlice = spm_detrend(reSlice,detOpt); + else % do this because spm_detrend is just too slow when detOpt = 0 + for t=1:nTime + reSlice(:,t) = reSlice(:,t) - mean(reSlice(:,t)); + end + end + end + %get z score + zScoreSlice = zscore(reSlice); + inputData(:,:,z,:) = abs( reshape(zScoreSlice',xDim,yDim,1,nTime) ); +end + +AAZ = zeros(nSlice,nTime); +% Average the Z-scores across slices and time +for t=1:nTime + temp = sum(sum(inputData(:,:,:,t)))./(xDim*yDim); + AAZ(:,t) = temp(:); +end + +AJKZ = zeros(nSlice,nTime); +indexes = [1:nSlice]'; +% Calculate AJKZ +for z=1:nSlice + loc = (indexes ~= z); + included = AAZ(loc,:); + mu_i = mean(included,1); + std_i = std(included,1); + std_i(std_i==0) = 1; + AJKZ(z,:) = (AAZ(z,:) - mu_i)./(std_i); +end + +results = abs(AJKZ); +success = toc; + +return \ No newline at end of file diff --git a/spm8Batch/matlab/simplejob.mat b/spm8Batch/.DS_Store old mode 100755 new mode 100644 similarity index 55% rename from spm8Batch/matlab/simplejob.mat rename to spm8Batch/.DS_Store index a6034fe9..ecb0e306 Binary files a/spm8Batch/matlab/simplejob.mat and b/spm8Batch/.DS_Store differ diff --git a/spm8Batch/.gitignore b/spm8Batch/.gitignore index 3535c5b2..70b7bd11 100644 --- a/spm8Batch/.gitignore +++ b/spm8Batch/.gitignore @@ -1,2 +1 @@ -.spm8BatchVersion Usage/ \ No newline at end of file diff --git a/spm8Batch/.spm8BatchVersion b/spm8Batch/.spm8BatchVersion new file mode 100644 index 00000000..b1024c69 --- /dev/null +++ b/spm8Batch/.spm8BatchVersion @@ -0,0 +1 @@ +spm8Batch VBM8 2012-03-13 diff --git a/spm8Batch/SPM8Batch_Supplement.key b/spm8Batch/SPM8Batch_Supplement.key new file mode 100644 index 00000000..2bb2214c Binary files /dev/null and b/spm8Batch/SPM8Batch_Supplement.key differ diff --git a/spm8Batch/SPM8Batch_Supplement.pdf b/spm8Batch/SPM8Batch_Supplement.pdf new file mode 100644 index 00000000..7ec6a27a Binary files /dev/null and b/spm8Batch/SPM8Batch_Supplement.pdf differ diff --git a/spm8Batch/auxiliary/case_all_runs b/spm8Batch/auxiliary/case_all_runs deleted file mode 100644 index 0e42ac23..00000000 --- a/spm8Batch/auxiliary/case_all_runs +++ /dev/null @@ -1,6 +0,0 @@ - # - # All runs in func - # - "A") - ALLRUNSFLAG=1 - ;; diff --git a/spm8Batch/auxiliary/case_anatomy_path b/spm8Batch/auxiliary/case_anatomy_path deleted file mode 100644 index 862ca220..00000000 --- a/spm8Batch/auxiliary/case_anatomy_path +++ /dev/null @@ -1,6 +0,0 @@ - # - # Path name to find virgin anatomy files. - # - "a") - . ${thisDir}/auxiliary/setAnatomyPath - ;; diff --git a/spm8Batch/auxiliary/case_coreg_path b/spm8Batch/auxiliary/case_coreg_path deleted file mode 100644 index 181618bf..00000000 --- a/spm8Batch/auxiliary/case_coreg_path +++ /dev/null @@ -1,6 +0,0 @@ - # - # Path name to place coregistration results. - # - "w") - . ${thisDir}/auxiliary/setCoRegPath - ;; diff --git a/spm8Batch/auxiliary/case_debug_flag b/spm8Batch/auxiliary/case_debug_flag deleted file mode 100644 index 152f2588..00000000 --- a/spm8Batch/auxiliary/case_debug_flag +++ /dev/null @@ -1,6 +0,0 @@ - # - # debug flag - # - "d") - . ${thisDir}/auxiliary/setDebugFlag - ;; diff --git a/spm8Batch/auxiliary/case_error b/spm8Batch/auxiliary/case_error deleted file mode 100644 index 5aa6bcf1..00000000 --- a/spm8Batch/auxiliary/case_error +++ /dev/null @@ -1,6 +0,0 @@ - # - # Anything should result in an error. - # - *) - . ${thisDir}/auxiliary/caseError - exit 1 diff --git a/spm8Batch/auxiliary/case_flirt_options b/spm8Batch/auxiliary/case_flirt_options deleted file mode 100644 index 32522cbd..00000000 --- a/spm8Batch/auxiliary/case_flirt_options +++ /dev/null @@ -1,6 +0,0 @@ - # - # find the flirt options - # - "m") - . ${thisDir}/auxiliary/setMCFlirtOptions - ;; diff --git a/spm8Batch/auxiliary/case_fmri_tr b/spm8Batch/auxiliary/case_fmri_tr deleted file mode 100644 index 724c981e..00000000 --- a/spm8Batch/auxiliary/case_fmri_tr +++ /dev/null @@ -1,6 +0,0 @@ - # - # Set the TR - # - "F") - . ${thisDir}/auxiliary/setVolumeTR - ;; diff --git a/spm8Batch/auxiliary/case_functional_path b/spm8Batch/auxiliary/case_functional_path deleted file mode 100644 index 5dff75d6..00000000 --- a/spm8Batch/auxiliary/case_functional_path +++ /dev/null @@ -1,6 +0,0 @@ - # - # Path name to search for functional images. - # - "f") - . ${thisDir}/auxiliary/setFunctionalPath - ;; diff --git a/spm8Batch/auxiliary/case_hires_name b/spm8Batch/auxiliary/case_hires_name deleted file mode 100644 index 95cf7a0e..00000000 --- a/spm8Batch/auxiliary/case_hires_name +++ /dev/null @@ -1,6 +0,0 @@ - # - # SPGR (hiRES) name to use - # - "h") - . ${thisDir}/auxiliary/setHiResName - ;; diff --git a/spm8Batch/auxiliary/case_other_names b/spm8Batch/auxiliary/case_other_names deleted file mode 100644 index bfec7e8a..00000000 --- a/spm8Batch/auxiliary/case_other_names +++ /dev/null @@ -1,6 +0,0 @@ - # - # Simliar Other images - # - "O") - . ${thisDir}/auxiliary/setOtherNames - ;; diff --git a/spm8Batch/auxiliary/case_output_name b/spm8Batch/auxiliary/case_output_name deleted file mode 100644 index 2a954c9c..00000000 --- a/spm8Batch/auxiliary/case_output_name +++ /dev/null @@ -1,6 +0,0 @@ - # - # Set the name to add. - # - "n") - . ${thisDir}/auxiliary/setOutputName - ;; diff --git a/spm8Batch/auxiliary/case_overlay_name b/spm8Batch/auxiliary/case_overlay_name deleted file mode 100644 index f03ee12f..00000000 --- a/spm8Batch/auxiliary/case_overlay_name +++ /dev/null @@ -1,6 +0,0 @@ - # - # overlay name to use - # - "o") - . ${thisDir}/auxiliary/setOverlayName - ;; diff --git a/spm8Batch/auxiliary/case_reslice_1 b/spm8Batch/auxiliary/case_reslice_1 deleted file mode 100644 index ed47926b..00000000 --- a/spm8Batch/auxiliary/case_reslice_1 +++ /dev/null @@ -1,6 +0,0 @@ - # - # reslice the geometry? - # - "r") - resliceFLAG=1 - ;; diff --git a/spm8Batch/auxiliary/case_reslice_2 b/spm8Batch/auxiliary/case_reslice_2 deleted file mode 100644 index f546a1ff..00000000 --- a/spm8Batch/auxiliary/case_reslice_2 +++ /dev/null @@ -1,6 +0,0 @@ - # - # reslice the geometry only with no estimation? - # - "R") - resliceFLAG=2 - ;; diff --git a/spm8Batch/auxiliary/case_run_number b/spm8Batch/auxiliary/case_run_number deleted file mode 100644 index 23186362..00000000 --- a/spm8Batch/auxiliary/case_run_number +++ /dev/null @@ -1,15 +0,0 @@ - # - # run numbers - # - "#") - shift - let argn++ - if (( $argn >= $args )) - then - echo "Missing parameter for run number, aborting" - exit 0 - else - runNAMES[$nRUN]=$1 - let nRUN++ - fi - ;; diff --git a/spm8Batch/auxiliary/case_set_run b/spm8Batch/auxiliary/case_set_run deleted file mode 100644 index 0e303acd..00000000 --- a/spm8Batch/auxiliary/case_set_run +++ /dev/null @@ -1,6 +0,0 @@ - # - # run list - # - "i") - . ${thisDir}/auxiliary/setRunList - ;; diff --git a/spm8Batch/auxiliary/case_standard_volume b/spm8Batch/auxiliary/case_standard_volume deleted file mode 100644 index 0d9ced36..00000000 --- a/spm8Batch/auxiliary/case_standard_volume +++ /dev/null @@ -1,6 +0,0 @@ - # - # find the standard volume number. - # - "S") - . ${thisDir}/auxiliary/setStandardVolumeNumber - ;; diff --git a/spm8Batch/auxiliary/case_sub_path b/spm8Batch/auxiliary/case_sub_path deleted file mode 100644 index dd227d91..00000000 --- a/spm8Batch/auxiliary/case_sub_path +++ /dev/null @@ -1,6 +0,0 @@ - # - # sub-Path name to search for functional images. - # - "s") - . ${thisDir}/auxiliary/setFunctionalSubPathName - ;; diff --git a/spm8Batch/auxiliary/case_subject_dir b/spm8Batch/auxiliary/case_subject_dir deleted file mode 100644 index c05a9b7b..00000000 --- a/spm8Batch/auxiliary/case_subject_dir +++ /dev/null @@ -1,6 +0,0 @@ - # - # subject directory name to use - # - "M") - . ${thisDir}/auxiliary/setSubjectsMasterDir - ;; diff --git a/spm8Batch/auxiliary/case_super_debug_flag b/spm8Batch/auxiliary/case_super_debug_flag deleted file mode 100644 index 739c870c..00000000 --- a/spm8Batch/auxiliary/case_super_debug_flag +++ /dev/null @@ -1,6 +0,0 @@ - # - # super debug flag - # - "D") - . ${thisDir}/auxiliary/setSuperDebugFlag - ;; diff --git a/spm8Batch/auxiliary/case_template_name b/spm8Batch/auxiliary/case_template_name deleted file mode 100644 index 194997e1..00000000 --- a/spm8Batch/auxiliary/case_template_name +++ /dev/null @@ -1,6 +0,0 @@ - # - # Template Image. - # - "T") - . ${thisDir}/auxiliary/setTemplateImageName - ;; diff --git a/spm8Batch/auxiliary/case_test_flag b/spm8Batch/auxiliary/case_test_flag deleted file mode 100644 index 2d84bab0..00000000 --- a/spm8Batch/auxiliary/case_test_flag +++ /dev/null @@ -1,6 +0,0 @@ - # - # Test FLAG - # - "t") - . ${thisDir}/auxiliary/setTestFlag - ;; diff --git a/spm8Batch/auxiliary/case_user_email b/spm8Batch/auxiliary/case_user_email deleted file mode 100644 index c8dc7fd6..00000000 --- a/spm8Batch/auxiliary/case_user_email +++ /dev/null @@ -1,6 +0,0 @@ - # - # Where to send email when finished - # - "U") - . ${thisDir}/auxiliary/setUserEmail - ;; diff --git a/spm8Batch/auxiliary/case_volume_name b/spm8Batch/auxiliary/case_volume_name deleted file mode 100644 index d27790d7..00000000 --- a/spm8Batch/auxiliary/case_volume_name +++ /dev/null @@ -1,6 +0,0 @@ - # - # wildcard name to use for which to co-reg. - # - "v") - . ${thisDir}/auxiliary/setVolumeWildCard - ;; diff --git a/spm8Batch/auxiliary/case_voxel_size b/spm8Batch/auxiliary/case_voxel_size deleted file mode 100644 index a418a84b..00000000 --- a/spm8Batch/auxiliary/case_voxel_size +++ /dev/null @@ -1,6 +0,0 @@ - # - # Voxel size - # - "z") - . ${thisDir}/auxiliary/setVoxelSize - ;; diff --git a/spm8Batch/auxiliary/checkDetectSpikeParts b/spm8Batch/auxiliary/checkDetectSpikeParts new file mode 100644 index 00000000..4bc26f37 --- /dev/null +++ b/spm8Batch/auxiliary/checkDetectSpikeParts @@ -0,0 +1,14 @@ +# validate that we have what we need. + +for CRITICALMATLAB in detect_spike_part_1.m detect_spike_part_2.m +do + if [ ! -e "${SPM8B2}/parts/${CRITICALMATLAB}" ] + then + echo + echo "Validate that you have 'detect_spike_1.m' and 'detect_spike_part_2.m' " + echo "Missing a critical component '${CRITICALMATLAB}'" + echo + exit 0 + fi +done + diff --git a/spm8Batch/auxiliary/checkInputForSubjects b/spm8Batch/auxiliary/checkInputForSubjects index 5bc87640..cf46bdc2 100644 --- a/spm8Batch/auxiliary/checkInputForSubjects +++ b/spm8Batch/auxiliary/checkInputForSubjects @@ -1,6 +1,6 @@ if (( ${#subjects[@]} < 1 )) then . ${thisDir}/auxiliary/noSubjectsErrorMsg - exit 1 + . ${thisDir}/auxiliary/exit_w_removal fi diff --git a/spm8Batch/auxiliary/checkVBMParts b/spm8Batch/auxiliary/checkVBMParts new file mode 100644 index 00000000..18006351 --- /dev/null +++ b/spm8Batch/auxiliary/checkVBMParts @@ -0,0 +1,14 @@ +# validate that we have what we need. + +for CRITICALMATLAB in vbm8_part_01.m vbm8_part_02.m +do + if [ ! -e "${SPM8B2}/parts/${CRITICALMATLAB}" ] + then + echo + echo "Validate that you have 'vbm8_part_01.m' and 'vbm_part_02.m' " + echo "Missing a critical component '${CRITICALMATLAB}'" + echo + exit 0 + fi +done + diff --git a/spm8Batch/auxiliary/checkVBMParts~ b/spm8Batch/auxiliary/checkVBMParts~ new file mode 100644 index 00000000..e463b0e5 --- /dev/null +++ b/spm8Batch/auxiliary/checkVBMParts~ @@ -0,0 +1,14 @@ +# validate that we have what we need. + +for CRITICALMATLAB in warp_part_1.m warp_fMRI_part_2.m warp_HIRES_part_2.m +do + if [ ! -e "${SPM8B2}/parts/${CRITICALMATLAB}" ] + then + echo + echo "Validate that you have 'warp_part_1.m' and 'warp_part_2.m' " + echo "Missing a critical component '${CRITICALMATLAB}'" + echo + exit 0 + fi +done + diff --git a/spm8Batch/auxiliary/commonCode_Detect_01 b/spm8Batch/auxiliary/commonCode_Detect_01 new file mode 100644 index 00000000..52d4481f --- /dev/null +++ b/spm8Batch/auxiliary/commonCode_Detect_01 @@ -0,0 +1,7 @@ +# validate that we have what we need. + +. ${thisDir}/auxiliary/checkDetectSpikeParts + +# Initialize warping variables. + +. ${thisDir}/auxiliary/initialization_all diff --git a/spm8Batch/auxiliary/commonCode_VBM8_01 b/spm8Batch/auxiliary/commonCode_VBM8_01 new file mode 100644 index 00000000..370d4ea3 --- /dev/null +++ b/spm8Batch/auxiliary/commonCode_VBM8_01 @@ -0,0 +1,8 @@ +# validate that we have what we need. + +. ${thisDir}/auxiliary/checkVBMParts + +# Initialize warping variables. + +. ${thisDir}/auxiliary/initialization_all + diff --git a/spm8Batch/auxiliary/coregDirectoryErrorCheck b/spm8Batch/auxiliary/coregDirectoryErrorCheck index f5dd4488..183abf53 100755 --- a/spm8Batch/auxiliary/coregDirectoryErrorCheck +++ b/spm8Batch/auxiliary/coregDirectoryErrorCheck @@ -5,6 +5,6 @@ echo echo " ABORTING " echo - exit 1 + . ${thisDir}/auxiliary/exit_w_removal fi diff --git a/spm8Batch/auxiliary/coregFindSourceAndMove b/spm8Batch/auxiliary/coregFindSourceAndMove index 2f9203d1..286b6b67 100755 --- a/spm8Batch/auxiliary/coregFindSourceAndMove +++ b/spm8Batch/auxiliary/coregFindSourceAndMove @@ -52,7 +52,7 @@ echo echo "ABORTING" echo - exit 1 + . ${thisDir}/auxiliary/exit_w_removal fi if [ -e "${UMBatchMaster}/${SUBJDIR}/${subjects[$is]}/${anatomyPATH}/${SOURCENAME}${USEEXT}" ] @@ -67,7 +67,7 @@ echo echo "ABORTING" echo - exit 1 + . ${thisDir}/auxiliary/exit_w_removal fi fileLIST=`ls -1 ${destSOURCENAME}* | wc |awk '{print $1}'` diff --git a/spm8Batch/auxiliary/coregPrepOtherImages b/spm8Batch/auxiliary/coregPrepOtherImages index 3cd28712..0972e8b1 100755 --- a/spm8Batch/auxiliary/coregPrepOtherImages +++ b/spm8Batch/auxiliary/coregPrepOtherImages @@ -57,7 +57,7 @@ do echo echo ABORTING echo - exit 1 + . ${thisDir}/auxiliary/exit_w_removal fi otherSOURCE=${otherSRCNAME}${USEEXT} @@ -84,7 +84,7 @@ do echo echo "* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * " echo - exit 1 + . ${thisDir}/auxiliary/exit_w_removal fi done fi diff --git a/spm8Batch/auxiliary/detectSpikePart_01 b/spm8Batch/auxiliary/detectSpikePart_01 new file mode 100644 index 00000000..12808ea9 --- /dev/null +++ b/spm8Batch/auxiliary/detectSpikePart_01 @@ -0,0 +1,14 @@ +# Use common in-line code #01 -- comments out to standard output. + +. ${thisDir}/auxiliary/buildMatlabScripts_01 + +cat ${thisDir}/parts/detect_spike_part_1.m > ${FULLSCRIPTNAME}.m + +. ${thisDir}/auxiliary/buildMatlabScripts_02 + +echo "SandBoxDIR = '${SANDBOX}/';" >> ${FULLSCRIPTNAME}.m + +echo "SandBoxPID = '${SANDBOXPID}/';" >> ${FULLSCRIPTNAME}.m + +. ${thisDir}/auxiliary/buildMatlabScripts_03 + diff --git a/spm8Batch/auxiliary/exit_w_removal b/spm8Batch/auxiliary/exit_w_removal new file mode 100644 index 00000000..0cf1a6aa --- /dev/null +++ b/spm8Batch/auxiliary/exit_w_removal @@ -0,0 +1,36 @@ + +# +# We must do a graceful exit and clean up everthing that was possibly written. +# + +echo +echo "An error was found in your data and/or parameter specification, se we can not proceed. Going to now" +echo "gently remove any script files partially written." +echo + +if [ ! -z ${FULLSCRIPTNAME} ] +then + for EXT in sh m log + do + if [ -e ${FULLSCRIPTNAME}.${EXT} ] + then + echo -n "Found '${FULLSCRIPTNAME}.${EXT}', removing...." + rm ${FULLSCRIPTNAME}.${EXT} 2> /dev/null + echo + fi + done +fi + +# +# Now exiting +# + +echo +echo "Clean up finished, now exiting." +echo + +exit 1 + +# +# all done. +# \ No newline at end of file diff --git a/spm8Batch/auxiliary/exit_w_removal~ b/spm8Batch/auxiliary/exit_w_removal~ new file mode 100644 index 00000000..e69de29b diff --git a/spm8Batch/auxiliary/help/detectSpike_Help b/spm8Batch/auxiliary/help/detectSpike_Help new file mode 100644 index 00000000..bf504234 --- /dev/null +++ b/spm8Batch/auxiliary/help/detectSpike_Help @@ -0,0 +1,22 @@ + echo + echo " A command line to drive batch processing to detect spike instensities" + echo " in slices for a 4D scan." + echo + . ${thisDir}/auxiliary/help/help_options_start + + + echo " e.g. " + echo + echo " To detect spikes:" + echo + echo " detectSpike -f func/MSIT 050126zz" + echo + echo " Note: Results are written in a text file 'subject_[run_##_]ds.txt'" + echo " in the same directory where the 4D scan is located." + echo + echo + echo " Current command default configuration is:" + echo + echo + + . ${thisDir}/auxiliary/help/help_${thisCommand}_Options diff --git a/spm8Batch/auxiliary/help/help_case_hires_name b/spm8Batch/auxiliary/help/help_case_hires_name index e723668c..8ea631ed 100644 --- a/spm8Batch/auxiliary/help/help_case_hires_name +++ b/spm8Batch/auxiliary/help/help_case_hires_name @@ -1,3 +1,3 @@ echo " -h HiResName name of high resolution file, " - echo " default is 'eht1spgr'" + echo " default is '${HIRESNAME}'" echo diff --git a/spm8Batch/auxiliary/help/help_case_set_reference b/spm8Batch/auxiliary/help/help_case_set_reference new file mode 100644 index 00000000..a17d16f1 --- /dev/null +++ b/spm8Batch/auxiliary/help/help_case_set_reference @@ -0,0 +1,8 @@ + echo " -I ReferenceName set the reference image to use for VBM8, " + echo " you can specify relative to :" + echo " ${TemplateImageDir}, or." + echo " specify an absolute directory path." + echo " default is none, but to use defaults.normalise.write.bb" + echo + echo " A reference image takes precedence over the voxel size." + echo diff --git a/spm8Batch/auxiliary/help/help_case_template_name b/spm8Batch/auxiliary/help/help_case_template_name index b69dc309..20d59ef2 100644 --- a/spm8Batch/auxiliary/help/help_case_template_name +++ b/spm8Batch/auxiliary/help/help_case_template_name @@ -1,5 +1,6 @@ echo " -T TEMPLATENAME set the template to use for normalization, " - echo " you can specify relative to ${TemplateImageDir}, or." + echo " you can specify relative to:" + echo " ${TemplateImageDir}, or." echo " specify an absolute directory path." echo " default is ${TemplateImage}" echo diff --git a/spm8Batch/auxiliary/help/help_case_voxel_size b/spm8Batch/auxiliary/help/help_case_voxel_size index f3144a32..2b210382 100644 --- a/spm8Batch/auxiliary/help/help_case_voxel_size +++ b/spm8Batch/auxiliary/help/help_case_voxel_size @@ -1,3 +1,4 @@ echo " -z VOXELSIZE set the voxel size for resampling, " echo " default is spm default." + echo " See '-I' flag for overriding this for 'vbm8HiRes' and 'warpfMRI'." echo diff --git a/spm8Batch/auxiliary/help/help_case_warpmethod b/spm8Batch/auxiliary/help/help_case_warpmethod new file mode 100644 index 00000000..29c1a021 --- /dev/null +++ b/spm8Batch/auxiliary/help/help_case_warpmethod @@ -0,0 +1,3 @@ + echo " -W Enable VBM8 warping for fMRI, you need to run vbm8HiRes first." + echo " Default is to use standard SPM8 normalization." + echo diff --git a/spm8Batch/auxiliary/help/help_case_warpmethod~ b/spm8Batch/auxiliary/help/help_case_warpmethod~ new file mode 100644 index 00000000..1646dd12 --- /dev/null +++ b/spm8Batch/auxiliary/help/help_case_warpmethod~ @@ -0,0 +1,3 @@ + echo " -t enable testing flag, script will be built" + echo " but not run." + echo diff --git a/spm8Batch/auxiliary/help/help_detectSpike_Options b/spm8Batch/auxiliary/help/help_detectSpike_Options new file mode 100644 index 00000000..af977db2 --- /dev/null +++ b/spm8Batch/auxiliary/help/help_detectSpike_Options @@ -0,0 +1,5 @@ + echo "${helpComment} volumeWILD : $volumeWILD" + echo "${helpComment} functional sub-dir : $subPATH" + echo + + . ${thisDir}/auxiliary/help/help_options_end diff --git a/spm8Batch/auxiliary/help/help_options_start b/spm8Batch/auxiliary/help/help_options_start index 8b560dd0..ae521fee 100644 --- a/spm8Batch/auxiliary/help/help_options_start +++ b/spm8Batch/auxiliary/help/help_options_start @@ -75,6 +75,9 @@ "h") . ${thisDir}/auxiliary/help/help_case_hires_name ;; + "I") + . ${thisDir}/auxiliary/help/help_case_set_reference + ;; "i") . ${thisDir}/auxiliary/help/help_case_set_run ;; @@ -132,6 +135,9 @@ "v") . ${thisDir}/auxiliary/help/help_case_volume_name ;; + "W") + . ${thisDir}/auxiliary/help/help_case_warpmethod + ;; "w") . ${thisDir}/auxiliary/help/help_case_coreg_path ;; diff --git a/spm8Batch/auxiliary/help/help_vbm8Check_Options b/spm8Batch/auxiliary/help/help_vbm8Check_Options new file mode 100644 index 00000000..feef6201 --- /dev/null +++ b/spm8Batch/auxiliary/help/help_vbm8Check_Options @@ -0,0 +1,5 @@ + echo "${helpComment} anatomy path : ${anatomyPATH}" + echo "${helpComment} name of hisres image : ${HIRESNAME}" + echo + + . ${thisDir}/auxiliary/help/help_options_end diff --git a/spm8Batch/auxiliary/help/help_vbm8HiRes_Options b/spm8Batch/auxiliary/help/help_vbm8HiRes_Options new file mode 100644 index 00000000..3dccdf30 --- /dev/null +++ b/spm8Batch/auxiliary/help/help_vbm8HiRes_Options @@ -0,0 +1,6 @@ + echo "${helpComment} anatomy path : $anatomyPATH" + echo "${helpComment} name of hisres image : $HIRESNAME" + echo "${helpComment} directory to vbm8 : $coregPATH/" + echo + + . ${thisDir}/auxiliary/help/help_options_end diff --git a/spm8Batch/auxiliary/help/help_vbm8HiRes_Options~ b/spm8Batch/auxiliary/help/help_vbm8HiRes_Options~ new file mode 100644 index 00000000..427f3b61 --- /dev/null +++ b/spm8Batch/auxiliary/help/help_vbm8HiRes_Options~ @@ -0,0 +1,7 @@ + echo "${helpComment} anatomy path : $anatomyPATH" + echo "${helpComment} name of hisres image : $HIRESNAME" + echo "${helpComment} BET gradient : $BETGRADIENT" + echo "${helpComment} BET gradient name : $BETNAME" + echo + + . ${thisDir}/auxiliary/help/help_options_end diff --git a/spm8Batch/auxiliary/help/help_warpfMRI_Options b/spm8Batch/auxiliary/help/help_warpfMRI_Options index f53b4711..402cff88 100644 --- a/spm8Batch/auxiliary/help/help_warpfMRI_Options +++ b/spm8Batch/auxiliary/help/help_warpfMRI_Options @@ -1,5 +1,6 @@ echo "${helpComment} directory to coreg : ${fmriPATH}/$coregPATH/" echo "${helpComment} name of the high res : $HIRESNAME" + echo "${helpComment} Warping Method (1=VBM8) : ${WARPMETHOD}" echo "${helpComment} template image dir/name : ${TemplateImage}" echo "${helpComment} prepending name : $outputName" echo "${helpComment} Voxel dimension (0=spm) : ${voxelSize}" diff --git a/spm8Batch/auxiliary/help/smoothfMRI_Help b/spm8Batch/auxiliary/help/smoothfMRI_Help index 28d63726..cd5efbdc 100644 --- a/spm8Batch/auxiliary/help/smoothfMRI_Help +++ b/spm8Batch/auxiliary/help/smoothfMRI_Help @@ -3,7 +3,7 @@ echo " NIFTI images." echo - . ${thisDir}/auxiliary/help/help_Options_Start + . ${thisDir}/auxiliary/help/help_options_start echo echo " e.g. to smooth 'raprun' for 2 subjects with 5x6x7" diff --git a/spm8Batch/auxiliary/help/tmp.help b/spm8Batch/auxiliary/help/tmp.help deleted file mode 100644 index df35716e..00000000 --- a/spm8Batch/auxiliary/help/tmp.help +++ /dev/null @@ -1,31 +0,0 @@ -# ${thisDir}/auxiliary/help/help_case_run_number -A ${thisDir}/auxiliary/help/help_case_all_runs -D ${thisDir}/auxiliary/help/help_case_super_debug_flag -F ${thisDir}/auxiliary/help/help_case_fmri_tr -M ${thisDir}/auxiliary/help/help_case_subject_dir -N ${thisDir}/auxiliary/help/help_case_output_name -O ${thisDir}/auxiliary/help/help_case_other_names -P ${thisDir}/auxiliary/help/help_case_physiooptions -R ${thisDir}/auxiliary/help/help_case_reslice_2 -S ${thisDir}/auxiliary/help/help_case_standard_volume -T ${thisDir}/auxiliary/help/help_case_template_name -U ${thisDir}/auxiliary/help/help_case_user_email -V ${thisDir}/auxiliary/help/help_case_verify_flag -a ${thisDir}/auxiliary/help/help_case_anatomy_path -b ${thisDir}/auxiliary/help/help_case_bet_best_flag -d ${thisDir}/auxiliary/help/help_case_debug_flag -f ${thisDir}/auxiliary/help/help_case_functional_path -g ${thisDir}/auxiliary/help/help_case_BET_gradient -h ${thisDir}/auxiliary/help/help_case_hires_name -i ${thisDir}/auxiliary/help/help_case_set_run -m ${thisDir}/auxiliary/help/help_case_flirt_options -n ${thisDir}/auxiliary/help/help_case_output_name -o ${thisDir}/auxiliary/help/help_case_overlay_name -p ${thisDir}/auxiliary/help/help_case_physioname -r ${thisDir}/auxiliary/help/help_case_reslice_1 -s ${thisDir}/auxiliary/help/help_case_sub_path -t ${thisDir}/auxiliary/help/help_case_test_flag -u ${thisDir}/auxiliary/help/help_case_best_bet -v ${thisDir}/auxiliary/help/help_case_volume_name -w ${thisDir}/auxiliary/help/help_case_coreg_path -z ${thisDir}/auxiliary/help/help_case_voxel_size diff --git a/spm8Batch/auxiliary/help/tmp_076460.txt b/spm8Batch/auxiliary/help/tmp_076460.txt deleted file mode 100644 index a5fbabe5..00000000 --- a/spm8Batch/auxiliary/help/tmp_076460.txt +++ /dev/null @@ -1,26 +0,0 @@ - echo - echo " A command line command to drive batch processing to warp the fMRI time series" - echo " to the standard template using normalization derived during the 'warpHiRes' phase." - echo - . ${thisDir}/auxiliary/help/help_options_start - - - echo " e.g. " - echo - echo " To warp fmri using the 'het1spgr':" - echo - echo " warpfMRI -w func/MSIT 050126zz" - echo - echo - echo "*NOTE: This code will actually hunt out rapruns's (or those specified in the -v flag" - echo " The code does not actually care where the files live and will attempt to warp " - echo " any and all volumes using the specified SPGR (or default) volume. However you" - echo " can narrow the search by supplying the '-s subdir' option which will then require" - echo " that 'subdir' is a string contained in the list of directories returned for warping." - echo " If this DOES NOT make sense to you please contact Robert before proceeding." - echo - echo " Current command default configuration is:" - echo - echo - - . ${thisDir}/auxiliary/help/help_${thisCommand}_Options diff --git a/spm8Batch/auxiliary/help/tmp_078468.txt b/spm8Batch/auxiliary/help/tmp_078468.txt deleted file mode 100644 index a5fbabe5..00000000 --- a/spm8Batch/auxiliary/help/tmp_078468.txt +++ /dev/null @@ -1,26 +0,0 @@ - echo - echo " A command line command to drive batch processing to warp the fMRI time series" - echo " to the standard template using normalization derived during the 'warpHiRes' phase." - echo - . ${thisDir}/auxiliary/help/help_options_start - - - echo " e.g. " - echo - echo " To warp fmri using the 'het1spgr':" - echo - echo " warpfMRI -w func/MSIT 050126zz" - echo - echo - echo "*NOTE: This code will actually hunt out rapruns's (or those specified in the -v flag" - echo " The code does not actually care where the files live and will attempt to warp " - echo " any and all volumes using the specified SPGR (or default) volume. However you" - echo " can narrow the search by supplying the '-s subdir' option which will then require" - echo " that 'subdir' is a string contained in the list of directories returned for warping." - echo " If this DOES NOT make sense to you please contact Robert before proceeding." - echo - echo " Current command default configuration is:" - echo - echo - - . ${thisDir}/auxiliary/help/help_${thisCommand}_Options diff --git a/spm8Batch/auxiliary/help/tmp_081508.txt b/spm8Batch/auxiliary/help/tmp_081508.txt deleted file mode 100644 index a5fbabe5..00000000 --- a/spm8Batch/auxiliary/help/tmp_081508.txt +++ /dev/null @@ -1,26 +0,0 @@ - echo - echo " A command line command to drive batch processing to warp the fMRI time series" - echo " to the standard template using normalization derived during the 'warpHiRes' phase." - echo - . ${thisDir}/auxiliary/help/help_options_start - - - echo " e.g. " - echo - echo " To warp fmri using the 'het1spgr':" - echo - echo " warpfMRI -w func/MSIT 050126zz" - echo - echo - echo "*NOTE: This code will actually hunt out rapruns's (or those specified in the -v flag" - echo " The code does not actually care where the files live and will attempt to warp " - echo " any and all volumes using the specified SPGR (or default) volume. However you" - echo " can narrow the search by supplying the '-s subdir' option which will then require" - echo " that 'subdir' is a string contained in the list of directories returned for warping." - echo " If this DOES NOT make sense to you please contact Robert before proceeding." - echo - echo " Current command default configuration is:" - echo - echo - - . ${thisDir}/auxiliary/help/help_${thisCommand}_Options diff --git a/spm8Batch/auxiliary/help/vbm8Check_Help b/spm8Batch/auxiliary/help/vbm8Check_Help new file mode 100644 index 00000000..5f40a491 --- /dev/null +++ b/spm8Batch/auxiliary/help/vbm8Check_Help @@ -0,0 +1,15 @@ + echo + echo " A command line command to fslview the ht1spgr and vbm8 bet" + echo + . ${thisDir}/auxiliary/help/help_options_start + + echo + echo " e.g. " + echo + echo " vbm8Check 050126zz" + echo + echo + echo " Current command default configuration is:" + echo + + . ${thisDir}/auxiliary/help/help_vbm8Check_Options diff --git a/spm8Batch/auxiliary/help/vbm8Check_Help~ b/spm8Batch/auxiliary/help/vbm8Check_Help~ new file mode 100644 index 00000000..77511a91 --- /dev/null +++ b/spm8Batch/auxiliary/help/vbm8Check_Help~ @@ -0,0 +1,15 @@ + echo + echo " A command line command to fslview the ht1spgr and best BET" + echo + . ${thisDir}/auxiliary/help/help_options_start + + echo + echo " e.g. " + echo + echo " fslCheck 050126zz" + echo + echo + echo " Current command default configuration is:" + echo + + . ${thisDir}/auxiliary/help/help_fslCheck_Options diff --git a/spm8Batch/auxiliary/help/vbm8HiRes_Help b/spm8Batch/auxiliary/help/vbm8HiRes_Help new file mode 100644 index 00000000..3c2fb5ad --- /dev/null +++ b/spm8Batch/auxiliary/help/vbm8HiRes_Help @@ -0,0 +1,18 @@ + echo + echo " A command line command to drive batch processing to VBM8 the 'HIRES' image." + echo + . ${thisDir}/auxiliary/help/help_options_start + + echo + echo " e.g. " + echo + echo " To process the image 'ht1spgr.nii' through VBM8 to create a skull-stripped" + echo " image in the native space do:" + echo + echo " vbm8HiRes 050126zz" + echo + echo + echo " Current command default configuration is:" + echo + + . ${thisDir}/auxiliary/help/help_vbm8HiRes_Options diff --git a/spm8Batch/auxiliary/help/vbm8HiRes_Help~ b/spm8Batch/auxiliary/help/vbm8HiRes_Help~ new file mode 100644 index 00000000..92736184 --- /dev/null +++ b/spm8Batch/auxiliary/help/vbm8HiRes_Help~ @@ -0,0 +1,19 @@ + echo + echo " A command line command to drive batch processing to coregister the 'HIRES'" + echo " to 'overlay' analyze image. " + echo + . ${thisDir}/auxiliary/help/help_options_start + + echo + echo " e.g. " + echo + echo " To coregister the 'het1spgr.img' to the 'het1overlay.img' that has been coreg'd" + echo " to the fMRI times series and to drop the results in 'func/MSIT/coReg' :" + echo + echo " coregSPGR -w MSIT/coReg 050126zz" + echo + echo + echo " Current command default configuration is:" + echo + + . ${thisDir}/auxiliary/help/help_coregHiRes_Options diff --git a/spm8Batch/auxiliary/help/warpfMRI_Help b/spm8Batch/auxiliary/help/warpfMRI_Help index a5fbabe5..0f5f6724 100644 --- a/spm8Batch/auxiliary/help/warpfMRI_Help +++ b/spm8Batch/auxiliary/help/warpfMRI_Help @@ -1,6 +1,6 @@ echo echo " A command line command to drive batch processing to warp the fMRI time series" - echo " to the standard template using normalization derived during the 'warpHiRes' phase." + echo " to the standard template using normalization derived during the 'warpHiRes/vbm8HiRes' phase." echo . ${thisDir}/auxiliary/help/help_options_start @@ -12,12 +12,14 @@ echo " warpfMRI -w func/MSIT 050126zz" echo echo - echo "*NOTE: This code will actually hunt out rapruns's (or those specified in the -v flag" - echo " The code does not actually care where the files live and will attempt to warp " - echo " any and all volumes using the specified SPGR (or default) volume. However you" - echo " can narrow the search by supplying the '-s subdir' option which will then require" - echo " that 'subdir' is a string contained in the list of directories returned for warping." - echo " If this DOES NOT make sense to you please contact Robert before proceeding." + echo "*NOTE: This code will actually hunt out rapruns's (or those specified in the -v flag" + echo " The code does not actually care where the files live and will attempt to warp " + echo " any and all volumes using the specified SPGR (or default) volume. However you" + echo " can narrow the search by supplying the '-s subdir' option which will then require" + echo " that 'subdir' is a string contained in the list of directories returned for warping." + echo " If this DOES NOT make sense to you please contact Robert before proceeding." + echo + echo "**NOTE: You can also use the VBM8 toolbox to process data, see vbm8HiRes" echo echo " Current command default configuration is:" echo diff --git a/spm8Batch/auxiliary/initialization_detectSpike b/spm8Batch/auxiliary/initialization_detectSpike new file mode 100644 index 00000000..83de4ecc --- /dev/null +++ b/spm8Batch/auxiliary/initialization_detectSpike @@ -0,0 +1,13 @@ +# +# Inialization. +# + +# Output name +outputName= + +# Use different default volumeWILD +volumeWILD=run + +# +# all done +# diff --git a/spm8Batch/auxiliary/initialization_vbm8Check b/spm8Batch/auxiliary/initialization_vbm8Check new file mode 100644 index 00000000..bcfe4be1 --- /dev/null +++ b/spm8Batch/auxiliary/initialization_vbm8Check @@ -0,0 +1,13 @@ +# Inialization. + +FSL_COMMENT_B="fsl check reging between best BET and original hi res from VBM8" + +BATCHCOMMAND=0 + +# Hiresolution image +HIRESNAME=ht1spgr +HIRESEXT= + +# +# all done +# diff --git a/spm8Batch/auxiliary/initialization_vbm8HiRes b/spm8Batch/auxiliary/initialization_vbm8HiRes new file mode 100644 index 00000000..1a930636 --- /dev/null +++ b/spm8Batch/auxiliary/initialization_vbm8HiRes @@ -0,0 +1,20 @@ +# +# Inialization. +# + +# we do things in the top level of the subject, so not +# in the func directory. + +fmriPATH=./ + +# Output directory + +coregPATH=anatomy/vbm8/ + +# + +outputName=vbm8_ + +# +# all done +# diff --git a/spm8Batch/auxiliary/initialization_warpHiRes b/spm8Batch/auxiliary/initialization_warpHiRes index 83e621cf..e2b5c42a 100755 --- a/spm8Batch/auxiliary/initialization_warpHiRes +++ b/spm8Batch/auxiliary/initialization_warpHiRes @@ -5,6 +5,9 @@ # Output name outputName=w +# Warping method +WARPMETHOD=0 + # # all done # diff --git a/spm8Batch/auxiliary/initialization_warpfMRI b/spm8Batch/auxiliary/initialization_warpfMRI index 83e621cf..fef64645 100755 --- a/spm8Batch/auxiliary/initialization_warpfMRI +++ b/spm8Batch/auxiliary/initialization_warpfMRI @@ -5,6 +5,15 @@ # Output name outputName=w +# Warping method, 0=SPM8, 1=VBM8 + +WARPMETHOD=0 + +# The VBM8ReferenceImage to override the bounding box and voxelsize +# if this is left blank we use the defaults. + +VBM8ReferenceImage= + # # all done # diff --git a/spm8Batch/auxiliary/parse_arguments b/spm8Batch/auxiliary/parse_arguments index dcde2802..8f11ef2a 100644 --- a/spm8Batch/auxiliary/parse_arguments +++ b/spm8Batch/auxiliary/parse_arguments @@ -2,6 +2,15 @@ # Parse the arguments # +# permitted arguments +# +# AabDdFfghiMmnOopPRrSsTtUuVvwZ# +# +# + +echo "Parsing commands:" +echo + while (( $argn < $args )) do # @@ -9,6 +18,8 @@ do # this means you need to specify the subject # master directory first. ( SUBJDIR ) # + debugout "Current param: $1" $SuperDebugFLAG + if [ -d "./${SUBJDIR}/$1" ] then let nSubjects++ @@ -32,8 +43,11 @@ do echo echo "Option : $curParam : is not allowed for ${thisCommand}" echo - exit 1 + . ${thisDir}/auxiliary/exit_w_removal fi + + debugout "Parsing command : ${curParam}" $SuperDebugFLAG + case "${curParam:1:1}" in @@ -41,258 +55,272 @@ do # # All runs in func # - "A") - ALLRUNSFLAG=1 - ;; + "A") + ALLRUNSFLAG=1 + ;; # case_anatomy_path # # Path name to find virgin anatomy files. # - "a") - . ${thisDir}/auxiliary/setAnatomyPath - ;; + "a") + . ${thisDir}/auxiliary/setAnatomyPath + ;; # case_bet_best_flag # # look at the BET best flag # - "b") - . ${thisDir}/auxiliary/setBETFLAG - ;; - + "b") + . ${thisDir}/auxiliary/setBETFLAG + ;; + # case_super_debug_flag # # super debug flag # - "D") - . ${thisDir}/auxiliary/setSuperDebugFlag - ;; + "D") + . ${thisDir}/auxiliary/setSuperDebugFlag + ;; # case_debug_flag # # debug flag # - "d") - . ${thisDir}/auxiliary/setDebugFlag - ;; + "d") + . ${thisDir}/auxiliary/setDebugFlag + ;; # case_fmri_tr # # Set the TR # - "F") - . ${thisDir}/auxiliary/setVolumeTR - ;; + "F") + . ${thisDir}/auxiliary/setVolumeTR + ;; # case_functional_path # # Path name to search for functional images. # - "f") - . ${thisDir}/auxiliary/setFunctionalPath - ;; - + "f") + . ${thisDir}/auxiliary/setFunctionalPath + ;; + # case_set_BET_gradient # # Set the gradient scale for bestBET # - "g") - . ${thisDir}/auxiliary/setGradientValue - ;; + "g") + . ${thisDir}/auxiliary/setGradientValue + ;; # case_hires_name # # SPGR (hiRES) name to use # - "h") - . ${thisDir}/auxiliary/setHiResName - ;; + "h") + . ${thisDir}/auxiliary/setHiResName + ;; + # case_set_referenceImage + # + # reference image for warpfMRI with vbm8 + # + "I") + . ${thisDir}/auxiliary/setReferenceImage + ;; # case_set_run # # run list # - "i") - . ${thisDir}/auxiliary/setRunList - ;; - + "i") + . ${thisDir}/auxiliary/setRunList + ;; + # case_subject_dir # # subject directory name to use # - "M") - . ${thisDir}/auxiliary/setSubjectsMasterDir - ;; - + "M") + . ${thisDir}/auxiliary/setSubjectsMasterDir + ;; + # case_flirt_options # # find the flirt options # - "m") - . ${thisDir}/auxiliary/setMCFlirtOptions - ;; - + "m") + . ${thisDir}/auxiliary/setMCFlirtOptions + ;; + # case_output_name # # Set the name to add. # - "n") - . ${thisDir}/auxiliary/setOutputName - ;; - + "n") + . ${thisDir}/auxiliary/setOutputName + ;; + # case_other_names # # Simliar Other images # - "O") - . ${thisDir}/auxiliary/setOtherNames - ;; + "O") + . ${thisDir}/auxiliary/setOtherNames + ;; # case_overlay_name # # overlay name to use # - "o") - . ${thisDir}/auxiliary/setOverlayName - ;; - + "o") + . ${thisDir}/auxiliary/setOverlayName + ;; + # case_physfile_name # # physio phys file table # - "p") - . ${thisDir}/auxiliary/setPhysioName - ;; + "p") + . ${thisDir}/auxiliary/setPhysioName + ;; # case_physio_options # # physio options # - "P") - . ${thisDir}/auxiliary/setPhysioOptions - ;; + "P") + . ${thisDir}/auxiliary/setPhysioOptions + ;; # case_reslice_2 # # reslice the geometry only with no estimation? # - "R") - resliceFLAG=2 - ;; + "R") + resliceFLAG=2 + ;; # case_reslice_1 # # reslice the geometry? # - "r") - resliceFLAG=1 - ;; + "r") + resliceFLAG=1 + ;; # case_standard_volume # # find the standard volume number. # - "S") - . ${thisDir}/auxiliary/setStandardVolumeNumber - ;; + "S") + . ${thisDir}/auxiliary/setStandardVolumeNumber + ;; # case_sub_path # # sub-Path name to search for functional images. # - "s") - . ${thisDir}/auxiliary/setFunctionalSubPathName - ;; + "s") + . ${thisDir}/auxiliary/setFunctionalSubPathName + ;; # case_template_name # # Template Image. # - "T") - . ${thisDir}/auxiliary/setTemplateImageName - ;; + "T") + . ${thisDir}/auxiliary/setTemplateImageName + ;; # case_test_flag # # Test FLAG # - "t") - . ${thisDir}/auxiliary/setTestFlag - ;; + "t") + . ${thisDir}/auxiliary/setTestFlag + ;; # case_user_email # # Where to send email when finished # - "U") - . ${thisDir}/auxiliary/setUserEmail - ;; + "U") + . ${thisDir}/auxiliary/setUserEmail + ;; # case_set_bet # # Pick up the best BET threshold # - "u") - . ${thisDir}/auxiliary/setBestBET - ;; + "u") + . ${thisDir}/auxiliary/setBestBET + ;; # case_verify_flag # # Set the verify flag # - "V") - . ${thisDir}/auxiliary/setVerifyFLAG - ;; + "V") + . ${thisDir}/auxiliary/setVerifyFLAG + ;; # case_volume_name # # wildcard name to use for which to co-reg. # - "v") - . ${thisDir}/auxiliary/setVolumeWildCard - ;; + "v") + . ${thisDir}/auxiliary/setVolumeWildCard + ;; # case_coreg_path # # Path name to place coregistration results, our output of anatomy routines. # - "w") - . ${thisDir}/auxiliary/setCoRegPath - ;; + "w") + . ${thisDir}/auxiliary/setCoRegPath + ;; + # case_warp_method + # + # Use VBM8 for warping + # + "W") + . ${thisDir}/auxiliary/setWarpMethod + ;; # case_voxel_size # # Voxel size # - "z") - . ${thisDir}/auxiliary/setVoxelSize - ;; + "z") + . ${thisDir}/auxiliary/setVoxelSize + ;; # case_run_number # # run numbers # - "#") - shift - let argn++ - if (( $argn >= $args )) - then - echo "Missing parameter for run number, aborting" - exit 0 - else - runNAMES[$nRUN]=$1 - let nRUN++ - fi - ;; + "#") + shift + let argn++ + if (( $argn >= $args )) + then + echo "Missing parameter for run number, aborting" + . ${thisDir}/auxiliary/exit_w_removal + else + runNAMES[$nRUN]=$1 + let nRUN++ + fi + ;; # case_error # # Anything should result in an error. # - *) - . ${thisDir}/auxiliary/caseError - exit 1 - + *) + . ${thisDir}/auxiliary/caseError + . ${thisDir}/auxiliary/exit_w_removal + esac else if [ "${thisCommand}" == "smoothfMRI" ] @@ -307,14 +335,14 @@ do echo -e "\a" echo "Parameter number ${nParam} with a value of $1 is not a valid number" echo "Buggering out" - exit 1 + . ${thisDir}/auxiliary/exit_w_removal fi else # # It is not a directory and not an option, so it will be an error. # . ${thisDir}/auxiliary/unrecognizedArgument - exit 1 + . ${thisDir}/auxiliary/exit_w_removal fi fi fi diff --git a/spm8Batch/auxiliary/parse_arguments_end b/spm8Batch/auxiliary/parse_arguments_end deleted file mode 100644 index 2c18937f..00000000 --- a/spm8Batch/auxiliary/parse_arguments_end +++ /dev/null @@ -1,15 +0,0 @@ - esac - else - # - # It is not a directory and not an option, so it will be an error. - # - . ${thisDir}/auxiliary/unrecognizedArgument - exit 1 - fi - fi - # - # get the next argument. - # - shift - let argn++ -done diff --git a/spm8Batch/auxiliary/parse_arguments_start b/spm8Batch/auxiliary/parse_arguments_start deleted file mode 100644 index 3ef131fb..00000000 --- a/spm8Batch/auxiliary/parse_arguments_start +++ /dev/null @@ -1,24 +0,0 @@ -# -# Parse the arguments -# - -while (( $argn < $args )) - do - # - # If a directory then we assume it is a subject, - # this means you need to specify the subject - # master directory first. ( SUBJDIR ) - # - if [ -d "./${SUBJDIR}/$1" ] - then - let nSubjects++ - subjects[${nSubjects}]=$1 - else - # - # Else it could be an option flag. - # - curParam=$1 - # Check to see if option - if [ "${curParam:0:1}" == "-" ] - then - case "${curParam:1:1}" in diff --git a/spm8Batch/auxiliary/parse_case_code b/spm8Batch/auxiliary/parse_case_code deleted file mode 100644 index 23ecd8df..00000000 --- a/spm8Batch/auxiliary/parse_case_code +++ /dev/null @@ -1,209 +0,0 @@ - - # case_all_runs - # - # All runs in func - # - "A") - ALLRUNSFLAG=1 - ;; - - # case_anatomy_path - # - # Path name to find virgin anatomy files. - # - "a") - . ${thisDir}/auxiliary/setAnatomyPath - ;; - - # case_debug_flag - # - # debug flag - # - "d") - . ${thisDir}/auxiliary/setDebugFlag - ;; - - # case_super_debug_flag - # - # super debug flag - # - "D") - . ${thisDir}/auxiliary/setSuperDebugFlag - ;; - - # case_fmri_tr - # - # Set the TR - # - "F") - . ${thisDir}/auxiliary/setVolumeTR - ;; - - # case_functional_path - # - # Path name to search for functional images. - # - "f") - . ${thisDir}/auxiliary/setFunctionalPath - ;; - - # case_hires_name - # - # SPGR (hiRES) name to use - # - "h") - . ${thisDir}/auxiliary/setHiResName - ;; - - # case_set_run - # - # run list - # - "i") - . ${thisDir}/auxiliary/setRunList - ;; - - # case_subject_dir - # - # subject directory name to use - # - "M") - . ${thisDir}/auxiliary/setSubjectsMasterDir - ;; - - # case_flirt_options - # - # find the flirt options - # - "m") - . ${thisDir}/auxiliary/setMCFlirtOptions - ;; - - # case_output_name - # - # Set the name to add. - # - "n") - . ${thisDir}/auxiliary/setOutputName - ;; - - # case_other_names - # - # Simliar Other images - # - "O") - . ${thisDir}/auxiliary/setOtherNames - ;; - - # case_overlay_name - # - # overlay name to use - # - "o") - . ${thisDir}/auxiliary/setOverlayName - ;; - - # case_reslice_2 - # - # reslice the geometry only with no estimation? - # - "R") - resliceFLAG=2 - ;; - - # case_reslice_1 - # - # reslice the geometry? - # - "r") - resliceFLAG=1 - ;; - - # case_standard_volume - # - # find the standard volume number. - # - "S") - . ${thisDir}/auxiliary/setStandardVolumeNumber - ;; - - # case_sub_path - # - # sub-Path name to search for functional images. - # - "s") - . ${thisDir}/auxiliary/setFunctionalSubPathName - ;; - - # case_template_name - # - # Template Image. - # - "T") - . ${thisDir}/auxiliary/setTemplateImageName - ;; - - # case_test_flag - # - # Test FLAG - # - "t") - . ${thisDir}/auxiliary/setTestFlag - ;; - - # case_user_email - # - # Where to send email when finished - # - "U") - . ${thisDir}/auxiliary/setUserEmail - ;; - - # case_volume_name - # - # wildcard name to use for which to co-reg. - # - "v") - . ${thisDir}/auxiliary/setVolumeWildCard - ;; - - # case_coreg_path - # - # Path name to place coregistration results. - # - "w") - . ${thisDir}/auxiliary/setCoRegPath - ;; - - # case_voxel_size - # - # Voxel size - # - "z") - . ${thisDir}/auxiliary/setVoxelSize - ;; - - # case_run_number - # - # run numbers - # - "#") - shift - let argn++ - if (( $argn >= $args )) - then - echo "Missing parameter for run number, aborting" - exit 0 - else - runNAMES[$nRUN]=$1 - let nRUN++ - fi - ;; - - # case_error - # - # Anything should result in an error. - # - *) - . ${thisDir}/auxiliary/caseError - exit 1 diff --git a/spm8Batch/auxiliary/setAnatomyPath b/spm8Batch/auxiliary/setAnatomyPath index 8f022a91..3df18f40 100755 --- a/spm8Batch/auxiliary/setAnatomyPath +++ b/spm8Batch/auxiliary/setAnatomyPath @@ -3,7 +3,9 @@ if (( $argn >= $args )) then echo "Missing parameter for path name, aborting" - exit 1 + . ${thisDir}/auxiliary/exit_w_removal else anatomyPATH=$1 fi + + debugout "Anatomy path set to: $anatomyPATH" $SuperDebugFLAG \ No newline at end of file diff --git a/spm8Batch/auxiliary/setBestBET b/spm8Batch/auxiliary/setBestBET index 66b35dca..67544df4 100644 --- a/spm8Batch/auxiliary/setBestBET +++ b/spm8Batch/auxiliary/setBestBET @@ -3,7 +3,7 @@ if (( $argn >= $args )) then echo "Missing parameter for best BET threshold" - exit 1 + . ${thisDir}/auxiliary/exit_w_removal else USEBETBEST=$1 isnumber ${USEBETBEST} @@ -13,6 +13,6 @@ echo -e "\a" echo "Parameter $1 is not a valid number" echo "Buggering out" - exit 0 + . ${thisDir}/auxiliary/exit_w_removal fi fi diff --git a/spm8Batch/auxiliary/setCoRegPath b/spm8Batch/auxiliary/setCoRegPath index efed29b0..35953e49 100755 --- a/spm8Batch/auxiliary/setCoRegPath +++ b/spm8Batch/auxiliary/setCoRegPath @@ -3,7 +3,7 @@ if (( $argn >= $args )) then echo "Missing parameter for path name to place results, aborting" - exit 1 + . ${thisDir}/auxiliary/exit_w_removal else coregPATH=$1 fi diff --git a/spm8Batch/auxiliary/setFunctionalPath b/spm8Batch/auxiliary/setFunctionalPath index 5ef11119..8e538c6c 100755 --- a/spm8Batch/auxiliary/setFunctionalPath +++ b/spm8Batch/auxiliary/setFunctionalPath @@ -3,7 +3,7 @@ if (( $argn >= $args )) then echo "Missing parameter for functional path name, aborting" - exit 1 + . ${thisDir}/auxiliary/exit_w_removal else fmriPATH=$1 fi diff --git a/spm8Batch/auxiliary/setFunctionalSubPathName b/spm8Batch/auxiliary/setFunctionalSubPathName index 2a06072e..71048b8f 100755 --- a/spm8Batch/auxiliary/setFunctionalSubPathName +++ b/spm8Batch/auxiliary/setFunctionalSubPathName @@ -3,7 +3,7 @@ if (( $argn >= $args )) then echo "Missing parameter for path name, aborting" - exit 1 + . ${thisDir}/auxiliary/exit_w_removal else subPATH=$1 fi diff --git a/spm8Batch/auxiliary/setGenericFileName b/spm8Batch/auxiliary/setGenericFileName index a7ca00ad..016d6339 100755 --- a/spm8Batch/auxiliary/setGenericFileName +++ b/spm8Batch/auxiliary/setGenericFileName @@ -3,7 +3,7 @@ if (( $argn >= $args )) then echo "Missing parameter for overlay name, aborting" - exit 1 + . ${thisDir}/auxiliary/exit_w_removal else FILENAME=$1 fi @@ -15,5 +15,5 @@ echo echo "ABORTING" echo - exit 1 + . ${thisDir}/auxiliary/exit_w_removal fi diff --git a/spm8Batch/auxiliary/setGradientValue b/spm8Batch/auxiliary/setGradientValue index a10623aa..9406471d 100644 --- a/spm8Batch/auxiliary/setGradientValue +++ b/spm8Batch/auxiliary/setGradientValue @@ -3,7 +3,7 @@ if (( $argn >= $args )) then echo "Missing parameter for setting the gradient for BET" - exit 1 + . ${thisDir}/auxiliary/exit_w_removal else BETGRADIENT=$1 . ${thisDir}/auxiliary/calcBETname diff --git a/spm8Batch/auxiliary/setMCFlirtOptions b/spm8Batch/auxiliary/setMCFlirtOptions index 49144c22..ac2062d7 100755 --- a/spm8Batch/auxiliary/setMCFlirtOptions +++ b/spm8Batch/auxiliary/setMCFlirtOptions @@ -3,7 +3,7 @@ if (( $argn >= $args )) then echo "Missing mcflirt options, aborting" - exit 0 + . ${thisDir}/auxiliary/exit_w_removal else mcOPT=$1 fi diff --git a/spm8Batch/auxiliary/setOtherNames b/spm8Batch/auxiliary/setOtherNames index 7eaf2509..0a583483 100644 --- a/spm8Batch/auxiliary/setOtherNames +++ b/spm8Batch/auxiliary/setOtherNames @@ -3,7 +3,7 @@ if (( $argn >= $args )) then echo "Missing parameter for other image name, aborting" - exit 1 + . ${thisDir}/auxiliary/exit_w_removal else otherName[$iother]=$1 let iother++ @@ -24,7 +24,7 @@ echo echo "ABORTING" echo - exit 1 + . ${thisDir}/auxiliary/exit_w_removal fi otherName[$iother]=${FILENAME} otherExt[$iother]=${FILEEXT} diff --git a/spm8Batch/auxiliary/setOutputName b/spm8Batch/auxiliary/setOutputName index 9721b8e4..606fb2d3 100755 --- a/spm8Batch/auxiliary/setOutputName +++ b/spm8Batch/auxiliary/setOutputName @@ -3,7 +3,7 @@ if (( $argn >= $args )) then echo "Missing parameter for output name, aborting" - exit 1 + . ${thisDir}/auxiliary/exit_w_removal else outputName=$1 fi diff --git a/spm8Batch/auxiliary/setPhysioName b/spm8Batch/auxiliary/setPhysioName index e3fa1a54..085383a1 100644 --- a/spm8Batch/auxiliary/setPhysioName +++ b/spm8Batch/auxiliary/setPhysioName @@ -3,7 +3,7 @@ if (( $argn >= $args )) then echo "Missing parameter for physio xref table name, aborting" - exit 1 + . ${thisDir}/auxiliary/exit_w_removal else PHYSIOTABLE=$1 fi diff --git a/spm8Batch/auxiliary/setPhysioOptions b/spm8Batch/auxiliary/setPhysioOptions index 0aaede08..e819d0c6 100644 --- a/spm8Batch/auxiliary/setPhysioOptions +++ b/spm8Batch/auxiliary/setPhysioOptions @@ -4,7 +4,7 @@ then echo echo "Missing physio options, aborting" - exit 0 + . ${thisDir}/auxiliary/exit_w_removal else PHYSIOOPTIONS="$1" fi @@ -16,7 +16,7 @@ then echo echo "You need to specifiy three options: 'rate', 'disdaq' and 'down', aborting" - exit 0 + . ${thisDir}/auxiliary/exit_w_removal fi for IELE in 0 1 2 do @@ -27,7 +27,7 @@ echo echo "Physio Option '$THISOPTION' missing assignment (=), aborting" echo - exit 0 + . ${thisDir}/auxiliary/exit_w_removal fi OPTIONVARIABLE=`echo $THISOPTION | awk -F= '{print $1}'` OPTIONVALUE=`echo $THISOPTION | awk -F= '{print $2}'` @@ -37,7 +37,7 @@ echo echo "Physio Option '$OPTIONVARIABLE' not recognized, needs to be either 'down', 'disdaq', or 'rate', aborting" echo - exit 0 + . ${thisDir}/auxiliary/exit_w_removal fi done # @@ -52,6 +52,6 @@ echo echo "You need to specifiy threee: 'rate','disdaq', and 'down', aborting" echo - exit 0 + . ${thisDir}/auxiliary/exit_w_removal fi done diff --git a/spm8Batch/auxiliary/setReferenceImage b/spm8Batch/auxiliary/setReferenceImage new file mode 100644 index 00000000..730311bf --- /dev/null +++ b/spm8Batch/auxiliary/setReferenceImage @@ -0,0 +1,17 @@ + ERRORMESSAGE="Trying to determine the VBM8 reference image." + + . ${thisDir}/auxiliary/setGenericFileName + + # If they speficified the directory, else we use the default directory. + + if [ "${FILENAME:0:1}" == "/" ] + then + TARGETNAME=${FILENAME} + else + TARGETNAME=${TemplateImageDir}/${FILENAME} + fi + TARGETEXT=${FILEEXT} + + . ${thisDir}/auxiliary/verifyTargetImage + + VBM8ReferenceImage=${TARGETIMG} diff --git a/spm8Batch/auxiliary/setRunList b/spm8Batch/auxiliary/setRunList index cb19e716..9d4c6b37 100755 --- a/spm8Batch/auxiliary/setRunList +++ b/spm8Batch/auxiliary/setRunList @@ -3,7 +3,7 @@ if (( $argn >= $args )) then echo "Missing run list option, abortin." - exit 0 + . ${thisDir}/auxiliary/exit_w_removal else runLIST=$1 run0=`echo ${runLIST} | awk -F- '{print $1}'` diff --git a/spm8Batch/auxiliary/setStandardVolumeNumber b/spm8Batch/auxiliary/setStandardVolumeNumber index 599c991d..1a6eba70 100755 --- a/spm8Batch/auxiliary/setStandardVolumeNumber +++ b/spm8Batch/auxiliary/setStandardVolumeNumber @@ -3,7 +3,7 @@ if (( $argn >= $args )) then echo "Missing standard volume number, aborting" - exit 0 + . ${thisDir}/auxiliary/exit_w_removal else standardVolume=$1 fi diff --git a/spm8Batch/auxiliary/setSubjectsMasterDir b/spm8Batch/auxiliary/setSubjectsMasterDir index ba2656e9..36ff170e 100755 --- a/spm8Batch/auxiliary/setSubjectsMasterDir +++ b/spm8Batch/auxiliary/setSubjectsMasterDir @@ -3,12 +3,12 @@ if (( $argn >= $args )) then echo "Missing parameter for subject directory." - exit 1 + . ${thisDir}/auxiliary/exit_w_removal else SUBJDIR=$1 if [ ! -d "${SUBJDIR}" ] then echo "The master subject directory that you have specified does not exist." - exit 1 + . ${thisDir}/auxiliary/exit_w_removal fi fi diff --git a/spm8Batch/auxiliary/setSuperDebugFlag b/spm8Batch/auxiliary/setSuperDebugFlag index 4699fd08..2e762450 100644 --- a/spm8Batch/auxiliary/setSuperDebugFlag +++ b/spm8Batch/auxiliary/setSuperDebugFlag @@ -1,2 +1,4 @@ SuperDebugFLAG=D debugFLAG=1 + + echo "Turning on debugger" \ No newline at end of file diff --git a/spm8Batch/auxiliary/setUserEmail b/spm8Batch/auxiliary/setUserEmail index 38339249..77d7816f 100755 --- a/spm8Batch/auxiliary/setUserEmail +++ b/spm8Batch/auxiliary/setUserEmail @@ -3,7 +3,7 @@ if (( $argn >= $args )) then echo "Missing parameter for user email name, aborting" - exit 1 + . ${thisDir}/auxiliary/exit_w_removal else USEREMAIL=$1 fi diff --git a/spm8Batch/auxiliary/setVolumeTR b/spm8Batch/auxiliary/setVolumeTR index 1b70f343..e355204a 100644 --- a/spm8Batch/auxiliary/setVolumeTR +++ b/spm8Batch/auxiliary/setVolumeTR @@ -3,7 +3,7 @@ if (( $argn >= $args )) then echo "Missing parameter for volume TR, aborting" - exit 1 + . ${thisDir}/auxiliary/exit_w_removal else TR=$1 fi diff --git a/spm8Batch/auxiliary/setVolumeWildCar b/spm8Batch/auxiliary/setVolumeWildCar deleted file mode 100755 index 3e8689a2..00000000 --- a/spm8Batch/auxiliary/setVolumeWildCar +++ /dev/null @@ -1,9 +0,0 @@ - shift - let argn++ - if (( $argn >= $args )) - then - echo "Missing parameter for volume name functional, aborting" - exit 1 - else - volumeWILD=$1 - fi diff --git a/spm8Batch/auxiliary/setVolumeWildCard b/spm8Batch/auxiliary/setVolumeWildCard index 3e8689a2..a1fdd6b7 100755 --- a/spm8Batch/auxiliary/setVolumeWildCard +++ b/spm8Batch/auxiliary/setVolumeWildCard @@ -3,7 +3,7 @@ if (( $argn >= $args )) then echo "Missing parameter for volume name functional, aborting" - exit 1 + . ${thisDir}/auxiliary/exit_w_removal else volumeWILD=$1 fi diff --git a/spm8Batch/auxiliary/setVoxelSize b/spm8Batch/auxiliary/setVoxelSize index ee9c6c82..b900c605 100755 --- a/spm8Batch/auxiliary/setVoxelSize +++ b/spm8Batch/auxiliary/setVoxelSize @@ -3,7 +3,7 @@ if (( $argn >= $args )) then echo "Missing parameter for voxel size, aborting" - exit 1 + . ${thisDir}/auxiliary/exit_w_removal else voxelSize=$1 fi diff --git a/spm8Batch/auxiliary/setWarpMethod b/spm8Batch/auxiliary/setWarpMethod new file mode 100644 index 00000000..767d8574 --- /dev/null +++ b/spm8Batch/auxiliary/setWarpMethod @@ -0,0 +1,16 @@ +# +# Set the flag to say we are using VBM8 for +# warping of fMRI data. +# + + WARPMETHOD=1 + +# If using VBM8 then we can default to using the vbm8_ outputname +# We force it to be "w", unless the person specifies "w" after +# they have specified VBM8 as the warping method. + + if [ "${outputName}" == "w" ] + then + outputName=vbm8_ + fi + diff --git a/spm8Batch/auxiliary/set_all_runs b/spm8Batch/auxiliary/set_all_runs deleted file mode 100644 index 0e42ac23..00000000 --- a/spm8Batch/auxiliary/set_all_runs +++ /dev/null @@ -1,6 +0,0 @@ - # - # All runs in func - # - "A") - ALLRUNSFLAG=1 - ;; diff --git a/spm8Batch/auxiliary/toDelete/commonCode_01 b/spm8Batch/auxiliary/toDelete/commonCode_01 deleted file mode 100755 index 9aef15a2..00000000 --- a/spm8Batch/auxiliary/toDelete/commonCode_01 +++ /dev/null @@ -1,14 +0,0 @@ -# Bring in configuration for spm8 batch processing from command line. - -. ${thisDir}/spm8Batch_Global - -# Verify that the user has examined the help aspect of the command. -# This is a bit anal, but just making sure that people read the help! - -. ${thisDir}/permittedToRunComand - -# Kludge in case they issue this command back to back and it creates -# the script twice ... - -sleep 1 - diff --git a/spm8Batch/auxiliary/vbm8FindSourceAndMove b/spm8Batch/auxiliary/vbm8FindSourceAndMove new file mode 100644 index 00000000..8b5c784b --- /dev/null +++ b/spm8Batch/auxiliary/vbm8FindSourceAndMove @@ -0,0 +1,72 @@ + # Now lets find the source and move it into where we need it to be. + + cd ${fmriPATH}/${coregPATH}/ + anatPATH=`pwd` + + + destSOURCENAME=${SOURCENAME} + + # + # remove any current coregistation in that directory. + # + \rm ${destSOURCENAME}.* 2> /dev/null + + # + # now copy over the virgin copy of the anatomy, after we find it. + # + + USEEXT= + + # + # If no extension was specified so we will find one, and we can do this independently for each + # subject, else we use the one specified and we stripped. But we also check to see if the overlay + # image really exists, else we bugger out with error. + # + + if [ -z ${SOURCEEXT} ] + then + for EXT in .nii.gz .nii + do + if [ -e "${UMBatchMaster}/${SUBJDIR}/${subjects[$is]}/${anatomyPATH}/${SOURCENAME}${EXT}" ] + then + USEEXT=${EXT} + fi + done + else + USEEXT=${SOURCEEXT} + fi + # + # We did not find anything. + # + if [ -z ${USEEXT} ] + then + echo + echo "Scanning for source image : ${SOURCENAME} for subject : ${subjects[$is]} returned no result." + echo + echo "ABORTING" + echo + . ${thisDir}/auxiliary/exit_w_removal + fi + + if [ -e "${UMBatchMaster}/${SUBJDIR}/${subjects[$is]}/${anatomyPATH}/${SOURCENAME}${USEEXT}" ] + then + cp ${UMBatchMaster}/${SUBJDIR}/${subjects[$is]}/${anatomyPATH}/${SOURCENAME}${USEEXT} ${destSOURCENAME}${USEEXT} + debugout "- - - - - - - - - - - - - -" $SuperDebugFLAG + debugout "cp ${UMBatchMaster}/${SUBJDIR}/${subjects[$is]}/${anatomyPATH}/${SOURCENAME}.nii ${destSOURCENAME}.nii" $SuperDebugFLAG + debugout "- - - - - - - - - - - - - -" $SuperDebugFLAG + else + echo + echo "Scanning for source image : ${SOURCENAME}${USEEXT} for subject : ${subjects[$is]} returned no result." + echo + echo "ABORTING" + echo + . ${thisDir}/auxiliary/exit_w_removal + fi + + fileLIST=`ls -1 ${destSOURCENAME}* | wc |awk '{print $1}'` + + debugout "- - - - - - - - - - - - - -" $SuperDebugFLAG + debugout "Total # of ${destSOURCENAME} is $fileLIST in directory ${anatPATH}" $SuperDebugFLAG + + SOURCEIMG=${anatPATH}/${destSOURCENAME}${USEEXT} + diff --git a/spm8Batch/auxiliary/vbm8_part_01 b/spm8Batch/auxiliary/vbm8_part_01 new file mode 100644 index 00000000..2a3b770a --- /dev/null +++ b/spm8Batch/auxiliary/vbm8_part_01 @@ -0,0 +1,19 @@ +# Use common in-line code #01 -- comments out to standard output. + +. ${thisDir}/auxiliary/buildMatlabScripts_01 + +cat ${SPM8B2}/parts/vbm8_part_01.m > ${FULLSCRIPTNAME}.m + +# Use common in-line code #02 -- header information + +. ${thisDir}/auxiliary/buildMatlabScripts_02 + +echo "VoxelSize = ${voxelSize};" >> ${FULLSCRIPTNAME}.m + +echo "VBM8RefImage = '${VBM8ReferenceImage}';" >> ${FULLSCRIPTNAME}.m + +echo "OutputName = '${outputName}';" >> ${FULLSCRIPTNAME}.m + +# Use common in-line code #03 -- subject list. +. ${thisDir}/auxiliary/buildMatlabScripts_03 + diff --git a/spm8Batch/auxiliary/verifyTargetImage b/spm8Batch/auxiliary/verifyTargetImage index 4fc2791f..69286278 100755 --- a/spm8Batch/auxiliary/verifyTargetImage +++ b/spm8Batch/auxiliary/verifyTargetImage @@ -10,9 +10,11 @@ # image really exists, else we bugger out with error. # + # For now SPM8 can NOT handle nift-gz images, only nifti. - @rcwelsh + if [ -z ${TARGETEXT} ] then - for EXT in .nii.gz .nii + for EXT in .nii do if [ -e "${TARGETNAME}${EXT}" ] then @@ -32,7 +34,7 @@ echo echo "ABORTING" echo - exit 1 + . ${thisDir}/auxiliary/exit_w_removal fi if [ ! -e "${TARGETNAME}${USEEXT}" ] @@ -42,7 +44,7 @@ echo echo "ABORTING" echo - exit 1 + . ${thisDir}/auxiliary/exit_w_removal fi TARGETIMG=${TARGETNAME}${USEEXT} diff --git a/spm8Batch/auxiliary/warpPart_01 b/spm8Batch/auxiliary/warpPart_01 index 1d7a2dc2..cb53a20c 100644 --- a/spm8Batch/auxiliary/warpPart_01 +++ b/spm8Batch/auxiliary/warpPart_01 @@ -10,6 +10,10 @@ echo "TemplateImage = '${TemplateImage}';" >> ${FULLSCRIPTNAM echo "VoxelSize = ${voxelSize};" >> ${FULLSCRIPTNAME}.m +echo "WARPMETHOD = ${WARPMETHOD};" >> ${FULLSCRIPTNAME}.m + +echo "VBM8RefImage = '${VBM8ReferenceImage}';" >> ${FULLSCRIPTNAME}.m + echo "OutputName = '${outputName}';" >> ${FULLSCRIPTNAME}.m echo "SandBoxDIR = '${SANDBOX}/';" >> ${FULLSCRIPTNAME}.m diff --git a/spm8Batch/auxiliary/warpPrepOtherImages b/spm8Batch/auxiliary/warpPrepOtherImages index 5ad25da9..84d65016 100644 --- a/spm8Batch/auxiliary/warpPrepOtherImages +++ b/spm8Batch/auxiliary/warpPrepOtherImages @@ -56,7 +56,7 @@ do echo echo ABORTING echo - exit 1 + . ${thisDir}/auxiliary/exit_w_removal fi otherSOURCE=${otherSRCNAME}${USEEXT} @@ -82,7 +82,7 @@ do echo echo "* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * " echo - exit 1 + . ${thisDir}/auxiliary/exit_w_removal fi done fi diff --git a/spm8Batch/detectSpike b/spm8Batch/detectSpike new file mode 100755 index 00000000..31b7db78 --- /dev/null +++ b/spm8Batch/detectSpike @@ -0,0 +1,131 @@ +#!/bin/bash + +# # # # # # # # # # # # # # # # # # +# +# A command to make it easier on the user to detect +# spikes in the fmri time-series. +# +# This command will build a script to run and will also +# run the script in background. +# +# e.g. detectSpike +# +# +# detectSpike +# +# # # # # # # # # # # # # # # # # # + +# +# Main detectSpike function. +# + +VERSION="2.1" +VERSIONDATE="2012-04-28" + +# Find out where the current command lives and execute some common code. + +theFullCommand="$0 $*" +execDIR=`pwd` + +# Find out where the current command lives and execute some common code. + +theCommand=`which $0` +thisDir=`dirname $theCommand` + +thisCommand=`echo $theCommand | awk -F/ '{print $NF}'` + +allowedOptions="AfMi#sUv" + +# This piece of code all of the spm8Batch scripts will use +. ${thisDir}/auxiliary/commonCode_AllScriptsStart + +# This is the common in-line code for the warping steps. ### +. ${thisDir}/auxiliary/commonCode_Detect_01 + +# This is common in-line code for all spm8Batch script to make sure arguments were passed +. ${thisDir}/auxiliary/commonCode_checkIfArgsPassed + +# +# The actual function. +# + +. ${thisDir}/auxiliary/parse_arguments + +# + +. ${thisDir}/auxiliary/superDebugStatus + +# Make the sandbox if possible. + +. ${thisDir}/auxiliary/make_sandbox + +# +# Ok - let's start displaying things back to the terminal +# + +. ${thisDir}/auxiliary/shellScriptInfo + +# +# Prepare to write the script. +# + +# Makes sure they speficied some subjects. +. ${thisDir}/auxiliary/checkInputForSubjects + +# Write out debug status +. ${thisDir}/auxiliary/debugStatus + +# Ok, lets do the business. + +# Print out the list of subjects that we operate upon. +. ${thisDir}/auxiliary/printSubjectsList + +# Now start building the automatic scripts. + +# +# the following environmental variables are from spm8Batch_Global +# +# HOSTCOMPUTER - name of the computer. +# SCRIPTNAME - name of the scripts to write. +# MATLABDIR - location of the scripts. +# UMBatchMatcher - present working directory. +# FULLSCRIPTNAME - full path and name of scripts to write. +# + +. ${thisDir}/auxiliary/detectSpikePart_01 + +# Name of the functional volumes to find. + +echo "UMVolumeWild = '${volumeWILD}';" >> ${FULLSCRIPTNAME}.m + +# Now build the list of directories for each subject. + +. ${thisDir}/auxiliary/createDirectoryList + +echo " 4) finalizing matlab scripts" + +cat ${thisDir}/parts/detect_spike_part_2.m >> ${FULLSCRIPTNAME}.m ### + +echo " 5) building shell script" + + +# Now build the shell script command that will get launched into the background. + +# Common start to all shell scripts +. ${thisDir}/auxiliary/shellScriptStart + +# Add the matlab code to the shell script + +. ${thisDir}/auxiliary/shellScriptMATLABCall + +# Finalize the shell script. + +. ${thisDir}/auxiliary/shellScriptFinalize + +# Now launch into the background if desired. + +. ${thisDir}/auxiliary/shellScriptLaunch + +# +# all done. +# diff --git a/spm8Batch/dev/post-commit b/spm8Batch/dev/post-commit deleted file mode 100755 index 9eeb58ae..00000000 --- a/spm8Batch/dev/post-commit +++ /dev/null @@ -1,8 +0,0 @@ -#!/bin/sh -# -# An example hook script that is called after a successful -# commit is made. -# -# To enable this hook, rename this file to "post-commit". - -cat .git/`cat .git/HEAD | awk '{print $NF'}` > .spm8BatchVersion diff --git a/spm8Batch/matlab/coregOnly_Job.m b/spm8Batch/matlab/coregOnly_Job.m deleted file mode 100755 index 59f07adf..00000000 --- a/spm8Batch/matlab/coregOnly_Job.m +++ /dev/null @@ -1,16 +0,0 @@ - -% -%matlabbatch{1}.spm.spatial.coreg.estimate -% -% ref: {[1x84 char]} -% source: {[1x82 char]} -% other: {2x1 cell} -% eoptions: [1x1 struct] -% -% matlabbatch{1}.spm.spatial.coreg.estimate.ref{1} = '....../run_01.nii,1'; -% -% matlabbatch{1}.spm.spatial.coreg.estimate.source{1} = '....../ht1overlay.nii,1'; -% -% matlabbatch{1}.spm.spatial.coreg.estimate.other{n} = '....../otherImage_n.nii,1'; -% -% \ No newline at end of file diff --git a/spm8Batch/matlab/coregOnly_Job.mat b/spm8Batch/matlab/coregOnly_Job.mat deleted file mode 100755 index 03d7e991..00000000 Binary files a/spm8Batch/matlab/coregOnly_Job.mat and /dev/null differ diff --git a/spm8Batch/matlab/coregResliceJob_only.mat b/spm8Batch/matlab/coregResliceJob_only.mat deleted file mode 100755 index 3c15ca1d..00000000 Binary files a/spm8Batch/matlab/coregResliceJob_only.mat and /dev/null differ diff --git a/spm8Batch/matlab/coreg_EstimateOnly_Job.mat b/spm8Batch/matlab/coreg_EstimateOnly_Job.mat deleted file mode 100755 index aa3ec84a..00000000 Binary files a/spm8Batch/matlab/coreg_EstimateOnly_Job.mat and /dev/null differ diff --git a/spm8Batch/matlab/coreg_EstimateOnly_NoOthers_Job.mat b/spm8Batch/matlab/coreg_EstimateOnly_NoOthers_Job.mat deleted file mode 100755 index fc654bc6..00000000 Binary files a/spm8Batch/matlab/coreg_EstimateOnly_NoOthers_Job.mat and /dev/null differ diff --git a/spm8Batch/matlab/coreg_EstimateReslice_Job.mat b/spm8Batch/matlab/coreg_EstimateReslice_Job.mat deleted file mode 100755 index 7d5ea342..00000000 Binary files a/spm8Batch/matlab/coreg_EstimateReslice_Job.mat and /dev/null differ diff --git a/spm8Batch/matlab/coreg_EstimateReslice_WithOthers_Job.mat b/spm8Batch/matlab/coreg_EstimateReslice_WithOthers_Job.mat deleted file mode 100755 index 0638bc96..00000000 Binary files a/spm8Batch/matlab/coreg_EstimateReslice_WithOthers_Job.mat and /dev/null differ diff --git a/spm8Batch/matlab/coreg_ResliceOnly_Job.mat b/spm8Batch/matlab/coreg_ResliceOnly_Job.mat deleted file mode 100755 index d8aea46a..00000000 Binary files a/spm8Batch/matlab/coreg_ResliceOnly_Job.mat and /dev/null differ diff --git a/spm8Batch/matlab/coreg_Reslice_Only_Job.mat b/spm8Batch/matlab/coreg_Reslice_Only_Job.mat deleted file mode 100644 index 599aa580..00000000 Binary files a/spm8Batch/matlab/coreg_Reslice_Only_Job.mat and /dev/null differ diff --git a/spm8Batch/matlab/segmentation_job_in_native_space.mat b/spm8Batch/matlab/segmentation_job_in_native_space.mat deleted file mode 100755 index bfdafe8e..00000000 Binary files a/spm8Batch/matlab/segmentation_job_in_native_space.mat and /dev/null differ diff --git a/spm8Batch/matlab/smooth_warped_functions_job.mat b/spm8Batch/matlab/smooth_warped_functions_job.mat deleted file mode 100755 index 39f5ee8b..00000000 Binary files a/spm8Batch/matlab/smooth_warped_functions_job.mat and /dev/null differ diff --git a/spm8Batch/matlab/warp_all_phases_functionals_job.mat b/spm8Batch/matlab/warp_all_phases_functionals_job.mat deleted file mode 100755 index ef78be1d..00000000 Binary files a/spm8Batch/matlab/warp_all_phases_functionals_job.mat and /dev/null differ diff --git a/spm8Batch/matlab/warp_t1spgr_and_write_job.mat b/spm8Batch/matlab/warp_t1spgr_and_write_job.mat deleted file mode 100755 index 5ebabb78..00000000 Binary files a/spm8Batch/matlab/warp_t1spgr_and_write_job.mat and /dev/null differ diff --git a/spm8Batch/matlabScripts/UMBatchCoReg.m b/spm8Batch/matlabScripts/UMBatchCoReg.m index efc0b5ab..3b82a553 100755 --- a/spm8Batch/matlabScripts/UMBatchCoReg.m +++ b/spm8Batch/matlabScripts/UMBatchCoReg.m @@ -36,6 +36,7 @@ % changed by users, we don't want to hard-code options here. global defaults +global UMBatch % % Set the return status to -1, that is error by default. @@ -43,6 +44,17 @@ results = -1; +% Make the call to prepare the system for batch processing. + +UMBatchPrep + +if UMBatch == 0 + fprintf('UMBatchPrep failed.') + return +end + +% Only proceed if successful. + fprintf('Entering UMBatchCoReg V2.0 for SPM8\n'); if TestFlag~=0 diff --git a/spm8Batch/matlabScripts/UMBatchDetectSpike.m b/spm8Batch/matlabScripts/UMBatchDetectSpike.m new file mode 100644 index 00000000..70e68a5d --- /dev/null +++ b/spm8Batch/matlabScripts/UMBatchDetectSpike.m @@ -0,0 +1,97 @@ +% - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +% UMBatchDetectSpike +% +% A function that performs a batch detect spike upon several subjects. +% +% Call as : +% +% function results = UMBatchDetectSpike(Images,OutputFile,Subject,Run) +% +% To Make this work you need to provide the following input: +% +% Images = char array of images to test +% OutputFile = file to write detected spikes +% ImagePath = full directory path to Images +% +% Output +% +% results = -1 if failure +% 1 if success +% - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +function results = UMBatchDetectSpike(Images,OutputFile,ImagePath) + detOpt = 1; + Thres = 10; + results = -1; + + fid = fopen(OutputFile,'w'); + if fid == -1 + fprintf('Cannot open file: %s\n',Outputfile); + fprintf(' * * * A B O R T I N G * * *\n'); + return; + end + + % + % Build 4D array + % + if size(Images,1) > 1 + firstImage = nifti( strtrim(Images(1,:)) ); + data = zeros( [firstImage.dat.dim(1:3) size(Images,1)] ); + clear firstImage + + for i=1:size(Images,1) + dumImage = nifti( strtrim(Images(i,:)) ); + data(:,:,:,i) = dumImage.dat(:,:,:,1); + clear dumImage + end + else + dumImage = nifti( strtrim(Images) ); + data = dumImage.dat(:,:,:,:); + clear dumImage + end + + % + % Detect spikes here + % + [success results] = dSpike(data,detOpt); + if success == -1 + return; + end + + % + % Write output to text file + % + [nSlice nTime] = size(results); + + % Common header first + fprintf(fid,'%s\n\n',ImagePath); + fprintf(fid,'Slices:%d\n',nSlice); + fprintf(fid,'nTime :%d\n',nTime); + fprintf(fid,'Thres :%d\n',Thres); + fprintf(fid,'detOpt:%d\n\n',detOpt); + + % Write detected spikes now + [Slice Timepoint] = find(results > Thres); + if isempty(Slice) + fprintf(fid,'Status : No spikes found\n'); + else + fprintf(fid,'Status : %d spikes found\n',size(Slice,1)); + + for i=1:size(Slice,1) + fprintf(fid,'Slice:%d,Timepoint:%d,AJKZ:%f\n',Slice(i),Timepoint(i),results( Slice(i), Timepoint(i) ) ); + end + end + fprintf(fid,'\n'); + fclose(fid); + + % Log detectSpike was performed + DetectSpikeDir = fileparts( strtrim( Images(1,:) ) ); + + UMBatchLogProcess(DetectSpikeDir,sprintf('UMBatchDetectSpike : Scanned images (%04d) : %s',size(Images,1),Images(1,:))); + + if size(Images,1) > 1 + UMBatchLogProcess(DetectSpikeDir,sprintf('UMBatchDetectSpike : through image : %s',Images(end,:))); + end + + results = 1; +end + diff --git a/spm8Batch/matlabScripts/UMBatchPrep.m b/spm8Batch/matlabScripts/UMBatchPrep.m index 2db6eb69..a8e8b196 100755 --- a/spm8Batch/matlabScripts/UMBatchPrep.m +++ b/spm8Batch/matlabScripts/UMBatchPrep.m @@ -12,7 +12,12 @@ % Turn off progress bar. +function UMBatchPrep + global UMBatch +global UMBatchInit + +% Success code. UMBatch = 1; @@ -20,14 +25,16 @@ if exist('spm') ~= 2 fprintf('\nFATAL ERROR, no SPM in the matlab path!!!\n'); - exit + UMBatch = 0; + return end % Check for SPM8 if strcmp(spm('ver'),'SPM8') == 0 fprintf('\nFATAL ERROR, these scripts only are SPM8 specific!!!\n'); - exit + UMBatch = 0; + return end % Make sure spm_defaults has been called. @@ -43,21 +50,25 @@ if isempty(defaults) fprintf('\n\n* * * * * \nAre you not running SPM8?\n\n* * * * * \n\n'); fprintf(' A B O R T I N G\n\n'); - exit + UMBatch = 0; return end end % Initialize the batch processing system. -fprintf('Initializing the job manager in SPM\n'); - -spm_jobman('initcfg'); +if isempty(UMBatchInit) + fprintf('Initializing the job manager in SPM8\n'); + spm_jobman('initcfg'); + UMBatchInit = 1; +end % Turn off annoying warnings. warning off +return + % % That is all. % diff --git a/spm8Batch/matlabScripts/UMBatchSegment.m b/spm8Batch/matlabScripts/UMBatchSegment.m index da084014..7e3a95e0 100755 --- a/spm8Batch/matlabScripts/UMBatchSegment.m +++ b/spm8Batch/matlabScripts/UMBatchSegment.m @@ -38,6 +38,7 @@ function results = UMBatchSegment(Image2Segment,TestFlag,NormedAlready); global defaults +global UMBatch results = -1; @@ -49,6 +50,13 @@ UMBatchPrep +if UMBatch == 0 + fprintf('UMBatchPrep failed.') + return +end + +% Only proceed if successful. + fprintf('Entering UMBatchSegment V0.1\n'); if TestFlag~=0 diff --git a/spm8Batch/matlabScripts/UMBatchSmooth.m b/spm8Batch/matlabScripts/UMBatchSmooth.m index d4c67fcc..acb29b19 100755 --- a/spm8Batch/matlabScripts/UMBatchSmooth.m +++ b/spm8Batch/matlabScripts/UMBatchSmooth.m @@ -40,6 +40,7 @@ function results = UMBatchSmooth(Images2Smooth,sKernel,OutputName,TestFlag); global defaults +global UMBatch % % Set the return status to -1, that is error by default. @@ -47,6 +48,17 @@ results = -1; +% Make the call to prepare the system for batch processing. + +UMBatchPrep + +if UMBatch == 0 + fprintf('UMBatchPrep failed.') + return +end + +% Only proceed if successful. + fprintf('Entering UMBatchSmooth V0.1\n'); if TestFlag~=0 diff --git a/spm8Batch/matlabScripts/UMBatchVBM8.m b/spm8Batch/matlabScripts/UMBatchVBM8.m new file mode 100644 index 00000000..9219fe1a --- /dev/null +++ b/spm8Batch/matlabScripts/UMBatchVBM8.m @@ -0,0 +1,248 @@ +% - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +% Robert C. Welsh +% Ann Arbor Michigan, USA +% +% March 2005-2011 +% Copyright. +% +% UMBatchWarp +% +% A drivable routine for warping some images using the +% batch options of spm2. +% +% Version 1.0 +% +% Call as : +% +% function results = UMBatchWarpVBM8(ParamImage,TestFlag); +% +% To Make this work you need to provide the following input: +% +% ParamImage = Image to determine warping parameters. +% TestFlag = Flag to test file existance but do nothing. +% +% If the TemplateImage is blank then we are doing "Write Normalized Only" +% +% If Images2Write is blank then we are doing "Determine Parameters Only" +% +% If ObjectMask = [] or '' then no masking. +% +% ParamImage CAN NOT BE BLANK and must exist, as must its "_sn.mat" file. +% +% If TestFlag = 0 then execute, else just test files. +% +% Output +% +% results = -1 if failure +% # of seconds to execute. +% +% If you wish to use any normalization parameters other than the default +% you must set them yourself! +% +% You should make call to UMBatchPrep first. +% +% - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + +function results = UMBatchVBM8(ParamImage,ReferenceImage,Img2Write,TestFlag,VoxelSize,OutputName); + +% Get the defaults from SPM. + +global defaults +global vbm8 +global UMBatch + +% +% Set the return status to -1, that is error by default. +% + +results = -1; + +if isempty(vbm8) + if exist('cg_vbm8_defaults') == 0 + fprintf('\n\n* * * * * * * * * * * * \n\n'); + fprintf(' FATAL ERROR \n'); + fprintf(' You do no have the VBM8 toolbox\n'); + fprintf('\n\n* * * * * * * * * * * * \n\n'); + return + else + fprintf('\nConfiguring VBM8 to defaults\n'); + cg_vbm8_defaults + end +end + +% Make the call to prepare the system for batch processing. + +UMBatchPrep + +if UMBatch == 0 + fprintf('UMBatchPrep failed.') + return +end + +% Only proceed if successful. + +fprintf('Entering UMBatchVBM8 V2.0 SPM8 Compatible\n'); + +if TestFlag~=0 + fprintf('\nTesting only, no work to be done\n\n'); +end + +% - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + +% +% Make sure that the ParamImage is there. +% + +tic; + +if isempty(ParamImage) | exist(ParamImage) == 0 + fprintf('\n\nThe Parameter Image Must EXIST!\n'); + fprintf(' * * * A B O R T I N G * * *\n\n'); + return +end + +% We need to make sure tha the VBM8 toolbox is present. + +if exist('spm_vbm8.m') ~= 2 + fprintf('\n\n* * * * * * MISSING THE VBM8 TOOLBOX * * * * * * \n') + fprintf(' * * * A B O R T I N G * * *\n\n'); + return +end + +clear matlabbatch + +matlabbatch{1}.spm.tools.vbm8.estwrite.data = {[ParamImage ',1']}; +matlabbatch{1}.spm.tools.vbm8.estwrite.opts = vbm8.opts; +matlabbatch{1}.spm.tools.vbm8.estwrite.output = rmfield(vbm8.output,'surf'); + +% But now we also turn on ALL native output. + +matlabbatch{1}.spm.tools.vbm8.estwrite.output.GM.native = 1; +matlabbatch{1}.spm.tools.vbm8.estwrite.output.GM.warped = 1; + +matlabbatch{1}.spm.tools.vbm8.estwrite.output.WM.native = 1; +matlabbatch{1}.spm.tools.vbm8.estwrite.output.WM.warped = 1; + +matlabbatch{1}.spm.tools.vbm8.estwrite.output.CSF.native = 1; +matlabbatch{1}.spm.tools.vbm8.estwrite.output.CSF.warped = 1; + +matlabbatch{1}.spm.tools.vbm8.estwrite.output.bias.native = 1; +matlabbatch{1}.spm.tools.vbm8.estwrite.output.bias.warped = 1; + +matlabbatch{1}.spm.tools.vbm8.estwrite.output.label.native = 1; +matlabbatch{1}.spm.tools.vbm8.estwrite.output.label.warped = 1; + +matlabbatch{1}.spm.tools.vbm8.estwrite.output.warps = [1 0]; + +% Now the extopts. + +matlabbatch{1}.spm.tools.vbm8.estwrite.extopts.dartelwarp.normhigh.darteltpm = vbm8.extopts.darteltpm; + +matlabbatch{1}.spm.tools.vbm8.estwrite.extopts.sanlm = 2; +matlabbatch{1}.spm.tools.vbm8.estwrite.extopts.mrf = 0.15; +matlabbatch{1}.spm.tools.vbm8.estwrite.extopts.cleanup = 1; +matlabbatch{1}.spm.tools.vbm8.estwrite.extopts.print = 1; + +% Now call the batch manager. + +spm_jobman('run_nogui',matlabbatch); + +% Log that we finished this portion. + +[ParamImageDirectory ParamImageName ParamImageExt] = fileparts(ParamImage); + +UMBatchLogProcess(ParamImageDirectory,sprintf('UMBatchVBM8 : VBM8 processed : %s',ParamImage)); + +% Now create the masked image of the input. We will take the p0 image and +% use spm_imcalc to create a skull stripped which we will preprend as +% "bet_" + +CURDIR=pwd; + +cd(ParamImageDirectory); + +% Get the masking image, which is the "p0" image. + +MaskParam = fullfile(ParamImageDirectory,['p0' ParamImageName ParamImageExt]); + +% Now create the skull stripped brain. + +inputImages = strvcat(ParamImage,MaskParam); + +Vi = spm_vol(inputImages); + +clear Vo + +Vo.fname = fullfile(ParamImageDirectory,['bet_' ParamImageName ParamImageExt]); +Vo.dim = Vi(1).dim; +Vo.mat = Vi(1).mat; +Vo.descrip = ['Skull Stripped spm8Batch/VMB8 ' Vi(1).descrip]; +Vo.dt = Vi(1).dt; + +spm_imcalc(Vi,Vo,'i1.*(i2>0)'); + +% Now create an intensity normalized stripped brain. + +ParamImageNorm = fullfile(ParamImageDirectory,['m' ParamImageName ParamImageExt]); + +inputImages = strvcat(ParamImageNorm,MaskParam); + +Vi = spm_vol(inputImages); + +clear Vo + +Vo.fname = fullfile(ParamImageDirectory,['bet_m' ParamImageName ParamImageExt]); +Vo.dim = Vi(1).dim; +Vo.mat = Vi(1).mat; +Vo.descrip = ['Skull Stripped spm8Batch/VMB8 (intensity normalized)' Vi(1).descrip]; +Vo.dt = Vi(1).dt; + +spm_imcalc(Vi,Vo,'i1.*(i2>0)'); + +% And now log it. + +UMBatchLogProcess(ParamImageDirectory,sprintf('UMBatchVBM8 : VBM8 created skull stripped : %s',Vo.fname)); + +% And now warp the parent image to the specification and with the +% name specified. But we only do that if they specified anything +% different. + +if exist(ReferenceImage) | VoxelSize(1) > 0 | strcmp(OutputName,'w')==0 + % + % Okay looks like they want us to override what they have, so we + % need to build a list and then pass on to UMBatchWarpVBM8 + % + % The images to warp are [ParamImage], bet_[ParamImage], + % p0_[ParamImage], p1_[ParamImage], and p2_[ParamImage]; + % + IMAGELIST={'','m','bet_','p0','p1','p2','p3'}; + PList = []; + for iP = 1:length(IMAGELIST) + Pthis = spm_select('ExtFPList',ParamImageDirectory,sprintf('^%s%s.nii',IMAGELIST{iP},ParamImageName),[1 inf]); + PList = strvcat(PList,Pthis); + end + results = UMBatchWarpVBM8(ParamImage,ReferenceImage,PList,TestFlag,VoxelSize,OutputName); + UMCheckFailure(results); +end + +% Now warp other images that might be speficied. + +if length(Img2Write) > 0 + results = UMBatchWarpVBM8(ParamImage,ReferenceImage,Img2Write,TestFlag,VoxelSize,OutputName); + UMCheckFailure(results); +end + +clear matlabbatch + +% Set the flag to the amount of time to execute. +% + +results = toc; + +fprintf('Deformation finished in %f seconds\n',results); + +return + +% +% All done. +% diff --git a/spm8Batch/matlabScripts/UMBatchVBM8.m~ b/spm8Batch/matlabScripts/UMBatchVBM8.m~ new file mode 100644 index 00000000..b9e2b2dc --- /dev/null +++ b/spm8Batch/matlabScripts/UMBatchVBM8.m~ @@ -0,0 +1,279 @@ +% - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +% Robert C. Welsh +% Ann Arbor Michigan, USA +% +% March 2005-2011 +% Copyright. +% +% UMBatchWarp +% +% A drivable routine for warping some images using the +% batch options of spm2. +% +% Version 2.0 +% +% This should ONLY BE CALLED BY UMBatchWarp and NOT directly. +% +% Call as : +% +% function results = UMBatchWarpVBM8(ParamImage,ObjectMask,Images2Write,TestFlag,VoxelSize,OutputName); +% +% To Make this work you need to provide the following input: +% +% ParamImage = Image to determine warping parameters. +% ObjectMask = Masking Image. +% Images2Write = Images to write normalize. +% TestFlag = Flag to test file existance but do nothing. +% +% If the TemplateImage is blank then we are doing "Write Normalized Only" +% +% If Images2Write is blank then we are doing "Determine Parameters Only" +% +% If ObjectMask = [] or '' then no masking. +% +% ParamImage CAN NOT BE BLANK and must exist, as must its "_sn.mat" file. +% +% If TestFlag = 0 then execute, else just test files. +% +% Output +% +% results = -1 if failure +% # of seconds to execute. +% +% If you wish to use any normalization parameters other than the default +% you must set them yourself! +% +% You should make call to UMBatchPrep first. +% +% - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + +function results = UMBatchVBM8(ParamImage,ObjectMask,Images2Write,TestFlag,VoxelSize,OutputName); + +% Get the defaults from SPM. + +global defaults + +% Make the call to prepare the system for batch processing. + +UMBatchPrep + +fprintf('Entering UMBatchWarpVBM8 V2.0 SPM8 Compatible\n'); + +if TestFlag~=0 + fprintf('\nTesting only, no work to be done\n\n'); +end + +% +% Set the return status to -1, that is error by default. +% + +results = -1; + +% - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + +% +% Make sure that the ParamImage is there. +% + +tic; + +if isempty(ParamImage) | exist(ParamImage) == 0 + fprintf('\n\nThe Parameter Image Must EXIST!\n'); + fprintf(' * * * A B O R T I N G * * *\n\n'); + return +end + +% We need to make sure tha the VBM8 toolbox is present. + +if exist('spm_vbm8.m') ~= 2 + fprintf('\n\n* * * * * * MISSING THE VBM8 TOOLBOX * * * * * * \n') + fprintf(' * * * A B O R T I N G * * *\n\n'); + return +end + + +% +% Check to see if they want a mask on the object. +% + +if isempty(ObjectMask) | ObjectMask == '' + ObjectMask = ''; +else + if exist(ObjectMask) == 0 + fprintf('Object mask specified is missing\n'); + fprintf(' * * * A B O R T I N G * * *\n\n'); + return + end +end + +% +% Now see about the images to write. Bugger out at ANY error! +% + +WarpMATName = [spm_str_manip(ParamImage,'sd') '_sn.mat']; + +if isempty(Images2Write) + WriteImage = 0; +else + WriteImage = 1; + for iP = 1:size(Images2Write,1) + tmpFile=Images2Write(iP,:); + commaIDX = findstr(',',tmpFile); + if ~isempty(commaIDX) + tmpFile = tmpFile(1:commaIDX(1)-1); + end + if exist(tmpFile) == 0 + WriteImage = 0 + fprintf('Error, image file : %s \n does not exist\n',tmpFile); + end + end + % + % Only require the warping matrix to pre-exist if we are NOT + % attempting to determine the warping parameters. + % + if DetermineParam == 0 & exist(WarpMATName) == 0 + fprintf('Error, warping matrix file: %s\n does not exist.\n',WarpMATName); + WriteImage == 0; + end + if WriteImage == 0 + fprintf('\n * * * A B O R T I N G * * *\n\n'); + end +end + +% +% Check to see if they actually want anything done? +% + +if DetermineParam == 0 & WriteImage == 0 + fprintf('You have chosen to do nothing, check your input params.\n'); + return +end + +% +% Now if we are determining the warping parameters let's do that. +% + +if DetermineParam == 1 + if TestFlag ~= 0 + fprintf('Would be calculating warp for \n%s to\n%s\n',ParamImage,TemplateImage) + else + % Warping estimating and writing + + fprintf('Warping %s to \n %s\n',ParamImage,TemplateImage); + + % We need to add the ",1" to the name for spm to handle + % nifti/nifti_gz images. + + % Pull out the directory + + ParamImageDirectory = fileparts(ParamImage); + + % Need to indicate to SPM which frame to use. + + TemplateImage = [ TemplateImage ',1']; + ParamImage = [ParamImage ',1']; + + % Set up the estimation + + matlabbatch{1}.spm.spatial.normalise.estwrite.subj.source{1} = ParamImage; + matlabbatch{1}.spm.spatial.normalise.estwrite.subj.wtsrc = ''; + matlabbatch{1}.spm.spatial.normalise.estwrite.subj.resample{1} = ParamImage; + + matlabbatch{1}.spm.spatial.normalise.estwrite.eoptions = defaults.normalise.estimate; + matlabbatch{1}.spm.spatial.normalise.estwrite.eoptions.template{1} = TemplateImage; + + % And set up the write options. + + matlabbatch{1}.spm.spatial.normalise.estwrite.roptions = defaults.normalise.write; + + % Only override the default if explicitly set > 0 + + if VoxelSize > 0 + matlabbatch{1}.spm.spatial.normalise.estwrite.roptions.vox ... + = VoxelSize * ones(1,3); + else + VoxelSize = defaults.normalise.write.vox(1); + end + + % And the output name prefix. + + matlabbatch{1}.spm.spatial.normalise.estwrite.roptions.prefix ... + = OutputName; + + % Now call the batch manager. + + spm_jobman('run_nogui',matlabbatch); + + % Log that we finished this portion. + + UMBatchLogProcess(ParamImageDirectory,sprintf('UMBatchWarp : Determined parameter for : %s',ParamImage)); + + end + clear matlabbatch +end + +% +% If we are warping some images to write then let's do that. +% + +if WriteImage == 1 + fprintf('Using warping matrix \n%s\n',WarpMATName); + if TestFlag ~= 0 + fprintf('Would be warping %d images like %s\n',size(Images2Write,1),deblank(Images2Write(1,:))); + % Warping writing only. + else + matlabbatch{1}.spm.spatial.normalise.write.subj.matname{1} = WarpMATName; + matlabbatch{1}.spm.spatial.normalise.write.subj.resample = {}; + for iP = 1:size(Images2Write,1) + matlabbatch{1}.spm.spatial.normalise.write.subj.resample{iP,1} ... + = strtrim(Images2Write(iP,:)); + end + matlabbatch{1}.spm.spatial.normalise.write.roptions = defaults.normalise.write; + + % Only override the default if explicitly set > 0 + + if VoxelSize > 0 + matlabbatch{1}.spm.spatial.normalise.write.roptions.vox ... + = VoxelSize * ones(1,3); + else + VoxelSize = defaults.normalise.write.vox(1); + end + + % And the output name prefix. + + matlabbatch{1}.spm.spatial.normalise.write.roptions.prefix ... + = OutputName; + + fprintf('Warping %d images like %s to voxel size %f\n',size(Images2Write,1),deblank(Images2Write(1,:)),VoxelSize); + + spm_jobman('run_nogui',matlabbatch); + + % Log that we finished this portion. + + % Get the directory of the images that we warped. + + ImageDirectory = fileparts(Images2Write(1,:)); + + UMBatchLogProcess(ImageDirectory,sprintf('UMBatchWarp : Warped images (%04d) : %s -> %s',size(Images2Write,1),Images2Write(1,:),OutputName)); + + if size(Images2Write,1) > 1 + UMBatchLogProcess(ImageDirectory,sprintf('UMBatchWarp : through image : %s',Images2Write(end,:))); + end + + end + clear matlabbatch +end + +% +% Set the flag to the amount of time to execute. +% + +results = toc; + +fprintf('Warping finished in %f seconds\n',results); + +return + +% +% All done. +% diff --git a/spm8Batch/matlabScripts/UMBatchWarp.m b/spm8Batch/matlabScripts/UMBatchWarp.m index e1724142..14916774 100755 --- a/spm8Batch/matlabScripts/UMBatchWarp.m +++ b/spm8Batch/matlabScripts/UMBatchWarp.m @@ -21,7 +21,7 @@ % % TemplateImage = Image to warp the Parameter image. % ParamImage = Image to determine warping parameters. -% ObjectMask = Masking Image. +% ObjectMask = Masking Image/ReferenceImage for VBM8 % Images2Write = Images to write normalize. % TestFlag = Flag to test file existance but do nothing. % @@ -47,16 +47,24 @@ % % - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -function results = UMBatchWarp(TemplateImage,ParamImage,ObjectMask,Images2Write,TestFlag,VoxelSize,OutputName); +function results = UMBatchWarp(TemplateImage,ParamImage,ObjectMask,Images2Write,TestFlag,VoxelSize,OutputName,WARPMETHOD); % Get the defaults from SPM. global defaults +global UMBatch % Make the call to prepare the system for batch processing. UMBatchPrep +if UMBatch == 0 + fprintf('UMBatchPrep failed.') + return +end + +% Only proceed if successful. + fprintf('Entering UMBatchWarp V2.0 SPM8 Compatible\n'); if TestFlag~=0 @@ -67,6 +75,11 @@ % Set the return status to -1, that is error by default. % +if exist('WARPMETHOD') == 1 & WARPMETHOD + results = UMBatchWarpVBM8(ParamImage,ObjectMask,Images2Write,TestFlag,VoxelSize,OutputName); + return +end + results = -1; % - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/spm8Batch/matlabScripts/UMBatchWarpVBM8.m b/spm8Batch/matlabScripts/UMBatchWarpVBM8.m new file mode 100644 index 00000000..1a319a86 --- /dev/null +++ b/spm8Batch/matlabScripts/UMBatchWarpVBM8.m @@ -0,0 +1,285 @@ +% - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +% Robert C. Welsh +% Ann Arbor Michigan, USA +% +% March 2005-2011 +% Copyright. +% +% UMBatchWarp +% +% A drivable routine for warping some images using the +% batch options of spm2. +% +% Version 2.0 +% +% This should ONLY BE CALLED BY UMBatchWarp and NOT directly. +% +% Call as : +% +% function results = UMBatchWarpVBM8(ParamImage,ReferenceImage,Images2Write,TestFlag,VoxelSize,OutputName); +% +% To Make this work you need to provide the following input: +% +% ParamImage = Image to determine warping parameters. +% ObjectMask = Masking Image. +% Images2Write = Images to write normalize. +% TestFlag = Flag to test file existance but do nothing. +% +% If the TemplateImage is blank then we are doing "Write Normalized Only" +% +% If Images2Write is blank then we are doing "Determine Parameters Only" +% +% If ObjectMask = [] or '' then no masking. +% +% ParamImage CAN NOT BE BLANK and must exist, as must its "_sn.mat" file. +% +% If TestFlag = 0 then execute, else just test files. +% +% Output +% +% results = -1 if failure +% # of seconds to execute. +% +% If you wish to use any normalization parameters other than the default +% you must set them yourself! +% +% You should make call to UMBatchPrep first. +% +% - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + +function results = UMBatchWarpVBM8(ParamImage,ReferenceImage,Images2Write,TestFlag,VoxelSize,OutputName); + +% Get the defaults from SPM. + +global defaults + +% Make the call to prepare the system for batch processing. + +UMBatchPrep + +fprintf('Entering UMBatchWarpVBM8 V2.0 SPM8 Compatible\n'); + +if TestFlag~=0 + fprintf('\nTesting only, no work to be done\n\n'); +end + +% +% Set the return status to -1, that is error by default. +% + +results = -1; + +% - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + +% +% Make sure that the ParamImage is there. +% + +tic; + +if isempty(ParamImage) | exist(ParamImage) == 0 + fprintf('\n\nThe Parameter Image Must EXIST!\n'); + fprintf(' * * * A B O R T I N G * * *\n\n'); + return +end + +% We need to make sure tha the VBM8 toolbox is present. + +if exist('spm_vbm8.m') ~= 2 + fprintf('\n\n* * * * * * MISSING THE VBM8 TOOLBOX * * * * * * \n') + fprintf(' * * * A B O R T I N G * * *\n\n'); + return +end + +% + +% Store where we are presently to restore before going back. + +CURDIR = pwd; + +clear matlabbatch + +% grab what we need, first break apart the file name. + +[ParamImageDirectory ParamImageName ParamImageExt ParamImageNum] = spm_fileparts(ParamImage); + +% Name of the deformation file + +matlabbatch{1}.spm.util.defs.comp{1}.def{1} = fullfile(ParamImageDirectory,['y_r' ParamImageName ParamImageExt]); + +% Check to make sure that the defomation field is there. + +if isempty(matlabbatch{1}.spm.util.defs.comp{1}.def{1}) | exist(matlabbatch{1}.spm.util.defs.comp{1}.def{1}) == 0 + fprintf('\n\nDeformation field is missing!\n'); + fprintf(' * * * A B O R T I N G * * *\n\n'); + return +end + +% Now if there is a reference image then we rewrite comp{2} + +if length(ReferenceImage) > 0 + [d1 d2 d3 d4] = spm_fileparts(ReferenceImage); +else + d1 = ''; + d2 = ''; + d3 = ''; +end + +if length(ReferenceImage) > 0 & exist(fullfile(d1,[d2 d3])) + matlabbatch{1}.spm.util.defs.comp{2}.id.space{1} = [fullfile(d1,[d2 d3]),',1']; + USINGREF=1; +else + % Size of the data we want to write out. + + if VoxelSize > 0 + matlabbatch{1}.spm.util.defs.comp{2}.idbbvox.vox = VoxelSize*ones(3,1); + else + matlabbatch{1}.spm.util.defs.comp{2}.idbbvox.vox = defaults.normalise.write.vox; + end + + % We use the default bounding box. + % Though we need to add the option of using a reference images as + % well. + + matlabbatch{1}.spm.util.defs.comp{2}.idbbvox.bb = defaults.normalise.write.bb; + USINGREF=0; +end + +% No option here. + +matlabbatch{1}.spm.util.defs.ofname = ''; + +% Save to the directory where the times-series data exist. + +matlabbatch{1}.spm.util.defs.savedir.savesrc = 1; + +% Now get the file/frame names as the utility wants them, which is +% different from other routines. + +matlabbatch{1}.spm.util.defs.fnames = {}; +for iP = 1:size(Images2Write,1) + matlabbatch{1}.spm.util.defs.fnames{iP} = strtrim(Images2Write(iP,:)); +end + +% Interpolation method: + +matlabbatch{1}.spm.util.defs.interp = 1; + +% +% Now see about the images to write. Bugger out at ANY error! +% + +if isempty(Images2Write) + fprintf('\nYou did not specify any images to write deformed\m'); + fprintf('\n * * * A B O R T I N G * * *\n\n'); + return +else + for iP = 1:size(Images2Write,1) + tmpFile=Images2Write(iP,:); + commaIDX = findstr(',',tmpFile); + if ~isempty(commaIDX) + tmpFile = tmpFile(1:commaIDX(1)-1); + end + if exist(tmpFile) == 0 + WriteImage = 0 + fprintf('Error, image file : %s \n does not exist\n',tmpFile); + fprintf('\n * * * A B O R T I N G * * *\n\n'); + return + end + end +end + +% +% If we are warping some images to write then let's do that. +% + +fprintf('Using deformation field \n%s\n',matlabbatch{1}.spm.util.defs.comp{1}.def{1}); + +if TestFlag ~= 0 + fprintf('Would be warping %d images like %s\n',size(Images2Write,1),deblank(Images2Write(1,:))); + % Warping writing only. +else + if USINGREF + fprintf('Warping %d images like %s to space of %s\n',size(Images2Write,1),... + deblank(Images2Write(1,:)),matlabbatch{1}.spm.util.defs.comp{2}.id.space{1}); + else + fprintf('Warping %d images like %s to voxel size %f\n',size(Images2Write,1),... + deblank(Images2Write(1,:)),matlabbatch{1}.spm.util.defs.comp{2}.idbbvox.vox(1)); + end + spm_jobman('run_nogui',matlabbatch); + + % Log that we finished this portion. + + % Get the directory of the images that we warped. + + % Now let's find out if successful? + + % We only operate on NIFTI so we can just take the unique ones, + % and return the count. + + [Images2WriteUnique Images2WriteCount] = uniqueNII(Images2Write); + + for iNII = 1:size(Images2WriteUnique,1) + [d1 d2 d3 d4] = spm_fileparts(strtrim(Images2WriteUnique(iNII,:))); + newFile = fullfile(d1,['w' d2 d3]); + if exist(newFile) == 0 + fprintf('\n\n* * * * * * * * * * * * \n\n'); + fprintf('FATAL ERROR - I CAN''T FIND THE OUTPUT FILE EXPECTED : %s\n',newFile); + fprintf('ABORTING\n'); + fprintf('\n\n* * * * * * * * * * * * \n\n'); + return + end + end + + % Everything up to this point is okay + % Okay, if the OutputName option is not specified, or it's + % already set to 'w', then we do nothing, else we rename the file + % for them as moveOutOfSandbox is expecting the new name. + + newImages2WriteUnique = []; + if exist('OutputName') == 1 & strcmp(OutputName,'w') ~= 1 + % We need to identify all of the files that need to be renamed. + for iNII = 1:size(Images2WriteUnique,1) + [d1 d2 d3 d4] = spm_fileparts(strtrim(Images2WriteUnique(iNII,:))); + oldFile = fullfile(d1,['w' d2 d3]); + newFile = fullfile(d1,[OutputName d2 d3]); + [mS mM mI] = movefile(oldFile,newFile); + if ~mS + fprintf('\n\n* * * * * * * * * * * * \n\n'); + fprintf('FATAL ERROR - I CAN''T NAME OUTPUT FILE AS EXPECTED : \n %s\n %s\n',oldFile,newFile); + fprintf('ABORTING\n'); + fprintf('\n\n* * * * * * * * * * * * \n\n'); + return + end + newImages2WriteUnique = strvcat(newImages2WriteUnique, newFile); + end + end + + ImageDirectory = fileparts(Images2Write(1,:)); + + for iNII = 1:size(Images2WriteUnique,1); + UMBatchLogProcess(ImageDirectory,... + sprintf('UMBatchWarp : Warped images (frames:%04d) : %s -> %s',... + Images2WriteCount(iNII),... + Images2WriteUnique(iNII,:),... + newImages2WriteUnique(iNII,:))); + + end + +end + +clear matlabbatch + +% +% Set the flag to the amount of time to execute. +% + +results = toc; + +fprintf('Deformation finished in %f seconds\n',results); + +return + +% +% All done. +% diff --git a/spm8Batch/matlabScripts/UMBatchWarpVBM8.m~ b/spm8Batch/matlabScripts/UMBatchWarpVBM8.m~ new file mode 100644 index 00000000..230bbe18 --- /dev/null +++ b/spm8Batch/matlabScripts/UMBatchWarpVBM8.m~ @@ -0,0 +1,285 @@ +% - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +% Robert C. Welsh +% Ann Arbor Michigan, USA +% +% March 2005-2011 +% Copyright. +% +% UMBatchWarp +% +% A drivable routine for warping some images using the +% batch options of spm2. +% +% Version 2.0 +% +% +% Call as : +% +% function results = UMBatchWarp(TemplateImage,ParamImage,ObjectMask,Images2Write,TestFlag,VoxelSize,OutputName); +% +% To Make this work you need to provide the following input: +% +% TemplateImage = Image to warp the Parameter image. +% ParamImage = Image to determine warping parameters. +% ObjectMask = Masking Image. +% Images2Write = Images to write normalize. +% TestFlag = Flag to test file existance but do nothing. +% +% If the TemplateImage is blank then we are doing "Write Normalized Only" +% +% If Images2Write is blank then we are doing "Determine Parameters Only" +% +% If ObjectMask = [] or '' then no masking. +% +% ParamImage CAN NOT BE BLANK and must exist, as must its "_sn.mat" file. +% +% If TestFlag = 0 then execute, else just test files. +% +% Output +% +% results = -1 if failure +% # of seconds to execute. +% +% If you wish to use any normalization parameters other than the default +% you must set them yourself! +% +% You should make call to UMBatchPrep first. +% +% - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + +function results = UMBatchWarpVBM8(TemplateImage,ParamImage,ObjectMask,Images2Write,TestFlag,VoxelSize,OutputName,WARPMETHOD); + +% Get the defaults from SPM. + +global defaults + +% Make the call to prepare the system for batch processing. + +UMBatchPrep + +fprintf('Entering UMBatchWarp V2.0 SPM8 Compatible\n'); + +if TestFlag~=0 + fprintf('\nTesting only, no work to be done\n\n'); +end + +% +% Set the return status to -1, that is error by default. +% + +if WARPMETHOD + results = UMBatchWarpVBM8(ParamImage,ObjectMask,Images2Write,TestFlag,VoxelSize,OutputName,WARPMETHOD); + return +end + +results = -1; + +% - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + +% +% Make sure that the ParamImage is there. +% + +tic; + +if isempty(ParamImage) | exist(ParamImage) == 0 + fprintf('\n\nThe Parameter Image Must EXIST!\n'); + fprintf(' * * * A B O R T I N G * * *\n\n'); + return +end + +% +% Check to see if the template image exists? +% + +if isempty(TemplateImage) | exist(TemplateImage) == 0 + DetermineParam = 0; +else + DetermineParam = 1; +end + +% +% Check to see if they want a mask on the object. +% + +if isempty(ObjectMask) | ObjectMask == '' + ObjectMask = ''; +else + if exist(ObjectMask) == 0 + fprintf('Object mask specified is missing\n'); + fprintf(' * * * A B O R T I N G * * *\n\n'); + return + end +end + +% +% Now see about the images to write. Bugger out at ANY error! +% + +WarpMATName = [spm_str_manip(ParamImage,'sd') '_sn.mat']; + +if isempty(Images2Write) + WriteImage = 0; +else + WriteImage = 1; + for iP = 1:size(Images2Write,1) + tmpFile=Images2Write(iP,:); + commaIDX = findstr(',',tmpFile); + if ~isempty(commaIDX) + tmpFile = tmpFile(1:commaIDX(1)-1); + end + if exist(tmpFile) == 0 + WriteImage = 0 + fprintf('Error, image file : %s \n does not exist\n',tmpFile); + end + end + % + % Only require the warping matrix to pre-exist if we are NOT + % attempting to determine the warping parameters. + % + if DetermineParam == 0 & exist(WarpMATName) == 0 + fprintf('Error, warping matrix file: %s\n does not exist.\n',WarpMATName); + WriteImage == 0; + end + if WriteImage == 0 + fprintf('\n * * * A B O R T I N G * * *\n\n'); + end +end + +% +% Check to see if they actually want anything done? +% + +if DetermineParam == 0 & WriteImage == 0 + fprintf('You have chosen to do nothing, check your input params.\n'); + return +end + +% +% Now if we are determining the warping parameters let's do that. +% + +if DetermineParam == 1 + if TestFlag ~= 0 + fprintf('Would be calculating warp for \n%s to\n%s\n',ParamImage,TemplateImage) + else + % Warping estimating and writing + + fprintf('Warping %s to \n %s\n',ParamImage,TemplateImage); + + % We need to add the ",1" to the name for spm to handle + % nifti/nifti_gz images. + + % Pull out the directory + + ParamImageDirectory = fileparts(ParamImage); + + % Need to indicate to SPM which frame to use. + + TemplateImage = [ TemplateImage ',1']; + ParamImage = [ParamImage ',1']; + + % Set up the estimation + + matlabbatch{1}.spm.spatial.normalise.estwrite.subj.source{1} = ParamImage; + matlabbatch{1}.spm.spatial.normalise.estwrite.subj.wtsrc = ''; + matlabbatch{1}.spm.spatial.normalise.estwrite.subj.resample{1} = ParamImage; + + matlabbatch{1}.spm.spatial.normalise.estwrite.eoptions = defaults.normalise.estimate; + matlabbatch{1}.spm.spatial.normalise.estwrite.eoptions.template{1} = TemplateImage; + + % And set up the write options. + + matlabbatch{1}.spm.spatial.normalise.estwrite.roptions = defaults.normalise.write; + + % Only override the default if explicitly set > 0 + + if VoxelSize > 0 + matlabbatch{1}.spm.spatial.normalise.estwrite.roptions.vox ... + = VoxelSize * ones(1,3); + else + VoxelSize = defaults.normalise.write.vox(1); + end + + % And the output name prefix. + + matlabbatch{1}.spm.spatial.normalise.estwrite.roptions.prefix ... + = OutputName; + + % Now call the batch manager. + + spm_jobman('run_nogui',matlabbatch); + + % Log that we finished this portion. + + UMBatchLogProcess(ParamImageDirectory,sprintf('UMBatchWarp : Determined parameter for : %s',ParamImage)); + + end + clear matlabbatch +end + +% +% If we are warping some images to write then let's do that. +% + +if WriteImage == 1 + fprintf('Using warping matrix \n%s\n',WarpMATName); + if TestFlag ~= 0 + fprintf('Would be warping %d images like %s\n',size(Images2Write,1),deblank(Images2Write(1,:))); + % Warping writing only. + else + matlabbatch{1}.spm.spatial.normalise.write.subj.matname{1} = WarpMATName; + matlabbatch{1}.spm.spatial.normalise.write.subj.resample = {}; + for iP = 1:size(Images2Write,1) + matlabbatch{1}.spm.spatial.normalise.write.subj.resample{iP,1} ... + = strtrim(Images2Write(iP,:)); + end + matlabbatch{1}.spm.spatial.normalise.write.roptions = defaults.normalise.write; + + % Only override the default if explicitly set > 0 + + if VoxelSize > 0 + matlabbatch{1}.spm.spatial.normalise.write.roptions.vox ... + = VoxelSize * ones(1,3); + else + VoxelSize = defaults.normalise.write.vox(1); + end + + % And the output name prefix. + + matlabbatch{1}.spm.spatial.normalise.write.roptions.prefix ... + = OutputName; + + fprintf('Warping %d images like %s to voxel size %f\n',size(Images2Write,1),deblank(Images2Write(1,:)),VoxelSize); + + spm_jobman('run_nogui',matlabbatch); + + % Log that we finished this portion. + + % Get the directory of the images that we warped. + + ImageDirectory = fileparts(Images2Write(1,:)); + + UMBatchLogProcess(ImageDirectory,sprintf('UMBatchWarp : Warped images (%04d) : %s -> %s',size(Images2Write,1),Images2Write(1,:),OutputName)); + + if size(Images2Write,1) > 1 + UMBatchLogProcess(ImageDirectory,sprintf('UMBatchWarp : through image : %s',Images2Write(end,:))); + end + + end + clear matlabbatch +end + +% +% Set the flag to the amount of time to execute. +% + +results = toc; + +fprintf('Warping finished in %f seconds\n',results); + +return + +% +% All done. +% diff --git a/spm8Batch/matlabScripts/UMCheckFailure.m b/spm8Batch/matlabScripts/UMCheckFailure.m new file mode 100644 index 00000000..2af4d820 --- /dev/null +++ b/spm8Batch/matlabScripts/UMCheckFailure.m @@ -0,0 +1,30 @@ +% - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +% Robert C. Welsh +% Ann Arbor Michigan, USA +% +% March 2012 +% Copyright. +% +% Simple code to check the error status. +% +% If results == -1 then error. +% +% function UMCheckFailure(results) +% +% - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + +function UMCheckFailure(results) + +global UMBatchProcessName + +if results == -1 + fprintf('* * * * * FAILURE * * * *\n') + fprintf(' %s failed.\n',UMBatchProcessName); + fprintf('* * * * * FAILURE * * * *\n') +end + +return + +% +% all done. +% diff --git a/spm8Batch/matlabScripts/dSpike.m b/spm8Batch/matlabScripts/dSpike.m new file mode 100644 index 00000000..a964b74e --- /dev/null +++ b/spm8Batch/matlabScripts/dSpike.m @@ -0,0 +1,110 @@ +%- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +% dSpike +% +% A routine that implements the spike detection algorithm from "Automatic +% Spike Detection for fMRI" by Greve et al. +% +% Call as : +% +% function results = dSpike(inputData,options) +% +% To Make this work you need to provide the following input: +% +% inputData = Either a 4D matrix or file name +% detOpt = polynomial order used in spm_detrend (OPTIONAL) +% +% Output +% +% success = seconds for operation if no errors; otherwise, -1 +% results = nSlice x nTime array of the absolute measure of the +% jackknife z-score for each slice in each timepoint (AJKZ) +% +% Comments +% +% Obvious spikes will be obvious in the output. The paper classifies +% any AJKZ > 25 as a spike. It seems reasonable. Figure 1 in paper +% was not exactly reproduced. The distrubution of AJKZ was shifted +% further left. +% +% - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +function [success results]= dSpike(inputData,detOpt) + +success = -1; +results = []; +tic; + +if ischar(inputData) + inputData = strtrim(inputData); + % Check if file exists + if exist(inputData,'file') ~= 2 + fprintf('Input data "%s"\n does not exist.\n',inputData); + fprintf(' * * * A B O R T I N G * * *\n\n'); + return + end + P = nifti(inputData); + inputData = P.dat(:,:,:,:); +end + +% support only 4D arrays for now +if ndims(inputData) ~= 4 + fprintf('Expected 4D time series\n'); + fprintf(' * * * A B O R T I N G * * *\n\n'); + return +end + +if nargin < 2 + detOpt = []; +end + +[xDim yDim nSlice nTime] = size(inputData); + +% Remove mean per slice per time +for z=1:nSlice + slice = inputData(:,:,z,:); + mu_slice = mean( slice(:) ); + inputData(:,:,z,:) = slice - mu_slice; +end + +% Remove temporal trend, then compute temporal Z-score for each voxel +for z=1:nSlice + slice = squeeze(inputData(:,:,z,:)); + reSlice = reshape(slice,xDim*yDim,nTime)'; + % detrend + if ~isempty(detOpt) + if detOpt ~= 0 + reSlice = spm_detrend(reSlice,detOpt); + else % do this because spm_detrend is just too slow when detOpt = 0 + for t=1:nTime + reSlice(:,t) = reSlice(:,t) - mean(reSlice(:,t)); + end + end + end + %get z score + zScoreSlice = zscore(reSlice); + inputData(:,:,z,:) = abs( reshape(zScoreSlice',xDim,yDim,1,nTime) ); +end + +AAZ = zeros(nSlice,nTime); +% Average the Z-scores across slices and time +for t=1:nTime + for z=1:nSlice + AAZ(z,t) = sum(sum(inputData(:,:,z,t)))/(xDim*yDim); + end +end + +AJKZ = zeros(nSlice,nTime); +indexes = [1:nSlice]'; +% Calculate AJKZ +for z=1:nSlice + loc = (indexes ~= z); + included = AAZ(loc,:); + mu_i = mean(included,1); + std_i = std(included,1); + std_i(std_i==0) = 1; + AJKZ(z,:) = (AAZ(z,:) - mu_i)./(std_i); +end + +results = abs(AJKZ); +success = toc; + +return \ No newline at end of file diff --git a/spm8Batch/matlabScripts/uniqueNII.m b/spm8Batch/matlabScripts/uniqueNII.m new file mode 100644 index 00000000..d7aabd52 --- /dev/null +++ b/spm8Batch/matlabScripts/uniqueNII.m @@ -0,0 +1,43 @@ +% - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +% Robert C. Welsh +% Ann Arbor Michigan, USA +% +% March 2005-2011 +% Copyright. +% +% uniqueNII +% +% A utility function to return a unique list of files +% names, after the frame number has been discarded. +% +% function [uniqueList count] = uniqueNII(inputList) +% +% - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + +function [uniqueList count] = uniqueNII(inputList) + +uniqueList = []; +count = []; + +for iP = 1:size(inputList,1) + [d1 d2 d3 d4] = spm_fileparts(inputList(iP,:)); + uniqueList = strvcat(uniqueList,fullfile(d1,[d2 d3])); +end + +uniqueList = unique(uniqueList,'rows'); + +count = zeros(size(uniqueList,1),1); + +for iP = 1:size(uniqueList,1) + count(iP) = 0; + for iO = 1:size(inputList,1) + [d1 d2 d3 d4] = spm_fileparts(inputList(iO,:)); + if strcmp(strtrim(uniqueList(iP,:)),fullfile(d1,[d2 d3])) + count(iP) = count(iP) + 1; + end + end +end + +% +% all done. +% \ No newline at end of file diff --git a/spm8Batch/matlabScripts/uniqueNII.m~ b/spm8Batch/matlabScripts/uniqueNII.m~ new file mode 100644 index 00000000..087006b6 --- /dev/null +++ b/spm8Batch/matlabScripts/uniqueNII.m~ @@ -0,0 +1,42 @@ +% - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +% Robert C. Welsh +% Ann Arbor Michigan, USA +% +% March 2005-2011 +% Copyright. +% +% uniqueNII +% +% A utility function to return a unique list of files +% names, after the frame number has been discarded. +% +% function [uniqueList count] = uniqueNII(inputList) +% +% - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + +function [uniqueList count] = uniqueNII(inputList) + +uniqueList = []; +count = []; + +for iP = 1:size(inputList,1) + [d1 d2 d3 d4] = spm_fileparts(inputList(iP,:)); + uniqueList = strvcat(uniqueList,fullfile(d1,[d2 d3])); + count = [count ; 0]; +end + +uniqueList = unique(uniqueList,'rows'); + +for iP = 1:size(uniqueList,1) + count(iP) = 0; + for iO = 1:size(inputList,1) + [d1 d2 d3 d4] = spm_fileparts(inputList(iO,:)); + if strcmp(uniqueList(iP,:),fullfile(d1,[d2 d3])) + count(iP) = count(iP) + 1; + end + end +end + +% +% all done. +% \ No newline at end of file diff --git a/spm8Batch/parts/coreg_part_2.m b/spm8Batch/parts/coreg_part_2.m index dd55ca47..23503e24 100755 --- a/spm8Batch/parts/coreg_part_2.m +++ b/spm8Batch/parts/coreg_part_2.m @@ -15,7 +15,8 @@ fprintf('%s\n',TargetImageFull); fprintf('%s\n',ObjectImageFull); fprintf('UMReSlice:%d\n',UMReSlice); - UMBatchCoReg(TargetImageFull,ObjectImageFull,UMOtherImages{iSub},UMReSlice,UMTestFlag); + results = UMBatchCoReg(TargetImageFull,ObjectImageFull,UMOtherImages{iSub},UMReSlice,UMTestFlag); + UMCheckFailure(results); end fprintf('\nAll done with coregistration.\n'); diff --git a/spm8Batch/parts/detect_spike_part_1.m b/spm8Batch/parts/detect_spike_part_1.m new file mode 100644 index 00000000..9462f0d6 --- /dev/null +++ b/spm8Batch/parts/detect_spike_part_1.m @@ -0,0 +1,55 @@ +% +% This is to be used with SPM8. +% +% To detect spikes in a run using batch use the following code. +% + +% You must point to the batch processing code +% +% addpath /net/dysthymia/spm8Batch +% + +% You need to fill the following variables: +% +% UMBatchMaster = point to the directory of the experiment. +% +% Images = char array of images in a run +% +% OutputFile = results of spike detection is writeen here +% +% Subject = subject name +% +% Run = run name +% +% +% If you are needing to write alot of images out I suggest you use +% a command like this: +% +% Images = spm_select('files',ImagesDir,'ravol*.img'); +% +% where "ImagesDir" is the directory where the images live. You can of +% course put a loop around to write normalize each run seperately etc. +% +% UMBatchSubjs = list of subjects within experiment. Space +% pad if need be. +% + + +% - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + +% Make sure the UM Batch system is installed. + +if exist('UMBatchPrep') ~= 2 | exist('UMBatchWarp') ~= 2 + fprintf('You need to have the UM Batch system\n'); + return +end + +% +% Prepare the batch processes +% + +UMBatchPrep + +% - - - - - - - END OF PART I - - - - - - - - - - - - - - - - - + + diff --git a/spm8Batch/parts/detect_spike_part_2.m b/spm8Batch/parts/detect_spike_part_2.m new file mode 100644 index 00000000..d2666b86 --- /dev/null +++ b/spm8Batch/parts/detect_spike_part_2.m @@ -0,0 +1,61 @@ +% - - - - - - - -BEGINNING OF PART II - - - - - - - - - - - - - + +% Deblank just in case. + +UMBatchMaster = strtrim(UMBatchMaster); + +% - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + +fprintf('Looping on the subjects now\n\n'); + +% +% Loop over the subjects and test each run. +% + +for iSub = 1:length(UMBatchSubjs) + % + fprintf('Working on %s\n',UMBatchSubjs{iSub}) + + % Loop on the runs and get the names of the files to test. + % We use the "spm_select('FPLIst',[directory],[file wildcard])" command + % to get the list of files. + for iRun = 1:length(UMImgDIRS{iSub}) + % + % Grab the images + % + Images = spm_select('FPList',UMImgDIRS{iSub}{iRun},['^' UMVolumeWild '.*.nii']); + nFiles = size(Images,1); + fprintf('Testing a total of %d %s''s\n',nFiles,UMVolumeWild); + % + % Create OutputFile name + % + index = strfind(UMImgDIRS{iSub}{iRun},'run'); + if isempty(index) + OutputFile = fullfile( UMImgDIRS{iSub}{iRun},[UMBatchSubjs{iSub} '_ds.txt'] ); + else + % + % Find out what run it is and put in in OutputFile name + % + temp = UMImgDIRS{iSub}{iRun}; + temp = temp(index(1):end); + index2 = strfind(temp,filesep); + if isempty(index2) + RunStr = strtrim(temp); + else + RunStr = temp( 1:index2(1)-1 ); + end + OutputFile = fullfile( UMImgDIRS{iSub}{iRun},[UMBatchSubjs{iSub} '_' RunStr '_ds.txt'] ); + end + % + % Detect the spikes + % + UMBatchDetectSpike(Images,OutputFile,UMImgDIRS{iSub}{iRun}); + + end +end + +fprintf('\nAll done spike detection.\n'); + +% +% All done. +% diff --git a/spm8Batch/parts/smooth_part_2.m b/spm8Batch/parts/smooth_part_2.m index 9784651a..3785af81 100755 --- a/spm8Batch/parts/smooth_part_2.m +++ b/spm8Batch/parts/smooth_part_2.m @@ -23,7 +23,8 @@ [CS SandBoxPID Images2Write] = moveToSandBox(UMImgDIRS{iSub}{iRun},UMVolumeWild,SandBoxPID); %P = spm_select('ExtFPList',UMImgDIRS{iSub}{iRun},['^' UMVolumeWild '.*.nii'],inf); fprintf('Smoothing %d "%s" images in %s with %2.1f %2.1f %2.1f\n',size(Images2Write,1),UMImgWildCard,UMImgDIRS{iSub}{iRun},UMKernel(1),UMKernel(2),UMKernel(3)); - UMBatchSmooth(Images2Write,UMKernel,OutputName,UMTestFlag); + results = UMBatchSmooth(Images2Write,UMKernel,OutputName,UMTestFlag); + UMCheckFailure(results); % % Now move back out of sandbox if so specified % diff --git a/spm8Batch/parts/vbm8_part_01.m b/spm8Batch/parts/vbm8_part_01.m new file mode 100644 index 00000000..cfa192ac --- /dev/null +++ b/spm8Batch/parts/vbm8_part_01.m @@ -0,0 +1,43 @@ +% +% Copyright Robert C. Welsh +% Ann Arbor, Michigan 2005 +% +% This is to be used with the UMBatch System for SPM8. +% +% To Warp image using batch use the following code. +% + +% You must point to the batch processing code +% +% addpath /net/dysthymia/spm8Batch +% + +% You need to fill the following variables: +% +% UMBatchMaster = point to the directory of the experiment. +% +% ParamImage = image for determining the normalization. +% +% UMBatchSubjs = list of subjects within experiment. Space +% pad if need be. +% + + +% - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + +% Make sure the UM Batch system is installed. + +if exist('UMBatchPrep') ~= 2 | exist('UMBatchVBM8') ~= 2 + fprintf('You need to have the UM Batch system\n'); + return +end + +% +% Prepare the batch processes +% + +UMBatchPrep + +% - - - - - - - END OF PART I - - - - - - - - - - - - - - - - - + + diff --git a/spm8Batch/parts/vbm8_part_02.m b/spm8Batch/parts/vbm8_part_02.m new file mode 100644 index 00000000..d841b2e3 --- /dev/null +++ b/spm8Batch/parts/vbm8_part_02.m @@ -0,0 +1,49 @@ + +% - - - - - - - START OF PART II - - - - - - - - - - - - - - - + +% Deblank just in case. + +UMBatchMaster = deblank(UMBatchMaster); + +% If all of the subjects are in the same organization scheme +% then you should not have to modify this piece of code from this point +% forward. + +fprintf('\nWarping images using UMBatchVBM8\n'); + +fprintf('Looping on the subjects now\n\n'); + +% +% Loop over the subjects and coregister each one. +% + +for iSub = 1:length(UMBatchSubjs) + % + fprintf('Working on %s\n',UMBatchSubjs{iSub}); + % + % Break into two steps, one to calculate the normalization for the + % SPGR. + % + ParamImage = UMImg2Warp{iSub}; + % + % Make sure the image exists. + % + ParamImage=UMImg2Warp{iSub}; + Img2Write=[]; + for iW = 1:length(UMOtherImages{iSub}) + Img2Write = strvcat(Img2Write,[UMOtherImages{iSub}{iW},',1']); + end + if exist(ParamImage) == 2 + results = UMBatchVBM8(ParamImage,VBM8RefImage,Img2Write,UMTestFlag,VoxelSize,OutputName); + UMCheckFailure(results); + else + fprintf('FATAL ERROR : Image to warpVBM8 process does not exist: %s\n',ParamImage) + break + end +end + +fprintf('\nAll done with warpingVBM8 processing of High Resolution image.\n'); + +% +% All done. +% diff --git a/spm8Batch/parts/vbm8_part_02.m~ b/spm8Batch/parts/vbm8_part_02.m~ new file mode 100644 index 00000000..6ff183db --- /dev/null +++ b/spm8Batch/parts/vbm8_part_02.m~ @@ -0,0 +1,43 @@ + +% - - - - - - - START OF PART II - - - - - - - - - - - - - - - + +% Deblank just in case. + +UMBatchMaster = deblank(UMBatchMaster); + +% If all of the subjects are in the same organization scheme +% then you should not have to modify this piece of code from this point +% forward. + +fprintf('\nWarping images using UMBatchVBM8\n'); + +fprintf('Looping on the subjects now\n\n'); + +% +% Loop over the subjects and coregister each one. +% + +for iSub = 1:length(UMBatchSubjs) + % + fprintf('Working on %s\n',UMBatchSubjs{iSub}); + % + % Break into two steps, one to calculate the normalization for the + % SPGR. + % + ParamImage = UMImg2Warp{iSub}; + % + % Make sure the image exists. + % + if exist(ParamImage) == 2 + UMBatchWarp(ParamImage,[],Img2Write,UMTestFlag,VoxelSize,OutputName); + else + fprintf('FATAL ERROR : Image to warp does not exist: %s\n',ParamImage) + exit + end +end + +fprintf('\nAll done with warping of High Resolution images to template\n'); + +% +% All done. +% diff --git a/spm8Batch/parts/warp_HIRES_part_2.m b/spm8Batch/parts/warp_HIRES_part_2.m index 59d54c74..b48eed98 100755 --- a/spm8Batch/parts/warp_HIRES_part_2.m +++ b/spm8Batch/parts/warp_HIRES_part_2.m @@ -23,7 +23,7 @@ fprintf('Working on %s\n',UMBatchSubjs{iSub}); % % Break into two steps, one to calculate the normalization for the - % SPGR. + % HiRes. % ParamImage = UMImg2Warp{iSub}; % @@ -34,10 +34,12 @@ for iW = 1:length(UMOtherImages{iSub}) Img2Write = strvcat(Img2Write,[UMOtherImages{iSub}{iW},',1']); end - UMBatchWarp(TemplateImage,ParamImage,[],Img2Write,UMTestFlag,VoxelSize,OutputName); + % Force the warping method to be the standard SPM8 + results = UMBatchWarp(TemplateImage,ParamImage,[],Img2Write,UMTestFlag,VoxelSize,OutputName,0); + UMCheckFailure(results); else fprintf('FATAL ERROR : Image to warp does not exist: %s\n',ParamImage) - exit + break end end diff --git a/spm8Batch/parts/warp_fMRI_part_2.m b/spm8Batch/parts/warp_fMRI_part_2.m index 34365de5..7432e874 100755 --- a/spm8Batch/parts/warp_fMRI_part_2.m +++ b/spm8Batch/parts/warp_fMRI_part_2.m @@ -34,7 +34,12 @@ % % The other step to apply the normalization to the SPGR. % - UMBatchWarp([],ParamImage,[],Images2Write,UMTestFlag,VoxelSize,OutputName); + if WARPMETHOD + results = UMBatchWarp([],ParamImage,VBM8RefImage,Images2Write,UMTestFlag,VoxelSize,OutputName,WARPMETHOD); + else + results = UMBatchWarp([],ParamImage,[],Images2Write,UMTestFlag,VoxelSize,OutputName,WARPMETHOD); + end + UMCheckFailure(results); % % Now move back out of sandbox if so specified % diff --git a/spm8Batch/spm8Batch_Global b/spm8Batch/spm8Batch_Global index e0d5e0f4..99e1cf0d 100755 --- a/spm8Batch/spm8Batch_Global +++ b/spm8Batch/spm8Batch_Global @@ -42,17 +42,17 @@ then # You must point to SPM8 !!! - SPM8B1=${topDIR}/SPM8/spm8_with_R4290 + SPM8B1=${topDIR}/SPM8/spm8_with_R4667 # This is Robert Welsh's UNIX batch interface to spm8 - SPM8B2=${topDIR}/spm8Batch_V2.0.4 + SPM8B2=${topDIR}/spm8Batch/spm8Batch_VBM8 # This must point to the place where the SPM8 patch is locally. - SPM8B3=${topDIR}/spm8Batch_V2.0.4/matlabScripts + SPM8B3=${SPM8B2}/matlabScripts - AUXPATH=${topDIR}/spm8Batch_V2.0.4/spm8_patch + AUXPATH=${SPM8B2}/spm8_patch # # If the sandbox is populated then we copy files to local disk for processing diff --git a/spm8Batch/vbm8Check b/spm8Batch/vbm8Check new file mode 100644 index 00000000..6da8238b --- /dev/null +++ b/spm8Batch/vbm8Check @@ -0,0 +1,78 @@ +#!/bin/bash + +# # # # # # # # # # # # # # # # # # +# +# Pull up the ht1spgr and the best BET +# +# Robert C. Welsh +# Copyright 2005-2011 +# +# +# # # # # # # # # # # # # # # # # # + +# +# Main fslCheck function. +# + +VERSION="2.0" +VERSIONDATE="2011-09-13" + +# Find out where the current command lives and execute some common code. + +theFullCommand="$0 $*" +execDIR=`pwd` + +# Find out where the current command lives and execute some common code. + +theCommand=`which $0` +thisDir=`dirname $theCommand` + +thisCommand=`echo $theCommand | awk -F/ '{print $NF}'` + +#allowedOptions="abhMu" +allowedOptions="aDdhM" + +# This piece of code all of the spm8Batch scripts will use +. ${thisDir}/auxiliary/commonCode_AllScriptsStart + +# Validate that we have FSL installed. +. ${thisDir}/auxiliary/commonCode_FSL_01 + +# This is common in-line code for all spm8Batch script to make sure arguments were passed +. ${thisDir}/auxiliary/commonCode_checkIfArgsPassed + +# +# The actual function. +# + +. ${thisDir}/auxiliary/parse_arguments + +for (( is=1 ; is<=$nSubjects ; is++ )) +do + SUBJECTANATOMY=${UMBatchMaster}/${SUBJDIR}/${subjects[$is]}/${anatomyPATH} + if [ ! -d "${SUBJECTANATOMY}" ] + then + echo + echo " FATAL ERROR, can't find directory ${SUBJECTANATOMY}" + echo + echo + exit 0 + fi + cd ${SUBJECTANATOMY} + IMG1=`ls ${SUBJECTANATOMY}/bet_m${HIRESNAME}*.nii 2> /dev/null` + IMG2=`ls ${SUBJECTANATOMY}/m${HIRESNAME}*.nii 2> /dev/null` + if [ -z "${IMG1}" ] + then + echo " ${SUBJECTANATOMY}: I can't find bet_m${HIRESNAME}*.nii" + else + if [ -z "${IMG2}" ] + then + echo " ${SUBJECTANATOMY}: I can't find bet_m${HIRESNAME}*.nii" + else + echo ${SUBJECTANATOMY} + #fslview ${IMG2} -b 0,2000 & ${IMG1} -l Copper -t .7 -b 0,2000 + fslview ${IMG2} -b 0,2000 ${IMG1} -l Copper -t .7 -b 0,2000 + fi + fi +done + diff --git a/spm8Batch/vbm8Check~ b/spm8Batch/vbm8Check~ new file mode 100644 index 00000000..e69de29b diff --git a/spm8Batch/vbm8HiRes b/spm8Batch/vbm8HiRes new file mode 100755 index 00000000..c70f43c8 --- /dev/null +++ b/spm8Batch/vbm8HiRes @@ -0,0 +1,169 @@ +#!/bin/bash + +# # # # # # # # # # # # # # # # # # +# +# A command to make it easier on the user to warp the +# SPGR to the standard template. +# +# This command will build a script to run and will also +# run the script in background. +# +# e.g. vbm8HiRes +# +# +# Robert C. Welsh +# Copyright 2005-2011 +# +# warpHiRes +# +# # # # # # # # # # # # # # # # # # + +# +# Main vbm8HiRes function. +# + +VERSION="1.0" +VERSIONDATE="2012-03-05" + +# Find out where the current command lives and execute some common code. + +theFullCommand="$0 $*" +execDIR=`pwd` + +# Find out where the current command lives and execute some common code. + +theCommand=`which $0` +thisDir=`dirname $theCommand` + +thisCommand=`echo $theCommand | awk -F/ '{print $NF}'` + +allowedOptions="aDdhIMnOtUwz" + +# This piece of code all of the spm8Batch scripts will use +. ${thisDir}/auxiliary/commonCode_AllScriptsStart + +# This is the common in-line code for the warping steps. +. ${thisDir}/auxiliary/commonCode_VBM8_01 + +# This is common in-line code for all spm8Batch script to make sure arguments were passed +. ${thisDir}/auxiliary/commonCode_checkIfArgsPassed + +# +# The actual function. +# + +. ${thisDir}/auxiliary/parse_arguments + +# + +. ${thisDir}/auxiliary/superDebugStatus + +# +# Ok - let's start displaying things back to the terminal +# + +. ${thisDir}/auxiliary/shellScriptInfo + +# +# Prepare to write the script. +# + +# Makes sure they speficied some subjects. +. ${thisDir}/auxiliary/checkInputForSubjects + +# Write out debug status +. ${thisDir}/auxiliary/debugStatus + +# Ok, lets do the business. + +# Print out the list of subjects that we operate upon. +. ${thisDir}/auxiliary/printSubjectsList + +# Now start building the automatic scripts. + +# +# the following environmental variables are from spm8Batch_Global +# +# HOSTCOMPUTER - name of the computer. +# SCRIPTNAME - name of the scripts to write. +# MATLABDIR - location of the scripts. +# UMBatchMatcher - present working directory. +# FULLSCRIPTNAME - full path and name of scripts to write. +# + +. ${thisDir}/auxiliary/vbm8_part_01 + +# Now build the list of directories for each subject. + +echo "UMImg2Warp = {..." >> ${FULLSCRIPTNAME}.m + +declare -i is +declare -i ii + +curDIR=`pwd` + +for (( is=1 ; is<=$nSubjects ; is++ )) +do + + cd ${UMBatchMaster}/${SUBJDIR}/${subjects[$is]}/ + # + # create the vbm8 directory. + # + + debugout "- - - - - - - - - - - - - -" $SuperDebugFLAG + debugout "mkdir -p ${fmriPATH}/${coregPATH}/" $SuperDebugFLAG + debugout "- - - - - - - - - - - - - -" $SuperDebugFLAG + mkdir -p ${fmriPATH}/${coregPATH}/ + debugout "- - - - - - - - - - - - - -" $SuperDebugFLAG + debugout "cd ${fmriPATH}/${coregPATH}/" $SuperDebugFLAG + debugout "- - - - - - - - - - - - - -" $SuperDebugFLAG + + . ${thisDir}/auxiliary/coregDirectoryErrorCheck + + # The hires is becoming the source, + + SOURCENAME=${HIRESNAME} + SOURCEEXT=${HIRESEXT} + + debugout "HiRes name is : ${SOURCENAME}" $SuperDebugFLAG + debugout "- - - - - - - - - - - - - - - -" $SuperDebugFLAG + + . ${thisDir}/auxiliary/vbm8FindSourceAndMove + + echo "'${SOURCEIMG}';..." >> ${FULLSCRIPTNAME}.m + +done + +echo " };" >> ${FULLSCRIPTNAME}.m + +echo + +. ${thisDir}/auxiliary/warpPrepOtherImages + +echo " 4) finalizing matlab scripts" + +cat ${thisDir}/parts/vbm8_part_02.m >> ${FULLSCRIPTNAME}.m + +echo " 5) building shell script" +echo + +# Now build the shell script command that will get launched into the background. + +# Common star to all shell scripts +. ${thisDir}/auxiliary/shellScriptStart + +# Add the matlab code to the shell script + +. ${thisDir}/auxiliary/shellScriptMATLABCall + +# Finalize the shell script. + +. ${thisDir}/auxiliary/shellScriptFinalize + +# Now launch into the background if desired. + +. ${thisDir}/auxiliary/shellScriptLaunch + +# +# all done. +# diff --git a/spm8Batch/warpfMRI b/spm8Batch/warpfMRI index 790a27f5..044947d5 100755 --- a/spm8Batch/warpfMRI +++ b/spm8Batch/warpfMRI @@ -37,7 +37,7 @@ thisDir=`dirname $theCommand` thisCommand=`echo $theCommand | awk -F/ '{print $NF}'` -allowedOptions="DdfhMntUvwz" +allowedOptions="DdfhIMntUvWwz" # This piece of code all of the spm8Batch scripts will use . ${thisDir}/auxiliary/commonCode_AllScriptsStart @@ -119,12 +119,21 @@ do . ${thisDir}/auxiliary/verifyTargetImage debugout "HiRes name is : ${TARGETIMG}" $SuperDebugFLAG + debugout "HiRes name is : ${HIRESNAME}" $SuperDebugFLAG debugout "- - - - - - - - - - - - - - - -" $SuperDebugFLAG - if [ ! -e "${UMBatchMaster}/${SUBJDIR}/${subjects[$is]}/${fmriPATH}/${coregPATH}/${HIRESNAME}_sn.mat" ] + # Check for the warping matrix (_sn.mat) or the deformation field (y_r). + + if [ "${WARPMETHOD}" -eq "1" ] + then + WARP_FILE=${UMBatchMaster}/${SUBJDIR}/${subjects[$is]}/${fmriPATH}/${coregPATH}/y_r${HIRESNAME}.nii + else + WARP_FILE=${UMBatchMaster}/${SUBJDIR}/${subjects[$is]}/${fmriPATH}/${coregPATH}/${HIRESNAME}_sn.mat + fi + if [ ! -e "${WARP_FILE}" ] then echo - echo "MISSING _sn.mat for ${subjects[$is]}" + echo "MISSING warping instuctions ${WARP_FILE} for ${subjects[$is]}" echo # # remove the sandbox if we made one. @@ -132,7 +141,6 @@ do ${thisDir}/auxiliary/remove_sandbox ${SANDBOXYES} ${SANDBOXPID} exit 1 fi - echo "'${TARGETIMG}';..." >> ${FULLSCRIPTNAME}.m done