我正在使用RAM包。 我使用的函数对于多样性索引非常简单,在我的元数据中添加一列;
outname <-OTU.diversity(data=OTUtables, meta=metatables)
(参数:数据OTU表列表。
meta元数据以附加输出)
我正在循环它,但是我收到了这个错误:
请提供otu表作为列表;看?RAM.input.formatting
所以我去帮助菜单阅读:
一个数据集:
data=list(data=otu)
多个数据集:
data=list(data1=otu1, data2=otu2, data3=otu3)
这是我的代码:
i <- 1
for(i in 1:nrow(metadataMasterTax)){
temp <- read.table(paste(metadataMasterTax$DataAnFilePath[i], metadataMasterTax$meta[i], sep = ""),
sep = "\t", header = TRUE, dec = ".", comment.char = "", quote = "", stringsAsFactors = TRUE,
as.is = TRUE)
temp2 <- temp
temp2$row.names <- NULL #to unactivate numbers generated in the margin
trans <- read.table(paste(metadataMasterTax$taxPath[i], metadataMasterTax$taxName[i], sep = ""),
sep = "\t", header = TRUE, dec = ".", comment.char = "", quote = "", stringsAsFactors = TRUE,
as.is = TRUE, check.names = FALSE)
trans2 <- trans
trans2$row.names <- NULL #to unactivate numbers generated in the margin
data=list(data=trans2[i])
temp2[i] <- OTU.diversity(data=trans2[i], meta=temp2[i])
# Error in OTU.diversity(trans2, temp2) :
# please provide otu tables as list; see ?RAM.input.formatting
# is.list(trans2)
# [1] TRUE
# is.list(data)
# [1] TRUE
temp$taxonomy <- temp2$taxonomy
write.table(temp, file=paste(pathDataAn, "diversityDir/", metadataMasterTax$ShortName[i], ".meta.div.tsv", sep = ""),
append = FALSE,
sep = "\t",
row.names = FALSE)
}
任何人都可以帮助我.... 非常感谢
答案 0 :(得分:0)
因为主要问题似乎是让OTU.diversity
功能起作用,所以我专注于这个问题。下面的代码段使用OP提供的Google工作表数据运行OTU.diversity
,没有任何问题。
library(gsheet)
library(RAM)
for (i in 1:2) {
# Meta data
temp <- as.data.frame(gsheet2tbl("https://drive.google.com/open?id=1hF47MbYZ1MG6RzGW-fF6tbMT3z4AxbGN5sAOxL4E8xM"))
temp$row.names <- NULL
# OTU
trans <- as.data.frame(gsheet2tbl("https://drive.google.com/open?id=1gOaEjDcs58T8v1GA-OKhnUsyRDU8Jxt2lQZuPWo6XWU"))
trans$row.names <- NULL
rownames(temp) <- colnames(trans)[-ncol(trans)]
temp2 <- OTU.diversity(data = list(data = trans), meta = temp)
write.table(temp2,
file = paste0("file", i, ".meta.div.tsv"), # replace
append = FALSE,
sep = "\t",
row.names = FALSE)
}
将for (i in 1:2)
替换为for(i in 1:nrow(metadataMasterTax))
,将as.data.frame(gsheet2tbl(...))
替换为read.table(...)
,将file
参数替换为write.table
中的相应字符串。