Skip to content

Instantly share code, notes, and snippets.

@josephwb
josephwb / getNexson.sh
Last active December 30, 2015 04:18
Get nexson(s) study files from Phylografter.
#!/bin/bash
## script to grab individual nexson(s) from Phylografter
## Usage:
## ./getNexson.sh study1ID study2ID ...
## where study*ID is the Phylografter study identifier. For example, to get studies 420 and 1428, type:
## ./getNexson.sh 1428 420
## It may be necessary to change access permission to make the script executable. Type:
## chmod 755 getNexson.sh
@josephwb
josephwb / cmpFiles.sh
Created March 6, 2014 16:52
Compare 2 files, byte-by-byte
#!/bin/bash
## script to check if files contain identical data (by byte). stops at first difference.
## Usage:
## ./cFiles.sh file1 file2
## It may be necessary to change access permission to make the script executable. Type:
## chmod 755 cFiles.sh
if [ "$#" -ne 2 ]
then
@josephwb
josephwb / getlineSafe
Created June 4, 2014 15:53
C++ getline for when line endings are unknown
// g++ -Wall getlineSafe.cpp -o getlineSafe -O
#include <string.h>
#include <iostream>
#include <fstream>
#include <cstdlib>
std::istream& getlineSafe(std::istream& is, std::string& t) {
t.clear();
@josephwb
josephwb / getopt_long
Created January 28, 2015 16:41
getopt_long: hack to read in an arbitrary number of arguments for a single option
/* Compile with:
* g++ -Wall -std=c++11 dummy.cpp -o dummy -O
* Run as:
* ./dummy -s *.txt
*/
#include <iostream>
#include <string>
#include <fstream>
#include <vector>
# gist copied from: https://gist.github.com/emhart/89fd49401bc9795d790ef47ca638726f
# for Ubuntu 18, had to do:
# sudo apt-get install portaudio19-dev
# before installing audio package
# might have to install these packages first
library("dplyr");
library("audio");
@josephwb
josephwb / BayesTraits Makefile
Last active November 20, 2017 16:28
Simple makefile to compile BayesTraitsv3
## Simple makefile to compile BayesTraitsv3 ##
#
# Program info:
# BayesTraits V3.0 (Mar 14 2017)
# Mark Pagel and Andrew Meade
# www.evolution.reading.ac.uk
#
# source: http://www.evolution.rdg.ac.uk/BayesTraitsV3/BayesTraitsV3.html
#
# By default, compiles serial version. To compile threaded version, do:
@josephwb
josephwb / Baron_et_al_2017_Nature.NEX
Last active November 15, 2017 16:18
Baron et al 2017 Nature dino matrix
#NEXUS
[ *** NOTE (JWB) *** 1st character (all 0, except Dimorphodon_macronyx who was missing the char) in original matrix (Supp. Info. pdf) was a dummy character because TNT is zero-indexed?]
[ It has been deleted here so char indices of 'ordered' list line up. So this martix has 457 chars, while the (incorrect) published matrix has 458.]
Begin data;
Dimensions ntax=75 nchar=457;
[Format Datatype=Standard Missing=? Gap=-;] [MRBAYES]
Format Datatype=Standard SYMBOLS="0 1 2 3 4" Missing=? Gap=-; [PAUP]
MATRIX
@josephwb
josephwb / get_mrca_fast.R
Last active August 26, 2020 13:52
Faster tree MRCA calculator in R (alt to APE's getMRCA)
## written by:
# Joseph W. Brown (josephwb, @j0sephwb)
# Klaus Schliep (KlausVigo, @Klaus_Schlp)
get_mrca_fast <- function(phy, tip) {
if (!inherits(phy, "phylo")) {
stop('object "phy" is not of class "phylo"');
}
if (length(tip) < 2) {
return(NULL);
}
@josephwb
josephwb / Makefile.BEAST.likes
Created February 16, 2018 15:51
Compile and install native BEAST likelihood cores (BEAST v1.8.*). Assumes linux
# run from BEASTv1.8.*/native
# will compile and install into ../lib/
CC=gcc
CFLAGS=-O2 -funroll-loops
INCLUDES=-I${JAVA_HOME}/include/ -I${JAVA_HOME}/include/linux
all: libNucleotideLikelihoodCore.so libAminoAcidLikelihoodCore.so
.c.o:
@josephwb
josephwb / subtree.induced.R
Created April 13, 2018 10:43
(R) From a larger tree, extract the subtree induced from a specified set of tips. Requires ape.
# extract subtree induced from a set of tips
subtree.induced <- function (phy, tip) {
if (!inherits(phy, "phylo")) {
stop("object \"phy\" is not of class \"phylo\"");
}
Ntip <- length(phy$tip.label);
# convert to indices if strings passed in
if (is.character(tip)) {
idx <- match(tip, phy$tip.label);