#! /bin/csh -f # # latgroup-sess # # Original Author: Doug Greve # CVS Revision Info: # $Author: nicks $ # $Date: 2007/01/09 22:41:18 $ # $Revision: 1.4 $ # # Copyright (C) 2002-2007, # The General Hospital Corporation (Boston, MA). # All rights reserved. # # Distribution, usage and copying of this software is covered under the # terms found in the License Agreement file named 'COPYING' found in the # FreeSurfer source code root directory, and duplicated here: # https://surfer.nmr.mgh.harvard.edu/fswiki/FreeSurferOpenSourceLicense # # General inquiries: freesurfer@nmr.mgh.harvard.edu # Bug reports: analysis-bugs@nmr.mgh.harvard.edu # set VERSION = '$Id: latgroup-sess,v 1.4 2007/01/09 22:41:18 nicks Exp $'; set inputargs = ($argv); set analysis = (); set hemi = (); set ActConds = (); set CtrlConds = (); set latdir = (); set instem = latm; set outstem = (); set targetsubject = margaret set GroupDesMat = (); set synth = 0; set MLF = (); set monly = 0; set PrintHelp = 0; set DateStr = "`date '+%y%m%d%H%M%S'`" if($#argv == 0) goto usage_exit; set n = `echo $argv | grep version | wc -l` if($n != 0) then echo $VERSION exit 0; endif set n = `echo $argv | grep -e -help | wc -l` if($n != 0) then set PrintHelp = 1; goto usage_exit; endif set SessList = `getsesspath $inputargs`; if($status || $#SessList == 0) then echo "ERROR: finding sessions" echo " $SessList" exit 1; endif goto parse_args; parse_args_return: goto check_params; check_params_return: ## Get functional subdirectory from the info file ## set infofile = $analysis/analysis.info set cfgfile = $analysis/analysis.cfg if(! -e $infofile) then echo "ERROR: cannot find $infofile" exit 1; endif set fsd = `cat $infofile | awk '{if($1 == "fsd") print $2}'`; set designtype = `cat $infofile | awk '{if($1 == "designtype") print $2}'`; set spmhrf = `cat $cfgfile | awk '{if($1 == "-spmhrf") print $2}'`; if($#spmhrf == 0) then echo "ERROR: analysis must use spmhrf" exit 1; endif if($spmhrf != 1) then echo "ERROR: spmhrf must have one derivative" exit 1; endif # Make sure each input is there echo latdir $latdir foreach sess ($SessList) set inpath = $sess/$fsd/$analysis/$latdir/$instem-average7-$hemi.mgh if(! -e $inpath) then echo "ERROR: cannot find $inpath" exit 1; endif end ##### Create a log file ###### set LF = $outstem-$targetsubject-$hemi.log if(-e $LF) mv $LF $LF.old echo "--------------------------------------------------------------" echo "latgroup-sess logfile is $LF" echo "--------------------------------------------------------------" echo "latgroup-sess log file" >> $LF echo $VERSION >> $LF id >> $LF pwd >> $LF echo $0 >> $LF echo $inputargs >> $LF uname -a >> $LF date >> $LF echo $SessList >> $LF if(! $monly) set MLF = /tmp/latgroup-sess-$$.m echo MLF is $MLF | tee -a $LF rm -f $MLF set okfile = /tmp/latgroup-sess-$$.ok rm -f $okfile set matfile = $outstem-$targetsubject-$hemi.mat rm -f $matfile #--------------------------------------------------------------# tee $MLF > /dev/null < : active condition in condition contrast" echo " -cc C1 <-cc C2> : control condition in condition contrast" echo " -latdir latdir : latency contrast directory" echo " -hemi hemi : lh or rh" echo " -instem instem : default is latm" echo " -o outstem : output will be outstem-fsig-targsubj-?h.w" echo " -targ targetsubject : default is $targetsubject" echo " -gdm gdmfile : group design matrix file" echo "" echo " -sf sessidfile ..." echo " -df srchdirfile ..." echo " -s sessid ..." echo " -d srchdir ..." echo "" echo " -help" echo " -umask umask : set unix file permission mask" echo " -version : print version and exit" echo " " if(! $PrintHelp ) exit 1; echo " " echo "$VERSION " echo " " cat $0 | awk 'BEGIN{prt=0}{if(prt) print $0; if($1 == "BEGINHELP") prt = 1 }' exit 1; #---- Everything below here is printed out as part of help -----# BEGINHELP Group and intergroup analysis using the results of first-level latency analysis (see latgrinder-sess). -a analysis Name of the first-level latency analysis as created by mkanalysis-sess -ca A1 <-ca A2> Active conditions in the condition contrast. At least one active condition must be specified. -cc C1 <-cc C2> Control conditions in the condition contrast. If no control conditions are specified, then baseline (ie, 0) is assumed. -latdir latdir Latency contrast directory as specified in latgrinder-sess. -instem instem Stem to use as input to the group/intergroup analysis. Default is latm. Other possibilties include h and lat. latm will perform the analysis on the masked latency. h will perform the analysis on the average hemodynamic response. In this case, the results should look similar to using isxavg-re-sess and intergroupavg-sess. -o outstem Output stem. The results will be stored as outstem-fsig-targsubj-?h.w and outstem-ces-targsubj-?h.w. fsig is the significance and ces is the contrast effects size. The sign of fsig will be based on ces. -targ targetsubject Render results on targetsubject. -gdm gdmfile Group design matrix (GDM) file. This is the matrix that assigns group membership. Each row corresponds to a different session. The order of the rows corresponds to the order of the sessions as listed in the -sf file(s). Each column in the matrix corresponds to a group. Currently, only two columns (groups) are allowed. The values in the matrix must be either 1 or 0 and code group membership, ie, if the subject belongs to a group, then the group column for that subject should be 1 and all other columns should be 0. If no gdm file is specified, then it is assumed that all subjects belong to the same group. Example: if the -sf file looks like: fred margaret ziggy marcus and the GDM file looked like: 1 0 1 0 0 1 0 1 Then fred and margaret belong to Group1 and ziggy and marcus belong to Group2. HOW IT WORKS When the results from latgrinder-sess are initially read in, there will be a value at each voxel for each condition. These values are distilled down to one value by computing a weighted average of the values. The weights are determined by the CONDITION CONTRAST. The values for the CONTROL CONDITIONS are averaged together and subtracted from the values for the ACTIVE CONDITIONS. This gives one value at each voxel for each subject. This value is referred to as the CONDITION CONTRAST (CC). When a GDM file is specified, then there will be two groups. The CCs for each group are averaged separately, and then Group2 is subtracted from Group1 to obtain the CONTRAST EFFECT SIZE (CES): CES = CCGroup1 - CCGroup2 This is what is stored in the outstem-ces-targsubj-?h.w file. The significance of this difference is also computed and stored in outstem-fsig-targsubj-?h.w file. Positive values indicate that CCGroup1 > CCGroup2. IF a GDM file is not used, then all subjects are assumed to be in Group1, and CCGroup2=0. There are two other files created: outstem-ces-targsubj-?h.log and outstem-ces-targsubj-?h.mat. These are just their for bookkeeping purposes. EXAMPLES: This command will test the differnce between groups of the difference between latencies of conditions 1 and 2. latgroup-sess -a latency1 -latdir latdir -instem latm\ -ca 1 -cc 2 \ -hemi lh -o latgroup/latm-1v2 \ -sf controls -sf patients -df dir -gdm gdm.dat This command will test the differnce between groups of the difference between hemodynamic amplitudes of conditions 1 and 2. latgroup-sess -a latency1 -latdir latdir -instem h\ -ca 1 -cc 2 \ -hemi lh -o latgroup/h-1v2 \ -sf controls -sf patients -df dir -gdm gdm.dat This command will test the hemodynamic amplitude averaged across of conditions 1 and 3, treating all input sessions as a single group. latgroup-sess -a latency1 -latdir latdir -instem h\ -ca 1 -ca 3 \ -hemi lh -o latgroup/h-13v0 \ -sf controls -sf patients -df dir