Overview

The whole pipeline from fid to MLR is done mostly automatically with a matlab script. There are the steps you need to do:

  1. Run dofmrigru to create directories and move files This part creates a few directories: Etc, Pre, Pre/Aux, Pre/Mask. Fid files/directories are placed in Pre., supporting files (e.g. stimfiles, etc.) are placed in Etc, Fid files which are not likely to be used are placed in Pre/Aux and a Pre/Mask subfolder is also created as a working folder for generating a mask in sense (this will come later). It will also prompt you to setup MotionComp parameters that will get run in the second pass.
      dofmrigru
  2. Mark peaks Use the command peak to mark the peaks in the cardiac, respiratory and acquisition traces of the car/ext files.
  3. Mask for sense Make a mask for the sense processing (only necessary if your using parallel acquisition)
  4. Run dofmrigru again to process files, convert into nifti and move into MLR directories It will run epirri5, postproc, sense reconstruction etc.. It will then create directories needed by MLR: Anatomy, Raw, and Raw/TSeries. Files are converted into nifti format and stored in the appropriate place. Then mrInit is run.
      dofmrigru
  5. mrAlign You should now run mrAlign and align your session anatomy to your canonical 3D anatomy. Then “Reload Source as Destionation” and load one of your Raw/TSeries as Source and do “Initialize Alignment from Header” and then Export the Alignment to MLR 4.5. See detailed instructions here.
  6. MLR motion correction If you did not run motionComp in the second pass of the dofrmigru script, you can now run motion compensation in mrLoadRet (Analysis→Motion Compensation→Full Motion Comp). You can do this before or after you have run mrAlign. It should take about an hour to run.

Computer setup

Make sure your computer has the following:

XCode

  1. XCode from your install CD (came with the computer). Or you can get it from the App Store or download from Apple Developers website. You can use Justin's login:
      login: eigenvalue
      password: 1q2w3e4r

If you do not have XCode installed you will get an error if you try to run the peak function.

Install libraries with fink

  • The easiest thing to do, is copy from someone else's working installation, by doing:
  cd /
  rsync justin@terranova:/sw .

If you copy from someone else's installation, you should make sure that fink is in your local path (in your cshrc/bashrc.mine file). The two paths that you need to set up are /sw/bin and /sw/sbin. See Fink: Setting up your environment variables for a detailed walkthrough.

Or, you can copy it from internal server:

sudo cp -r /usr4/public/sw_dev /sw

since the latest fink has library problem with RRC command(e.g. peak), don't download it.
Then, set the path to fink bin

sourse /sw/bin/init.sh

set the path to your .cshrc or .bash_profile

echo 'source /sw/bin/init.sh' >> ~/.cshrc (or ~/.bash_profile)

Install this version of fink but beware that it is likely outdated. Update to latest version by typing command line

  fink selfupdate-rsync

following installation.

  • Then run the following
    fink index
    fink scanpackages
  • Find fftw3 and other libraries through fink.
    fink install fftw3
    fink install openmotif4
    fink install mesa-libglw-openmotif4
    fink install libpng3
    fink install libjpeg-shlibs
  • You also need the xview library to run “stimulate.” The installer is located at http://www.cbm.brain.riken.go.jp/~uken/mac/xview-universal.zip.

MRI Support Unit functions that use perl need the following link set up

ln -s /usr/bin/perl /usr/local/bin/

To do this, you may need to create the directory /usr/local/bin – you may also need to be root to do this.

MRI Support Unit network folders

There are two network folders (/usr1 and /usr4) from the MRI Support Unit that you should always have mounted on your computer. /usr1 is usually used for data and /usr4 has software tools.

For Mac OS 10.5 Leopard you can mount them using the program “Directory Utility” which is found in /Applications/Utilities. If you are using Snow Leopard, see below.

