Tuesday, January 7, 2014

The Craft of Homebrew-ing for Mac OS

Author: John Urban
Original publish date: circa Dec. 2012
Originally appeared: Brown University Genomics Club

Do you want to install a bunch of bioinformatics programs, such as bowtie, bedtools, and samtools, on your MacBook Pro?  Want to do it in a super-fast, super-easy way?

Homebrew is the solution. What is Homebrew? There are webpages in the 'More Help' section at the bottom of the page that may help you understand it better. For now, suffice it to say that it makes installing software packages quite straightforward. All you will have to do to get bowtie, for example, is type 'brew install bowtie' at the command line. Wait a minute or so. Now you have bowtie.

First you need to install Homebrew. Unfortunately, you cannot just do 'brew install homebrew'. Fortunately, the installation is straightforward. Read on!

You will need Xcode on your MacBook Pro. This can be downloaded for free from the Mac App Store.

Download Xcode before starting installation of homebrew.

General tip: It is best to stay with latest OS for MAC -- currently 10.8.2 (when writing this). You may consider upgrading before anything else. It might be that you have to in order to get the latest version of Xcode. It is cheap and to quell any fears - it will not erase anything on your computer. Mostly, things will continue unperturbed from the OS upgrade. You may find some issues that can be overcome with TimeMachine backups.

(1) Get Homebrew
Find out how to get Homebrew here.

That link basically says to enter this at the command line:
    ruby -e "$(curl -fsSkL raw.github.com/mxcl/homebrew/go)"

It will then give you a lot of prompts to continue or abort, which will scare you if you're new to all this. 

If you continue through all of the prompts, then proceed to Step (2).

(2) Doctor Homebrew
Homebrew will tell you to do this, but in case you're not the type to pay attention to the silly messages programs print to you and assuming you are paying attention to the words you are reading right now, here is what to do.

First thing to do after installing homebrew is to type at the command line:
    brew doctor

This will result in a self-diagnosis and a printout of all potential 'illnesses and ailments' that  you should 'cure' before doing anything else. I will cover the warnings I took care of here. It may not be comprehensive. Simply pasting your warnings into google is usually sufficient to find further advice though.

I received the following types of warnings. 

(a) I had to update my Xcode
If you just downloaded it you should have the latest version. For me, it was just a matter of updating it through the app store. My computer had been prompting me to update it for months. 

(b) I had to update to the latest version of Xquartz
When I upgraded my MAC OS from 10.6.8 to 10.8.x I found the new OS no longer came with X11. Xquartz was the answer to this. However, I have been using "terminal" instead of X11/Zquartz. Nonetheless, you need most updated version. If you already have an older version of Xquartz, it is just a matter of opening it. It will ask you to update automatically. Otherwise, download latest version.

(c) I had to download Xcode command line tools
These do not download automatically with Xcode as they are not necessary for most people. If you have the latest version of Xcode already (do that first), then just open Xcode and click on the following menu bar options:
                  Xcode --> preferences --> downloads --> components. 
 Then choose to install command line tools.

(d) It gave me the suggestion to arrange the order of my PATH variable a certain way. 
This can be done by going into your .bash_profile (and/or .bashrc) file in home directory and typing something like this:
             export PATH=/usr/local/bin:/usr/local/sbin:~/bin:$PATH

Alternatively, you can find the path file to modify at:
Switch the paths inside it around accordingly.

(e) I had to update python

Verbatim warning:

Warning: "config" scripts exist outside your system or Homebrew directories.
`./configure` scripts often look for *-config scripts to determine if software packages are installed, and what additional flags to use when compiling and linking.

Having additional scripts in your path can confuse software installed via Homebrew if the config script overrides a system or Homebrew provided script of the same name. We found the following "config" scripts:


   I had installed python 2.7 at one point (my Mac came with 2.6) and it modified my .bash_profile file in the following way:

#Setting PATH for Python 2.7
#The orginal version is saved in .bash_profile.pysave
export PATH

    In other words, it put the new python in my PATH variable. However, now homebrew has that covered. The solution was to just silence (or erase) those modifications made by python installation.

#Setting PATH for Python 2.7
#The orginal version is saved in .bash_profile.pysave
#export PATH

    I chose to use '#' to silence them in case I uninstall homebrew in the future, which I doubt I will do. It all can just be erased though. 

(f) I had to sudo chown something

Verbatim warning:

Warning: Some directories in /usr/local/share/man aren't writable.
This can happen if you "sudo make install" software that isn't managed
by Homebrew. If a brew tries to add locale information to one of these
directories, then the install will fail during the link step.
You should probably `chown` them:


The following solution should only be employed if you are using your own machine and you are the only user. For example, I am the only user of my MacBook Pro. This means you know your computer's pw, which will be necessary.

        To be sure of your username, type into the command line:
        It spits out your exact username.

        Next use the following commands to chown the files as homebrew wants:
            sudo chown username /usr/local/share/man/de
            ## Had to enter computer pw, then
            sudo chown username /usr/local/share/man/de/man1/

Those were all of my warnings.
After each attempt at a solution, re-run 'brew doctor' to see if the diagnosis has changed (i.e. make sure it does not include what you sought to fix).

When all ailments are fixed, 'brew doctor' will return:
    "Your system is raring to brew."

At this point, you may still need to (or just want to) type:
     brew update 
This will ensure homebrew is completely updated upon all fixes.

(3) Use Homebrew
Homebrew is easy to use and there is a lot of tutorials on the web.

brew list
    to see the current list of 'formula' you have

brew search
    to see full list of 'formula' you may want to get

brew info 'formula'
    to find out more about a given formula

brew install 'formula'
    to install a given formula in the search list

brew uninstall 'formula'
    to remove something from your list or something that did not install correctly

brew tap 'keg'
    e.g. brew tap homebrew/science
    --> I had to 'tap' this 'keg' for quite a few things I wanted.
          So you might as well just tap that keg now.
    --> See the full list of formula that may be dependent on tapping this keg here:

An idea of all the 'formulas' I used 'brew install "formula"' for:
    gfortran (needed for octave)
    octave (an open-source MatLab-like program)
    blast (type 'brew info blast' first. You may want the smaller 'dynamic version')

*A note on gnuplot, octave, aquaterm:
Gnuplot is needed for plots in octave. But you may also need/want aquaterm. If so, a slight nuance (read annoyance) is that you must install aquaterm before gnuplot. So if you installed gnuplot before aqua term, then trying to plot in octave will not work if the GNUTERM variable in octave is set to aqua (you can try setting GNUTERM to x11 though). There is an easy Home Brew solution. First do, 'brew uninstall gnuplot'. If aquaterm was already installed, then just do 'brew install gnuplot' and you are done. If not aqauterm has not been installed yet, then install aquaterm (follow their instructions) before doing 'brew install gnuplot' and being done. Note that for an open source language that feels like MatLab, "Julia" (a quickly developing and impressive language) may be a better option than Octave these days.

If you are unfamiliar with any of the above bioinformatics tools, either:
1- Type the name along with 'bioinformatics' (to narrow down possible interpretations) into google
    e.g. sga bioinformatics
OR try:
2 - brew info formula
    e.g. brew info sga

1 - type 'brew help'
2 - type 'man brew'

1 comment:

  1. Great blog! Is your theme custom made or did you download it from somewhere? A design like yours with a few simple adjustements would really make my blog stand out. Please let me know where you got your theme. Ecommerce website design