From 23ebe4aad6a773695627d22d5477659c2509d6cb Mon Sep 17 00:00:00 2001
From: Tim Behrens <behrens@fmrib.ox.ac.uk>
Date: Fri, 27 Aug 2004 16:44:03 +0000
Subject: [PATCH] *** empty log message ***

---
 old_bedpost         | 45 ++++++++++++++++++++++++++++-----------------
 old_bedpost_cleanup |  6 +++---
 probtrackOptions.cc |  9 +++++++--
 probtrackOptions.h  |  7 ++++---
 reord_OM.cc         | 25 +++++++------------------
 5 files changed, 49 insertions(+), 43 deletions(-)

diff --git a/old_bedpost b/old_bedpost
index 7b4ff61..27c85b7 100755
--- a/old_bedpost
+++ b/old_bedpost
@@ -20,9 +20,9 @@ Clean_Exit(){
 	    for j in ${i};do 
 		host=`echo $j | awk -F _fdt_ '{print $1}'`
 		pid=`echo $j | awk -F _fdt_ '{print $2}'`
-		if [ "x${FSL_MACHINE_LIST}" != "x" ]; then
-#	            ${FSL_REMOTE_CALL} $host "kill -KILL $pid" #this leaves one child process per processor - what can you do?
-		    $FSL_REMOTE_CALL $host  "if [ -r /etc/fslconf/fsl.sh ];then . /etc/fslconf/fsl.sh; elif [ -r /usr/local/etc/fslconf/fsl.sh ];then . /usr/local/etc/fslconf/fsl.sh; elif [ -r \${HOME}/.fslconf/fsl.sh ]; then . \${HOME}/.fslconf/fsl.sh; fi; if [ x\${FSLDIR} != "x" ];then \${FSLDIR}/bin/bedpost_kill_pid ${pid} >/dev/null 2>&1; else echo FSLDIR not set in any default location on machine `hostname`;fi" >/dev/null 2>&1 &
+		if [ "x${FSLMACHINELIST}" != "x" ]; then
+#	            ${FSLREMOTECALL} $host "kill -KILL $pid" #this leaves one child process per processor - what can you do?
+		    $FSLREMOTECALL $host "if [ -r /usr/local/etc/fslconf/fsl.sh ];then . /usr/local/etc/fslconf/fsl.sh;fi; if [ -r /etc/fslconf/fsl.sh ];then . /etc/fslconf/fsl.sh;fi; if [ -r \${HOME}/.fslconf/fsl.sh ]; then . \${HOME}/.fslconf/fsl.sh; fi; if [ x\${FSLDIR} != "x" ];then \${FSLDIR}/bin/bedpost_kill_pid ${pid} >/dev/null 2>&1; else echo FSLDIR not set in any default location on machine `hostname`;fi" >/dev/null 2>&1 &
 		else
 		    ${FSLDIR}/bin/bedpost_kill_pid ${pid}
 		fi
@@ -33,14 +33,14 @@ Clean_Exit(){
 }
 
 Lock(){
-    if [ "x${FSL_LOCK_DIR}" != "x" ];then
-	touch ${FSL_LOCK_DIR}/.bedpost.lock
+    if [ "x${FSLLOCKDIR}" != "x" ];then
+	touch ${FSLLOCKDIR}/.bedpost.lock
     fi
 }
 
 ExitUnlock(){
-    if [ -e ${FSL_LOCK_DIR}/.bedpost.lock ];then
-	rm ${FSL_LOCK_DIR}/.bedpost.lock
+    if [ -e ${FSLLOCKDIR}/.bedpost.lock ];then
+	rm ${FSLLOCKDIR}/.bedpost.lock
     fi
 
     #clean up slices
@@ -58,9 +58,9 @@ ExitUnlock(){
 }
 
 LockTest(){
-    if [ "x${FSL_LOCK_DIR}" = "x" ];then
+    if [ "x${FSLLOCKDIR}" = "x" ];then
 	echo 1;
-    elif [ ! -e ${FSL_LOCK_DIR}/.bedpost.lock ];then
+    elif [ ! -e ${FSLLOCKDIR}/.bedpost.lock ];then
 	echo 1;
     else
 	echo 0;
@@ -148,21 +148,20 @@ ${FSLDIR}/bin/avwslice ${subjdir}/data
 ${FSLDIR}/bin/avwslice ${subjdir}/nodif_brain_mask
 
 #for parallel processing, the following need to be setup elsewhere
-#FSL_MACHINE_LIST="list of machines (can be duplicated for two processors etc.)"
-#FSL_REMOTE_CALL="ssh (or rsh or whatever you want to use)"
+#FSLMACHINELIST="list of machines (can be duplicated for two processors etc.)"
+#FSLREMOTECALL="ssh (or rsh or whatever you want to use)"
 
-if [ "x$FSL_MACHINE_LIST" = "x" ] ; then
+if [ "x$FSLMACHINELIST" = "x" ] ; then
     echo "processing data on local host"
     ${FSLDIR}/bin/bedpost_proc $subjdir $nslices ${subjdir}.bedpost/logs/pid_${$} &
 else
-    echo "processing data on hosts: $FSL_MACHINE_LIST"
-    for machine in $FSL_MACHINE_LIST; do
-	$FSL_REMOTE_CALL $machine  "if [ -r /etc/fslconf/fsl.sh ];then . /etc/fslconf/fsl.sh; elif [ -r /usr/local/etc/fslconf/fsl.sh ];then . /usr/local/etc/fslconf/fsl.sh; elif [ -r \${HOME}/.fslconf/fsl.sh ]; then . \${HOME}/.fslconf/fsl.sh; fi; if [ x\${FSLDIR} != "x" ];then \${FSLDIR}/bin/bedpost_proc $subjdir $nslices ${subjdir}.bedpost/logs/pid_${$}; else echo FSLDIR not set in any default location on machine `hostname`;fi"  &
+    echo "processing data on hosts: $FSLMACHINELIST"
+    for machine in $FSLMACHINELIST; do
+	$FSLREMOTECALL $machine  "if [ -r /usr/local/etc/fslconf/fsl.sh ];then . /usr/local/etc/fslconf/fsl.sh;fi; if [ -r /etc/fslconf/fsl.sh ];then . /etc/fslconf/fsl.sh;fi; if [ -r \${HOME}/.fslconf/fsl.sh ]; then . \${HOME}/.fslconf/fsl.sh; fi; if [ x\${FSLDIR} != "x" ];then \${FSLDIR}/bin/bedpost_proc $subjdir $nslices ${subjdir}.bedpost/logs/pid_${$}; else echo FSLDIR not set in any default location on machine `hostname`;fi"  &
     done
 fi
 
 
-
 b=0
 finished=0;
 while [ $finished -eq 0 ];do
@@ -191,6 +190,19 @@ ${FSLDIR}/bin/avwmaths ${subjdir}.bedpost/merged_thsamples -Tmean ${subjdir}.bed
 ${FSLDIR}/bin/avwmaths ${subjdir}.bedpost/merged_phsamples -Tmean ${subjdir}.bedpost/mean_phsamples
 ${FSLDIR}/bin/avwmaths ${subjdir}.bedpost/merged_fsamples -Tmean ${subjdir}.bedpost/mean_fsamples
 
+if [ ${finished} -eq 1 ];then
+    if [ `imtest ${subjdir}.bedpost/merged_thsamples` -eq 1 ];then
+	if [ `imtest ${subjdir}.bedpost/merged_phsamples` -eq 1 ];then
+	    if [ `imtest ${subjdir}.bedpost/merged_fsamples` -eq 1 ];then
+		rm -rf ${subjdir}.bedpost/diff_slices
+		rm -f ${subjdir}/data_slice_*
+		rm -f ${subjdir}/nodif_brain_mask_slice_*
+	    fi
+	fi
+    fi
+fi
+
+
 
 mkdir -p ${subjdir}.bedpost/xfms
 xfmdir=${subjdir}.bedpost/xfms
@@ -200,7 +212,6 @@ echo 0 0 1 0 >> ${xfmdir}/eye.mat
 echo 0 0 0 1 >> ${xfmdir}/eye.mat
 
 echo "DONE"
-
 ExitUnlock()
 
 
diff --git a/old_bedpost_cleanup b/old_bedpost_cleanup
index 1243fef..bd07090 100755
--- a/old_bedpost_cleanup
+++ b/old_bedpost_cleanup
@@ -1,12 +1,12 @@
 #!/bin/sh
 
-if [ "$FSL_MACHINE_LIST" = "" ] ; then
+if [ "x$FSLMACHINELIST" = "x" ] ; then
     ${FSLDIR}/bin/bedpost_kill_all
 else
-    unique_machines=`echo $FSL_MACHINE_LIST |tr " " \\\n |sort -u`
+    unique_machines=`echo $FSLMACHINELIST |tr " " \\\n |sort -u`
     echo $unique_machines;
      for machine in $unique_machines; do
-	  $FSL_REMOTE_CALL $machine  "if [ -r /etc/fslconf/fsl.sh ];then . /etc/fslconf/fsl.sh; elif [ -r /usr/local/etc/fslconf/fsl.sh ];then . /usr/local/etc/fslconf/fsl.sh; elif [ -r \${HOME}/.fslconf/fsl.sh ]; then . \${HOME}/.fslconf/fsl.sh; fi; if [ x\${FSLDIR} != "x" ];then \${FSLDIR}/bin/bedpost_kill_all; else echo FSLDIR not set in any default location on machine `hostname`;fi"  &
+	  $FSLREMOTECALL $machine  "if [ -r /usr/local/etc/fslconf/fsl.sh ];then . /usr/local/etc/fslconf/fsl.sh;fi; if [ -r /etc/fslconf/fsl.sh ];then . /etc/fslconf/fsl.sh;fi; if [ -r \${HOME}/.fslconf/fsl.sh ]; then . \${HOME}/.fslconf/fsl.sh; fi; if [ x\${FSLDIR} != "x" ];then \${FSLDIR}/bin/bedpost_kill_all; else echo FSLDIR not set in any default location on machine `hostname`;fi"  &
      done
 fi
 
diff --git a/probtrackOptions.cc b/probtrackOptions.cc
index 91ee23e..b7cee78 100644
--- a/probtrackOptions.cc
+++ b/probtrackOptions.cc
@@ -175,9 +175,14 @@ probtrackOptions* probtrackOptions::gopt = NULL;
   
   void probtrackOptions::modehelp()
   {
-    cout<<"tracking mode -  Options are:\n\n simple (default)\n    Input is text file defining start point.\n    Output is dti space volume with connectivity values at each voxel.\n   Note-everything in simple mode is in\n    diffusion space.\n\n seeds_to_targets\n    Inputs are a volume with ones at all seed points\n    (requires a matrix taking it to DTI space (--xfm))\n    and a text file with the name of a single target mask\n    on each new line (--targetmasks).\n    Output is a single volume for each target mask where the value of each\n    volume within the seed mask corresponds to the number of particles \n    seeded from this voxel reaching this target mask.\n\n seedmask\n    Input is a volume with ones at all seed points\n    (requires a matrix taking it to DTI space (--xfm))\n    Output is seed space volume with connectivity values at each voxel\n    summed from every seed.\n\n twomasks_symm\n    Input is a binary volume for first mask (-x)\n    also requires a binary volume for second mask (--mask2)\n    (requires a matrix taking both seeds to DTI space (--xfm))\n    Output is the sum of all paths the from first mask which pass\n    through the second and vice-versa  i.e. only paths\n    which pass through both masks are retained.\n\n waypoints\n    Input is a binary volume for seed mask (-x)\n    also requires a binary waypoint mask or ascii list\n    of waypoint masks (--mask2)\n    (requires a matrix taking both seeds to DTI space (--xfm))\n    Output is a volume containing all the paths from the\n    seedmask which pass through ALL of the waypoint masks. \n\n matrix1\n    Input is a volume with ones at all seed points\n    (requires a matrix taking it to DTI space (--xfm))\n    Output is an avw format nseeds x nseeds matrix \n    where element ij contains the number of particles leaving seed \n    voxel i and passing through seed voxel j. \n    Second output is an nsees x 3 matrix containing the \n    anatomical locations in Seed space of each matrix node.\n\n matrix2\n    Inputs are a volume with ones at all seed points\n    (requires a matrix taking it to DTI space (--xfm))\n    and a low resolution binary mask in register with the\n    seed volume (--lrmask)\n    Output is a matrix of size nseeds x nlowres \n    which contains the connectivity distributions from every seed voxel.\n    Auxiliary outputs are index matrices for each axis \n    of this matrix containing the anatomical location of each\n    node in seed space (x-axis) and low res space (y-axis)\n\n maskmatrix\n    Input is volume with integers in each seed location\n    Integer values distinguish different clusters\n    (e.g. output of Feat clustering)\n    (requires a matrix taking it to DTI space (--xfm))\n    Output is two matrices whose ij^th element is the\n     mean and max number of particles seeded from cluster i which pass \n    through cluster j\n"<<endl;
-  }
+    cout<<"tracking mode -  Options are:\n\n simple (default)\n    Input is text file defining start point.\n    Output is dti space volume with connectivity values at each voxel.\n   Note-everything in simple mode is in\n    diffusion space.\n\n seeds_to_targets\n    Inputs are a volume with ones at all seed points\n    (requires a matrix taking it to DTI space (--xfm))\n    and a text file with the name of a single target mask\n    on each new line (--targetmasks).\n    Output is a single volume for each target mask where the value of each\n    volume within the seed mask corresponds to the number of particles \n    seeded from this voxel reaching this target mask.\n\n seedmask\n    Input is a volume with ones at all seed points\n    (requires a matrix taking it to DTI space (--xfm))\n    Output is seed space volume with connectivity values at each voxel\n    summed from every seed.\n\n twomasks_symm\n    Input is a binary volume for first mask (-x)\n    also requires a binary volume for second mask (--mask2)\n    (requires a matrix taking both seeds to DTI space (--xfm))\n    Output is the sum of all paths the from first mask which pass\n    through the second and vice-versa  i.e. only paths\n    which pass through both masks are retained.\n\n waypoints\n    Input is a binary volume for seed mask (-x)\n    also requires a binary waypoint mask or ascii list\n    of waypoint masks (--mask2)\n    (requires a matrix taking both seeds to DTI space (--xfm))\n    Output is a volume containing all the paths from the\n    seedmask which pass through ALL of the waypoint masks.\n"<<endl;
+    if ( getenv("FSLINFMRIB"))
+      matrixmodehelp(); 
+ }
   
+  void probtrackOptions::matrixmodehelp(){
+    cout<<" matrix1\n    Input is a volume with ones at all seed points\n    (requires a matrix taking it to DTI space (--xfm))\n    Output is an avw format nseeds x nseeds matrix \n    where element ij contains the number of particles leaving seed \n    voxel i and passing through seed voxel j. \n    Second output is an nsees x 3 matrix containing the \n    anatomical locations in Seed space of each matrix node.\n\n matrix2\n    Inputs are a volume with ones at all seed points\n    (requires a matrix taking it to DTI space (--xfm))\n    and a low resolution binary mask in register with the\n    seed volume (--lrmask)\n    Output is a matrix of size nseeds x nlowres \n    which contains the connectivity distributions from every seed voxel.\n    Auxiliary outputs are index matrices for each axis \n    of this matrix containing the anatomical location of each\n    node in seed space (x-axis) and low res space (y-axis)\n\n maskmatrix\n    Input is volume with integers in each seed location\n    Integer values distinguish different clusters\n    (e.g. output of Feat clustering)\n    (requires a matrix taking it to DTI space (--xfm))\n    Output is two matrices whose ij^th element is the\n     mean and max number of particles seeded from cluster i which pass \n    through cluster j\n"<<endl;
+  }
   
   
   void probtrackOptions::status()
diff --git a/probtrackOptions.h b/probtrackOptions.h
index 658bbe0..8d05930 100644
--- a/probtrackOptions.h
+++ b/probtrackOptions.h
@@ -37,11 +37,11 @@ class probtrackOptions {
   Option<string> outfile;
   Option<string> rubbishfile;
   Option<string> seeds_to_dti;
-  Option<string> skipmask;
+  FmribOption<string> skipmask;
   Option<string> seedref;
   Option<string> mask2;
   Option<string> meshfile;
-  Option<string> lrmask;
+  FmribOption<string> lrmask;
   Option<string> logdir; 
   Option<bool> forcedir;
   Option<int> nparticles;
@@ -55,6 +55,7 @@ class probtrackOptions {
   void parse_command_line(int argc, char** argv,Log& logger);
   void modecheck();
   void modehelp();
+  void matrixmodehelp();
   void status();
  private:
   probtrackOptions();  
@@ -112,7 +113,7 @@ class probtrackOptions {
 	 string("Reference vol to define seed space in simple mode - diffusion space assumed if absent"),
 	 false, requires_argument),
   mask2(string("--mask2"), string(""),
-	 string("second mask in both 2 mask modes."),
+	 string("second mask in twomask_symm mode. Waypoint mask or ascii list of masks in wapoints mode."),
        false, requires_argument),
   meshfile(string("--mesh"), string(""),
 	 string(""),
diff --git a/reord_OM.cc b/reord_OM.cc
index 9279553..6c63d01 100644
--- a/reord_OM.cc
+++ b/reord_OM.cc
@@ -311,15 +311,10 @@ int main ( int argc, char **argv ){
  }
  // write_ascii_matrix(newOMmat.t(),"preprecock");
  //Checking for and loading up Seed Coordinates
- string coordname="coords_for_"+ip+".hdr";
- ifstream coordfile(coordname.c_str());
- if(!coordfile){
-   string coordname="coords_for_"+ip+".hdr.gz";
-   ifstream coordfile(coordname.c_str());
- }
- if(coordfile){
-   coordfile.close();
-   read_volume(coordvol,"coords_for_"+ip);
+
+ string coordname="coords_for_"+ip;
+ if(fsl_imageexists(coordname)){
+   read_volume(coordvol,coordname);
    coordbool=true;
    mycoordmat.ReSize(coordvol.xsize(),coordvol.ysize());
    for(int j=0;j<coordvol.ysize();j++){
@@ -333,15 +328,9 @@ int main ( int argc, char **argv ){
  }
 
 //Checking For and Loading Up Tract coordinates
- string trcoordname="tract_space_coords_for_"+ip+".hdr";
- ifstream trcoordfile(trcoordname.c_str());
- if(!trcoordfile){
-   string trcoordname="tract_space_coords_for_"+ip+".hdr.gz";
-   ifstream trcoordfile(trcoordname.c_str());
- }
- if(trcoordfile){
-   trcoordfile.close();
-   read_volume(tractcoordvol,"tract_space_coords_for_"+ip);
+ string trcoordname="tract_space_coords_for_"+ip;
+ if(fsl_imageexists(trcoordname)){
+   read_volume(tractcoordvol,trcoordname);
    tractcoordbool=true;
    mytractcoordmat.ReSize(tractcoordvol.xsize(),tractcoordvol.ysize());
    for(int j=0;j<tractcoordvol.ysize();j++){
-- 
GitLab