Script
require(vegan)
require(ape)
require(MASS)
require(ggplot2)
mg = eval(parse(text=traitsIn));
mg.dinuc = eval(parse(text=dinucDfIn));
mg.codon = eval(parse(text=codonDfIn));
mg.aa = eval(parse(text=aaDfIn));
mg.phylo.hel = eval(parse(text=phyloHelIn));
mg.func.hel = eval(parse(text=funcHelIn));
#Create distance matrices
mg.traits.dist<- vegdist(decostand(mg[,4:ncol(mg)], method="standardize"), method="euclidean")
mg.dinuc.dist<-vegdist(mg.dinuc, method="euclidean")
mg.codon.dist<-vegdist(mg.codon, method="euclidean")
mg.aa.dist<-vegdist(mg.aa, method="euclidean")
mg.func.dist<-vegdist(mg.func.hel, method="bray")
mg.phylo.dist<-vegdist(mg.phylo.hel, method="bray")
#####################################################################################
#PHYLOGENETIC AND FUNCTIONAL RESPONSES
#####################################################################################
#Relationship between functional traits and phylogenetic/functional matrix
#Create a distance matrix for each individual trait
for (i in 4:ncol(mg)) {
x<-vegdist(mg[,i], method="euclidean")
assign(paste(colnames(mg)[i],"distance",sep="_"), x)
}
#Mantel test against phylogenetic distance matrix (controlling for functional response)
gc.mantel<-mantel.partial(mg.phylo.dist, GC_distance, mg.func.dist, method="spearman")
vargc.mantel<-mantel.partial(mg.phylo.dist, varGC_distance, mg.func.dist, method="spearman")
rRNA.mantel<-mantel.partial(mg.phylo.dist, rRNA_distance, mg.func.dist, method="spearman")
genes.mantel<-mantel.partial(mg.phylo.dist, Genes_distance, mg.func.dist, method="spearman")
ab.mantel<-mantel.partial(mg.phylo.dist, ABratio_distance, mg.func.dist, method="spearman")
tf.mantel<-mantel.partial(mg.phylo.dist, TF_distance, mg.func.dist, method="spearman")
class.mantel<-mantel.partial(mg.phylo.dist, Classified_distance, mg.func.dist, method="spearman")
dinuc.mantel<-mantel.partial(mg.phylo.dist, mg.dinuc.dist, mg.func.dist, method="spearman")
codon.mantel<-mantel.partial(mg.phylo.dist, mg.codon.dist, mg.func.dist, method="spearman")
aa.mantel<-mantel.partial(mg.phylo.dist, mg.aa.dist, mg.func.dist, method="spearman")
funcH.mantel<-mantel.partial(mg.phylo.dist, Functional.H_distance, mg.func.dist, method="spearman")
phylo.mantel<-mantel.partial(mg.phylo.dist, mg.phylo.dist, mg.func.dist, method="spearman")
phyloH.mantel<-mantel.partial(mg.phylo.dist, Phylogeny.H_distance, mg.func.dist, method="spearman")
traits.mantel<-mantel.partial(mg.traits.dist, mg.phylo.dist, mg.func.dist, method="spearman")
phylo.mantel.df<-cbind('GC content', gc.mantel$statistic, gc.mantel$signif)
phylo.mantel.df<-rbind(phylo.mantel.df, cbind('Variance of GC content', vargc.mantel$statistic, vargc.mantel$signif))
phylo.mantel.df<-rbind(phylo.mantel.df, cbind('Dinucleotides', dinuc.mantel$statistic, dinuc.mantel$signif))
phylo.mantel.df<-rbind(phylo.mantel.df, cbind('Number of rRNA/genome', rRNA.mantel$statistic, rRNA.mantel$signif))
phylo.mantel.df<-rbind(phylo.mantel.df, cbind('Number of genes/genome', genes.mantel$statistic, genes.mantel$signif))
phylo.mantel.df<-rbind(phylo.mantel.df, cbind('Codons', codon.mantel$statistic, codon.mantel$signif))
phylo.mantel.df<-rbind(phylo.mantel.df, cbind('Amino acids', aa.mantel$statistic, aa.mantel$signif))
phylo.mantel.df<-rbind(phylo.mantel.df, cbind('Acidic to basic amino acids ratio', ab.mantel$statistic, ab.mantel$signif))
phylo.mantel.df<-rbind(phylo.mantel.df, cbind('% of Transcriptional factors', tf.mantel$statistic, tf.mantel$signif))
phylo.mantel.df<-rbind(phylo.mantel.df, cbind('% of classified reads', class.mantel$statistic, class.mantel$signif))
phylo.mantel.df<-rbind(phylo.mantel.df, cbind('Functional diversity', funcH.mantel$statistic, funcH.mantel$signif))
phylo.mantel.df<-rbind(phylo.mantel.df, cbind('Taxonomic content', phylo.mantel$statistic, phylo.mantel$signif))
phylo.mantel.df<-rbind(phylo.mantel.df, cbind('Taxonomic diversity', phyloH.mantel$statistic, phyloH.mantel$signif))
phylo.mantel.df<-rbind(phylo.mantel.df, cbind('All community traits', traits.mantel$statistic, traits.mantel$signif))
phylo.mantel.df<-as.data.frame(phylo.mantel.df)
#row.names(phylo.mantel.df)<-phylo.mantel.df$V1
#phylo.mantel.df$V1<-NULL
colnames(phylo.mantel.df)[1]<-'traits'
colnames(phylo.mantel.df)[2]<-'statistic'
colnames(phylo.mantel.df)[3]<-'signif'
write.table(phylo.mantel.df, file=phyloMantel, quote=F, sep="\t", row.names=F)
#Mantel test against functional (Subsystems) distance matrix (controlling for phylogenetic response)
gc.mantel<-mantel.partial(mg.func.dist, GC_distance, mg.phylo.dist, method="spearman")
vargc.mantel<-mantel.partial(mg.func.dist, varGC_distance, mg.phylo.dist, method="spearman")
rRNA.mantel<-mantel.partial(mg.func.dist, rRNA_distance, mg.phylo.dist, method="spearman")
genes.mantel<-mantel.partial(mg.func.dist, Genes_distance, mg.phylo.dist, method="spearman")
ab.mantel<-mantel.partial(mg.func.dist, ABratio_distance, mg.phylo.dist, method="spearman")
tf.mantel<-mantel.partial(mg.func.dist, TF_distance, mg.phylo.dist, method="spearman")
class.mantel<-mantel.partial(mg.func.dist, Classified_distance, mg.phylo.dist, method="spearman")
dinuc.mantel<-mantel.partial(mg.func.dist, mg.dinuc.dist, mg.phylo.dist, method="spearman")
codon.mantel<-mantel.partial(mg.func.dist, mg.codon.dist, mg.phylo.dist, method="spearman")
aa.mantel<-mantel.partial(mg.func.dist, mg.aa.dist, mg.phylo.dist, method="spearman")
func.mantel<-mantel.partial(mg.func.dist, mg.func.dist, mg.phylo.dist, method="spearman")
funcH.mantel<-mantel.partial(mg.func.dist, Functional.H_distance, mg.phylo.dist, method="spearman")
phyloH.mantel<-mantel.partial(mg.func.dist, Phylogeny.H_distance, mg.phylo.dist, method="spearman")
traits.mantel<-mantel.partial(mg.func.dist, mg.func.dist, mg.phylo.dist, method="spearman")
phylo.mantel.df<-cbind('GC content', gc.mantel$statistic, gc.mantel$signif)
phylo.mantel.df<-rbind(phylo.mantel.df, cbind('Variance of GC content', vargc.mantel$statistic, vargc.mantel$signif))
phylo.mantel.df<-rbind(phylo.mantel.df, cbind('Dinucleotides', dinuc.mantel$statistic, dinuc.mantel$signif))
phylo.mantel.df<-rbind(phylo.mantel.df, cbind('Number of rRNA/genome', rRNA.mantel$statistic, rRNA.mantel$signif))
phylo.mantel.df<-rbind(phylo.mantel.df, cbind('Number of genes/genome', genes.mantel$statistic, genes.mantel$signif))
phylo.mantel.df<-rbind(phylo.mantel.df, cbind('Codons', codon.mantel$statistic, codon.mantel$signif))
phylo.mantel.df<-rbind(phylo.mantel.df, cbind('Amino acids', aa.mantel$statistic, aa.mantel$signif))
phylo.mantel.df<-rbind(phylo.mantel.df, cbind('Acidic to basic amino acids ratio', ab.mantel$statistic, ab.mantel$signif))
phylo.mantel.df<-rbind(phylo.mantel.df, cbind('% of Transcriptional factors', tf.mantel$statistic, tf.mantel$signif))
phylo.mantel.df<-rbind(phylo.mantel.df, cbind('% of classified reads', class.mantel$statistic, class.mantel$signif))
phylo.mantel.df<-rbind(phylo.mantel.df, cbind('Functional content', func.mantel$statistic, func.mantel$signif))
phylo.mantel.df<-rbind(phylo.mantel.df, cbind('Functional diversity', funcH.mantel$statistic, funcH.mantel$signif))
phylo.mantel.df<-rbind(phylo.mantel.df, cbind('Taxonomic diversity', phyloH.mantel$statistic, phyloH.mantel$signif))
phylo.mantel.df<-rbind(phylo.mantel.df, cbind('All community traits', traits.mantel$statistic, traits.mantel$signif))
phylo.mantel.df<-as.data.frame(phylo.mantel.df)
#row.names(phylo.mantel.df)<-phylo.mantel.df$V1
#phylo.mantel.df$V1<-NULL
colnames(phylo.mantel.df)[1]<-'traits'
colnames(phylo.mantel.df)[2]<-'statistic'
colnames(phylo.mantel.df)[3]<-'signif'
write.table(phylo.mantel.df, file=funcMantel, quote=F, sep="\t", row.names=F)
Comments (0)
No comments yet
Log in to make a comment