Monday, January 18, 2016

AFNI Install on OS X El Capitan

It's been two and half years (three, if you round up) since I uploaded the first videos about AFNI: How to install it, how to run it, how to make it fulfill all your wildest dreams, which may or may not include taking a dollop of Nutella, drying it in the sun, grinding it into a fine powder, and then snorting it.

I was in Rochester for three weeks in July, lodged at a fly-blown hostel. During the days I would talk with researchers and go to meetings and help design studies, but found myself more often on the benches of Eastman Quadrangle, lazily swatting at mosquitoes and feeling the burst of their rubescent abdomens against my skin. I would sit outside where in the distance you could see a church with large oval stained glass and I would think about nothing in particular. The weather in the mornings was perfect, and I took my exercise down by the Erie canal, up around Cobbs Hill Reservoir, and through neighborhoods I didn't know. In the evenings I would make my way downtown for music at the Eastman School and barbecue on the Genesee. And in those nights I worked, obsessively, on those tutorials and videos whose fate had somehow become strangely entangled with mine. Who knew who was reading, who was watching? There was something of an inverted voyeuristic pleasure in thinking about it.

And now here I am, three years later, promoted to seedy manhood and reminiscing of towns and cities; those icy runs on the country lanes of Northfield in windchills of forty below; going to the piano rooms of the Wexner center to practice Scriabin etudes and my beloved, immortal Waldstein; running around Woodlawn field, each loop zero point four-two miles, running ten, twenty, thirty loops at a time, hoping that enough physical exertion would work off a serious infection of heartsickness; crossing the finish line in Indianapolis with burning lungs and knotted calves, surrounded by the vomit of fellow runners, the clock just a shade under two hours and thirty minutes, feeling something break inside me and knowing it was the end of something.

Such were the days, comrades - and how the days have changed! All that I did back then was well enough for its time; but as new wine requires new bottles, so do new operating systems require new installation instructions; and it has come to my attention that several AFNI users are having issues, both technically and emotionally, with getting AFNI to cooperate with Macintosh's newest OS, El Capitan (which is Spanish for, "The Capitan.")

Sensing that urgent action was needed, I turned on my computer, booted up my web browser, and sat with my posterior firmly planted on my chair until somebody else fixed the problem. Fortunately this was not long in coming, and Pete Molfese over at Crash Log has documented how to do it; however, as I am sensitive to how long it takes to click on links, I have reproduced all of the instructions here in full, along with a helpful video which maybe includes a special effect involving my sports jacket.

Here are the steps:

  1. Install XQuartz from (Allows GUIs to run from Unix shells; the "X" symbol that pops up in your dock when you first run AFNI)
  2. Install XCode from the Apple Store
  3. Install Homebrew (a package manager for Mac) using the following command:
    1. For bash: ruby -e "$(curl -fsSL"
    2. For tcsh: curl -fsSL | ruby
  4. Use homebrew to get the following:
    1. The GNU Compiler Collection (GCC) with: brew install gcc --with-all-languages --without-multilib
    2. Pyqt, which you'll need for the .py scripts in AFNI: brew install pyqt
    3. GLib, low-level libraries that take care of the little things under the hood: brew install glib
  5. Link libgomp to the correct location using the following:
    1. ln -s /usr/local/Cellar/gcc/5.3.0/lib/gcc/5/libgomp.1.dylib /usr/local/lib/libgomp
    2. Note that the version is continually being updated, so this command may change; for example, replace the 5.2.0 part with 5.3.0. Check the path to /usr/local/Cellar/gcc to see if the path exists. If you link the wrong path, rerun the command with the correct path and the -sf option.
  6. Download the latest AFNI package here, or type the following into your terminal (assuming you are installing version 10.7; replace with whatever version you want to download):  
mkdir abin
curl -O
 tar -xzf macosx_10.7_Intel_64.tgz 
