Skip to content

Instantly share code, notes, and snippets.

@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 / 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 / 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: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 / 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 / build-mb-3.2.2-with-beagle.sh
Created December 4, 2013 02:51
compile mb 3.2.2 with beagle on ubuntu
#!/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 / grep_ot_code
Last active August 29, 2015 14:01
If you have checked the main open tree of life repos out into a directory which you lovingly call OPEN_TREE_REPO_ROOT in your env, then this will run grep on the files that appear to be java, python, or shell scripts in those repos.
#!/bin/sh
for repo in api.opentreeoflife.org deployed-systems gcmdr opentree ot-base oti ott peyotl phylografter taxomachine reference-taxonomy treemachine ;
do
for suffix in .java .py .sh
do
find "$OPEN_TREE_REPO_ROOT/$repo" -name "*$suffix" -exec grep -H $@ {} \; | sed -e "s+$OPEN_TREE_REPO_ROOT/++"
done
done
@mtholder
mtholder / fetch_phylografter_study.py
Created May 31, 2014 02:11
(if you have peyotl installed and configured) this will download studies from phylografter and store each as NexSON in a file named <studyId>.json *WARNING*: this will overwrite <studyId>.json !
#!/usr/bin/env python
import sys
from peyotl.api.phylografter import Phylografter
pg = Phylografter()
for study_id in sys.argv[1:]:
pg.fetch_study(study_id, study_id + '.json')
@mtholder
mtholder / annotations.xsd
Last active August 29, 2015 14:02
hacky version of nexml/xsd/meta/annotations.xsd that allows any element inside a LiteralMeta
<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" targetNamespace="http://www.nexml.org/2009"
xmlns:xml="http://www.w3.org/XML/1998/namespace" xmlns="http://www.nexml.org/2009"
xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:sawsdl="http://www.w3.org/ns/sawsdl"
xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
xmlns:xhtml="http://www.w3.org/1999/xhtml/datatypes/" elementFormDefault="qualified">
<!-- <xs:annotation>
<xs:documentation>
This module defines annotations that can be attached to
@mtholder
mtholder / force_oti_reindexing_of_non_namespaced_ids.py
Created June 12, 2014 04:31
force_oti_reindexing_of_non_namespaced_ids.py
#!/usr/bin/env python
import sys
from peyotl.api import APIWrapper
aw = APIWrapper(phylesystem_api_kwargs={'get_from':'api'})
pa = aw.phylesystem_api
o = aw.oti
for line in open(sys.argv[1], 'rU'):
ls = line.strip()
if '_' in ls:
continue