Unix Tutorial for FreeSurfer Users Allison Stevens.

Post on 24-Dec-2015

232 views 3 download

transcript

Unix Tutorial for

FreeSurfer Users

Allison Stevens

What is Unix/Linux?

• An operating system (like Windows and OS X)

• Linux is the free, modifiable, and redistributable version of Unix

• Why use it?

What is Unix/Linux?

• An operating system (like Windows and OS X)

• Linux is the free, modifiable, and redistributable version of Unix

• Why use it?– power to write many scripts with many

commands to work with lots of data– to use computer resources on the

network efficiently, such as clusters

Getting Started

Communicate with operating system through a “shell” or terminal window.

For course-provided Linux computers:Double click Terminal icon on Desktop For Macs:Applications > Utilities > XQuartz (double click)Applications > Utilities > Terminal

Warm Up

Type: and hit enter.

date

Warm Up

Type: and hit enter. Should see

date Mon Apr 6 8:05:24 EDT 2009

Warm Up

Type: and hit enter. Should see

Type: and hit enter.

date Mon Apr 6 8:05:24 EDT 2009

cal

Warm Up

Type: and hit enter. Should see

Type: and hit enter. Should see

date Mon Apr 6 8:05:24 EDT 2009

cal April 2009Su Mo Tu We Th Fr Sa 1 2 3 4 5 6 7 8 9 10 1112 13 14 15 16 17 1819 20 21 22 23 24 2526 27 28 29 30

Directories

• Unix uses a hierarchical file system (think folders in Windows)

Directories

• Unix uses a hierarchical file system (think folders in Windows)

Home is like “My Computer”

Directories

• Unix uses a hierarchical file system(think folders in Windows)

Home is like “My Computer”

Like “My Documents”

Directories

• Unix uses a hierarchical file system (think folders in Windows) Home is like

“My Computer”

Like “My Documents”

Like “My Photos”

Directories

• Unix uses a hierarchical file system (think folders in Windows) Home is like

“My Computer”

Like “My Documents”

Like “My Photos”

picture.jpg

Location

path:/MyComputer/MyDocuments/MyPhotos

Type: and hit enter. Should see

shows “present working directory” or current location as a path

pwd

/home/nmrclass

/Users/YourName

OR

Opening a Directory

• Not double clicking • Type command to “open”

• Commands to open files will differ

Navigating Directories

“change directory”: move into a folder

“list”: see contents of directory

ls

cd __

ls __

Navigating Directories

“change directory”: move into a folder

“list”: see contents of directory

ls

cd __

ls __

Desktop matlab tmp TUTORIAL_DATA

Anatomy of a Command

command -option1 –option2 file

command - -help

Anatomy of a Command

command -option1 –option2 file

command - -help

ls --help

Try:

Directory Contents

• List contents of directory you are in lists names of directories/filesls

ls -lrt

ls -l

ls -a

Directory Contents

• List contents of directory you are in lists names of directories/files lists hidden files too

.cshrc

.bashrc

.alias

ls

ls -lrt

ls -l

ls -a

Directory Contents

• List contents of directory you are in lists names of directories/files lists hidden files too lists file details

drwxrwx---

user groupothers

ls

ls -lrt

ls -l

ls -a

Directory Contents

• List contents of directory you are in lists names of directories/files lists hidden files too lists file details lists recent files last

ls

ls -lrt

ls -l

ls -a

Save Some Time

Filename Completion

hit Tab key should see hit

enter

History

hit key should see

ls Des

ls Desktop

ls Desktop

Changing Directories

makes a new directory “practice”

changes to directory “practice”

mkdir practice

cd practice

ls -lrt

pwd

ls

pwd

/home/nmrclass

/home/nmrclass/practice

should see

should see

should see Nothing!

Changing Directories

Changing Directoriesmkdir stuff

ls

makes folder “stuff” inside practiceshould see “stuff”

Using an Editor

