Skip to content. | Skip to navigation

Personal tools

Sections

R distances figS2

### 16s - distances
# applied to taxotofreq_script output
# paper version

rm(list=ls())

setwd()

freq=read.table("filename_taxotofreq.txt", header=T, sep="\t")
colnames(freq)[4]="exp"
freq$unclassified=NULL

library(data.table, quietly = T)

for (j in 5:ncol(freq)){
set(freq,which(freq[[j]]<0),j,0)
}


test=freq[,c(5:ncol(freq))]
summary(test)
for(i in 1:nrow(test)){
test[i,]=round(100*test[i,]/sum(test[i,]),2)
}

prop=cbind(freq[,c(1:4)], test)

s=1
library(data.table, quietly = T)
## Change NA into 0 faaaaast
for (j in 5:ncol(prop)){
set(prop,which(prop[[j]]<s),j,0)
}


prop=prop[!prop$sample.ID%in%c("AB01", "AB02", "AB03", "AB04"),]
DVEC=c()
GROUP=c()
for(j in levels(prop$sample.type)){
for(k in levels(prop$level)){
name=paste(k,j,sep="_")
d=dist(prop[prop$sample.type==j & prop$level==k, -(1:4)])
if(length(d)!=0){
d=as.matrix(d)
n=nrow(d)
for(i in 1:(ncol(d)-1)){
dvec=d[(i+1):n,i]
DVEC=c(DVEC,dvec)
group=rep(name,length(dvec))
GROUP=c(GROUP,group)
}
}
}
}

DIST=data.frame(Distance=DVEC, Condition=GROUP)

boxplot(Distance~Condition,DIST)
stripchart(Distance~Condition,DIST,
vertical = TRUE, method="stack",
pch = 21, cex=1.2, col = "black", bg="darkgoldenrod1",
add = TRUE)
title("intra-condition distances")

pairwise.t.test(DIST$Distance,DIST$Condition,p.adjust.method = "none")