snow leopard

Setup Clojure Snow Leopard

*****

In 2013 you can now do:

brew install lein. ¬†You can then start a clojure repl by typing ‘lein repl’, to start a project type ‘lein new my-project’.

Don’t waste time reading the rest of this.

*****

 

 

 

Setting up clojure on the mac is fairly simple:
1. use port/homebrew
2. download (svn/git/zip)

If using (2) it is necessary to create a script to startup the REPL or run scripts with *command-line-args*. It’s also a good idea to grab jline to make the REPL a tad more user friendly.

The script used to run clojure, as clj, looks like this:


CLOJURE_HOME=/Users/biomunky/svn/clojure
CLOJURE=$CLOJURE_HOME/clojure/clojure.jar
CONTRIB=$CLOJURE_HOME/clojure-contrib-1.0.0/clojure-contrib.jar
JLINE=$CLOJURE_HOME/jline-0_9_5.jar #if you got it
CP=$PWD:$CLOJURE:$JLINE:$CONTRIB
if [ -f .clojure ];
	then
	CP=$CP:`cat .clojure`
fi

if [ -z "$1" ]; then
	java -server -cp $CP jline.ConsoleRunner clojure.main
else
	java -server -cp $CP clojure.main $*
fi

Add an alias to this script in the .bashrc/.bash_profile

alias clj=/Users/biomunky/svn/clojure/clojure.sh

Source your file and *boom* working clojure.

It’s also nice to have an editor, macvim/vim serves the purpose. First go and grab vim-clojure and copy the files to .vim/. It should look something like this in your .vim/


biomunky@joshua:.vim$ ls *
autoload:
vimclojure.vim

colors:
candycode.vim wombat.vim

doc:
clojure.txt

ftdetect:
clojure.vim scala.vim

ftplugin:
clojure     clojure.vim

indent:
clojure.vim scala.vim

syntax:
clojure.vim scala.vim

Then, to get some nice rainbow parentheses, add the following to the .vimrc file in ~/

syntax on
set title
set ttyfast
set smartindent
set number
" Settings for VimClojure
let g:clj_highlight_builtins=1      " Highlight Clojure's builtins
let g:clj_paren_rainbow=1           " Rainbow parentheses'!
" because light colors on a dark background are easy on the eye
colorscheme wombat

copy and paste the following code into a text file, save it as pdb-fetch.clj and then execute it clj pdb-fetch.clj 1hnn, about 20 seconds later a fasta sequence file will appear in the same directory … woo hoo

