From 806e6f8d6bb25c1024e6b2ae411952733508f754 Mon Sep 17 00:00:00 2001 From: "Daniel A. Kessler" Date: Tue, 11 Oct 2011 17:18:21 -0400 Subject: [PATCH 01/30] Wrote scaffold of new code --- svmbatch/README | 0 svmbatch/filelist1 | 0 svmbatch/filelist2 | 0 svmbatch/svmbatch.sh | 36 ++++++++++++++++++++++++++++++++++++ svmbatch/svmdir | 0 5 files changed, 36 insertions(+) create mode 100644 svmbatch/README create mode 100644 svmbatch/filelist1 create mode 100644 svmbatch/filelist2 create mode 100644 svmbatch/svmbatch.sh create mode 100644 svmbatch/svmdir diff --git a/svmbatch/README b/svmbatch/README new file mode 100644 index 00000000..e69de29b diff --git a/svmbatch/filelist1 b/svmbatch/filelist1 new file mode 100644 index 00000000..e69de29b diff --git a/svmbatch/filelist2 b/svmbatch/filelist2 new file mode 100644 index 00000000..e69de29b diff --git a/svmbatch/svmbatch.sh b/svmbatch/svmbatch.sh new file mode 100644 index 00000000..e0c3fd4b --- /dev/null +++ b/svmbatch/svmbatch.sh @@ -0,0 +1,36 @@ +#!/bin/sh + +#List of some useful variables + + +filelist1=`cat filelist1` +filelist2=`cat filelist2` +svmdir=`cat svmdir` + + + +3dbucket -sessiondir $svmdir -prefixname bucket1 $filelist1 +3dbucket -sessiondir $svmdir -prefixname bucket2 $filelist2 + +cd $svmdir + +3dbucket -prefixname bucket bucket1 bucket2 + +3dcalc -a bucket -expr "a" -prefixname shortbucket -datum short + +3dTcat -prefix timeshortbucket shortbucket + +for i in $filelist1 +do +echo 1 >>labels.1D +done + +for i in $filelist2 +do +echo 2 >> labels.1D +done + +3dAutomask timeshortbucket + +3dsvm -trainvol timeshortbucket -trainlabels labels.1D -mask automask -model model -bucket bucket + diff --git a/svmbatch/svmdir b/svmbatch/svmdir new file mode 100644 index 00000000..e69de29b From dfae375fd58ce18bf671a28ec8b4596cc42bb540 Mon Sep 17 00:00:00 2001 From: "Daniel A. Kessler" Date: Thu, 13 Oct 2011 14:31:45 -0400 Subject: [PATCH 02/30] First skeleton of svmbatch.sh written Fixed file references to include '+orig'. Successful test run through on garbage data Updated readme file --- svmbatch/README | 27 +++++++++++++++++++++++++++ svmbatch/svmbatch.sh | 33 ++++++++++++++++++++++----------- 2 files changed, 49 insertions(+), 11 deletions(-) diff --git a/svmbatch/README b/svmbatch/README index e69de29b..5d57114d 100644 --- a/svmbatch/README +++ b/svmbatch/README @@ -0,0 +1,27 @@ +SVM Batch + +Written 2011 by Daniel Kessler, kesslerd@umich.edu + +**Prerequisites** +This was code was written and tested in AFNI_2011_05_26_1457 + + +This batch script should not require any modification by you. Instead, you customize it by editing the support text files that come with it, namely: + +*svmdir +This file should contain a path to an extant directory where the script should store all of its intermediates and results + +*filelist1 +This should contain a whitespace-delimted list of (ideally absolute) paths to files that 3dsvm will consider to be examples of class 1. If you are giving it data from img/hdr pairs, be sure to point to the hdr (it will figure out where the img is based on the hdr). + +*filelist2 +Just like filelist1, except these are files that represent examples from class 2. + +That's it. Other support files may be added as we extend functionality. + + +**Likely future additions + +1) Automatic testing of model on training set +2) Automated partitioning of examples into training set and test set for model cross-validation +3) Permutation testing. This will be computationally intensive, but not too hard to implement. diff --git a/svmbatch/svmbatch.sh b/svmbatch/svmbatch.sh index e0c3fd4b..3908964e 100644 --- a/svmbatch/svmbatch.sh +++ b/svmbatch/svmbatch.sh @@ -1,24 +1,28 @@ -#!/bin/sh - -#List of some useful variables - +#!/bin/bash + +#Read in variable values from associated files filelist1=`cat filelist1` filelist2=`cat filelist2` svmdir=`cat svmdir` - - +#Build bucket files out of each of your conditions 3dbucket -sessiondir $svmdir -prefixname bucket1 $filelist1 3dbucket -sessiondir $svmdir -prefixname bucket2 $filelist2 +#Change to the svm working directory (presumably where this script was called from) cd $svmdir -3dbucket -prefixname bucket bucket1 bucket2 +#Combine your two class bucket files into one super bucket +3dbucket -prefixname bucket bucket1+orig bucket2+orig + +#Convert your bucket file to shorts +3dcalc -a bucket+orig -expr "a" -prefixname shortbucket -datum short -3dcalc -a bucket -expr "a" -prefixname shortbucket -datum short +#Convert your short bucket to be of type "time" (required by 3dsvm) +3dTcat -prefix timeshortbucket shortbucket+orig -3dTcat -prefix timeshortbucket shortbucket +#Build filelist by appending 1s or 2s to label file based on number in each class category for i in $filelist1 do @@ -30,7 +34,14 @@ do echo 2 >> labels.1D done -3dAutomask timeshortbucket +#Build a mask (in the future we may want to learn more about these options, or allow for specification of a custom mask +3dAutomask timeshortbucket+orig + +#Run your 3dsvm model +3dsvm -trainvol timeshortbucket+orig -trainlabels labels.1D -mask automask+orig -model model -bucket weightbucket -3dsvm -trainvol timeshortbucket -trainlabels labels.1D -mask automask -model model -bucket bucket +##To add: +#1) Model testing (on training data itself, be sure to use set detrend to no +#2) Ability to automatically split examples into training and test set, and do cross validation randomly +#3) Permutation tests (basically just a for loop with random permutation of labels file. Tricky thing is querying test model weights against giant population of permutation weights \ No newline at end of file From 8038ad4498f4a345d5caa5386378ecc75ed2dd3e Mon Sep 17 00:00:00 2001 From: "Daniel A. Kessler" Date: Mon, 24 Oct 2011 16:07:46 -0400 Subject: [PATCH 03/30] Added two functions to the shell script. 1] If directory specified by svmdir doesn't exist, it will attempt to make it for you. 2] If you give the script an additional argument of 1, it will run a leave-one-out crossvalidation for you. --- svmbatch/svmbatch.sh | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/svmbatch/svmbatch.sh b/svmbatch/svmbatch.sh index 3908964e..530a140d 100644 --- a/svmbatch/svmbatch.sh +++ b/svmbatch/svmbatch.sh @@ -6,6 +6,11 @@ filelist1=`cat filelist1` filelist2=`cat filelist2` svmdir=`cat svmdir` +if [ ! -d $svmdir ] +then + mkdir $svmdir +fi + #Build bucket files out of each of your conditions 3dbucket -sessiondir $svmdir -prefixname bucket1 $filelist1 3dbucket -sessiondir $svmdir -prefixname bucket2 $filelist2 @@ -38,8 +43,14 @@ done 3dAutomask timeshortbucket+orig #Run your 3dsvm model -3dsvm -trainvol timeshortbucket+orig -trainlabels labels.1D -mask automask+orig -model model -bucket weightbucket +if [ $1 == 1 ] +then + 3dsvm -trainvol timeshortbucket+orig -trainlabels labels.1D -mask automask+orig -model model -bucket weightbucket -x 1 + +else + 3dsvm -trainvol timeshortbucket+orig -trainlabels labels.1D -mask automask+orig -model model -bucket weightbucket +fi ##To add: #1) Model testing (on training data itself, be sure to use set detrend to no From 917b94c958813b3aa5930a16171002c34045c143 Mon Sep 17 00:00:00 2001 From: "Daniel A. Kessler" Date: Fri, 2 Dec 2011 12:56:57 -0500 Subject: [PATCH 04/30] Huge update to svmbatch. Added ability to do totem mode, significant rearrangement of argument/parameter processing, etc. --- svmbatch/svmbatch.sh | 88 +++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 82 insertions(+), 6 deletions(-) mode change 100644 => 100755 svmbatch/svmbatch.sh diff --git a/svmbatch/svmbatch.sh b/svmbatch/svmbatch.sh old mode 100644 new mode 100755 index 530a140d..14fa43f6 --- a/svmbatch/svmbatch.sh +++ b/svmbatch/svmbatch.sh @@ -1,7 +1,58 @@ #!/bin/bash - +#A program to perform SVM based only on lists of files + +#CONSTANTS + +#FUNCTIONS + +function totembatch { + #Given a filelist, suffixlist, and totem directory, loop over + #combinations of filelist and suffixlist, and build totems + + totemsuf=`cat totem.suf` + + for file in $1; do + totemlist= #Clear the totemlist variable. This will hold the list of all the subfiles going into your totem + for suf in $totemsuf; do + totemlist=`echo $totemlist $file/$suf` #loop over suffixes, and build up the list of subfiles + done + newname=`echo $file | sed 's:/:_:2g'` #edit the filename to have underscores instead of slashes, it will keep the temp directory cleaner + fslmerge -z $totemtemp/$newname $totemlist #use fsl to merge your subfiles in the z direction into totems + newname= + done +} + + +#Parameter Processing + +totem= +crossv= +totemtemp=/tmp/totems #Where to store your totem files/examples + + +while [ "$1" != "" ]; do + case $1 in + -t | --totem ) totem=1 #Operate in totem stacking mode + shift + #totemtemp=$1 + echo Running in Totem Mode + ;; + -c | --crossv ) crossv=1 #Will perform cross validation + + esac + shift +done + + +##Main Function + + + #Read in variable values from associated files + + + filelist1=`cat filelist1` filelist2=`cat filelist2` svmdir=`cat svmdir` @@ -11,6 +62,20 @@ then mkdir $svmdir fi +#if in totem mode + +if [ "$totem" == 1 ]; + then + mkdir $totemtemp + totembatch "$filelist1" + totembatch "$filelist2" + + filelist1=`cat filelist1 | sed -e 's:/:_:2g' -e 's:^:/'$totemtemp: -e 's:$:.hdr:'` #Update the filelist to point to where the totem-ed files are + filelist2=`cat filelist2 | sed -e 's:/:_:2g' -e 's:^:/'$totemtemp: -e 's:$:.hdr:'` + + +fi + #Build bucket files out of each of your conditions 3dbucket -sessiondir $svmdir -prefixname bucket1 $filelist1 3dbucket -sessiondir $svmdir -prefixname bucket2 $filelist2 @@ -42,16 +107,27 @@ done #Build a mask (in the future we may want to learn more about these options, or allow for specification of a custom mask 3dAutomask timeshortbucket+orig -#Run your 3dsvm model -if [ $1 == 1 ] +#maskrule="-mask automask+orig" +if [ "$totem" = "1" ] then - 3dsvm -trainvol timeshortbucket+orig -trainlabels labels.1D -mask automask+orig -model model -bucket weightbucket -x 1 + maskrule="-nomodelmask" +fi -else - 3dsvm -trainvol timeshortbucket+orig -trainlabels labels.1D -mask automask+orig -model model -bucket weightbucket +crossvrule="" +if [ "$crossv" = "1" ] +then + crossvrule="-x 1" +fi +#Run your 3dsvm model +3dsvm -trainvol timeshortbucket+orig -trainlabels labels.1D $maskrule -model model -bucket weightbucket $crossvrule + +if [ "$totem" = "1" ] #delete your temporary totem files, if they existed +then + rm $totemtemp -rf fi + ##To add: #1) Model testing (on training data itself, be sure to use set detrend to no #2) Ability to automatically split examples into training and test set, and do cross validation randomly From 074a764528238ed621ad6a0a3c1ab7442a0ecf1b Mon Sep 17 00:00:00 2001 From: "Daniel A. Kessler" Date: Mon, 5 Dec 2011 17:09:16 -0500 Subject: [PATCH 05/30] Added kernel and directory support to SVM batch options --- svmbatch/svmbatch.sh | 30 ++++++++++++++++++++++++------ 1 file changed, 24 insertions(+), 6 deletions(-) diff --git a/svmbatch/svmbatch.sh b/svmbatch/svmbatch.sh index 14fa43f6..c919752b 100755 --- a/svmbatch/svmbatch.sh +++ b/svmbatch/svmbatch.sh @@ -34,11 +34,17 @@ totemtemp=/tmp/totems #Where to store your totem files/examples while [ "$1" != "" ]; do case $1 in -t | --totem ) totem=1 #Operate in totem stacking mode - shift + #shift #totemtemp=$1 echo Running in Totem Mode ;; - -c | --crossv ) crossv=1 #Will perform cross validation + -c | --crossv ) crossv=1;; #Will perform cross validation + -k | --kernel ) kernelmode=1 #Kernel has been specified + shift + kernel=$1 + echo Kernel specified is $kernel + ;; + -d | --directory ) shift ; svmdir=$1 esac shift @@ -55,7 +61,11 @@ done filelist1=`cat filelist1` filelist2=`cat filelist2` -svmdir=`cat svmdir` + +if [ -f svmdir ] +then + svmdir=`cat svmdir` +fi if [ ! -d $svmdir ] then @@ -113,14 +123,21 @@ then maskrule="-nomodelmask" fi -crossvrule="" +crossvrule="-x 1" if [ "$crossv" = "1" ] then crossvrule="-x 1" fi +if [ "$kernelmode" = "1" ] #if running in kernel mode +then + kernelrule="-kernel $kernel" +else + kernelrule="-bucket weightbucket" +fi + #Run your 3dsvm model -3dsvm -trainvol timeshortbucket+orig -trainlabels labels.1D $maskrule -model model -bucket weightbucket $crossvrule +3dsvm -trainvol timeshortbucket+orig -trainlabels labels.1D $maskrule -model model $kernelrule $crossvrule if [ "$totem" = "1" ] #delete your temporary totem files, if they existed then @@ -128,7 +145,8 @@ then fi + ##To add: #1) Model testing (on training data itself, be sure to use set detrend to no #2) Ability to automatically split examples into training and test set, and do cross validation randomly -#3) Permutation tests (basically just a for loop with random permutation of labels file. Tricky thing is querying test model weights against giant population of permutation weights \ No newline at end of file +#3) Permutation tests (basically just a for loop with random permutation of labels file. Tricky thing is querying test model weights against giant population of permutation weights From 6c58471d59c758956ab154b914c8410d7ff16802 Mon Sep 17 00:00:00 2001 From: "Daniel A. Kessler" Date: Fri, 2 Dec 2011 16:20:23 -0500 Subject: [PATCH 06/30] Added totem.suf (but currently dirty, contains examples of my data --- svmbatch/totem.suf | 2 ++ 1 file changed, 2 insertions(+) create mode 100644 svmbatch/totem.suf diff --git a/svmbatch/totem.suf b/svmbatch/totem.suf new file mode 100644 index 00000000..54b5d447 --- /dev/null +++ b/svmbatch/totem.suf @@ -0,0 +1,2 @@ +/con_0003 +/con_0004 From b7d09489132097d815a79fb3ed2ef10bbf0ee4e5 Mon Sep 17 00:00:00 2001 From: "Daniel A. Kessler" Date: Mon, 12 Dec 2011 10:39:22 -0500 Subject: [PATCH 07/30] Updated options (and updated options support to default to more reasonable settings for older, non-totem and linear applications. --- svmbatch/svmbatch.sh | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/svmbatch/svmbatch.sh b/svmbatch/svmbatch.sh index c919752b..85cc2dd1 100755 --- a/svmbatch/svmbatch.sh +++ b/svmbatch/svmbatch.sh @@ -44,7 +44,8 @@ while [ "$1" != "" ]; do kernel=$1 echo Kernel specified is $kernel ;; - -d | --directory ) shift ; svmdir=$1 + -d | --directory ) shift ; svmdir=$1;; + --nomodelmask ) nomodelmask=1;; esac shift @@ -117,13 +118,13 @@ done #Build a mask (in the future we may want to learn more about these options, or allow for specification of a custom mask 3dAutomask timeshortbucket+orig -#maskrule="-mask automask+orig" -if [ "$totem" = "1" ] +maskrule="-mask automask+orig" +if [ "$totem" = "1" | "$nomodelmask" = "1" ] then maskrule="-nomodelmask" fi -crossvrule="-x 1" +crossvrule="" if [ "$crossv" = "1" ] then crossvrule="-x 1" From b0b03344139d13d41dff8f4f96797ad1ce345269 Mon Sep 17 00:00:00 2001 From: "Daniel A. Kessler" Date: Mon, 12 Dec 2011 16:51:15 -0500 Subject: [PATCH 08/30] Huge rewrite. Everything in functional form now. Currently, main functionality is broken until it gets written back in. Hardcoded for crossval, which probably doesn't work anyway --- svmbatch/svmbatch.sh | 67 ++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 64 insertions(+), 3 deletions(-) diff --git a/svmbatch/svmbatch.sh b/svmbatch/svmbatch.sh index 85cc2dd1..dc4747b2 100755 --- a/svmbatch/svmbatch.sh +++ b/svmbatch/svmbatch.sh @@ -24,6 +24,8 @@ function totembatch { } + + #Parameter Processing totem= @@ -38,7 +40,8 @@ while [ "$1" != "" ]; do #totemtemp=$1 echo Running in Totem Mode ;; - -c | --crossv ) crossv=1;; #Will perform cross validation + -c | --crossv ) crossv=1;; #Will perform cross validation per SVM-light + -C | --CROSSV ) scrossv=1;; #will do super cross validation (per dan) -k | --kernel ) kernelmode=1 #Kernel has been specified shift kernel=$1 @@ -58,7 +61,7 @@ done #Read in variable values from associated files - +function svm_prep { filelist1=`cat filelist1` filelist2=`cat filelist2` @@ -73,6 +76,12 @@ then mkdir $svmdir fi +} + + + +function totem_build { + #if in totem mode if [ "$totem" == 1 ]; @@ -86,6 +95,9 @@ if [ "$totem" == 1 ]; fi +} + +function afni_build{ #Build bucket files out of each of your conditions 3dbucket -sessiondir $svmdir -prefixname bucket1 $filelist1 @@ -102,7 +114,9 @@ cd $svmdir #Convert your short bucket to be of type "time" (required by 3dsvm) 3dTcat -prefix timeshortbucket shortbucket+orig +} +function label_build { #Build filelist by appending 1s or 2s to label file based on number in each class category for i in $filelist1 @@ -114,10 +128,14 @@ for i in $filelist2 do echo 2 >> labels.1D done +} +function mask_build { #Build a mask (in the future we may want to learn more about these options, or allow for specification of a custom mask 3dAutomask timeshortbucket+orig +} +function setrules { maskrule="-mask automask+orig" if [ "$totem" = "1" | "$nomodelmask" = "1" ] then @@ -136,15 +154,58 @@ then else kernelrule="-bucket weightbucket" fi +} +function svm_train { #Run your 3dsvm model -3dsvm -trainvol timeshortbucket+orig -trainlabels labels.1D $maskrule -model model $kernelrule $crossvrule +3dsvm \ +-trainvol timeshortbucket+orig\ +-trainlabels labels.1D\ +$maskrule -model \ +model \ +$kernelrule \ +$crossvrule if [ "$totem" = "1" ] #delete your temporary totem files, if they existed then rm $totemtemp -rf fi +} + + +function main { +svm_prep +totem_build +afni_build +label_build +mask_build +setrules +svm_train +} + +#Super looper down here? + +#main #If nothing special, just run it I guess? + +svmdir_orig=echo $svmdir +filelist1_orig=echo "$filelist1" +filelist2_orig=echo "$filelist2" + +biglist=`cat filelist1 filelist2` +for file in $biglist +do +filename=`cat $file | sed -e 's:/:_:2g' ` +svmdir= echo $svmdir/$filename +filelist1=`echo "$filelist1" | sed "/$file/ d" ` +filelist2=`echo "$filelist2" | sed "/$file/ d" ` + +totem_build +afni_build +label_build +mask_build +setrules +svm_train ##To add: From b286e6acb8fd113083ba87d05584e7619d8116ea Mon Sep 17 00:00:00 2001 From: "Daniel A. Kessler" Date: Tue, 13 Dec 2011 11:26:40 -0500 Subject: [PATCH 09/30] Cleaned up functional rewrite --- svmbatch/svmbatch.sh | 134 +++++++++++++++++++++++++------------------ 1 file changed, 77 insertions(+), 57 deletions(-) diff --git a/svmbatch/svmbatch.sh b/svmbatch/svmbatch.sh index dc4747b2..77dd9c81 100755 --- a/svmbatch/svmbatch.sh +++ b/svmbatch/svmbatch.sh @@ -10,17 +10,17 @@ function totembatch { #Given a filelist, suffixlist, and totem directory, loop over #combinations of filelist and suffixlist, and build totems - totemsuf=`cat totem.suf` - - for file in $1; do - totemlist= #Clear the totemlist variable. This will hold the list of all the subfiles going into your totem - for suf in $totemsuf; do - totemlist=`echo $totemlist $file/$suf` #loop over suffixes, and build up the list of subfiles - done - newname=`echo $file | sed 's:/:_:2g'` #edit the filename to have underscores instead of slashes, it will keep the temp directory cleaner - fslmerge -z $totemtemp/$newname $totemlist #use fsl to merge your subfiles in the z direction into totems - newname= +totemsuf=`cat totem.suf` + +for file in $1; do + totemlist= #Clear the totemlist variable. This will hold the list of all the subfiles going into your totem + for suf in $totemsuf; do + totemlist=`echo $totemlist $file/$suf` #loop over suffixes, and build up the list of subfiles done + newname=`echo $file | sed 's:/:_:2g'` #edit the filename to have underscores instead of slashes, it will keep the temp directory cleaner + fslmerge -z $totemtemp/$newname $totemlist #use fsl to merge your subfiles in the z direction into totems + newname= +done } @@ -33,27 +33,42 @@ crossv= totemtemp=/tmp/totems #Where to store your totem files/examples + + + + while [ "$1" != "" ]; do case $1 in - -t | --totem ) totem=1 #Operate in totem stacking mode - #shift - #totemtemp=$1 - echo Running in Totem Mode - ;; - -c | --crossv ) crossv=1;; #Will perform cross validation per SVM-light - -C | --CROSSV ) scrossv=1;; #will do super cross validation (per dan) - -k | --kernel ) kernelmode=1 #Kernel has been specified - shift - kernel=$1 - echo Kernel specified is $kernel - ;; - -d | --directory ) shift ; svmdir=$1;; - --nomodelmask ) nomodelmask=1;; - + -t | --totem ) + totem=1 #Operate in totem stacking mode + #shift + #totemtemp=$1 + echo Running in Totem Mode + ;; + -c | --crossv ) + crossv=1 + ;; #Will perform cross validation per SVM-light + -C | --CROSSV ) + scrossv=1 + ;; #will do super cross validation (per dan) + -k | --kernel ) + kernelmode=1 #Kernel has been specified + shift + kernel=$1 + echo Kernel specified is $kernel + ;; + -d | --directory ) + shift + svmdir=$1 + ;; + --nomodelmask ) + nomodelmask=1 + ;; + esac shift done - + ##Main Function @@ -67,12 +82,12 @@ filelist1=`cat filelist1` filelist2=`cat filelist2` if [ -f svmdir ] -then + then svmdir=`cat svmdir` fi if [ ! -d $svmdir ] -then + then mkdir $svmdir fi @@ -84,7 +99,7 @@ function totem_build { #if in totem mode -if [ "$totem" == 1 ]; +if [ "$totem" == 1 ]; then mkdir $totemtemp totembatch "$filelist1" @@ -120,13 +135,13 @@ function label_build { #Build filelist by appending 1s or 2s to label file based on number in each class category for i in $filelist1 -do -echo 1 >>labels.1D + do + echo 1 >>labels.1D done for i in $filelist2 -do -echo 2 >> labels.1D + do + echo 2 >> labels.1D done } @@ -138,36 +153,36 @@ function mask_build { function setrules { maskrule="-mask automask+orig" if [ "$totem" = "1" | "$nomodelmask" = "1" ] -then + then maskrule="-nomodelmask" fi crossvrule="" if [ "$crossv" = "1" ] -then + then crossvrule="-x 1" fi if [ "$kernelmode" = "1" ] #if running in kernel mode -then - kernelrule="-kernel $kernel" + then + kernelrule="-kernel $kernel" else - kernelrule="-bucket weightbucket" + kernelrule="-bucket weightbucket" fi } function svm_train { #Run your 3dsvm model 3dsvm \ --trainvol timeshortbucket+orig\ --trainlabels labels.1D\ + -trainvol timeshortbucket+orig\ + -trainlabels labels.1D\ $maskrule -model \ -model \ -$kernelrule \ -$crossvrule + model \ + $kernelrule \ + $crossvrule if [ "$totem" = "1" ] #delete your temporary totem files, if they existed -then + then rm $totemtemp -rf fi @@ -194,20 +209,25 @@ filelist2_orig=echo "$filelist2" biglist=`cat filelist1 filelist2` for file in $biglist -do -filename=`cat $file | sed -e 's:/:_:2g' ` -svmdir= echo $svmdir/$filename -filelist1=`echo "$filelist1" | sed "/$file/ d" ` -filelist2=`echo "$filelist2" | sed "/$file/ d" ` - -totem_build -afni_build -label_build -mask_build -setrules -svm_train - + do + curdir=`echo $file | sed -e 's:/:_:2g' ` + svmdir= echo $svmdir/$curdir + filelist1=`echo "$filelist1" | sed "/$file/ d" ` + filelist2=`echo "$filelist2" | sed "/$file/ d" ` + + echo "$svmdir" + echo "$filelist1" + echo "$filelist2" + +# totem_build +# afni_build +# label_build +# mask_build +# setrules +# svm_train +done + ##To add: #1) Model testing (on training data itself, be sure to use set detrend to no #2) Ability to automatically split examples into training and test set, and do cross validation randomly From f27a9ab87b5857d14403dd424a44e06b2dd033ac Mon Sep 17 00:00:00 2001 From: "Daniel A. Kessler" Date: Wed, 14 Dec 2011 12:38:19 -0500 Subject: [PATCH 10/30] Huge functional rewrite of svmbatch code --- svmbatch/svmbatch.sh | 216 +++++++++++++++++++++++++++++++------------ 1 file changed, 157 insertions(+), 59 deletions(-) diff --git a/svmbatch/svmbatch.sh b/svmbatch/svmbatch.sh index 77dd9c81..65993e0d 100755 --- a/svmbatch/svmbatch.sh +++ b/svmbatch/svmbatch.sh @@ -4,24 +4,6 @@ #CONSTANTS -#FUNCTIONS - -function totembatch { - #Given a filelist, suffixlist, and totem directory, loop over - #combinations of filelist and suffixlist, and build totems - -totemsuf=`cat totem.suf` - -for file in $1; do - totemlist= #Clear the totemlist variable. This will hold the list of all the subfiles going into your totem - for suf in $totemsuf; do - totemlist=`echo $totemlist $file/$suf` #loop over suffixes, and build up the list of subfiles - done - newname=`echo $file | sed 's:/:_:2g'` #edit the filename to have underscores instead of slashes, it will keep the temp directory cleaner - fslmerge -z $totemtemp/$newname $totemlist #use fsl to merge your subfiles in the z direction into totems - newname= -done -} @@ -70,13 +52,61 @@ while [ "$1" != "" ]; do done -##Main Function +#FUNCTIONS + +function totem_build { # + +#if in totem mode + +if [ "$totem" == 1 ]; + then + mkdir $totemtemp + totembatch "$filelist1" + totembatch "$filelist2" + + filelist1= `hdr_append `prepend $totemtemp `slash_strip "$filelist1"` ` ` + filelist2= `hdr_append `prepend $totemtemp `slash_strip "$filelist2"` ` ` + + #filelist1=`cat filelist1 | sed -e 's:/:_:2g' -e 's:^:/'$totemtemp: -e 's:$:.hdr:'` #Update the filelist to point to where the totem-ed files are + #filelist2=`cat filelist2 | sed -e 's:/:_:2g' -e 's:^:/'$totemtemp: -e 's:$:.hdr:'` + + +fi +} + +function totembatch { #Read totem.suf, mk totemtemp, assemble totems, update filelist to point to totems + +totemsuf=`cat totem.suf` + +mkdir $totemtemp + +function totem_build { + +for file in $1; do + totemlist= #Clear totemlist. Holds names of files to go into totem + newname= #Clear newname. Holds name of target totem + for suf in $totemsuf; do + totemlist=`echo $totemlist $file/$suf` #loop over suffixes, and build up the list of subfiles + done + newname=`slash_strip $file` + fslmerge -z $totemtemp/$newname $totemlist #use fsl to merge your subfiles in the z direction into totems + newname= +done +} + +totem_build $filelist1 #Quoting doesn't matter here for list ops +totem_build $filelist2 #And function will not quote anyway + +filelist1=`hdr_append \`prepend $totemtemp \\\`slash_strip "$filelist1" \\\` \` ` +filelist2=`hdr_append \`prepend $totemtemp \\\`slash_strip "$filelist2" \\\` \` ` +} + #Read in variable values from associated files -function svm_prep { +function svm_prep { #Read in filelists, svmdir, totem.suf and make svmdir filelist1=`cat filelist1` filelist2=`cat filelist2` @@ -91,31 +121,84 @@ if [ ! -d $svmdir ] mkdir $svmdir fi +if [ "$totem" = "1" ]; thhen totemlist= #Clear the totemlist variable. This will hold the list of all the subfiles going into your totem + for suf in $totemsuf; + do + totemlist=`echo $totemlist $file/$suf` #loop over suffixes, and build up the list of subfiles + done + newname=`echo $file | sed 's:/:_:2g'` #edit the filename to have underscores instead of slashes, it will keep the temp directory cleaner + fslmerge -z $totemtemp/$newname $totemlist #use fsl to merge your subfiles in the z direction into totems + newname= + done } +#Read in variable values from associated files -function totem_build { +function svm_prep { #Read in filelists, svmdir, and make svmdir -#if in totem mode +filelist1=`cat filelist1` +filelist2=`cat filelist2` -if [ "$totem" == 1 ]; +if [ -f svmdir ] then - mkdir $totemtemp - totembatch "$filelist1" - totembatch "$filelist2" + svmdir=`cat svmdir` +fi - filelist1=`cat filelist1 | sed -e 's:/:_:2g' -e 's:^:/'$totemtemp: -e 's:$:.hdr:'` #Update the filelist to point to where the totem-ed files are - filelist2=`cat filelist2 | sed -e 's:/:_:2g' -e 's:^:/'$totemtemp: -e 's:$:.hdr:'` +if [ ! -d $svmdir ] + then + mkdir $svmdir +fi -fi + +} + +function slash_strip { #Strip all slashes off $1,prepend slash +echo "$1" | sed -e 's:/:_:g' -e 's:^:/:' +} + +function prepend { #Will prepend $1 to all of $2 +echo "$2" | sed "s:^:/$1:" +} + +function hdr_append { #Add .hdr to end of $1 +echo "$1" | sed "s:$:.hdr:" +} + +function hdr_strip { #Remove all instances of .hdr from $1 +echo "$1" | sed "s:.hdr::" +} + +function afni_bucket_build { #Build converted bucket files from list $1 +3dbucket -sessiondir $svmdir -prefixname bucket$2 $1 +} + +function afni_bucket_combine { #Combine buckets specified in $1, name them $2 +cd $svmdir + +bucketlist= +for bucket in $1; do + bucketlist=`echo $bucketlist $bucket+orig ` +done + +3dbucket -prefixname $2 $bucketlist +} + +function afni_bucket_short { #Convert bucket specified in $1 to short, named by $2 +cd $svmdir +3dcalc -a $1+orig -expr "a" -prefixname $2 -datum short +} + +function afni_bucket_time { #convert bucket in $1 to be of type time, named $2 +cd $svmdir +3dTcat -prefix $2 $1+orig } -function afni_build{ +function afni_build { #Build bucket files from list in $1, name suf $2 (convert, combine, calc, timeify) #Build bucket files out of each of your conditions -3dbucket -sessiondir $svmdir -prefixname bucket1 $filelist1 +3dbucket -sessiondir $svmdir -prefixname bucket$2 $1 3dbucket -sessiondir $svmdir -prefixname bucket2 $filelist2 #Change to the svm working directory (presumably where this script was called from) @@ -131,8 +214,7 @@ cd $svmdir 3dTcat -prefix timeshortbucket shortbucket+orig } -function label_build { -#Build filelist by appending 1s or 2s to label file based on number in each class category +function label_build { #Make label file for i in $filelist1 do @@ -145,49 +227,59 @@ for i in $filelist2 done } -function mask_build { -#Build a mask (in the future we may want to learn more about these options, or allow for specification of a custom mask +function mask_build { #Build automask 3dAutomask timeshortbucket+orig } -function setrules { +function set_train_rules { #Set rules for 3dsvm training based on options maskrule="-mask automask+orig" -if [ "$totem" = "1" | "$nomodelmask" = "1" ] - then +if [ "$totem" = "1" | "$nomodelmask" = "1" ]; then maskrule="-nomodelmask" fi crossvrule="" -if [ "$crossv" = "1" ] - then +if [ "$crossv" = "1" ]; then crossvrule="-x 1" fi -if [ "$kernelmode" = "1" ] #if running in kernel mode - then +kernelrule="-bucket weightbucket" +if [ "$kernelmode" = "1" ]; then #if running in kernel mode kernelrule="-kernel $kernel" -else - kernelrule="-bucket weightbucket" fi } -function svm_train { +function svm_train { #Train on timeshort labeled in $1 #Run your 3dsvm model 3dsvm \ - -trainvol timeshortbucket+orig\ + -trainvol $1+orig\ -trainlabels labels.1D\ -$maskrule -model \ + $maskrule -model \ model \ $kernelrule \ $crossvrule -if [ "$totem" = "1" ] #delete your temporary totem files, if they existed +} + +function totem_clean { #delete your temporary totem files, if they existed +if [ "$totem" = "1" ] then rm $totemtemp -rf fi } +function set_test_rules { #Set rules for 3dsvm testing based on options + +function svm_test { #Test model #1 against volume #2 +3dsvm \ + -model $1 \ + -testvol $2 \ + -predictions $pname\ + -nodetrend + +} + + function main { svm_prep @@ -199,25 +291,30 @@ setrules svm_train } + + #Super looper down here? #main #If nothing special, just run it I guess? -svmdir_orig=echo $svmdir -filelist1_orig=echo "$filelist1" -filelist2_orig=echo "$filelist2" +svm_prep + +svmdir_orig=$svmdir +filelist1_orig="$filelist1" +filelist2_orig="$filelist2" + -biglist=`cat filelist1 filelist2` +biglist=`echo -e "$filelist1\n$filelist1"` #Concatenate your two lists for file in $biglist do - curdir=`echo $file | sed -e 's:/:_:2g' ` - svmdir= echo $svmdir/$curdir - filelist1=`echo "$filelist1" | sed "/$file/ d" ` - filelist2=`echo "$filelist2" | sed "/$file/ d" ` + curdir=`hdr_strip \`slash_strip $file \` ` + svmdir=`echo $svmdir_orig/$curdir` + filelist1=`echo "$filelist1" | sed "\:$file: d" ` #Because our $file has tons of slashes, we use : as the delimeter + filelist2=`echo "$filelist2" | sed "\:$file: d" ` echo "$svmdir" - echo "$filelist1" - echo "$filelist2" +# echo "$filelist1" + # echo "$filelist2" # totem_build # afni_build @@ -227,8 +324,9 @@ for file in $biglist # svm_train done - + ##To add: #1) Model testing (on training data itself, be sure to use set detrend to no #2) Ability to automatically split examples into training and test set, and do cross validation randomly #3) Permutation tests (basically just a for loop with random permutation of labels file. Tricky thing is querying test model weights against giant population of permutation weights + From 90c39931e7eed40d2b712a5309d72412353e8580 Mon Sep 17 00:00:00 2001 From: "Daniel A. Kessler" Date: Wed, 14 Dec 2011 12:05:06 -0500 Subject: [PATCH 11/30] More updates. About to start testing --- svmbatch/svmbatch.sh | 171 +++++++++++++++---------------------------- 1 file changed, 58 insertions(+), 113 deletions(-) diff --git a/svmbatch/svmbatch.sh b/svmbatch/svmbatch.sh index 65993e0d..b5f63f8e 100755 --- a/svmbatch/svmbatch.sh +++ b/svmbatch/svmbatch.sh @@ -15,10 +15,6 @@ crossv= totemtemp=/tmp/totems #Where to store your totem files/examples - - - - while [ "$1" != "" ]; do case $1 in -t | --totem ) @@ -56,34 +52,11 @@ done #FUNCTIONS -function totem_build { # - -#if in totem mode - -if [ "$totem" == 1 ]; - then - mkdir $totemtemp - totembatch "$filelist1" - totembatch "$filelist2" - - filelist1= `hdr_append `prepend $totemtemp `slash_strip "$filelist1"` ` ` - filelist2= `hdr_append `prepend $totemtemp `slash_strip "$filelist2"` ` ` - - #filelist1=`cat filelist1 | sed -e 's:/:_:2g' -e 's:^:/'$totemtemp: -e 's:$:.hdr:'` #Update the filelist to point to where the totem-ed files are - #filelist2=`cat filelist2 | sed -e 's:/:_:2g' -e 's:^:/'$totemtemp: -e 's:$:.hdr:'` - - -fi -} function totembatch { #Read totem.suf, mk totemtemp, assemble totems, update filelist to point to totems - totemsuf=`cat totem.suf` - mkdir $totemtemp - function totem_build { - for file in $1; do totemlist= #Clear totemlist. Holds names of files to go into totem newname= #Clear newname. Holds name of target totem @@ -95,63 +68,23 @@ for file in $1; do newname= done } - totem_build $filelist1 #Quoting doesn't matter here for list ops totem_build $filelist2 #And function will not quote anyway - -filelist1=`hdr_append \`prepend $totemtemp \\\`slash_strip "$filelist1" \\\` \` ` +filelist1=`hdr_append \`prepend $totemtemp \\\`slash_strip "$filelist1" \\\` \` ` #update names to point at totems filelist2=`hdr_append \`prepend $totemtemp \\\`slash_strip "$filelist2" \\\` \` ` } -#Read in variable values from associated files - -function svm_prep { #Read in filelists, svmdir, totem.suf and make svmdir - -filelist1=`cat filelist1` -filelist2=`cat filelist2` - -if [ -f svmdir ] - then - svmdir=`cat svmdir` -fi - -if [ ! -d $svmdir ] - then - mkdir $svmdir -fi - -if [ "$totem" = "1" ]; thhen totemlist= #Clear the totemlist variable. This will hold the list of all the subfiles going into your totem - for suf in $totemsuf; - do - totemlist=`echo $totemlist $file/$suf` #loop over suffixes, and build up the list of subfiles - done - newname=`echo $file | sed 's:/:_:2g'` #edit the filename to have underscores instead of slashes, it will keep the temp directory cleaner - fslmerge -z $totemtemp/$newname $totemlist #use fsl to merge your subfiles in the z direction into totems - newname= - done -} - - -#Read in variable values from associated files - function svm_prep { #Read in filelists, svmdir, and make svmdir - filelist1=`cat filelist1` filelist2=`cat filelist2` - -if [ -f svmdir ] - then +if [ -f svmdir ]; then svmdir=`cat svmdir` fi -if [ ! -d $svmdir ] - then +if [ ! -d $svmdir ]; then mkdir $svmdir fi - - - } function slash_strip { #Strip all slashes off $1,prepend slash @@ -170,8 +103,8 @@ function hdr_strip { #Remove all instances of .hdr from $1 echo "$1" | sed "s:.hdr::" } -function afni_bucket_build { #Build converted bucket files from list $1 -3dbucket -sessiondir $svmdir -prefixname bucket$2 $1 +function afni_bucket_build { #Build converted bucket files from list $1, named $2 +3dbucket -sessiondir $svmdir -prefixname $2 $1 } function afni_bucket_combine { #Combine buckets specified in $1, name them $2 @@ -251,15 +184,27 @@ fi function svm_train { #Train on timeshort labeled in $1 #Run your 3dsvm model 3dsvm \ - -trainvol $1+orig\ - -trainlabels labels.1D\ - $maskrule -model \ - model \ + -trainvol $1+orig \ + -trainlabels labels.1D \ + $maskrule \ + -model model \ $kernelrule \ $crossvrule } +function svm_batchtrain { #Based on curval of $filelists and $svmdir, does all the lifting +afni_bucket_build "$filelist1" "bucket1" +afni_bucket_build "$filelist2" "bucket2" +afni_bucket_combine "bucket1 bucket2" "bucket" +afni_bucket_short "bucket" "bucketshort" +afni_bucket_time "bucketshort" "bucketshorttime" +label_build +set_train_rules +svm_train "bucketshorttime" +} + + function totem_clean { #delete your temporary totem files, if they existed if [ "$totem" = "1" ] then @@ -269,60 +214,60 @@ fi } function set_test_rules { #Set rules for 3dsvm testing based on options +echo You need to finish this one Dan +} -function svm_test { #Test model #1 against volume #2 +function svm_test { #Test model $1 against volume $2 3dsvm \ - -model $1 \ - -testvol $2 \ + -model $1+orig \ + -testvol $2+orig \ -predictions $pname\ -nodetrend } +function svm_batchtest { #Test model $1 against constructed volume based on hdrs in $2 +afni_bucket_build "$1" "testbucket" +afni_bucket_short "testbucket" "testbucketshort" +afni_bucket_time "testbucketshort" "testbucketshorttime" +set_test_rukes +svm_test $1 "testbucketshorttime" +} +function super_crossvalid { #no arguments. Performs LOO-CV manually, and saved predictions +svmdir_orig=$svmdir +filelist1_orig=$filelist1 +filelist2_orig=$filelist2 + +biglist=`echo -e "$filelist1\n$filelist2"` +for file in $filelist; do + echo "Now working on LOOCV for $file" + pname="pred" #this is the file predictions will get written to. file specific will be better + loodir=`hdr_strip \`slash_strip $file \` ` #Make file into a dirname + svmdir=`echo $svmdir_orig/LOOCV/$loodir ` #build a dir from loodir and svmdir_orig + filelist1=`echo "$filelist1" | sed "\:$file: d" ` #remove $file from filelist1 + filelist2=`echo "$filelist2" | sed "\:$file: d" ` #remove $file from filelist2 + svm_batchtrain #train up a model based on the updated filelist and svmdir + svm_batchtest "model" "$file" +done function main { svm_prep totem_build -afni_build -label_build -mask_build -setrules -svm_train -} - +if [ "$CROSSV" != "1" ]; then + echo "Training one and only model" + svm_batchtrain +else + echo "Entering Super Cross Validation Mode!" + super_crossvalid +fi -#Super looper down here? - -#main #If nothing special, just run it I guess? - -svm_prep +} -svmdir_orig=$svmdir -filelist1_orig="$filelist1" -filelist2_orig="$filelist2" +main -biglist=`echo -e "$filelist1\n$filelist1"` #Concatenate your two lists -for file in $biglist - do - curdir=`hdr_strip \`slash_strip $file \` ` - svmdir=`echo $svmdir_orig/$curdir` - filelist1=`echo "$filelist1" | sed "\:$file: d" ` #Because our $file has tons of slashes, we use : as the delimeter - filelist2=`echo "$filelist2" | sed "\:$file: d" ` - - echo "$svmdir" -# echo "$filelist1" - # echo "$filelist2" - -# totem_build -# afni_build -# label_build -# mask_build -# setrules -# svm_train -done ##To add: From 3abb1cef8b27f298d84ba2995a5cca3ca30a195d Mon Sep 17 00:00:00 2001 From: "Daniel A. Kessler" Date: Wed, 14 Dec 2011 12:27:01 -0500 Subject: [PATCH 12/30] Testing completed on new functional form --- svmbatch/svmbatch.sh | 24 +++++++++++++++++------- 1 file changed, 17 insertions(+), 7 deletions(-) diff --git a/svmbatch/svmbatch.sh b/svmbatch/svmbatch.sh index b5f63f8e..bdea64b9 100755 --- a/svmbatch/svmbatch.sh +++ b/svmbatch/svmbatch.sh @@ -49,7 +49,6 @@ done - #FUNCTIONS @@ -104,7 +103,7 @@ echo "$1" | sed "s:.hdr::" } function afni_bucket_build { #Build converted bucket files from list $1, named $2 -3dbucket -sessiondir $svmdir -prefixname $2 $1 +3dbucket -sessiondir $svmdir -prefixname $2 $1 2>/dev/null } function afni_bucket_combine { #Combine buckets specified in $1, name them $2 @@ -166,7 +165,7 @@ function mask_build { #Build automask function set_train_rules { #Set rules for 3dsvm training based on options maskrule="-mask automask+orig" -if [ "$totem" = "1" | "$nomodelmask" = "1" ]; then +if [ "$totem" = "1" -o "$nomodelmask" = "1" ]; then maskrule="-nomodelmask" fi @@ -227,7 +226,7 @@ function svm_test { #Test model $1 against volume $2 } function svm_batchtest { #Test model $1 against constructed volume based on hdrs in $2 -afni_bucket_build "$1" "testbucket" +afni_bucket_build "$2" "testbucket" afni_bucket_short "testbucket" "testbucketshort" afni_bucket_time "testbucketshort" "testbucketshorttime" set_test_rukes @@ -239,23 +238,34 @@ svmdir_orig=$svmdir filelist1_orig=$filelist1 filelist2_orig=$filelist2 +mkdir $svmdir_orig/LOOCV/ + biglist=`echo -e "$filelist1\n$filelist2"` -for file in $filelist; do +for file in $biglist; do echo "Now working on LOOCV for $file" - pname="pred" #this is the file predictions will get written to. file specific will be better + pname="$file" #this is the file predictions will get written to. file specific will be better loodir=`hdr_strip \`slash_strip $file \` ` #Make file into a dirname + pname=`echo "$loodir" | sed 's:/::'` svmdir=`echo $svmdir_orig/LOOCV/$loodir ` #build a dir from loodir and svmdir_orig filelist1=`echo "$filelist1" | sed "\:$file: d" ` #remove $file from filelist1 filelist2=`echo "$filelist2" | sed "\:$file: d" ` #remove $file from filelist2 svm_batchtrain #train up a model based on the updated filelist and svmdir svm_batchtest "model" "$file" done +} function main { svm_prep + +if [ "$totem" = "1" ]; then + totem_build + +fi + + -if [ "$CROSSV" != "1" ]; then +if [ "$scrossv" != "1" ]; then echo "Training one and only model" svm_batchtrain else From 2ae54f237fde4d42895534452eaab53bfbbd084f Mon Sep 17 00:00:00 2001 From: "Daniel A. Kessler" Date: Wed, 14 Dec 2011 13:07:41 -0500 Subject: [PATCH 13/30] Removed dirty lines from sample totem.suf --- svmbatch/totem.suf | 2 -- 1 file changed, 2 deletions(-) diff --git a/svmbatch/totem.suf b/svmbatch/totem.suf index 54b5d447..e69de29b 100644 --- a/svmbatch/totem.suf +++ b/svmbatch/totem.suf @@ -1,2 +0,0 @@ -/con_0003 -/con_0004 From 41042786ab2e0c754a953eda0bf9fed65241d56c Mon Sep 17 00:00:00 2001 From: "Daniel A. Kessler" Date: Wed, 14 Dec 2011 13:12:34 -0500 Subject: [PATCH 14/30] Fixed errors around totem mode --- svmbatch/svmbatch.sh | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/svmbatch/svmbatch.sh b/svmbatch/svmbatch.sh index bdea64b9..494a7b99 100755 --- a/svmbatch/svmbatch.sh +++ b/svmbatch/svmbatch.sh @@ -52,7 +52,7 @@ done #FUNCTIONS -function totembatch { #Read totem.suf, mk totemtemp, assemble totems, update filelist to point to totems +function totem_batch { #Read totem.suf, mk totemtemp, assemble totems, update filelist to point to totems totemsuf=`cat totem.suf` mkdir $totemtemp function totem_build { @@ -259,7 +259,7 @@ svm_prep if [ "$totem" = "1" ]; then -totem_build +totem_batch fi @@ -273,6 +273,12 @@ else super_crossvalid fi +if [ "$totem" = "1" ]; then + +totem_clean + +fi + } From 7e27b7ac06482acc32cbdb78275cfa0a77994b9e Mon Sep 17 00:00:00 2001 From: "Daniel A. Kessler" Date: Wed, 14 Dec 2011 14:04:19 -0500 Subject: [PATCH 15/30] Fixed issues with totem processor (mostly quoting problems). Fixed one small typo that had no present impact, but may if we use "test rules" in the future --- svmbatch/svmbatch.sh | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/svmbatch/svmbatch.sh b/svmbatch/svmbatch.sh index 494a7b99..807ca122 100755 --- a/svmbatch/svmbatch.sh +++ b/svmbatch/svmbatch.sh @@ -56,7 +56,7 @@ function totem_batch { #Read totem.suf, mk totemtemp, assemble totems, update fi totemsuf=`cat totem.suf` mkdir $totemtemp function totem_build { -for file in $1; do + for file in $1; do totemlist= #Clear totemlist. Holds names of files to go into totem newname= #Clear newname. Holds name of target totem for suf in $totemsuf; do @@ -67,10 +67,18 @@ for file in $1; do newname= done } -totem_build $filelist1 #Quoting doesn't matter here for list ops -totem_build $filelist2 #And function will not quote anyway -filelist1=`hdr_append \`prepend $totemtemp \\\`slash_strip "$filelist1" \\\` \` ` #update names to point at totems -filelist2=`hdr_append \`prepend $totemtemp \\\`slash_strip "$filelist2" \\\` \` ` +totem_build "$filelist1" #Quoting here DOES matter. Otherwise it will take only first element as $1 +totem_build "$filelist2" + + +filelist1=`slash_strip "$filelist1"` +filelist1=`prepend $totemtemp "$filelist1"` +filelist1=`hdr_append "$filelist1"` + +filelist2=`slash_strip "$filelist2"` +filelist2=`prepend $totemtemp "$filelist2"` +filelist2=`hdr_append "$filelist2"` + } @@ -229,7 +237,7 @@ function svm_batchtest { #Test model $1 against constructed volume based on hdrs afni_bucket_build "$2" "testbucket" afni_bucket_short "testbucket" "testbucketshort" afni_bucket_time "testbucketshort" "testbucketshorttime" -set_test_rukes +set_test_rules svm_test $1 "testbucketshorttime" } From 985372efca7ea44532e36e80d506d90d4a773804 Mon Sep 17 00:00:00 2001 From: "Daniel A. Kessler" Date: Wed, 14 Dec 2011 14:13:50 -0500 Subject: [PATCH 16/30] Fixed mistake in super cross validation that PROGRESSIVELY eliminated cases, rather than doing so with replacement after each LOOCV --- svmbatch/svmbatch.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/svmbatch/svmbatch.sh b/svmbatch/svmbatch.sh index 807ca122..4cca195a 100755 --- a/svmbatch/svmbatch.sh +++ b/svmbatch/svmbatch.sh @@ -255,8 +255,8 @@ for file in $biglist; do loodir=`hdr_strip \`slash_strip $file \` ` #Make file into a dirname pname=`echo "$loodir" | sed 's:/::'` svmdir=`echo $svmdir_orig/LOOCV/$loodir ` #build a dir from loodir and svmdir_orig - filelist1=`echo "$filelist1" | sed "\:$file: d" ` #remove $file from filelist1 - filelist2=`echo "$filelist2" | sed "\:$file: d" ` #remove $file from filelist2 + filelist1=`echo "$filelist1_orig" | sed "\:$file: d" ` #remove $file from filelist1 + filelist2=`echo "$filelist2_orig" | sed "\:$file: d" ` #remove $file from filelist2 svm_batchtrain #train up a model based on the updated filelist and svmdir svm_batchtest "model" "$file" done From 2945dec6221d2b6339276ff9df51800ed89d81ef Mon Sep 17 00:00:00 2001 From: "Daniel A. Kessler" Date: Fri, 16 Dec 2011 17:20:04 -0500 Subject: [PATCH 17/30] Added tentative support for permutation testing --- svmbatch/svmbatch.sh | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/svmbatch/svmbatch.sh b/svmbatch/svmbatch.sh index 4cca195a..76edfe10 100755 --- a/svmbatch/svmbatch.sh +++ b/svmbatch/svmbatch.sh @@ -42,6 +42,9 @@ while [ "$1" != "" ]; do --nomodelmask ) nomodelmask=1 ;; + -p | --permutation ) + permutationmode=1 + ;; esac shift @@ -167,6 +170,10 @@ for i in $filelist2 done } +function label_permute { #Randomly permute the labels in a given label file +for i in `cat $1`; do echo "$RANDOM $i"; done | sort | sed -r 's/^[0-9]+//' > $1 +} + function mask_build { #Build automask 3dAutomask timeshortbucket+orig } @@ -207,6 +214,9 @@ afni_bucket_combine "bucket1 bucket2" "bucket" afni_bucket_short "bucket" "bucketshort" afni_bucket_time "bucketshort" "bucketshorttime" label_build +if [ "$permute" = "1" ]; then + label_permute labels.1D +fi set_train_rules svm_train "bucketshorttime" } @@ -262,6 +272,16 @@ for file in $biglist; do done } +function permutation_test { #will perfrom $1 permutations on data, writing out weight buckets at each step +permute=1 +for i in `seq 1 $1`; do +svmdir=`echo svmdir/perm$i` +svm_batchtrain +done + +} + + function main { svm_prep @@ -281,6 +301,10 @@ else super_crossvalid fi +if [ "$permutationmode" = "1" ]; then + echo "Entering permutation mode" + sbm_batchtrain + if [ "$totem" = "1" ]; then totem_clean From 92f3fe998ba57428abf15f7d5a08ca15cac588f2 Mon Sep 17 00:00:00 2001 From: "Daniel A. Kessler" Date: Fri, 16 Dec 2011 17:33:35 -0500 Subject: [PATCH 18/30] hopefully fixed permutation test errors --- svmbatch/svmbatch.sh | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/svmbatch/svmbatch.sh b/svmbatch/svmbatch.sh index 76edfe10..b3042370 100755 --- a/svmbatch/svmbatch.sh +++ b/svmbatch/svmbatch.sh @@ -275,7 +275,8 @@ done function permutation_test { #will perfrom $1 permutations on data, writing out weight buckets at each step permute=1 for i in `seq 1 $1`; do -svmdir=`echo svmdir/perm$i` +echo "Running permutation $i of $1" +svmdir=`echo $svmdir/perms/$i` svm_batchtrain done @@ -303,7 +304,8 @@ fi if [ "$permutationmode" = "1" ]; then echo "Entering permutation mode" - sbm_batchtrain + svm_batchtrain +fi if [ "$totem" = "1" ]; then From b13d8aeb89492896f8d040b99771aad646fba632 Mon Sep 17 00:00:00 2001 From: "Daniel A. Kessler" Date: Mon, 19 Dec 2011 09:48:53 -0500 Subject: [PATCH 19/30] Permutation testing is now working. Planning to use symlinks for next release to speed up processing --- svmbatch/svmbatch.sh | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/svmbatch/svmbatch.sh b/svmbatch/svmbatch.sh index b3042370..4c248d97 100755 --- a/svmbatch/svmbatch.sh +++ b/svmbatch/svmbatch.sh @@ -95,6 +95,11 @@ fi if [ ! -d $svmdir ]; then mkdir $svmdir fi + +filelist1_orig="$filelist1" +filelist2_orig="$filelist2" +svmdir_orig="$svmdir" + } function slash_strip { #Strip all slashes off $1,prepend slash @@ -171,7 +176,9 @@ done } function label_permute { #Randomly permute the labels in a given label file -for i in `cat $1`; do echo "$RANDOM $i"; done | sort | sed -r 's/^[0-9]+//' > $1 +for i in `cat $1`; do echo "$RANDOM $i"; done | sort | sed -r 's/^[0-9]+//' > plabels.1D +rm labels.1D +mv plabels.1D labels.1D } function mask_build { #Build automask @@ -215,6 +222,7 @@ afni_bucket_short "bucket" "bucketshort" afni_bucket_time "bucketshort" "bucketshorttime" label_build if [ "$permute" = "1" ]; then + cd $svmdir label_permute labels.1D fi set_train_rules @@ -274,9 +282,11 @@ done function permutation_test { #will perfrom $1 permutations on data, writing out weight buckets at each step permute=1 +mkdir $svmdir/perms for i in `seq 1 $1`; do echo "Running permutation $i of $1" -svmdir=`echo $svmdir/perms/$i` +svmdir=`echo $svmdir_orig/perms/$i` +mkdir $svmdir svm_batchtrain done @@ -304,7 +314,7 @@ fi if [ "$permutationmode" = "1" ]; then echo "Entering permutation mode" - svm_batchtrain + permutation_test 100 fi if [ "$totem" = "1" ]; then From 6c7c26ca1a656c2b6d86fd1f5556be39575435a1 Mon Sep 17 00:00:00 2001 From: "Daniel A. Kessler" Date: Mon, 19 Dec 2011 09:53:40 -0500 Subject: [PATCH 20/30] Updated permutation test to leverage preexisting training examples through symlinks --- svmbatch/svmbatch.sh | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/svmbatch/svmbatch.sh b/svmbatch/svmbatch.sh index 4c248d97..fe3e58f3 100755 --- a/svmbatch/svmbatch.sh +++ b/svmbatch/svmbatch.sh @@ -176,7 +176,7 @@ done } function label_permute { #Randomly permute the labels in a given label file -for i in `cat $1`; do echo "$RANDOM $i"; done | sort | sed -r 's/^[0-9]+//' > plabels.1D +for i in `cat $1`; do echo "$RANDOM $i"; done | sort | sed -r 's/^[0-9]\s+//' > plabels.1D rm labels.1D mv plabels.1D labels.1D } @@ -287,9 +287,13 @@ for i in `seq 1 $1`; do echo "Running permutation $i of $1" svmdir=`echo $svmdir_orig/perms/$i` mkdir $svmdir -svm_batchtrain +cd $svmdir +ln -s $svmdir_orig/bucketshorttime* . +cp $svmdir_orig/labels.1D ./labels.1D +label_permute labels.1D +set_train_rules +svm_train "bucketshorttime" done - } From f78e0d87f35ed29b716754f51142768f75c33dd6 Mon Sep 17 00:00:00 2001 From: "Daniel A. Kessler" Date: Mon, 19 Dec 2011 10:03:11 -0500 Subject: [PATCH 21/30] Added support for specifying count of permutation tests at command line --- svmbatch/svmbatch.sh | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/svmbatch/svmbatch.sh b/svmbatch/svmbatch.sh index fe3e58f3..d46ffa5f 100755 --- a/svmbatch/svmbatch.sh +++ b/svmbatch/svmbatch.sh @@ -44,6 +44,8 @@ while [ "$1" != "" ]; do ;; -p | --permutation ) permutationmode=1 + shift + permcount=$1 ;; esac @@ -176,7 +178,7 @@ done } function label_permute { #Randomly permute the labels in a given label file -for i in `cat $1`; do echo "$RANDOM $i"; done | sort | sed -r 's/^[0-9]\s+//' > plabels.1D +for i in `cat $1`; do echo "$RANDOM $i"; done | sort | sed -r 's/^[0-9]+//' > plabels.1D rm labels.1D mv plabels.1D labels.1D } @@ -318,7 +320,7 @@ fi if [ "$permutationmode" = "1" ]; then echo "Entering permutation mode" - permutation_test 100 + permutation_test $permcount fi if [ "$totem" = "1" ]; then From cbdb7eacd26e2de58966d43be261339988627cf3 Mon Sep 17 00:00:00 2001 From: "Daniel A. Kessler" Date: Mon, 19 Dec 2011 14:55:41 -0500 Subject: [PATCH 22/30] Added matlab code for completing permutation tests --- svmbatch/permutation_test.m | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) create mode 100644 svmbatch/permutation_test.m diff --git a/svmbatch/permutation_test.m b/svmbatch/permutation_test.m new file mode 100644 index 00000000..a44092fc --- /dev/null +++ b/svmbatch/permutation_test.m @@ -0,0 +1,33 @@ +function [Y] = permutation_test(Pt,pdir,name) +% Calculate nonparametric distributions based on svm permutation tests +% Pt - filename of weight vector from real model +% Pdir - file directory in which to search for results of permutation test +% img/hdr pairs +% name - string of name to write out + +%% Make list of files +Pp=spm_select('List',pdir,'[0-9].hdr+') + +%% Read in files +th=spm_vol(Pt); +ph=spm_vol(Pp); + +tvol=spm_read_vols(th); +pvol=spm_read_vols(ph); + + +%% Create dumping space for comparisons + +rvol=zeros(size(tvol)); +rh=th; +rh.fname=name; + +%% Loop over dimensions + +for i=1:size(rvol,1), for j=1:size(rvol,2), for k=1:size(rvol,3) + rvol(i,j,k)=sum(pvol(i,j,k,:)>tvol(i,j,k))/size(pvol,4); + end,end,end + +%% Write out the resulting p values + +rvol=spm_write_vol(rh,rvol); \ No newline at end of file From 21a2e4fd4c8e181b5465834a8f41e0409fa1ffd0 Mon Sep 17 00:00:00 2001 From: "Daniel A. Kessler" Date: Mon, 19 Dec 2011 14:56:08 -0500 Subject: [PATCH 23/30] Added placeholder for code to rearrange permutation tests --- svmbatch/perm_test_arrange.sh | 0 1 file changed, 0 insertions(+), 0 deletions(-) create mode 100644 svmbatch/perm_test_arrange.sh diff --git a/svmbatch/perm_test_arrange.sh b/svmbatch/perm_test_arrange.sh new file mode 100644 index 00000000..e69de29b From 4658ca3da74eb2069fe23a6faca3a45ebb6b49b3 Mon Sep 17 00:00:00 2001 From: "Daniel A. Kessler" Date: Mon, 19 Dec 2011 15:11:07 -0500 Subject: [PATCH 24/30] updated permutation test results arranged --- svmbatch/perm_test_arrange.sh | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/svmbatch/perm_test_arrange.sh b/svmbatch/perm_test_arrange.sh index e69de29b..845cb31e 100644 --- a/svmbatch/perm_test_arrange.sh +++ b/svmbatch/perm_test_arrange.sh @@ -0,0 +1,18 @@ +#!/bin/bash + +#A program to reorganize permutation test results from svmbatch for later processing + +permdir= #String pointing to location of the permutation test directories + +targetdir= #where you want to put your files after conversion + +cd $permdir + +weights=`find -name "weight*HEAD"` #get a list of all your weight buckets + +let "i=1" + +for w in $weights; do + 3dAFNItoANALYZE -4D $targetdir/$i $w + let "i=$i+1" +done From 98430460d2642e67c91d942050eb75800e5738da Mon Sep 17 00:00:00 2001 From: "Daniel A. Kessler" Date: Mon, 19 Dec 2011 15:11:23 -0500 Subject: [PATCH 25/30] updated script for permutation test in matlab --- svmbatch/permutation_test.m | 1 + 1 file changed, 1 insertion(+) diff --git a/svmbatch/permutation_test.m b/svmbatch/permutation_test.m index a44092fc..fd1b31a9 100644 --- a/svmbatch/permutation_test.m +++ b/svmbatch/permutation_test.m @@ -10,6 +10,7 @@ %% Read in files th=spm_vol(Pt); +cd(pdir); ph=spm_vol(Pp); tvol=spm_read_vols(th); From 35fca2dbe0b18c7597301784a6332db67ad5feb9 Mon Sep 17 00:00:00 2001 From: "Daniel A. Kessler" Date: Fri, 6 Jan 2012 13:57:30 -0500 Subject: [PATCH 26/30] Updated supplemental scripts related to permutation testing --- svmbatch/perm_test_arrange.sh | 6 ++++-- svmbatch/permutation_test.m | 20 +++++++++++++++++++- 2 files changed, 23 insertions(+), 3 deletions(-) diff --git a/svmbatch/perm_test_arrange.sh b/svmbatch/perm_test_arrange.sh index 845cb31e..42ce8964 100644 --- a/svmbatch/perm_test_arrange.sh +++ b/svmbatch/perm_test_arrange.sh @@ -2,14 +2,16 @@ #A program to reorganize permutation test results from svmbatch for later processing -permdir= #String pointing to location of the permutation test directories +permdir='/net/data4/MAS/SVM/FIR_6_10_perms/perms' #String pointing to location of the permutation test directories -targetdir= #where you want to put your files after conversion +targetdir='/net/data4/MAS/SVM/FIR_6_10_perms/perms_analyze/' #where you want to put your files after conversion cd $permdir weights=`find -name "weight*HEAD"` #get a list of all your weight buckets +mkdir $targetdir + let "i=1" for w in $weights; do diff --git a/svmbatch/permutation_test.m b/svmbatch/permutation_test.m index fd1b31a9..3d915566 100644 --- a/svmbatch/permutation_test.m +++ b/svmbatch/permutation_test.m @@ -25,8 +25,26 @@ %% Loop over dimensions +% For each voxel, calculate proportion of permutations that resulted in +% smaller or equal value. This returns the nonparametric CDF. We then +% convert this, using norminv, to a z-score. Extremely positive values will +% have high CDF scores, high p scores, and high z scores. Very negative +% values will have very small CDF scores, small p scores, and negative z +% scores. We convert to z for easier visualization in xjview. + +for i=1:size(rvol,1), for j=1:size(rvol,2), for k=1:size(rvol,3) + rvol(i,j,k)=norminv(sum(pvol(i,j,k,:)<=tvol(i,j,k))/size(pvol,4)); + end,end,end + +%% Mask based on tvol +% Some voxels that were zero in the real weight vector are out-of-brain +% voxels. Implicit masking during first level testing should have set them +% to 0. All permutation tests will likely also return 0, yielding a bizarre +% value for the CDF. To protect against this, we set the z-score of these +% points to be 0, for a corresponding p of .5 + for i=1:size(rvol,1), for j=1:size(rvol,2), for k=1:size(rvol,3) - rvol(i,j,k)=sum(pvol(i,j,k,:)>tvol(i,j,k))/size(pvol,4); + if tvol(i,j,k)==0, rvol(i,j,k)=0; end end,end,end %% Write out the resulting p values From 289566232f0e1c0322768f7e9943ac00875d42dc Mon Sep 17 00:00:00 2001 From: "Daniel A. Kessler" Date: Wed, 15 Feb 2012 14:21:52 -0500 Subject: [PATCH 27/30] Some hacky edits of permutation visualization functions --- svmbatch/perm_test_arrange.sh | 23 +++++++++++++++--- svmbatch/permutation_test.m | 45 +++++++++++++++++++++++++++-------- 2 files changed, 55 insertions(+), 13 deletions(-) mode change 100644 => 100755 svmbatch/perm_test_arrange.sh diff --git a/svmbatch/perm_test_arrange.sh b/svmbatch/perm_test_arrange.sh old mode 100644 new mode 100755 index 42ce8964..27840b4a --- a/svmbatch/perm_test_arrange.sh +++ b/svmbatch/perm_test_arrange.sh @@ -2,9 +2,25 @@ #A program to reorganize permutation test results from svmbatch for later processing -permdir='/net/data4/MAS/SVM/FIR_6_10_perms/perms' #String pointing to location of the permutation test directories -targetdir='/net/data4/MAS/SVM/FIR_6_10_perms/perms_analyze/' #where you want to put your files after conversion +#Parameter Processing + +while [ "$1" != "" ]; do + case $1 in + -p) + shift + permdir=$1 + + ;; + -t) + shift + targetdir=$1 + ;; + *) + + esac + shift +done cd $permdir @@ -15,6 +31,7 @@ mkdir $targetdir let "i=1" for w in $weights; do - 3dAFNItoANALYZE -4D $targetdir/$i $w + 3dAFNItoANALYZE -4D $targetdir/$i $w >/dev/null + echo "Converting file $i" let "i=$i+1" done diff --git a/svmbatch/permutation_test.m b/svmbatch/permutation_test.m index 3d915566..9a41cd5d 100644 --- a/svmbatch/permutation_test.m +++ b/svmbatch/permutation_test.m @@ -1,27 +1,29 @@ -function [Y] = permutation_test(Pt,pdir,name) +%function [Y] = permutation_test(Pt,Pdir,name) % Calculate nonparametric distributions based on svm permutation tests % Pt - filename of weight vector from real model % Pdir - file directory in which to search for results of permutation test % img/hdr pairs -% name - string of name to write out +% name - string of name to write out (without .img extension) %% Make list of files -Pp=spm_select('List',pdir,'[0-9].hdr+') +Pp=spm_select('List',Pdir,'[0-9]+\.hdr'); %% Read in files th=spm_vol(Pt); -cd(pdir); -ph=spm_vol(Pp); - tvol=spm_read_vols(th); -pvol=spm_read_vols(ph); +cd(Pdir); +ph=spm_vol(Pp); +pvol=spm_read_vols(ph); +cd .. + %% Create dumping space for comparisons rvol=zeros(size(tvol)); rh=th; -rh.fname=name; +rh.fname=[name '.img']; +rh.descrip='SPM{T_[10000000]}'; %% Loop over dimensions @@ -47,6 +49,29 @@ if tvol(i,j,k)==0, rvol(i,j,k)=0; end end,end,end -%% Write out the resulting p values +%% Replace Inf and -Inf values with prior min and max, respectively +% rvol(find(rvol==Inf))=max(rvol(~isinf(rvol))); +% rvol(find(rvol==-Inf))=min(rvol(~isinf(rvol))); + +rvol(find(rvol==Inf))=norminv((1-1/size(pvol,4))); +rvol(find(rvol==-Inf))=norminv((1/size(pvol,4))); + +%Fix the origin for + +rh.mat(:,4)=[-81 -115 -53 1]; + + +%% Write out the resulting p values in one giant file +spm_write_vol(rh,rvol); + +%%Slice up the file into its sub-totems, and write them out separately from +%%bottom up -rvol=spm_write_vol(rh,rvol); \ No newline at end of file +for i=1:(th.dim(3)/46) + cth_range=[1:46] + (i-1)*46; + cth=rh; + cth.fname=sprintf('%s%s%s%.3d%s',pwd,'/', name ,i,'.img'); + cth.dim(3)=[46]; + ctvol=rvol(:,:,cth_range); + spm_write_vol(cth,ctvol); +end \ No newline at end of file From 460eb7d24f714cda30ba0cf967d1d68c5b5431e4 Mon Sep 17 00:00:00 2001 From: "Daniel A. Kessler" Date: Wed, 7 Mar 2012 11:33:41 -0500 Subject: [PATCH 28/30] cleaned up matlab portion of permutation testing --- .../{ => matlab_Scripts}/permutation_test.m | 0 svmbatch/perm_test_arrange.sh | 37 ------------------- 2 files changed, 37 deletions(-) rename svmbatch/{ => matlab_Scripts}/permutation_test.m (100%) delete mode 100755 svmbatch/perm_test_arrange.sh diff --git a/svmbatch/permutation_test.m b/svmbatch/matlab_Scripts/permutation_test.m similarity index 100% rename from svmbatch/permutation_test.m rename to svmbatch/matlab_Scripts/permutation_test.m diff --git a/svmbatch/perm_test_arrange.sh b/svmbatch/perm_test_arrange.sh deleted file mode 100755 index 27840b4a..00000000 --- a/svmbatch/perm_test_arrange.sh +++ /dev/null @@ -1,37 +0,0 @@ -#!/bin/bash - -#A program to reorganize permutation test results from svmbatch for later processing - - -#Parameter Processing - -while [ "$1" != "" ]; do - case $1 in - -p) - shift - permdir=$1 - - ;; - -t) - shift - targetdir=$1 - ;; - *) - - esac - shift -done - -cd $permdir - -weights=`find -name "weight*HEAD"` #get a list of all your weight buckets - -mkdir $targetdir - -let "i=1" - -for w in $weights; do - 3dAFNItoANALYZE -4D $targetdir/$i $w >/dev/null - echo "Converting file $i" - let "i=$i+1" -done From 652c8503d749b6049909af1d95ba5d41ba01986b Mon Sep 17 00:00:00 2001 From: "Daniel A. Kessler" Date: Wed, 7 Mar 2012 11:33:53 -0500 Subject: [PATCH 29/30] updated svmbatch.sh with routines for permutation testing --- svmbatch/svmbatch.sh | 59 ++++++++++++++++++++++++++++++++++---------- 1 file changed, 46 insertions(+), 13 deletions(-) diff --git a/svmbatch/svmbatch.sh b/svmbatch/svmbatch.sh index d46ffa5f..40f2afe1 100755 --- a/svmbatch/svmbatch.sh +++ b/svmbatch/svmbatch.sh @@ -282,20 +282,53 @@ for file in $biglist; do done } +function perms_to_analyze { #Will rewrite all of the weight buckets from the permutation tests as img/hdr pairs for easier readier downstream + + cd $svmdir/perms + + weights=`find -name "weight*HEAD"` #get a list of all your weight buckets + + mkdir $svmdir/perms_analyze + + let "i=1" + + for w in $weights; do + 3dAFNItoANALYZE -4D $svmdir/perms_analyze/$i $w >/dev/null + echo "Converting file $i" + let "i=$i+1" + done + +} + +function perms_vizi { +m64 -nodesktop -nojvm < Date: Wed, 7 Mar 2012 12:04:53 -0500 Subject: [PATCH 30/30] This empty commit should close #18 by adding the current body of svmbatch work into the MethodsCore repo. It should not be viewed as the "final" svmbatch product