Skip to content

Instantly share code, notes, and snippets.

Dave Armitage darmitage

Block or report user

Report or block darmitage

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
View cyanonest
############################################################################
#CODE FOR ANALYZING NESTEDNESS OF A COMMUNITY MATRIX & PLOTTING THE RESULTS#
############################################################################
require(vegan)
require(ade4)
#Here, samp_85 is simply a community matrix of my 85% OTU cyano bins. The [5:9] just chooses
#specific rows for analysis (here, a depth gradient).
samp <- samp_85[c(5:9),]
@darmitage
darmitage / cyanodiversity
Created Nov 1, 2011
Phylodiversity plots
View cyanodiversity
#This is code for those plots I made using the MPD and MNTD metrics. You need to organize them into a table such as the one below#
require(ggplot2)
data = read.csv("data.csv", header = TRUE, sep = "")
s <- c("NM1","NM2","NM3", "NM4", "NM5", "Green", "Pink", "Brown", "S1", "S2", "G1", "G2")
data$OTU <- factor(data$OTU)
cyanos = subset(data, group == "cyano")
PSBs = subset(data, group == "PSB")
closts = subset(data, group == "clost")
@darmitage
darmitage / bipartite code
Created Nov 1, 2011
Bipartite network Code
View bipartite code
#This code uses a community matrix a'la VEGAN to make a bipartite network of how your taxa are organized into a particular habitat#
#Gets really messy with >100 species#
samp <- samp[c(4,10,1,11,12),]
require(bipartite)
visweb(samp, type="nested", prednames=TRUE, preynames=TRUE, labsize=1,
plotsize=12, square="black", text="no", frame=NULL, textsize=1,
textcol="red", pred.lablength=NULL, prey.lablength = NULL, clear=TRUE,
@darmitage
darmitage / diversityprofile
Created Nov 17, 2011
Calculate Diversity Profile
View diversityprofile
#Example for calculating diversity profiles of Part of the Eectronic Supplementary Material for Leinster, T. & Cobbold C.A. 2011
#"Measuring diversity: the importance of species similarity" #
#URL: www.esajournals.org/doi/abs/10.1890/10-2402.1 #
require(picante)
#assumes you already have a phylogeny (called "phylo") and a community matrix (called "samp")#
#where rows = sites, columns = taxa (the way VEGAN and PICANTE like them).#
samp <- t(samp)
@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)
@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 / 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 / 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 / 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 / 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){
You can’t perform that action at this time.