Skip to content

Instantly share code, notes, and snippets.

@mtholder
mtholder / mb-and-beagle-from-svn.sh
Created December 4, 2013 02:42
compiling mrbayes with beagle in ubuntu. You may want to change the second line to whatever dir you would like to use as the parent of the prefix of the beagle installation.
#!/bin/sh
PREFIX_PARENT="${HOME}/envs"
set -x
mkdir -p "${PREFIX_PARENT}/beagle" || exit
svn checkout https://beagle-lib.googlecode.com/svn/trunk/ beagle-lib || exit
cd beagle-lib
sh autogen.sh
mkdir build || exit
@mtholder
mtholder / gist:5769321
Created June 12, 2013 21:33
test script for building opentree software on a "clean" machine
sudo apt-get install git
git clone git://github.com/mtholder/ot-vagrant.git
cd ot-vagrant/
git pull origin
cat >web2py_passwords.sh <<ENDOFHEREDOC
#!/bin/sh
export WEB2PY_DB_USER=greatusernamehere
export WEB2PY_DB_PASSWD=somepassword
ENDOFHEREDOC
@mtholder
mtholder / gist:5587724
Created May 15, 2013 21:53
Python function for a hacky approximation of the F_Tt factors in the Bryant et al SNAPP method as specialized for use by a homework assignment in the Kelly and Holder "Likelihood methods in Biology" class
def calc_F_Tt(r_Tb, n_Tt, r_Tt, param_vec):
if r_Tt > n_Tt:
return 0.0
Ne = param_vec[ParamOrder.PopSize].value
mu = param_vec[ParamOrder.MutRate].value
tau = param_vec[ParamOrder.DivTime].value
# The probability of coalescence along the Turkish branch goes to 1 as tau gets big or Ne gets small
prob_coalescence = 1 - exp(-tau/(2.0*Ne))
prob_no_coalescence = 1 - prob_coalescence
@mtholder
mtholder / gist:5587706
Created May 15, 2013 21:51
R function for a hacky approximation of the F_Tt factors in the Bryant et al SNAPP method as specialized for use by a homework assignment in the Kelly and Holder "Likelihood methods in Biology" class
calc.F_Tt <- function (r_Tb, n_Tt, r_Tt, param.vec) {
if (r_Tt > n_Tt) {
return (0.0);
}
# unnumbered eqn on the bottom of page 5
Ne <- param.vec[2];
mu <- param.vec[3];
tau <- param.vec[4];
# The probability of coalescence along the Turkish branch goes to 1 as tau gets big or Ne gets small
@mtholder
mtholder / complete-treemachine.sh
Created April 4, 2013 16:29
bash tab completion for the treemachine command
_treemachine()
{
local cur=${COMP_WORDS[COMP_CWORD]}
local prev=${COMP_WORDS[COMP_CWORD-1]}
if test $prev = "treemachine"
then
# if the previous word was treemachine, prompt with the commands
COMPREPLY=( $(compgen -W "addtree reprocess deletetrees jsgol fulltree fulltree_sources fulltreelist mrpdump graphml csvdump justtrees sourceexplorer listsources biparts mapsupport getlicanames counttips diversity labeltips getupdatedlist" -- $cur))
else
#otherwise do file completion. Which seems tougher than it should be...
@mtholder
mtholder / newick2taxalist.cpp
Created August 26, 2012 04:25
Reads a phylogenetic tree or data file and prints out the taxa labels one per line
// Copyright (C) 2012 Mark T. Holder
//
// Based on example/splitsinfile/splitsinfile.cpp in NEXUS class library
//
// After NCL has been installed at ${NCL_PREFIX}
//
// g++ newick2taxalist.cpp -o newick2taxalist -I "${NCL_PREFIX}/include" -lncl -L "${NCL_PREFIX}/lib/ncl"
//
// Takes a newick file and prints out the taxa labels, one per line.
//
@mtholder
mtholder / range_of_treebase2newick.sh
Created August 25, 2012 06:47
shell script that uses NCL to convert a series of sequentially numbered TreeBase NEXUS files to newick. NCL is available from http://sourceforge.net/projects/ncl/
#!/bin/sh
# Script to use NCLconverter to convert TreeBase NEXUS files to newick
# Invocation:
# sh range_of_treebase2newick.sh 10000 10100
# in a directory with filenames like S10001.nex to convert each file
# name like S10000.nex up to file S10100.nex to newick.
# you should get files like:
# outS####.tre newick tree for the first trees block
# 2outS####.tre , 3outS####.tre , etc if the file has multiple output blocks
# outS####.NameTranslationFile.txt is an ad hoc xml description of the name mapping
@mtholder
mtholder / phylotastic_tnrs_client.py
Created June 21, 2012 18:49
Example of a client of the demo of the TNRS API described at: http://www.evoio.org/wiki/Phylotastic/TNRS
#!/usr/bin/env python
'''
Example of a client of the demo of the TNRS API described at:
http://www.evoio.org/wiki/Phylotastic/TNRS
Reads names (separated by newline characters) from file names passed in as
command-line arguments (or reads name from standard input if no arguments
are given).
Outputs tab-delimited summary of the matches for each query sorted by score of
@mtholder
mtholder / build_gcc_4.7_on_mac.sh
Created June 10, 2012 19:04
Script to download and build gcc 4.7 and its dependencies on mac - it took about 40 minutes on my machine (and the "make check" in the gcc build failed for lack of an "autogen" script"), but the compiler seems to work.
#!/bin/sh
# You might want to modify the first line to specify your own install location.
# In theory the rest should not need tweaking...
export GCC_PREFIX="$HOME/gcc4.7"
# Hopefully, you can tweak these as they get out of date, but the download URL's
# may not be stable to text substitution.
GMP_DOWNLOAD_VERSION=gmp-5.0.5
MPFR_DOWNLOAD_VERSION=mpfr-3.1.0
MPC_DOWNLOAD_VERSION=mpc-0.8.2
@mtholder
mtholder / log_of_mean_exp.py
Created May 29, 2012 16:19
Log of the mean of the exp of values from standard input
#!/usr/bin/env python
import sys, math
v_list = [float(value) for value in sys.stdin]
offset = max(v_list)
n = len(v_list)
sum_exps = sum([math.exp(v - offset) for v in v_list])
mean_exps = sum_exps/n
sys.stdout.write('Log of mean of the exp of %d values is:\n' % n)
sys.stdout.write('%8.7f\n' % (math.log(mean_exps) + offset))