Differences between revisions 1 and 6 (spanning 5 versions)
Revision 1 as of 2013-02-22 13:33:48
Size: 2719
Comment:
Revision 6 as of 2013-02-22 19:34:49
Size: 5815
Comment:
Deletions are marked like this. Additions are marked like this.
Line 1: Line 1:
I've attached the script I use to get blue surfaces, a purple cursor, a
specific segmentation opacity, and a specific zoom. I've also attached a
file with a list of aliases I use. Within that list, you can find the
tkmedit command to call this script. (The aliases need to be saved in a
~/.alias).
<<TableOfContents>>
Line 7: Line 3:
A list of other options that can be added to the script are here:
https://surfer.nmr.mgh.harvard.edu/fswiki/TkMeditGuide/TkMeditReference/TkMedit$
== Scripts ==
=== tkmedit tcl script ===
As mentioned in the course, you can create a tcl script to use with tkmedit or tksurfer so that they open with your preferences already selected (such as surface color, surface thickness, etc.). Below is an example of a tcl script that interacts with tkmedit:
Line 10: Line 7:
 more allisons_surfaces.tcl {{{
Line 13: Line 10:
Line 18: Line 14:
SetSurfaceLineWidth 1 0 2
Line 19: Line 16:
SetSurfaceLineWidth 1 0 2
Line 24: Line 20:
}}}
Line 25: Line 22:
 more reconall_all.csh
#!/bin/tcsh -ef
The above script does the following things (the order below corresponds to the order of each line in the script above):
 *Zooms in once
 *!RedrawScreen applies this zoom
 *Sets one hemisphere of the white surface to blue
 *Sets the other hemisphere of the white surface to blue
 *Sets one hemisphere of the white surface to a thickness of 2
 *Sets the other hemisphere of the white surface to a thickness of 2
 *Sets one hemisphere of the pial surface to a thickness of 2
 *Sets the other hemisphere of the pial surface to a thickness of 2
 *Turns off the original surface
 *Changes the cursor (+) to purple
Line 28: Line 34:
source subjects.csh The script can be created in any text editor (i.e. emacs, vi, gedit) and should be saved with the {{{tcl}}} extension (i.e. surfaces.tcl) in a convenient location.
Line 30: Line 36:
foreach s ($SUBJECTS)
    set cmd = (recon-all -autorecon2-cp -autorecon3 -no-isrunning -s $s)
# set mdir=$SUBJECTS_DIR/$s/mri
# if (-e $mdir/aseg.frozen.auto.mgz) then
# echo skipping $s
# continue ;
# else
# echo processing $s
# endif
    if (`hostname` == seychelles) then
        pbsubmit -q lieutenant -l nodes=1:opteron -c "$cmd"
        sleep 30;
    else
        eval $cmd
    endif
end
A list of other options that can be added to the script are here:
https://surfer.nmr.mgh.harvard.edu/fswiki/TkMeditGuide/TkMeditReference/TkMeditScripting

In order to use the script, you would call it using the {{{-tcl}}} flag with your tkmedit command. For example:
{{{
 tkmedit subj001 brainmask.mgz -aux T1.mgz -surfs -tcl /path/to/surfaces.tcl
}}}

=== Aliases ===
If you find yourself typing the same commands over and over, a nice shortcut is to make an alias for it. An alias is a short nickname for the full command. For example, instead of typing out the command {{{ls -l}}} each time you want to use it, you can create an alias for it like this:
{{{
alias l "ls -l"
}}}

Now, if you type {{{l}}} and hit enter in a terminal, you'll get the same response as you would if you typed {{{ls -l}}}.

For every new terminal window you open, you will have to type the above command again in order for it to work. To avoid this, you can create a text file with all the aliases you commonly use. This file will need to be saved in your home directory with the name:
{{{
.alias
}}}

You're not done yet. You also need to source that text file within your configuration file (i.e. {{{.cshrc}}} or {{{.bashrc}}} found in the home directory). You would add this line to that file:
{{{
source ~/.alias
}}}

Now, every time you open a new terminal window, it will automatically source your alias file.

Below are some ideas for aliases you may find useful:
{{{
alias ../.. 'cd ../..'
alias ../../.. 'cd ../../..'
alias e emacs
alias .. cd ..
alias unpack 'unpacksdcmdir -src . -targ . -scanonly scan.log'
alias fvwm "freeview -v brainmask.mgz wm.mgz:colormap=heatscale -f ../surf/lh.white:edgecolor='blue' ../surf/rh.white:edgecolor='blue' ../surf/lh.pial:edgecolor='red' ../surf/rh.pial:edgecolor='red'"
}}}

(Note: That last alias is intended to be all on one line.)

For the below, {{{\!*}}} indicates to substitute it with whatever is typed on the commandline.
{{{
alias fv 'freeview \!*'
}}}
So if you typed:

{{{
fv orig.mgz
}}}