If using a Mac:

Type: I could write a script.File > Save (Buffer)

File > Exit emacs

should see “mynotes.txt”

emacs mynotes.txt open -e mynotes.txt

ls

Format > Make plain textFile > Save

Using an Editor

If using a Mac:

Type: I could write a script.File > Save (Buffer)

File > Exit emacs

should see “mynotes.txt”

gedit mynotes.txt

ls

Format > Make plain textFile > Save

open -e mynotes.txt

Using an Editor

Copying files

ls

cp --help

cp mynotes.txt stuff

cd stuff

more mynotes.txt

learn all the options or “arguments”

is the copy command

cp

Copying files

ls

cp --help

cp mynotes.txt stuff

cd stuff

less mynotes.txt

learn all the options or “arguments”

is the copy command

cp

Changing Directories

shows one directory up

ls ..

pwd /home/nmrclass/practice/stuff

ls ../.. goes up two!cd ..

should see

cd ../..

can also do (but don’t right now):on

Copying / Moving files

cp mynotes.txt myothernotes.txt

Could also use do:

mv myothernotes.txt hernotes.txt

mv hernotes.txt ..

Removing Files

rm mynotes.txt

ls

pwd should be in “stuff”

ls

Things to know

• Case sensitive• Does not like spaces in file names

(e.g. filename.txt vs. file name.txt)

• Ctrl+c kills a process & brings back command prompt

• Type ‘q’ to quit the program ‘less’• Highlight & middle click to copy & paste• Use ‘&’ to open a program in the background

Cannot open a 2nd program if do not have a command prompt

Review

• no double clicking• mkdir• ls• cd• pwd• emacs, gedit, vi, pico• cp• rm

Using FreeSurfer

With FreeSurfer, certain variables must be set in order to use it correctly:

FREESURFER_HOME

SUBJECTS_DIR

tell Operating System where FreeSurfer is

tell FreeSurfer where data is

Required Variables

• To use FreeSurfer you’ll have to do:

setenv FREESURFER_HOME /home/apps/freesurfer

source $FREESURFER_HOME/SetUpFreeSurfer.csh

tell Operating System where FreeSurfer is

source this script to get your computer ready to use FreeSurfer (sources other scripts & sets other variables)

setenv SUBJECTS_DIR /path/to/data

Required Variables

• To use FreeSurfer you’ll have to do:

export FREESURFER_HOME=/home/apps/freesurfer

source $FREESURFER_HOME/SetUpFreeSurfer.csh

tell Operating System where FreeSurfer is

source this script to get your computer ready to use FreeSurfer (sources other scripts & sets other variables)

export SUBJECTS_DIR=/path/to/data

Required Variables

To go to location of your data:

$ means take the value of the variable

cd $SUBJECTS_DIR

setenv SUBJECTS_DIR /path/to/data

Required Variables

To go to location of your data:

$ means take the value of the variable

cd $SUBJECTS_DIRaka

cd /path/to/data

setenv SUBJECTS_DIR /path/to/data

$

How ‘echo’ works:

To set a variable:

To check what a variable is set to:echo $TEST_VARIABLE

setenv TEST_VARIABLE yourfirstname

echo Allison is cool.

Required Variables

With FreeSurfer, certain variables must be set in order to use it correctly:

FREESURFER_HOME

SUBJECTS_DIR

tell Operating System where FreeSurfer is

tell FreeSurfer where data is

echo $FREESURFER_HOME

echo $SUBJECTS_DIR

To check variables

More Help

http://surfer.nmr.mgh.harvard.edu/fswiki/FsTutorial/CommandLineNavigation

Links on Wiki under “Unix Tutorial”

Glossary of Unix commands

The End

Good Luck!

Intro to FreeSurfer Jargon

voxelsurfacevolumevertexsurface-basedreconcortical, subcorticalparcellation/segmentationregistration, morph, deform, transforms

(computing vs. resampling)

