Skip to content

Instantly share code, notes, and snippets.

@mtholder
mtholder / download-and-run-geodispersal.sh
Created April 14, 2012 23:10
Install of Dendropy with test run of modified BPA using geodispersal-analysis.py
#!/bin/sh
set -x
wget http://pypi.python.org/packages/source/D/DendroPy/DendroPy-3.11.0.tar.gz
tar xfvz DendroPy-3.11.0.tar.gz
cd DendroPy-3.11.0
python setup.py install
cd extras/geodispersal/
python geodispersal-analysis.py LiebermanEBasidechenella.nex LiebermanEBasidechenella.nex --labels=labels.txt --paup --vicariance=vic --dispersal=disp
cat Readme.txt
@mtholder
mtholder / terminal_edges_to_dot_p.py
Created June 15, 2011 15:58
Takes a MrBayes .t file and writes (to standard out) a .p file with the parameters being the edge lengths for each of the Terminal edges.
#!/usr/bin/env python
'''Takes a MrBayes .t file and writes (to standard out) a .p file with
the parameters being the edge lengths for each of the Terminal edges.
This .p file can be used with Tracer http://tree.bio.ed.ac.uk/software/tracer/
or other MCMC diagnostics files.
Example invocation with redirection to a file called term_edges_myrun.p :
python terminal_edges_to_dot_p.py myrun.t > term_edges_myrun.p
@mtholder
mtholder / conflict_viz.py
Created June 7, 2011 20:26
Uses dendropy to calculate a similarity score for the trees in analyses based on split support
import sys
import dendropy
from copy import copy
threshold = float(sys.argv[1])
filename_list = sys.argv[2:]
SCRIPT_NAME = 'conflict_viz'
def debug(*valist):
msg = ' '.join([str(i) for i in valist])
sys.stderr.write(SCRIPT_NAME + ': ' + msg + '\n')
@mtholder
mtholder / alter_edge_lengths.py
Created June 6, 2011 15:52
Uses dendropy to traverse a tree and modifies the length of each edge
#!/usr/bin/env python
import sys
import dendropy
if __name__ == '__main__':
from optparse import OptionParser
from optparse import OptionGroup
import sys, os
_script_name = os.path.split(sys.argv[0])[1]
@mtholder
mtholder / balanced_tree.py
Created November 2, 2010 19:11
produces a balanced tree with 2^{$1} leaves when $1 is the first command line argument
#!/usr/bin/env python
def balanced_tree(n, level):
if level == 0:
return n + 1, 't%d' % n
n, leftsub = balanced_tree(n, level - 1)
n, rightsub = balanced_tree(n, level - 1)
return n, '(%s,%s)' % (leftsub, rightsub)
if __name__ == '__main__':
import sys