The alias will work as if you typed {{{freeview orig.mgz}}}. Similarly, you could use:

{{{
alias tkm "tkmedit \!* brainmask.mgz rh.white -aux T1.mgz -aux-surface lh.white -segmentation aseg.mgz -segmentation-opacity 0.2 -tcl ~/surfaces.tcl"
}}}

And only have to type {{{tkm subj001}}} to open a subject with tkmedit.

This alias will set the {{{SUBJECTS_DIR}}} variable to whichever directory you are currently in.
{{{
alias sd 'setenv SUBJECTS_DIR `pwd`'
}}}

The below alias illustrates that one alias could do multiple things. In this case, you can source !FreeSurfer, change directories to where your subjects are located and set the {{{SUBJECTS_DIR}}} variable all by simply typing {{{fs}}}.
{{{
alias fs 'setenv FREESURFER_HOME /home/apps/freesurfer; source $FREESURFER_HOME/SetUpFreeSurfer.csh; cd /home/apps/freesurfer/subjects; setenv SUBJECTS_DIR /home/apps/freesurfer/subjects'
}}}
Line 48: Line 105:
Finally, the aliases below may be useful but they will only work if they always remain at the bottom of your alias file:
{{{
alias subdir 'echo $SUBJECTS_DIR'
alias fshome 'echo $FREESURFER_HOME'
alias csubdir 'cd $SUBJECTS_DIR'
alias cfshome 'cd $FREESURFER_HOME'
}}}
 
Line 49: Line 114:
=== Batch Processing with recon-all ===
The script below is an example of how you can search for a subject's MPRAGE among several dicoms and then automatically create the recon-all command with its name and location. This script works with the way dicoms at the Martinos Center used to be named. It assumes the dicoms have been unpacked and searches the unpack log file for the typical MPRAGE dimensions, 256 x 256 x 128. From that location, it can find the name of the MPRAGE dicom (the 8th field in the log file, hence {{{awk '{print $8}'}}}) and prints it to a log file with the specified recon-all command.
Line 50: Line 117:
#if you want email notification then add -m $LOGNAME to the pbsubmit line (pbsubmit -q lieutenant -m $LOGNAME -l nodes
=1 etc...


 more run-recon-all.csh
{{{
Line 56: Line 119:
#run-recon-all.csh
Line 64: Line 126:
if (-e $dcmdir/$s/scan.dat) then
    echo "found scan.dat, finding mprages"
    set dat = $dcmdir/$s/scan.dat
if (-e $dcmdir/$s/scan.log) then
    echo "found scan.log, finding mprages"
    set dat = $dcmdir/$s/scan.log
Line 68: Line 130:
    echo "no scan.dat"     echo "no scan.log"
Line 74: Line 136:
echo pbsubmit -f -m astevens -c \"recon-all -i $dcmdir/$s/$mpr -all -s $subjid \"
echo pbsubmit -f -m astevens -c \"recon-all -i $dcmdir/$s/$mpr -all -s $subjid \" >> $log

 more aliases
alias tkm "tkmedit \!* brainmask.mgz rh.white -aux T1.mgz -aux-surface lh.white -segmentation aseg.mgz -segmentation-o
pacity 0.2 -tcl ~/analysis_scripts/allisons_surfaces.tcl"
alias tkmwm "tkmedit \!* brainmask.mgz rh.white -aux wm.mgz -aux-surface lh.white -segmentation aseg.mgz -segmentation
-opacity 0.2 -tcl ~/analysis_scripts/allisons_surfaces.tcl"
alias sp 'setenv SUBJECTS_DIR `pwd`'
alias unpack 'unpacksdcmdir -src . -targ . -scanonly scan.log'



#MUST STAY AT BOTTOM
alias subdir 'echo $SUBJECTS_DIR'
alias fshome 'echo $FREESURFER_HOME'
alias csubdir 'cd $SUBJECTS_DIR'
alias cfshome 'cd $FREESURFER_HOME'
echo recon-all -i $dcmdir/$s/$mpr -all -s $subjid >> $log
}}}

Scripts

tkmedit tcl script

As mentioned in the course, you can create a tcl script to use with tkmedit or tksurfer so that they open with your preferences already selected (such as surface color, surface thickness, etc.). Below is an example of a tcl script that interacts with tkmedit:

SetZoomLevel 2
RedrawScreen

SetSurfaceLineColor 0 0 0 0 1
SetSurfaceLineColor 1 0 0 0 1
SetSurfaceLineWidth 0 0 2
SetSurfaceLineWidth 1 0 2
SetSurfaceLineWidth 0 2 2
SetSurfaceLineWidth 1 2 2
SetDisplayFlag 5 0
SetCursorColor .5 0 .5

