Skip to content

Instantly share code, notes, and snippets.

@mtholder
mtholder / hide_prev.sh
Created January 4, 2023 16:29
server side custom synth hiding
#!/bin/sh
set -x
d=prev-`date +"%d-%b-%Y"`
if ! test -d "$d" ; then
mkdir "$d" || exit
fi
if ! test -d "${d}/results" ; then
mkdir "${d}/results" || exit
fi
if ! test -d "${d}/wrappers" ; then
@mtholder
mtholder / all.bash
Created May 23, 2022 20:44
grab the newick trees from timetree for your personal research and teaching use. Assumes https://gist.github.com/mtholder/615f1f77af9b7db8f0f9220fa514ab07 in same dir
#!/bin/bash
curl 'http://www.timetree.org/references' > studies.html
grep citation_data studies.html | sed -E 's:.*citation_data/::' | sed -E 's/".*//' > ids.txt
for i in `cat ids.txt` ; do
echo $i
if ! test -f "${i}.tre" ; then
python grab.py "$i" > "${i}.tre" || exit 1
fi
sleep 2
done
@mtholder
mtholder / grab.py
Created May 23, 2022 20:43
grab a newick tree from timetree for your personal research and teaching use if you have the study id (passed in as a command line arg)
#!/usr/bin/env python
import requests
import sys
durl = 'http://www.timetree.org/ajax/newick/publishedtree/download'
for i in sys.argv[1:]:
url = 'http://www.timetree.org/api/widget/citation_data/{i}'.format(i=i)
s = requests.Session()
r = s.get(url)
nr = s.post(durl, data={'export': 'newick', 'rank': 'na'})
nr.raise_for_status()
@mtholder
mtholder / tax-soln-num-internal-nodes.sh
Created October 7, 2021 16:55
Run from the subproblems subdirectory of the output of the open tree of life synthesis output to generate a TSV of # internal nds in taxonomy vs solution.
#!/bin/bash
if ! test -d cruft ; then
mkdir cruft
fi
for i in ott*.tre ; do
j=`echo ${i} | sed -E 's/^ott//' | sed -E 's/\.tre//'`
echo $j >&2
tail -n1 ${i} > cruft/tax.tre
ntax=`otc-degree-distribution cruft/tax.tre 2>&1 | tail -n2 | head -n1 | awk '{print $1}'`
nsoln=`otc-degree-distribution ../subproblem_solutions/${i} 2>&1 | tail -n2 | head -n1 | awk '{print $1}'`
@mtholder
mtholder / compress_tree_slices.py
Created March 16, 2021 19:34
Compresses the output of otc-explain-phylo-diffs to a terser form
#!/usr/bin/env python3
"""Tool to compress tree_slice_comparison JSON
otc-explain-phylo-diffs writes a form of this JSON in which multiple
adjacent slices of the tree can have the same topology for each
of the two trees that were compared.
This tool merges adjacent slices that are not differing in topology
to produces a terser representation that is easier to display
Roughly speaking, the schema of the JSON is:
@mtholder
mtholder / gist:1c7b597751bcf8f32a543eeee414b7b8
Created January 17, 2021 20:39
client-push-new-cert.sh
#!/bin/bash
n="$1"
if test -z $n ; then
echo "Expecting a machine name for the opentreeoflife.org domain as first arg"
exit 1
fi
if test -z $2 ; then
u=admin
else
u="${2}"
@mtholder
mtholder / gist:e54c90fa37d66c69687824434f0f14d3
Created January 17, 2021 20:38
client-push-then-check.sh
#!/bin/bash
n=${1}
if test -z $n ; then
echo "Takes a number argument n that, as ot${n}.opentreeoflife.org should be the machine to update"
exit 1
fi
u=${2}
if test -z $u ; then
u=admin
fi
@mtholder
mtholder / compare_fetched_certs.sh
Created January 17, 2021 20:36
fetches an opentreeoflife server SSL cert and compares it to a local copy from ot50 - used to assure that newly updated certs are being served.
#!/bin/bash
i="${1}"
if test -z $i ; then
echo "Number like 51 for ot51 needed as an arg"
exit 1
fi
echo "fetching cert from ot$i to compare to a local copy of a cert from ot50"
if echo | openssl s_client -servername ot${i}.opentreeoflife.org -connect ot${i}.opentreeoflife.org:443 | sed -ne '/-BEGIN CERTIFICATE-/,/-END CERTIFICATE-/p' > ot${i}-certificate.crt
diff ot50-certificate.crt ot${i}-certificate.crt ; then
echo "Success"
#!/usr/bin/env python3
def func(arg):
a_var.append(1)
loc_a_var = arg
b_var = list(arg)
print('func({} with id: {} and ids: {})'.format(repr(arg), id(arg), [id(i) for i in arg]))
print(' locals: {}'.format({k: id(v) for k, v in locals().items() if not k.startswith('__')}))
print(' globals: {}'.format({k: id(v) for k, v in globals().items() if not k.startswith('__')}))
@mtholder
mtholder / libgnparser.py
Created January 26, 2020 22:27
example of calling dimus' gnparser from python3
#!/usr/env python
""" Example of wrapping a call to gnparser from python
See https://gitlab.com/gogna/gnparser#command-line
Adapted based on instructions on
https://medium.com/learning-the-go-programming-language/calling-go-functions-from-other-languages-4c7d8bcc69bf
"""
import ctypes
import json
lib = ctypes.cdll.LoadLibrary("./libgnparser.so")