Skip to content

Instantly share code, notes, and snippets.

@mtholder
mtholder / gen-curl-oti.py
Created September 21, 2015 16:27
pull study info from OTI
#!/usr/bin/env
import sys
'''
python gen-curl-oti.py template.txt studies.txt
where studies.txt is the list of studies used in synthesis.
and template is a cURL call with XYZ inplace of the study id (and no other XYZ)
cURL
'''
@mtholder
mtholder / oti_responses_to_dict.py
Created September 21, 2015 16:34
after filling a directory from running a lot of curl calls generated by https://gist.github.com/mtholder/ddae56851edd81180767 run this giving it the path to the dir and an output filename
#!/usr/bin/env python
import sys
import os
import json
import codecs
dn = sys.argv[1]
outfn = sys.argv[2]
d = {}
for s in os.listdir(dn):
if s.endswith('.out'):
@mtholder
mtholder / normalize-and-partition-by-num-states-obs.py
Last active October 26, 2015 20:53
Takes a NEXUS file and writes SETS block with CharSet statements that partition the characters by the number of states
#!/usr/bin/env python
from collections import defaultdict
import dendropy
import sys
import os
_SCRIPT_NAME = os.path.split(sys.argv[0])[-1]
def error(msg):
sys.stderr.write('{}: Error: {}\n'.format(_SCRIPT_NAME, msg))
OUT = sys.stdout
@mtholder
mtholder / bootstrap-propinquity.sh
Created March 29, 2016 01:36
checkout the open tree of life repos used to build the synthetic tree of life - assumes that you have python 2.7, g++ and devtools for each language
#!/bin/bash
echo 'This script installs the tools needed for propinquity as subdirectories'
echo 'of the working directory. This assumes that you have a C++ dev environment (g++, boost, automake, libtool)'
echo 'installed. See README files for propinquity and otcetera if those builds fail'
echo 'Also assumes virtualenv for python'
CONTEXT_DIR="${PWD}"
virtualenv propinquity-env
source propinquity-env/bin/activate
#! /usr/bin/env python
import dendropy
def get_tree(r):
tree_str = "((C:1.3,D:4.)34:0.034,(A:1.1,(B:1.2,X:1.6)26:0.026)12:0.0126,E:1.5);"
tree = dendropy.Tree.get(
data=tree_str,
schema="newick",
rooting=r,
@mtholder
mtholder / print_nexml_keys_from_local.py
Created August 24, 2016 14:05
print keys in the nexml elelment of a nexson using a local phyleystemapi object
#!/usr/bin/env python
from __future__ import print_function
from peyotl.api import PhylesystemAPI
import sys
studyid = sys.argv[1]
phy = PhylesystemAPI(get_from='local')
nx = phy.get_study(studyid)['data']['nexml']
print(nx.keys())
@mtholder
mtholder / synth-tree-from-scratch.sh
Created September 21, 2016 23:23
overwrites your ~/.opentree and builds a tree in ~/OpenTree/
#!/bin/bash
cd ~
mkdir OpenTree
cd OpenTree/
git clone https://github.com/mtholder/propinquity.git
echo '[opentree]' > ~/.opentree
echo "home = $PWD" >> ~/.opentree
echo 'peyotl = %(home)s/peyotl' >> ~/.opentree
@mtholder
mtholder / find-taxonomy-only-from-annotations.py
Created April 17, 2017 16:50
reads an opentree summary tree annotated_supertree/annotations.json file and reports on the taxonomy-only nodes
#!/usr/bin/env python
import sys
try:
annot_fp = sys.argv[1]
except:
sys.exit("Expecting a path to an annotations.json file as the only argument.\n")
import json
import codecs
with codecs.open(annot_fp, 'rU', encoding='utf-8') as inp:
obj = json.load(inp)
@mtholder
mtholder / parsimony-informative-check.tex
Created April 19, 2017 19:20
description of an algorithm for detecting whether or not a character pattern is parsimony informative when there are ambiguously scored OTUs
\documentclass{article}
\usepackage{amsmath}
\usepackage{paralist}
\DeclareMathOperator*{\argmin}{argmin}
\begin{document}
\section*{Note on detecting whether a pattern is parsimony informative}
Let $\ell(T, c)$ be the unordered parsimony length of discrete character pattern $c$ on
tree $T$ and $\ell(T, c, i)$ be the parsimony length that combination of pattern and tree
when state $i$ is enforced as the state for the root of the tree.
Data pattern $c$ is ``parsimony informative'' if and only if,
@mtholder
mtholder / find-taxonomy-only-tips.sh
Created April 23, 2017 14:52
finds taxonomy only tips in the open tree synth. companion to https://gist.github.com/mtholder/924dd1da9e6bc2775d2d6fe88acade8f
#!/bin/bash
# works on the unpacked dir that is posted under the link
# text "All pipeline outputs " on the release page.
# E.g. the release page https://tree.opentreeoflife.org/about/synthesis-release/v9.1
# points to http://files.opentreeoflife.org/synthesis/opentree9.1/opentree9.1_output.tgz
# as its versions of "All pipeline outputs"
#
# I downloaded that, unpacked it, and provide the path to that dir as the only
# argument to this script.