#! /bin/csh -f # # groupreg-sess # # Original Author: Doug Greve # CVS Revision Info: # $Author: nicks $ # $Date: 2007/01/09 22:41:17 $ # $Revision: 1.9 $ # # 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: groupreg-sess,v 1.9 2007/01/09 22:41:17 nicks Exp $'; set inputargs = ($argv); set groupid = (); set analysis = (); set contrast = (); set xmat = (); set gconmat = (); set gconname = (); set monly = 0; set MLF = (); set nolog = 0; set volstem = ces; set spacename = (); set spacedir = (); set hemi = (); set hemicode = (); set PrintHelp = 0; set WLS = 0; set synth = 0; set nthframe = 1; if($#argv == 0) goto usage_exit; set n = `echo $argv | grep -e -help | wc -l` if($n != 0) then set PrintHelp = 1; goto usage_exit; endif set n = `echo $argv | grep version | wc -l` if($n != 0) then echo $VERSION exit 0; endif set n = `echo $argv | grep nolog | wc -l` if($n != 0) set nolog = 1; set SessList = `getsesspath $argv`; if($status || $#SessList == 0) then echo "ERROR: cannot find any sessions" echo $SessList exit 1; endif goto parse_args; parse_args_return: goto check_params; check_params_return: set nclines = `wc -l $gconmat | awk '{print $1}'`; if($nclines != 1) then echo "ERROR: the number of lines in $gconmat is $nclines." echo " There can only be one line." exit 1; endif ##### Create a log file ###### if(! $nolog) then set logdir = `pwd`/log; mkdir -p $logdir if(! -e $logdir) then echo "ERROR: could not create $logdir" exit 1; endif set LF = $logdir/groupreg-sess.log if(-e $LF) mv $LF $LF.old else echo "No log file" set LF = /dev/null endif echo "----------------------------------------------------------" echo "groupreg-sess logfile is $LF" echo "----------------------------------------------------------" echo "groupreg-sess log file" >> $LF echo $VERSION >> $LF pwd >> $LF echo $0 >> $LF echo $inputargs >> $LF uname -a >> $LF date >> $LF ## Get functional subdirectory from the info file ## set infofile = $analysis/analysis.info if(! -e $infofile) then echo "ERROR: cannot find $infofile" exit 1; endif set fsd = `cat $infofile | awk '{if($1 == "fsd") print $2}'`; mkdir -p $groupid set sessinfo = $groupid/session.info if(-e $sessinfo) then @ n1 = `cat $sessinfo | wc -l`; @ n1 = $n1 - 1; if($n1 != $#SessList) then echo "ERROR: Current Session List is inconistent with previous group average"\ |& tee -a $LF exit 1; endif foreach sess ($SessList) set sessid = `basename $sess` set n1 = `cat $sessinfo | grep -x $sessid | wc -l`; if($n1 == 0) then echo "ERROR: $sessid was not in original group average" exit 1; endif end else echo "SessionType: GroupAverage" > $sessinfo foreach sess ($SessList) set sessid = `basename $sess` echo $sessid >> $sessinfo end endif set outdir = $groupid/$fsd/$analysis/$spacedir-rfx/$gconname mkdir -p $outdir # Check that the input volume is there for each subj set InstemList = (); set InVarStemList = (); set FLAXMatList = (); foreach sess ($SessList) set instem = $sess/$fsd/$analysis/$spacedir/$contrast/$volstem$hemicode set fname = $instem"_000.hdr"; if(! -e $fname) then echo "ERROR: $fname does not exist" exit 1; endif set tmp = `cat $fname`; set nf = $tmp[3]; if($nf > 1 && 0) then echo "ERROR: contrast $contrast has multiple frames." exit 1; endif set InstemList = ($InstemList $instem); if($WLS) then set varstem = $sess/$fsd/$analysis/$spacedir/$contrast/cesvar$hemicode if(! -e $varstem.bhdr) then echo "ERROR: cannot find $varstem.bhdr" exit 1; endif set InVarStemList = ($InVarStemList $varstem); endif if("$spacename" == "tal") then set reg = $sess/$fsd/$analysis/$spacedir/register.dat cp $reg $groupid/$fsd/$analysis/$spacedir-rfx endif set FLAXMat = $sess/$fsd/$analysis/X.mat if(! -e $FLAXMat) then echo "ERROR: cannot find $FLAXMat" exit 1; endif set FLAXMatList = ($FLAXMatList $FLAXMat); end set FLAConMat = $analysis/$contrast.mat if(! -e $FLAConMat) then echo "ERROR: cannot find $FLAConMat" exit 1; endif if(! $monly) set MLF = /tmp/groupreg-sess-$$.m rm -f $MLF echo "MLF is $MLF" |& tee -a $LF set okfile = /tmp/groupreg-sess-$$.ok rm -f $okfile #--------------------------------------------# tee -a $MLF > /dev/null <