What FreeSurfer Does…

FreeSurfer creates computerized models of the

brain from MRI data.

Input:T1-weighted (MPRAGE)

1mm3 resolution(.dcm)

Output:Segmented & parcellated conformed

volume(.mgz)

Intro to FreeSurfer Jargon

voxel

Intro to FreeSurfer Jargon

surface

Intro to FreeSurfer Jargon

surface

Intro to FreeSurfer Jargon

vertex

Recon

“recon your data”…short for reconstruction

…cortical surface reconstruction…shows up in command

recon-all

Recon

Volumes

orig.mgz T1.mgz brainmask.mgz wm.mgz filled.mgz(Subcortical Mass)

Cortical vs. Subcortical GM

coronal

sagittal

subcortical gm

cortical gm

Cortical vs. Subcortical GM

coronal

sagittal

subcortical gm

Parcellation vs. Segmentation

(subcortical) segmentation

(cortical) parcellation

Intro to FreeSurfer Jargon

voxelsurfacevolumevertexsurface-basedreconcortical, subcorticalparcellation/segmentationregistration, morph, deform, transforms

(computing vs. resampling)

FreeSurfer Questions

Search for terms and answers to all your questions in the Glossary,

FAQ, orFreeSurfer Mailing List Archives

Registration

Goal:to find a common coordinate system for the input data sets

Examples: • comparing different MRI images of the

same individual (longitudinal scans, diffusion vs functional scans)

• comparing MRI images of different individuals

12/13/2011Flirt 6 DOF

subject

Flirt 9 DOF

target

Inter-subject, uni-modal example

Flirt 12 DOF

Linear registration: 6, 9, 12 DOF

Flirt 6 DOFFlirt 9 DOFFlirt 12 DOFsubjecttarget

Linear registration: 6, 9, 12 DOF

targetsubjectFlirt 6dofFlirt 9dofFlirt 12 DOF

Linear registration: 6, 9, 12 DOF

targetsubjectFlirt 6 DOFFlirt 9 DOFFlirt 12 DOF

Intra-subject, multi-modal example

before spatial alignment

after spatial alignment

before spatial alignment

after spatial alignment

before spatial alignment

after spatial alignment

Inter-subject non-linear example

target CVS reg

Some registration vocabulary

• Input datasets:– Fixed / template / target– Moving / subject

• Transformation models– rigid– affine– nonlinear

• Objective / similarity functions

• Applying the results– deform, morph, resample, transform

• Interpolation types– (tri)linear– nearest neighbor

Writing Scripts

• Putting multiple commands together. • Automatically running a sequence of

commands• Example: create a file named

my_first_script.csh with the contents: #!/bin/csh

setenv name FreeSurferecho I love $name !

% chmod u+x my_first_script.csh% ./my_first_script.csh

Loops in Scripts

• You can create loops, if statements, …• Example: create a file named

my_first_loop.csh with the contents:

#!/bin/csh

foreach name (‘Bill Murray’ ‘Wes Anderson’)echo I love $name !

end

Inputs to Scripts

• You can create take inputs from the command line

• Example: create a file named my_first_IO.csh with the contents:

#!/bin/csh

echo The $0 command is called with $#argv parametersecho parameter 1 is $1echo parameter 2 is $2

Required Variables

• To use FreeSurfer you’ll have to do:

setenv FREESURFER_HOME /home/apps/freesurfer

source $FREESURFER_HOME/SetUpFreeSurfer.csh

tell Operating System where FreeSurfer is

source this script to get your computer ready to use FreeSurfer (sources other scripts & sets other variables)

setenv SUBJECTS_DIR /path/to/data

Registration

-align subjects-common space-reference points b/w subjects will be

sametransforms

template

deform

morph

warp

compute

resample

More Help

alias e emacsman alias

ls file* lists file1, file2, file3ls file[12] lists file1 and file2 but not file3

command >>& file.txt save output to screen and errors in text file