Skip to content

Instantly share code, notes, and snippets.

@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")
@mtholder
mtholder / gen_all_reversed.sh
Created December 31, 2019 17:42
script to populate a reversed_subproblems subdirectory in a synth tree build.
#!/bin/bash
inpdir=$1
if ! test -d "${inpdir}" ; then
echo "$0 must be passed in a directory of subproblems (with ott###.tre files)."
exit 1
fi
rpwd=`realpath .`
rpid=`realpath $inpdir`
if test "${rpwd}" = "${rpid}" ; then
echo "$0 Cannot be run in place."
@mtholder
mtholder / gen_reversed.py
Created December 31, 2019 17:41
simple script to reverse the first n-1 lines of a file with n lines.
#!/usr/bin/env python3
'''Reverses the order of the first n-1 lines of a file
and writes it to stdout.
'''
import sys
fp = sys.argv[1]
with open(fp, 'r', encoding='utf-8') as inp:
lines = inp.readlines()
last = lines.pop(-1)
lines.reverse()
@mtholder
mtholder / table_from_subproblem_size_summary.py
Created December 28, 2019 22:14
summary of subproblem_size_summary.json as a .tsv
#!/bin/env python
import json
import sys
import subprocess
import itertools
inpjson = 'subproblem_size_summary.json'
with open(inpjson, 'r', encoding='utf-8') as inp:
summary_blob = json.load(inp)
@mtholder
mtholder / generate-subproblem-size-summary.py
Created December 28, 2019 21:47
executed from the subproblems directory of an Open Tree synth tree to create subproblem_size_summary.json
#!/bin/env python
import json
import sys
import subprocess
import itertools
DEBUG = False
def count_tips_and_inf_splits(fn):
out = subprocess.check_output(['otc-degree-distribution', fn], stderr=subprocess.DEVNULL).decode('utf-8')
@mtholder
mtholder / create_num_tips_for_ott_internals_in_labelled_tree_json.bash
Created December 28, 2019 21:40
generating a mapping of internal OTT ID that shows up in the synth tree to the number of descendant leaves
#!/bin/bash
otc-tree-tool --indented-table labelled_supertree/labelled_supertree_simplified_ottnames.tre > subproblems/indented-table.txt
cat subproblems/indented-table.txt | sed -E '/ +mrca/d' | sed -E 's/.* ott([0-9]+) : ([0-9]+)/"ott\1": \2,/' > num_tips_for_ott_internals_in_labelled_tree.json
rm subproblems/indented-table.txt
@mtholder
mtholder / generate-subproblem-scaffold.bash
Created December 28, 2019 19:20
generates subproblems/subproblems-scaffold.tre and subproblems/subproblems-scaffold-only.tre for an Open Tree synth. tree build
#!/bin/bash
# This needs to be made part of the propinquity process.
# MTH ran steps that made up the basis of this before the
# Jan 2020 SSB workshop. So the resulting file will be in
# the https://files.opentreeoflife.org/synthesis/opentree12.3/opentree12.3/subproblems/
# folder, but (perversely enough) not in the tar archive at https://files.opentreeoflife.org/synthesis/opentree12.3/opentree12.3.tgz
# If all goes as planned, we'll start adding this to the tree build process so that it will be in
# builds and archives made after 12.3
# This is to be run with the working directory being the propinquity