Skip to content

Instantly share code, notes, and snippets.

@darmitage
darmitage / PseudomonasSharedCode
Last active Mar 23, 2016
Data and code for EcoLetts submission
View PseudomonasSharedCode
require(AICcmodavg)
require(mgcv)
require(boot)
require(car)
require(MASS)
require(repmis)
require(pscl)
#Read in data from my public dropbox folder
dropURL <- "https://dl.dropboxusercontent.com/u/26280366/Papers/EcoLetts/AreaNrgPseudoFinal.csv"
@darmitage
darmitage / batcall_classify
Created Sep 18, 2012
Classification of zero-crossings bat calls using machine learning
View batcall_classify
require(kernlab)
require(caret)
require(e1071)
require(nnet)
require(randomForest)
set.seed(34873458)
#Open call library (needs name (eg. MYLU), and parameters)
setwd = ("Dropbox/Anabat files/Dave's Florida Bat Calls/")
@darmitage
darmitage / NaiiveD
Created Jul 25, 2012
Naiive Diversity Profiles + Rarefaction
View NaiiveD
require(picante)
require(gtools)
require(reshape)
###########################################################
### For calculation of Naiive (Z = I) diversity profiles ###
###########################################################
@darmitage
darmitage / PhyloClean
Created Jun 1, 2012
Cleaning up OTU tables and Phylogenies
View PhyloClean
phy = read.tree("mytree.tre")
samp = read.table("OTUtable.txt", head = T, sep = "")
#lists taxa in OTU table that are not in the phylogeny, and removes them
samp = (samp[rowSums(samp) != 0, , drop=FALSE])
samp = t(samp)
phy = prune.sample(samp, phy)
labs <- phy$tip.label
length(labs)
ncol(samp)
@darmitage
darmitage / ChaoPD
Created May 15, 2012
Chao's phylogenetic diversity
View ChaoPD
require(picante)
require(gtools)
require(reshape)
###########################################################
### Utility functions ###
###########################################################
internal2tips.self = function (phy, int.node){
@darmitage
darmitage / Phylo.Z.code
Created May 9, 2012
Phylogenetic Hill Numbers
View Phylo.Z.code
############Here's a function that calculates Hill number diversity using a phylogeny from the Leinster and Cobbold (2012) paper
#Requires a phylogeny with tip labels and a community matrix (rows = samples, columns = species)
Phylo.Z <- function(phy,samp){
#packages required for this to work:
require(reshape)
require(picante)
require(ape)
require(gtools)
@darmitage
darmitage / WorkingZCode
Created May 9, 2012
Working similarity matrix code sensu Leinster & Cobbold 2012
View WorkingZCode
require(reshape)
require(picante)
require(gtools)
#Function that lists all terminal tip labels descended from ancestral node
internal2tips.self = function (phy, int.node){
#require(picante); require(ape)
Ntaxa = length(phy$tip.label)
Nnode = phy$Nnode
if ((Ntaxa + Nnode - 1) != nrow(phy$edge)) {
@darmitage
darmitage / nodes2root
Created May 8, 2012
List nodes falling between specified node and root of phylogeny
View nodes2root
nodes2root <-
function(phy,int.node) {
Ntaxa = length(phy$tip.label) + phy$Nnode
Nnode = phy$Nnode
tips = c()
nodes = int.node
repeat {
nodes = phy$edge[which(phy$edge[,2]%in%nodes),1]
if (length(nodes)==0) break
tips = c(tips,nodes)
@darmitage
darmitage / node_collapse
Created Apr 24, 2012
Collapse a phylogenetic clade by support values
View node_collapse
#Code to collapse a phylogeny by a tree's support values, when nodes have support value names
#tree = phylogenetic tree, cutoff = support value cutoff (can be changed or made into a vector)
require(ape)
h <- which(tree$node.label < cutoff)
nodes <- matrix(h + Ntip(tree))
nodes <- nodes[-1]
k <- matrix(tree$edge[,2])
j <- matrix(nrow = length(i), ncol = 1)
@darmitage
darmitage / phylosim
Created Dec 12, 2011
histograms of phylogenetic similarity
View phylosim
require(picante)
#function that maps dissimilarity to similarity & scales between 0 and 1
range01 <- function(x){exp((-1/max(x))*x)}
#Calculate branch lengths bewteen taxa
dist <- cophenetic(tree)
#calculate similarity between taxa from 0 to 1
Z <- range01(dist)
You can’t perform that action at this time.