The whole pipeline from fid to MLR is done mostly automatically with a matlab script. There are the steps you need to do:
dofmrigru
dofmrigru
Please refer computer_setup
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.”
You also need to have petable copy in your home directory.
mkdir -p ~/vnmrsys/tablib; cp /usr1/justin/data/tablib/* ~/vnmrsys/tablib
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:
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…
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/export/usr4
Click Connect.
If you ls /usr1/justin/data in Terminal, a directory called s###yyyymmdd should already exist with fids, car 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 files that were scrapped downstairs. If some fid names contain periods '.' in the filename besides the extension, fix them (in matlab, there is a function called fixbadchars).
This is also a good time to update your online Scan History. Make notes if you were sleepy in some runs, if some car files may be corrupt/need to be checked…
Now you're ready to run dofmrigru. Read on…
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:
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 (not stim!) files are matched with the correct scans (sometimes, cars 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 was 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 cars 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 (typically, 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
For sdtDots
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.
Click OK. You are done with dofmrigru's first pass!
The second pass of dofmrigru will perform physiofix and sense reconstruction, as well as a full motion comp.
Here's how to do both…
You need to draw a mask for sensory reconstruction. This help to improve the SNR or the reconstruction. The mask will be a hand drawn ROI around your sense 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
Load any epi scan from “Raw” through the GUI: File > Base Anatomy > Load
Use current scan. Choose frame 2
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.
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)
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!
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 would take several hours and message “Done” will print when the script is finished.
After “dofmrigru” finishing, “mrAlign” needs to be run in order to align your scan to high resolution anatomy. With this alignment, we can compare different sessions. To run mrAlign, you better to make sure that you're in the session directory(sXXXYYYYMMDD) to make things easier. Please refer mralign.