This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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/") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require(picante) | |
require(gtools) | |
require(reshape) | |
########################################################### | |
### For calculation of Naiive (Z = I) diversity profiles ### | |
########################################################### |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require(picante) | |
require(gtools) | |
require(reshape) | |
########################################################### | |
### Utility functions ### | |
########################################################### | |
internal2tips.self = function (phy, int.node){ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
############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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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)) { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
NewerOlder