Make sure to click the “Show Advanced Settings” button to make it appear like the above. Then click on Mounts and enter the following:
Drives to mount: nfs:hebb/export/usr1 and nfs:is/export/usr4. Click verify/apply and then do the same thing for usr4. You will now have these drives mounted as /usr1 and /usr4. This mount point should be available even after rebooting your computer.

For Snow Leopard “Directory Utility” has moved and you need to instead be using “Disk Utility” (what is wrong with those people in Cupertino?). “Disk Utility” is in /Applications/Utilities . From Disk Utility go to the File menu and select “NFS mounts…”. Click on the “+” button at the bottom left and add /usr4 and /usr1 as above.

You should also add the directory /usr4/local/mac_bin2 which has the MRI Support Units software to your path. In your .cshrc.mine (or .cshrc) file add the following line, which will addend the /usr4 sub-directory to your current path ($path):

set path = ( $path /usr4/local/mac_bin2 ) 

Specifically, in terminal in your home directory, type

pico .cshrc

to bring up an editor. Paste in the 'set path' code from above and save the file (control-o) and exit.

Then check to see if it worked:

terranova:/Users/justin> source .cshrc
terranova:/Users/justin> which pp

The following should return:

/usr4/local/mac_bin2/pp

You can also check to make sure that your .cshrc file is being interpreted by your shell correctly. Open a new terminal. Assuming that your shell is tcsh (not bash), type echo $path. This should display your entire path and should include the /usr4 directory at the end.

We have several functions we will be using often from usr4 for SENSE processing:

peak, pp, epirri5, sense_prep, sense

If you have trouble accessing the directories, you should make sure that you have your fixed IP address set correctly in System Preferences/Network.

MRI Support Unit User ID

You should also change your user id so that you can access the files on /usr4. After Ken has set up an account for you on their system, you can check (on some other machine) what your id is, by doing

terranova:/usr4> ls -l /usr4
drwxr-xr-x    2 13341   3003      102 Mar  8 17:18 brett/

The number 13341 in this case, is your user ID. The number 3003 is the group ID for gru. You will now need to change this on your own system. But, first *and this is very important* make sure you have the root account enabled on your machine! Once you change your user id, you will not be able to access your own files and you will need to be sure to have root access to reset your files to your ownership. So, first go to a terminal and set the root password. Assuming your account has Administrator privileges:

sudo passwd root
Enter Password: 
Changing password for root
New password:  
Verify password:

Enter your password first and then the password you want for root next.

Now, got to System Preferences/Accounts unlock the lock at the bottom left and then right click on your account to get the “Advanced Options”, where you can set the User ID and Group:

Once this is done, you will need to change the ownership of your files:

su root
cd /Users
chown -R 13341:3003 brett

Where 13341 should be your user id, 3003 is our group id (should always be the same) and brett is the name of your user account.

Data Processing Stream

You can checkout gru processing scrips under ~/proj (e.g. dofmrigru) from:

svn checkout http://gru.brain.riken.jp/svnpub/gru ~/gru

Make sure the scripts are available in your path. The major script used for data processing is called “dofmrigru.”

Things to do after a scan, before you run dofmrigru at all...

At the end of your experiment, make a copy of the scan log, RRC consent form, and RRC questionnaire. The RRC needs these documents filed in their respective folders downstairs with the magnet. The copies are for GRU to keep.

The set of forms that needs to be filed for GRU records are:

  1. completed GRUExpProtocol document (available in gru svn repository)
  2. GRU explanation and informed consent forms
  3. (optional but useful) copy of RRC scan log
  4. (optional but useful) copy of RRC informed consent
  5. (optional but useful) copy of RRC questionnaire

A set of originals as well as a set of copies needs to be filed in a secure cabinet in Justin's office. Usually, Kenji can take care of this for you but always good to know what's going on. Kenji will also update the secure linkable annonymity (sp?) chart and non-online scan history chart as needed.