(use '[clojure.contrib.duck-streams :only (write-lines read-lines)])
(def pdbid ( .substring (nth *command-line-args* 0) 0 4 ) )
(def url (str  "http://www.pdb.org/pdb/files/fasta.txt?structureIdList=" pdbid ))
(def output (str pdbid ".fasta"))
(write-lines output  (read-lines (java.net.URL. url)))

The output:

>1HNN:B|PDBID|CHAIN|SEQUENCE
MSGADRSPNAGAAPDSAPGQAAVASAYQRFEPRAYLRNNYAPPRGDLCNPNGVGPWKLRCLAQTFATGEVSGRTLIDIGS
GPTVYQLLSACSHFEDITMTDFLEVNRQELGRWLQEEPGAFNWSMYSQHACLIEGKGECWQDKERQLRARVKRVLPIDVH
QPQPLGAGSPAPLPADALVSAFCLEAVSPDLASFQRALDHITTLLRPGGHLLLIGALEESWYLAGEARLTVVPVSEEEVR
EALVRSGYKVRDLRTYIMPAHLQTGVDDVKGVFFAWAQKVGL
>1HNN:A|PDBID|CHAIN|SEQUENCE
MSGADRSPNAGAAPDSAPGQAAVASAYQRFEPRAYLRNNYAPPRGDLCNPNGVGPWKLRCLAQTFATGEVSGRTLIDIGS
GPTVYQLLSACSHFEDITMTDFLEVNRQELGRWLQEEPGAFNWSMYSQHACLIEGKGECWQDKERQLRARVKRVLPIDVH
QPQPLGAGSPAPLPADALVSAFCLEAVSPDLASFQRALDHITTLLRPGGHLLLIGALEESWYLAGEARLTVVPVSEEEVR
EALVRSGYKVRDLRTYIMPAHLQTGVDDVKGVFFAWAQKVGL

the above code (probably) isn’t idiomatic, this is a learning experience – feel free to complain/suggest changes/fixes.

Install Matplotlib on Snow Leopard and Leopard.

////////////////////////////////////////////////////////////
THIS WON’T WORK ANYMORE – THE CODE BELOW WILL ATTEMPT TO GET DATA THAT DOESN’T EXIST. THE AUTHOR HAS MOVED TO LION (follow the links if you have lion). IF I GET TIME I WILL TRY TO CREATE AN ALTERNATIVE
////////////////////////////////////////////////////////////

The superpack has moved to GitHub – click here to get your fix.

— see the above? do that instead —

The matplotlib superpack was/is one of the easiest ways to get a working matplotlib/numpy/scipy setup on snow leopard. Over the last few weeks the site hosting the code has gone offline! Having spent the best part of the morning attempting to install the packages and failing, only to find the script in my svn dir is annoying, however I now have everything up and running (yey me) and figured I would share the scripts.

The superpack for 10.5:

#!/bin/sh
echo 'Would you like to install gFortran (required if not already installed)? (y/n)'
read install
if  [ "$install" == "y" ] || [ "$install" == "Y" ]; then
  echo 'Downloading gFortran ...'
  curl -o gfortran-4.2.3.dmg http://www.maths.otago.ac.nz/~fonnesbeck/gfortran-4.2.3.dmg
  echo 'Installing gFortran ...'
  hdiutil mount gfortran-4.2.3.dmg
  sudo installer -pkg '/Volumes/GNU Fortran 4.2.3/gfortran.pkg' -target '/'
  hdiutil unmount '/Volumes/GNU Fortran 4.2.3'
elif [ "$install" == "n" ] || [ "$install" == "N" ]; then
  echo 'Skipping gFortran install.'
else
  echo 'Did not recognize input. Exiting'
  exit 0
fi
echo 'Downloading ez_setup ...'
curl -o ez_setup.py http://peak.telecommunity.com/dist/ez_setup.py
echo 'Installing ez_setup ...'
sudo python ez_setup.py
echo 'Installing numpy ...'
sudo easy_install http://www.maths.otago.ac.nz/~fonnesbeck/numpy-1.4.0.dev7539-py2.5-macosx-10.3-fat.egg
echo 'Installing matplotlib ...'
sudo easy_install http://www.maths.otago.ac.nz/~fonnesbeck/matplotlib-0.98.6svn-py2.5-macosx-10.3-fat.egg
echo 'Installing scipy ...'
sudo easy_install http://www.maths.otago.ac.nz/~fonnesbeck/scipy-0.8.0.dev5970-py2.5-macosx-10.3-fat.egg
echo 'Installing pymc ...'
sudo easy_install http://www.maths.otago.ac.nz/~fonnesbeck/pymc-2.0_20091019-py2.5-macosx-10.3-fat.egg
echo 'Installing readline and ipython ...'
sudo easy_install readline ipython
echo 'Installing nose ...'
sudo easy_install http://www.maths.otago.ac.nz/~fonnesbeck/nose-0.11.0.dev_r0-py2.5.egg
echo 'Installing pytz ...'
sudo easy_install pytz
echo 'Installing DateUtils'
sudo easy_install DateUtils
echo 'Done'

for 10.6 see below (updated 7/01/11). For future updates see StrongInference (Chris Fonnesbeck is the guy that produces this handy little script).

#!/bin/sh
PYTHON=/usr/bin/python
SERVER=http://dl.dropbox.com/u/233041/PyMC

echo 'Would you like to install gFortran (required if not already installed)? (y/n)'
read install
if  [ "$install" == "y" ] || [ "$install" == "Y" ]; then
  echo 'Downloading gFortran ...'
  curl -o gfortran-42-5664.pkg http://r.research.att.com/gfortran-42-5664.pkg
  echo 'Installing gFortran ...'
  sudo installer -pkg 'gfortran-42-5664.pkg' -target '/'
elif [ "$install" == "n" ] || [ "$install" == "N" ]; then
  echo 'Skipping gFortran install.'
else
  echo 'Did not recognize input. Exiting'
  exit 0
fi
echo 'Downloading ez_setup ...'
curl -o ez_setup.py http://peak.telecommunity.com/dist/ez_setup.py
echo 'Installing ez_setup ...'
sudo python ez_setup.py
echo 'Installing numpy ...'
sudo "${PYTHON}" -m easy_install -Z ${SERVER}/numpy-2.0.0.dev_f72c605_20110113-py2.6-macosx-10.6-universal.egg
echo 'Installing matplotlib ...'
sudo "${PYTHON}" -m easy_install -Z ${SERVER}/matplotlib-1.0.0-py2.6-macosx-10.6-universal.egg
echo 'Installing scipy ...'
sudo "${PYTHON}" -m easy_install -Z ${SERVER}/scipy-0.10.0.dev_20110113-py2.6-macosx-10.6-universal.egg
echo 'Installing pymc ...'
sudo "${PYTHON}" -m easy_install -Z ${SERVER}/pymc-2.2alpha-py2.6-macosx-10.6-universal.egg
echo 'Installing readline ...'
sudo "${PYTHON}" -m easy_install -Z readline
echo 'Installing ipython ...'
sudo "${PYTHON}" -m easy_install -Z ${SERVER}/ipython-0.11.dev-py2.6.egg
echo 'Installing nose ...'
sudo "${PYTHON}" -m easy_install -Z nose==0.11
echo 'Installing DateUtils'
sudo "${PYTHON}" -m easy_install -Z DateUtils
echo 'Done'

There is also a matplotlib pack available from UCSF here

Chris Fonnesbeck has returned (the chap I obtained the above scripts from)! To get the most recent stuff visit his site: StrongInference.