微生物溯源分析!!!
metadata <- read.table('metadata.txt',sep='\t',h=T,row.names=1,check=F,comment='')
otus <- read.table('otus1.txt',sep='\t', header=T,row.names=1,check=F,skip=1,comment='')
otus <- t(as.matrix(otus))
common.sample.ids <- intersect(rownames(metadata), rownames(otus))
otus <- otus[common.sample.ids,]
metadata <- metadata[common.sample.ids,]
if(length(common.sample.ids) <= 3) {
message <- paste(sprintf('Error: there are %d sample ids in common ',length(common.sample.ids)),
'between the metadata file and data table')
stop(message)
}
train.ix <- which(metadata$SourceSink=='source')
test.ix <- which(metadata$SourceSink=='sink')
test.ix = head(test.ix)
envs <- metadata$Env
if(is.element('Description',colnames(metadata))) desc <- metadata$Description
source('SourceTracker.r')
alpha1 <- alpha2 <- 0.001
st <- sourcetracker(otus[train.ix,], envs[train.ix])
results <- predict(st,otus[test.ix,], alpha1=alpha1, alpha2=alpha2)
labels <- sprintf('%s %s', envs,desc)
plot(results, labels[test.ix], type='pie')
plot(results, labels[test.ix], type='bar')
plot(results, labels[test.ix], type='dist')
plot(results, labels[test.ix], type='pie', include.legend=TRUE, env.colors=c('#47697E','#5B7444','#CC6666','#79BEDB','#885588'))
plot(results, labels[test.ix], type='pie', include.legend=TRUE, env.colors=rainbow(5))
st <- sourcetracker(otus[train.ix,], envs[train.ix])
Error in x[i, ] : 下标出界
我以为是数据命名格式问题,或者是sourcetracker包跑出来的otu表不对,但修改后仍出现下标出界问题
无下标出界问题
下标出界报错代码发给我
模型没构建成功,不清楚你的输入数据啥情况,下标出界一般就是行名列名没对齐你检查一下otus[train.ix,]和envs[train.ix],另外我查到的都样本为列的你这为啥要转置成样本为行呢