mv macosx_10.7_Intel_64 abin
rm macosx_10.7_Intel_64.tgz
  1. Paste the following commands from the AFNI install webpage into your terminal (for tcsh shell):
echo 'set path = (/usr/local/bin $path $HOME/abin)' >> .cshrc
echo 'setenv DYLD_FALLBACK_LIBRARY_PATH $HOME/abin' >> .cshrc

echo 'setenv PYTHONPATH /usr/local/lib/python2.y/site-packages' >> .cshrc
source .cshrc

Wednesday, January 13, 2016

Top Ten Things I Learned in Graduate School (TRIGGER WARNING: Includes Spiro Agnew)

"It is a duty incumbent on upright and creditable men of all ranks who have performed anything noble or praiseworthy to record in their own words the events of their lives. But they should not undertake this honorable task until they are past the age of forty."

-Benvenuto Cellini, opening sentence of his Autobiography (c. 1558)

  1. Date within your cohort! Or not. Either way, you'll have a great time! Maybe.
  2. If you have more than ten things to say, you can make a longer list.
  3. If you rearrange the letters in the name "Spiro Agnew," you can spell "Grow A Penis." Really? Really.
  4. Think of teaching a class as a PG-13 movie: to keep the class titillated and interested, you're allowed to make slightly crude references without being explicit; and, if you want, you're entitled to say the f-word ("fuck") once during the semester.
  5. When they say, "Don't date your students until the class is over," they mean when the semester is over, not just when classtime is over.
  6. Virtually everyone who throws around the word "sustainable" has no idea what they're talking about, unless it's that water situation in California. Things are seriously f-worded over there.
  7. If you come into graduate school not knowing how to code, teach yourself. Only after getting frustrated and making no headway, only after you have exhausted every avenue of educating yourself - only then is it acceptable to find someone else to do it for you, and then take credit for it. You gotta at least try!
  8. You know you've been doing neuroimaging analysis for a long time when you don't think twice about labeling a directory "anal." Ditto for "GroupAnal."
  9. You know you've been in graduate school too long when you can remember the deidentification codes for all of your subjects, but not necessarily the names of all of your children.
  10. When you first start a blog in graduate school, everything you write is very proper and low-key, in the fear that you may offend one of your colleagues or a potential employer. Then after a while you loosen up. Then you tighten up again when you're on the job market. Then you get some kind of employment and you loosen up again. And so on.
  11. When I first started blogging, I figured that people would take the most interest in essays that I had taken considerable pains over, usually for several days or weeks. Judging from the amount of hits for each post, readers seem to vastly prefer satirical writings about juvenile things such as "the default poop network," and humorous neuroimaging journal titles with double entendres - silly crap I dashed off in a few minutes. Think about that.
  12. The whole academic enterprise is more social than anything. It sounds obvious and you will hear it everywhere, but you never appreciate it until you realize that you can't just piss off people arbitrarily and not suffer any consequences somewhere down the line. Likewise, if you are good to people and write them helpful blog posts and make them helpful tutorial videos, they are good to you, usually. Kind of like with everything else in life.
  13. If you get a good adviser, do not take that for granted. Make every effort to make that man's life easier by doing your duties, and by not breaking equipment or needlessly stabbing his other graduate students. By "good adviser" I mean someone who is considerate, generous with his time and resources, and clear about what you need to do to get your own career off the ground while giving you enough space to develop on your own. I had such an adviser, and that is a big part of the reason that the past five years of my life have also been the best five years. That, and the fact that I can rent cars on my own now.

Have you finished graduate school and are now in a slightly higher paying but still menial and depressing job, and would like to share your wisdom with the newer generation of young graduate students? Can you rent a car on your own now? Did you try the Spiro Agnew Anagram Challenge (SAAC)? Share your experiences in the comments section!

Sunday, January 10, 2016

SPM Smoothing: A Reader Writes