The above script does the following things (the order below corresponds to the order of each line in the script above):

  • Zooms in once
  • RedrawScreen applies this zoom

  • Sets one hemisphere of the white surface to blue
  • Sets the other hemisphere of the white surface to blue
  • Sets one hemisphere of the white surface to a thickness of 2
  • Sets the other hemisphere of the white surface to a thickness of 2
  • Sets one hemisphere of the pial surface to a thickness of 2
  • Sets the other hemisphere of the pial surface to a thickness of 2
  • Turns off the original surface
  • Changes the cursor (+) to purple

The script can be created in any text editor (i.e. emacs, vi, gedit) and should be saved with the tcl extension (i.e. surfaces.tcl) in a convenient location.

A list of other options that can be added to the script are here: https://surfer.nmr.mgh.harvard.edu/fswiki/TkMeditGuide/TkMeditReference/TkMeditScripting

In order to use the script, you would call it using the -tcl flag with your tkmedit command. For example:

 tkmedit subj001 brainmask.mgz -aux T1.mgz -surfs -tcl /path/to/surfaces.tcl

Aliases

If you find yourself typing the same commands over and over, a nice shortcut is to make an alias for it. An alias is a short nickname for the full command. For example, instead of typing out the command ls -l each time you want to use it, you can create an alias for it like this:

alias l "ls -l"

Now, if you type l and hit enter in a terminal, you'll get the same response as you would if you typed ls -l.

For every new terminal window you open, you will have to type the above command again in order for it to work. To avoid this, you can create a text file with all the aliases you commonly use. This file will need to be saved in your home directory with the name:

.alias

You're not done yet. You also need to source that text file within your configuration file (i.e. .cshrc or .bashrc found in the home directory). You would add this line to that file:

source ~/.alias

Now, every time you open a new terminal window, it will automatically source your alias file.

Below are some ideas for aliases you may find useful:

alias  ../..  'cd ../..'
alias  ../../..  'cd ../../..'
alias  e  emacs
alias  ..  cd ..
alias  unpack  'unpacksdcmdir -src . -targ . -scanonly scan.log'
alias fvwm "freeview -v brainmask.mgz wm.mgz:colormap=heatscale -f ../surf/lh.white:edgecolor='blue' ../surf/rh.white:edgecolor='blue' ../surf/lh.pial:edgecolor='red' ../surf/rh.pial:edgecolor='red'"

(Note: That last alias is intended to be all on one line.)

For the below, \!* indicates to substitute it with whatever is typed on the commandline.

alias fv 'freeview \!*'

So if you typed:

fv  orig.mgz

The alias will work as if you typed freeview orig.mgz. Similarly, you could use:

alias tkm "tkmedit \!* brainmask.mgz rh.white -aux T1.mgz -aux-surface lh.white -segmentation aseg.mgz -segmentation-opacity 0.2 -tcl ~/surfaces.tcl"

And only have to type tkm subj001 to open a subject with tkmedit.

This alias will set the SUBJECTS_DIR variable to whichever directory you are currently in.

alias  sd 'setenv SUBJECTS_DIR `pwd`'

The below alias illustrates that one alias could do multiple things. In this case, you can source FreeSurfer, change directories to where your subjects are located and set the SUBJECTS_DIR variable all by simply typing fs.

alias fs 'setenv FREESURFER_HOME /home/apps/freesurfer; source $FREESURFER_HOME/SetUpFreeSurfer.csh; cd /home/apps/freesurfer/subjects; setenv SUBJECTS_DIR /home/apps/freesurfer/subjects'

Finally, the aliases below may be useful but they will only work if they always remain at the bottom of your alias file:

alias subdir 'echo $SUBJECTS_DIR'
alias fshome 'echo $FREESURFER_HOME'
alias csubdir 'cd $SUBJECTS_DIR'
alias cfshome 'cd $FREESURFER_HOME'

Batch Processing with recon-all

The script below is an example of how you can search for a subject's MPRAGE among several dicoms and then automatically create the recon-all command with its name and location. This script works with the way dicoms at the Martinos Center used to be named. It assumes the dicoms have been unpacked and searches the unpack log file for the typical MPRAGE dimensions, 256 x 256 x 128. From that location, it can find the name of the MPRAGE dicom (the 8th field in the log file, hence awk '{print  $8}') and prints it to a log file with the specified recon-all command.

set s = $1
setenv SUBJECTS_DIR /path/to/your/data
set log = $SUBJECTS_DIR/recon-all-commands.log
set dcmdir = /path/to/your/dicoms
set subjid = `echo $s |gawk -F- '{print $2}'`

if (-e $dcmdir/$s/scan.log) then
    echo "found scan.log, finding mprages"
    set dat = $dcmdir/$s/scan.log
else
    echo "no scan.log"
endif

set mpr = (`cat $dat | grep "256 256 128" |grep ok | awk '{print  $8}'`)
echo "found mprages, $mpr"

echo recon-all -i $dcmdir/$s/$mpr -all -s $subjid >> $log

FsTutorial/Scripts (last edited 2016-11-04 17:13:29 by AllisonMoreau)