1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208
|
wd="/mnt/e/Researches/lujia16S/Analysis_20200907/exported-feature-table_2k_abund22/Raup_Crick"
save.wd="/mnt/e/Researches/lujia16S/Analysis_20200907/exported-feature-table_2k_abund22/Raup_Crick/Result2"
dir.create(save.wd, recursive = TRUE)
com.file="feature-table.tsv"
group.file="treatment.txt"
tree.file="tree.nwk"
nworker=8
rand.time=999
prefix="Lujia"
library(ape) library(iCAMP) library(NST) library(picante)
setwd(wd)
comm=t(read.table(com.file,header = TRUE, sep = "\t", row.names = 1, as.is = TRUE, stringsAsFactors = FALSE))
group=read.table(group.file, header = TRUE, sep = "\t", row.names = 1, as.is = TRUE, stringsAsFactors = FALSE)
phy<-read.tree(tree.file) prune_tree<-prune.sample(comm,phy) tree=prune_tree
samp.ck=NST::match.name(rn.list=list(comm=comm,group=group)) comm=samp.ck$comm comm=comm[,colSums(comm)>0,drop=FALSE] group=samp.ck$group
tax.ck=NST::match.name(cn.list = list(comm=comm),tree.list = list(tree=tree)) comm=tax.ck$comm tree=tax.ck$tree
groupi=group[,1,drop=FALSE]
prefixi=paste0(prefix,".Group")
meta.groupi=groupi
dist.method="bray"
t1=Sys.time()
setwd(save.wd)
tnst=tNST(comm=comm, group=groupi, meta.group=meta.groupi, meta.com=NULL, dist.method=dist.method, abundance.weighted=TRUE, rand=rand.time, output.rand=TRUE, nworker=nworker, LB=FALSE, null.model="PF", between.group=TRUE, SES=TRUE, RC=TRUE)
save(tnst, file = paste0(prefixi, ".tNST.rda"))
write.table(tnst$index.grp, file = paste0(prefixi, ".tNST.summary.csv"), quote = FALSE, sep = "\t")
write.table(tnst$index.pair.grp,file = paste0(prefixi,".tNST.pairwise.csv"),quote = FALSE,sep = "\t")
write.table(tnst$index.pair,file = paste0(prefixi,".tNST.pairwise.index.csv"),quote = FALSE,sep = "\t") write.table(tnst$index.between,file = paste0(prefixi,".tNST.between.summary.csv"),quote = FALSE,sep = "\t")
write.table(tnst$index.pair.between,file = paste0(prefixi,".tNST.pairwise.between.csv"),quote = FALSE,sep = "\t")
format(Sys.time()-t1)
t1=Sys.time()
tnstbt=nst.boot(nst.result=tnst, group=groupi, rand=rand.time, trace=TRUE, two.tail=FALSE, out.detail=TRUE, between.group=FALSE, nworker=nworker)
save(tnstbt,file = paste0(prefixi,".tNST.boot.rda"))
write.table(tnstbt$summary,file = paste0(prefixi,".tNST.boot.summary.csv"), quote = FALSE,sep = "\t") write.table(tnstbt$compare,file = paste0(prefixi,".tNST.boot.compare.csv"), quote = FALSE,sep = "\t") (t=format(Sys.time()-t1))
t1=Sys.time()
tnstpaov=nst.panova(nst.result=tnst, group = groupi, rand = rand.time, trace = TRUE)
write.table(tnstpaov,file = paste0(prefixi,".tNST.PERMANOVA.csv"), quote = FALSE,sep = "\t")
(t=format(Sys.time()-t1))
wd.pd=paste0(save.wd,"/pdbig")
if(!dir.exists(wd.pd)){dir.create(wd.pd)}
setwd(wd.pd)
if(file.exists("pd.desc")) { pdbig=list() pdbig$tip.label=read.table("pd.taxon.name.csv", sep = ",", row.names = 1, header = TRUE, stringsAsFactors = FALSE, as.is = TRUE)[,1] pdbig$pd.wd=wd.pd pdbig$pd.file="pd.desc" pdbig$pd.name.file="pd.taxon.name.csv" }else{ pdbig=iCAMP::pdist.big(tree = tree, wd = wd.pd, nworker = nworker) }
t1=Sys.time()
setwd(save.wd)
pnst=NST::pNST(comm=comm, pd.desc=pdbig$pd.file, pd.wd=pdbig$pd.wd, pd.spname=pdbig$tip.label, group=groupi, meta.group=meta.groupi, abundance.weighted=TRUE, rand=rand.time, output.rand=TRUE, taxo.null.model=NULL, phylo.shuffle=TRUE, exclude.conspecifics=FALSE, nworker=nworker, between.group=FALSE, SES=TRUE, RC=TRUE)
save(pnst,file = paste0(prefixi,".pNST.rda"))
write.table(pnst$index.grp,file = paste0(prefixi,".pNST.summary.csv"), quote = FALSE,sep = "\t")
write.table(pnst$index.pair.grp,file = paste0(prefixi,".pNST.pairwise.csv"),quote = FALSE,sep = "\t")
write.table(pnst$index.pair,file = paste0(prefixi,".pNST.pairwise.index.csv"),quote = FALSE,sep = "\t")
write.table(pnst$index.between,file = paste0(prefixi,".pNST.between.summary.csv"),quote = FALSE,sep = "\t")
write.table(pnst$index.pair.between,file = paste0(prefixi,".pNST.pairwise.between.csv"),quote = FALSE,sep = "\t")
format(Sys.time()-t1)
t1=Sys.time()
pnstbt=nst.boot(nst.result=pnst, group=groupi, rand=rand.time, trace=TRUE, two.tail=FALSE, out.detail=TRUE, between.group=FALSE, nworker=nworker)
save(pnstbt,file = paste0(prefixi,".pNST.boot.rda"))
write.table(pnstbt$summary,file = paste0(prefixi,".pNST.boot.summary.csv"), quote = FALSE,sep = "\t")
write.table(pnstbt$compare,file = paste0(prefixi,".pNST.boot.compare.csv"), quote = FALSE,sep = "\t")
(t=format(Sys.time()-t1))
t1=Sys.time()
pnstpaov=nst.panova(nst.result=pnst, group = groupi, rand = rand.time, trace = TRUE)
write.table(pnstpaov,file = paste0(prefixi,".pNST.PERMANOVA.csv"), quote = FALSE,sep = "\t")
(t=format(Sys.time()-t1))
|