Skip to content

Instantly share code, notes, and snippets.

View davipatti's full-sized avatar

David Pattinson davipatti

  • UW-Madison
  • New York, USA
View GitHub Profile
#!/usr/bin/env python3
"""2019-04-10 David Pattinson
Plot the parameter samples from a MrBayes run.
- Run this script in a directory that contains *.p files, or that contains
subdirectories (however deep) that contain *.p files.
- Any .p files in the same directory will be plotted on the same trace.
E.g. if HA.run1.p and HA.run2.p are in the same directory, their traces
@davipatti
davipatti / sortUniqcSort.py
Last active April 20, 2019 14:27
The sort | uniq -c | sort dance
#!/usr/bin/env python3
import sys
from itertools import groupby
lines = sorted(map(lambda l: l.rstrip(), sys.stdin.readlines()))
counts = ((len(list(group)), line) for line, group in groupby(lines))
for count, line in sorted(counts, key=lambda x: x[0]):
print("{:7d} {}".format(count, line))
@davipatti
davipatti / demo.ipynb
Created February 18, 2019 13:37
Demonstrating matplotlib subplots, list and dict comprehension to Sam and Caitlin
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
from sense_hat import SenseHat
from functools import reduce
from operator import add
import random
i = 51, 160, 44
o = 178, 223, 138
rows = 8
cols = 8
@davipatti
davipatti / dissimilar.md
Last active February 4, 2019 10:41
Select phylogenetically distant taxa in a tree

Selecting dissimilar leaves in a phylogenetic tree

Algorithm

To select N leaves.

- Pick a leaf at random. Add it to a selected list.

While N < len(selected):
@davipatti
davipatti / layout_tree.py
Created January 24, 2019 14:04
Compute and plot a layout for a dendropy.Tree instance in matplotlib.
def attachX(tree):
for node in tree.preorder_node_iter():
if node.parent_node is None:
node.x = 0
else:
node.x = node.edge.length + node.parent_node.x
def attatchYLeaves(tree):
for y, node in enumerate(tree.leaf_node_iter()):
node.y = y
@davipatti
davipatti / thinkpad-setup.md
Last active December 17, 2019 01:14
ThinkPad Ubuntu setup

ThinkPad setup

Notes from installing Ubuntu 18.04 on a Lenovo ThinkPad X1 Extreme, with nvidia graphics.

  • Turn off secure boot in the BIOS.

Installer freezing / non-responsive

@davipatti
davipatti / convexHull.R
Last active February 4, 2019 10:42
Plotting convex hulls in R with Arwen
library(geometry)
library(plotly)
xyz <- c("x", "y", "z")
convexHull <- function(group) {
# I forget whata he name of the variable containing
# the data.frame is, and the name of the column
# that contains the groups
Entity Code Year Life expectancy (Clio-Infra up to 1949; UN Population Division for 1950 to 2015)
Afghanistan AFG 1950 27.537001
Afghanistan AFG 1951 27.809999
Afghanistan AFG 1952 28.35
Afghanistan AFG 1953 28.879999
Afghanistan AFG 1954 29.399
Afghanistan AFG 1955 29.907
Afghanistan AFG 1956 30.403999
Afghanistan AFG 1957 30.891001
Afghanistan AFG 1958 31.367001
@davipatti
davipatti / life-expectancy.ipynb
Last active October 24, 2018 20:31
Life expectancy in the UK
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.