The angry red pustule of the Gaussian normal distribution
I love questions, because questions get answers. One question you may be asking is, "Why are my smoothness estimates in SPM so whack?" To which the obvious response is, "How much whack are we talking about here? Whiggidy-whack, or just the regular kind?" Details matter.

If the former, then the following code snippet may help. In the absence of a gold standard for calculating smoothness estimates, often we have to resort to our own ingenuity and cunning, by which I mean: Copy what other people are doing. One alert reader, Tamara, noticed that the standard SPM function for estimating smoothness, spm_est_smoothness, is so whack that all the other SPM functions want nothing to do with it. Which is kind of the goal of life, when you think about it - to not be that guy everyone else wants to avoid.

In any case, if you are having issues with it, the following code may help. I've also included the rest of the email, just to make you aware that I can and will publish your correspondence without your consent.

Hi Andy, I never figured out why spm_est_smoothness is not working, although other people have had the same issue with getting estimates in the thousands.  Ultimately, I ended up using this simple code to estimate each individual's smoothness, and then averaged across subjects.  Jim Lee posted this on the SPM listserv along with this note:  
The smoothness estimates in SPM.xVol.FWHM are in units of VOXELS, so you need to multiply by the voxel dimensions to get them in mm. Something like this:
load SPM.mat; M = SPM.xVol.M; VOX = sqrt(diag(M(1:3,1:3)'*M(1:3,1:3)))'; FWHM = SPM.xVol.FWHM; FWHMmm= FWHM.*VOX; disp(FWHMmm);

Thanks again for your help!!

Thursday, January 7, 2016

Mumford & Stats: Up Your Neuroscience Game

Jeanette Mumford, furious at the lack of accessible tutorials on neuroimaging statistics, has created her own Tumblr to distribute her knowledge to the masses.

I find examples like these heartening; researchers and statisticians providing help to newcomers and veterans of all stripes. Listservs, while useful, often suffer from poorly worded questions, opaque responses, and overspecificity - the issues are individual, and so are the answers, which go together like highly specific shapes of toast in a specialized toaster.* Tutorials like Mumford's are more like pancake batter spread out over a griddle, covering a wide area and seeping into the drip pans of understanding, while being sprinkled with chocolate chips of insight, lightly buttered with good humor, and drizzled with the maple syrup of kindness.

I also find tutorials like these useful because - let's admit it - we're all slightly stupid when it comes to statistics. Have you ever tried explaining it to your dad, and ended up feeling like a fool? Clearly, we need all the help we can get. If you've ever had to doublecheck why, for example, a t-test works the way it does, or brush up on how contrast weights are made, this website is for you. (People who never had to suffer to understand statistics, on the other hand, just like people who don't have any problems writing, are disgusting and should be avoided.)

Jeanette has thirty-two videos covering the basics of statistics and their application to neuroimaging data, a compression of one of her semester-long fMRI data courses which should be required viewing for any neophyte. More recent postings report on developments and concerns in neuroimaging methods, such as collinearity, orthogonalization, nonparametric thresholding, and whether you should date fellow graduate students in your cohort. (I actually haven't read all of the posts that closely, but I'm assuming that something that important is probably in there somewhere.) And, unlike myself, she doesn't make false promises and she posts regularly; you get to stay current on what's hot, what's not, and, possibly, you can begin to make sense of those knotty methods sections. At least you'll begin to make some sense of the gibberish your advisor mutters in your general direction the next time he wants you to do a new analysis on the default pancake network - the network of regions that is activated in response to a contrast of pancakes versus waffles, since they are matched on everything but texture.**

It is efforts such as this that make the universe of neuroimaging, if not less complex, at least more comprehensible, less bewildering; more approachable, less terrifying. And any effort like that deserves its due measure of praise and pancakes.

*It was only after writing this that I realized you put bread into a toaster - toast is what comes out - but I decided to just own it.

**Do not steal this study idea from me.