Now, an electronic copy of JUST THE GRU EXPERIMENT PROTOCOL SHEETS should be emailed to yourself so you can keep them with the scan directory on usr1. Use the GRU scanner upstairs to email a pdf copy (under filename, type s###yyyymmdd_protocol) to youraddress@brain.riken.jp. Where to file them will be discussed below…

"Hot off the scanner" datadir, usr1/justin/data

The GRU data directory on usr1, 'usr1/justin/data', will contain all hot-off-the-scanner fids. We will dump everything related to the scan in here - protocol sheets, car/ext files, stimfiles, etc. - and dofmrigru is designed to look in this directory and grab what we need into your local directory. Ultimately, datadir acts like a backup copy of your original data.

In case you haven't already, mount usr1 (scan data from downstairs) and usr4 (contains the functions you will need to process your data).

Open 'Connect to Server' (apple-K on Desktop)

Server Address: nfs://hebb/export/usr1  
Server Address: nfs://is/Volumes/usr4

Click Connect.

If you ls /usr1/justin/data in Terminal, a directory called s###yyyymmdd should already exist with fids, car/ext files, and stim files from downstairs.

Now, save emailed s###yyymmdd_protocol.pdf document into /usr1/justin/data/s####yyyymmdd.

You're also encouraged to carefully clean up /usr1/justin/data/s####yyyymmdd. Look over your GRUExpProtocol sheet and delete irrelevant stimfiles or car/ext files that were scrapped downstairs. But be careful! Make sure that your 3d anatomy was processed (was fftw3rd run before saving downstairs?). If some fid names contain periods '.' in the filename besides the extension, fix them (in matlab, there is a function called fixbadchars).

Update Online Scan History

This is also a good time to update your online Scan History. Make notes if you were sleepy in some runs, if some car/ext files may be corrupt/need to be checked…

Now you're ready to run dofmrigru. Read on…

Run dofmgrigru, First pass

The first pass of dofmrigru will grab and sort files from datadir into your newly created scan directory. It will run some initial processing scripts and set you up for the second pass of dofmrigru.

First make an new empty scan directory in your local data directory.

mkdir ~/data/Experiments/s###yyyymmdd

If your scan was a retinotopy, your scan directory may be ~/data/Retinotopy/s###yyyymmdd

Now, cd to this empty scan directory and start matlab (make sure you've already run X11 so your windows show up)

cd s###yyyymmdd
matlab -nodesktop
pwd

pwd should return the scan directory.

To run dofmrigru, type into the matlab terminal

dofmrigru

The dofmrigru script defaults to grabbing files from datadir /usr1/justin/data/s###yyyymmdd. If you happen to have your own “hot off the scanner” data directory (like /usr1/yourname/data) you can tell dofmrigru to look there instead by passing in the argument dofmrigru('dataDir=/usr1/yourname/data').

In your terminal, dofmrigru should print a list of files that it found in your datadir. Some things to check for:

  1. If you took both a 2d and 3d anatomy during your session, were they both picked up? If not, it may not have been processed (fftw3rd) downstairs.
  2. If running sense (actually, this page is written for sense processing using dofmrigru) make sure that both your reference and noise scans were picked up.
  3. If you copied the electronic version of your experiment protocol form into your own data directory, a pdf should have been picked up.
  4. Were all your relevant stimfiles found? Check your protocol notes.

Now, a window should pop up (often behind your terminal window if you're using X11) 'Match the car file with the scan.' Refer back to your experiment protocol sheet and check that the correct CAR/EXT (not stim!) files are matched with the correct scans (sometimes, car/exts are scrapped downstairs so check each number and make note of skipped files. The start and end timestamps may be useful if you're not sure which car/exts were terminated early). Use the arrow '>' button to toggle between scans. Press OK.

Your terminal should now print a list of commands that dofmrigru, first pass will run. Check that the car/exts are being dumped into their corresponding fid directories.

At prompt 'OK to run above commands? (y/n)?' type 'y.' 

The printed commands will be executed. Copying fid files and epirri5 processing will all take some time (on mrdarcy, 3minutes for 10fids). All terminal screen printouts will be logged in a text file called 'logbook.'

A mrInit window to 'Initialize session for mrTools' in s###yyyymmdd will pop up. Fill in the blanks and press Ok.

Another window 'Choose group parameters' will pop up so you can link the correct stimfiles to each scan. This can be done manually later, but it is much easier to do now when you have your protocol sheet in front of you.

The Copy Parameters button will let you copy the current scan description, nFrames, and junkFrames to other scans of the same type.

Here are some scan descriptions that GRU recommends (esp if you're using any of yuko's functions like shiftAvg or sdtDotsAnalysis… scan descriptions will start to matter):

For Retinotopy

  1. scanDescription: 'rings expanding' and 'rings contracting'
  2. scanDescription: usually, dir=-1 is 'wedge CW' and dir=+1 is 'wedge CCW' ← pay attention to non-pluralness and order
  3. junk the first 8 frames (half cycle)

For sdtDots

  1. sdtDots vanilla co5, 310 frames, don't junk
  2. sdtDots mixed co335, 310 frames, don't junk
  3. sdtDots localizer co100, 310 frames, don't junk
  4. block localizer, 210 frames but junk the first 10 frames = 200 frames (tr1.2s, 12s on, 12s off, 20 frames per cycle, junk first half cycle)

Click OK. Prompt will show up in matlab terminal, 'Do you want to append any notes? (y/n)?' type 'n.'

A window will ask you to 'Set motionComp parameters'. Note that motionComp will actually be run at the end of the second pass, but we will be setting the parameters now.

  1. default interpolation Method 'linear' is correct.
  2. 'baseScan' should be set to whichever run was taken closest to the session anatomical that you will be using to align - usually the first scan since the session anatomical is taken in the beginning of the experiment (not the case right now since we are still wondering if we should replace the 2danat scan with the 3danat).
  3. 'baseFrame' should be set to 'mean' (not default as of 23 feb '10)
  4. sliceTimeCorrection should be UNCHECKED (not default as of 23 feb 2010)
  5. press 'Set crop region' and the reconstructed sense reference image should show up. cropping in mrTools (like mrAlign) is for image normalization only, so don't worry if you're not including all of the slices. just aim to capture as many slices as you reasonably can with gray matter in it. crop so that most of the cropped region is the brain and not the skull or background noise:

Click OK. You are done with dofmrigru's first pass!

things to do before dofmrigru, second pass

The second pass of dofmrigru will perform physiofix and sense reconstruction, as well as a full motion comp.

  1. Sense reconstruction will require a hand-drawn mask around the brain (and anything non-noise)
  2. Physiofix will require that you have run a usr4 program called 'peak'

Here's how to do both…

Draw the Mask

The mask will be a hand drawn ROI around your sense reference image. dofmrigru created a dummy mrLoadRet directory to allow you to do this in folder 'Pre'. Draw the ROI in mrLoadRet and export it as a nifti file mask.img/hdr into Pre. Here are the details:

In your scan directory, start matlab (and X11):

cd ~/data/Experiments/s###yyyymmdd
matlab -nodesktop
pwd

pwd should return your scan directory.

In matlab, start mrLoadRet

mrLoadRet

Your sense reference image should try to load automatically. If this doesn't happen, load it through the GUI: File > Base Anatomy > Use current scan. Choose any frame but 0 or 1 (frame 1 contains the nav echo… a white streak and no brain).
You should see a sense reconstructed brain in mrLoadRet

Make sure you are on the first slice and go to ROI>Create>Polygon (or apple-P). 'Create a new ROI' window should pop up. Name this ROI 'mask' and choose a color that will stand out against black. Click OK.

Your pointer should have turned into a cross. This means you are in the polygon drawing mode and you should finish drawing a polygon before clicking other buttons to avoid running into errors. Draw a generous polygon around any part of the image that is not “black” whether it be brain or wrapped skull. You want to unfold as much of the non-noise image as possible during the sense reconstruction. The default Matlab-based polygon drawing method doesn't allow the mask to extend beyond the edge of the EPI. You can change the roiPolygonMethod option under Edit > Preferences to getptsNoDoubleClick to enable drawing outside the EPI edges as illustrated in the figure below. In the end, when you double click and close the polygon, your ROI will be restricted to the image boundaries. Click away!

If you use the default polygon drawing method in mrLoadRet, you will have to commit the shape of each new polygon before moving on to the next slice. This is done by double clicking on a vertex of the completed polygon. You can also stretch and edit the shape of your completed polygon by simply dragging a vertex of your choice. When you have committed your polygon, it will change into a line with the contrast color of your choice. If you use the getptsNoDoubleClick method you will instead have to press the return key to commit the shape.

Make sure your pointer is back to its original shape, not the cross, and slide over to slice 2. Go to ROI>Add>Polygon (apple-O) and draw another generous polygon around the brain. Repeat until you have encircled the brain in all slices. You can add or subtract polygons from your image using apple-O or apple-W.

Once you have created a mask ROI spanning all slices, you might want to save it to the s###yyyymmdd/Pre/Mask directory. In fact, you may want to save your ROI every 8-10 slices just in case you make a mistake during the process. Go to >File>ROI>Save to save a copy of the editable ROI. This is very useful if you ever want to go back to your ROI to edit it.

Next, you will want to export your ROI so that it can be used. Go to >File>Export>ROI and you should get a window 'Specify name of nifti file to export ROI to'. The name should include the word 'mask' (like mask.img) and should be exported to the s###yyyymmdd/Pre directory, which is not usually the default directory. Make sure you are in the parent Pre directory, not parent Pre/Mask/Pre!

You are done creating the mask.img/hdr in Pre.

!Peak

Physiofix will need you to have run 'peak' in every fid that you want to physiofix. The relevant car file should have been dumped into the corresponding fid directory in Pre during the first pass of dofmrigru. All three output “peak files” (respriatory, cardio, and acquisition) should be inside each fid directory before the second pass of dofmrigru is run. If you are missing any peak files, dofmrigru will assume that you want to skip that physiofix.

One thing to remember is that 'peak' is not justin's matlab command, peak.m, but a command found in usr4. The path is /usr4/local/mac_bin2/peak. If matlab is still running in your terminal, you will need to type this command with an exclamation point like this:

!peak

to tell matlab it is an external command. In matlab, type

!which peak

to check that the non-matlab “peak” command is indeed aliased to /usr4/local/mac_bin2/peak. If not, check that usr4 is mounted (see above), and type

!alias peak '/usr4/local/mac_bin2/peak'  <- not sure if this is the right format...

If you are running this outside of matlab, just omit the exclamation point.
Since MATLAB loads its own library, you can't run some command provided by fMRI support unit. For example

 >>!peak -help: Trace/breakpoint trap
 dyld: Library not loaded: /usr/X11/lib/libpng12.0.dylib
   Referenced from: /usr/X11/lib/libpng12.0.dylib
   Reason: Incompatible library version: libpng12.0.dylib requires version 45.0.0 or later, but libpng12.0.dylib provides version 40.0.0

you can run the command from the terminal, the MATLAB library updated manually. In the above case,

cd /Applications/MATLAB_R2011b.app/bin/maci64
sudo mv libpng12.0.dylib old_libpng12.0.dylib
sudo ln -s /sw/lib/libpng12.0.dylib .

When you run peak, this window should pop up:

Go to 'Load raw' in the upper right corner and look for the first fid directory in Pre. Inside this fid directory, you should see the corresponding car/ext file pair. The car file contains the information needed for physiofix (ext contains other information like square waves for button presses). Select that car file and click OK.

Your car file should have been loaded. The magenta spikes (tightly packed) are the acquisitions and the blue sinusoid is your physiological signal.

Below the Load raw button should be three radio buttons - respir, cardio, and acq. Clcik on the 'respir' radio button. We will start with your respiratory peaks.

Click the 'Smooth' button in the right column. You should see that your noisy respiration data was smoothed by the green line. Usually, the default settings are good, but in case the smoothing looks bad, try playing with the smooth window (Less or More buttons) and smooth again.

After smoothing, click the 'Find Peaks' button in the right column. Vertical yellow lines should hit at every peak. Sometimes, peaks will be missed, other times, peaks will be indicated in obvious rifts due to noise. As a rule of thumb, try to make the “peaks” occur in even intervals. If you're missing peaks because of signal drop out (sniusoid is just a flat line), place peaks at even intervals. You can add and remove peaks using the right mouse button. If you have the apple magic mouse, you will need to change your settings to have a right mouse button (Finder > System Preferences > Mouse > check the Secondary Mouse Button)

The gray slider below the black peaks window will let you toggle through the entire range of the recording. Make sure that all peaks are marked.

Note that you will need to place at least one peak before and one peak after the acquisition pulse train to run physiofix. If there happens to be no peak at the beginning or end of the acquisition period (magenta spikes), mark an arbitrary one at a reasonable frequency.

Once all peaks are marked, click 'Save peaks' in the right column above the Quit button (easy to mix this up with 'Save raw'… but you want 'Save peaks'). Keep the default naming and click save. respir.peak.bit should have been saved inside the corresponding fid directory.

Repeat the process for the cardio radio button. Finding peaks in cardio signals are harder.

Repeat the process for the acq radio button, but skip the smoothing process. Just click “Find peaks” and “Save peaks.”

If you look at your fid directory in Finder, you will notice that three new peak files: - respir.peak.bit - cardio.peak.bit - acq.peak.bit have been saved inside.

Now you have finished running peaks on your first fid!! Now go do the same for every functional fid… Have fun! (Oh, you'd better believe that I will)

If you have an “acq.peak.bit” doesn't match the acq pulse number, use a script “caracq” to specify correct number. For example,

 caracq 130312-08.car 9316

Checks before you go on to the second pass

Open up your local scan directory (~/data/Experiments/s###yyyymmdd) using Finder - Look in Pre and make sure that mask.img/hdr exists. - Use the arrow keys to toggle your selection over each functional fid folder in finder and make sure that the three peak files are present in each… if you are missing any peak files, the missing physiofix will be skipped.

General note: If you find that you need to rerun dofmrigru, first pass, anytime (like you found that you had linked a corrupted car file, the sense reference.img wasn't copied correctly… lots of things can happen), just move your scan folder to a different foldername such as 's###yyyymmdd_imessedup_deleteme' and create a new directory mkdir s###yyyymmdd (without overwriting your old work) and rerun dofmrigru, first pass. As long as this new directory does not contain folders like 'Pre' or 'Anatomy', the first pass will run. After the first pass is complete, you can ensure that peak and mask files are copied across from the old directory by using dofmrigru('getFiles=~/data/Experiments/s###yyyymmdd_imessedup_deleteme'). You don't have to redo everything!

Running dofmrigru, Second pass

Go to your scan directory that now contains Pre/Mask.img and .hdr as well as the three peak.bit files in each fid directory (ls Pre/*.fid/*.peak.bit).

cd ~/data/Experiments/s###yyyymmdd

Run matlab (after X11)

matlab -nodesktop
pwd

pwd should return your scan directory.

If the first pass has already been run on this directory (the flags we check for are whether if folders like Pre and Anatomy already exist), then dofmrigru should default to the second pass. Type into the matlab terminal

dofmrigru

If you are missing any peak files, you will get a prompt asking you if you would like to proceed. Answer yes if you skipped these files intentionally.

After Mauro's sense reconstruction, full motion comp will be performed according to the params set in the first pass of dofmrigru.

It takes several hours and message “Done” will print when the script is finished.