错误说我有 NA/NaN/Inf 值,但似乎存在 none。 hclustfun(distc) 中的错误:外部函数调用中的 NA/NaN/Inf (arg 11)

Error saying I have NA/NaN/Inf value when there seems to be none present. Error in hclustfun(distc) : NA/NaN/Inf in foreign function call (arg 11)

我有一个如下所示的文件:

Taxa,D0,D1,...
1,0,10,...
20,0,0,...
...

文件可在此处获得:https://www.dropbox.com/s/lvtxztz3kypnxre/Taxa_Conf.csv?dl=0

当我 运行 脚本时

$CONCOCT/scripts/ConfPlot.R -c Taxa_Conf.csv -o Taxa_Conf.pdf

我收到以下错误:

Error in hclustfun(distc) : NA/NaN/Inf in foreign function call (arg 11)
Calls: heatmap.2 -> hclustfun
Execution halted

其中 ConfPlot.R 看起来像

#!/usr/bin/Rscript

#load libraries
library(gplots)
library(getopt)

spec = matrix(c('verbose','v',0,"logical",'help','h',0,"logical",'confile','c',1,"character",'ofile','o',1,"character"),byrow=TRUE,ncol=4)

opt=getopt(spec)

if( !is.null(opt$help)) {
cat(getopt(spec, usage=TRUE)); 
q(status=1);
}

confFile <- opt$confile

Conf <- read.csv(confFile,header=TRUE,row.names=1)
Conf.t <- t(Conf)
ConfP <- Conf.t/rowSums(Conf.t)

crp <- colorRampPalette(c("blue","red","orange","yellow"))(100)

pdf(opt$ofile)

heatmap.2 (as.matrix(t(ConfP)),col=crp,trace="none",dendrogram="none",Rowv=FALSE,lwid = c(1.25,4.5),lhei = c(1.25,4.5),cexRow=0.5)

dev.off()

看完Error while creating heatmaps - NA/NaN/Inf in foreign function call (arg 11),我试了

> a=read.csv("/home/mathed/Simulation/custom_desman/1/Strains/Simulation/Metabat/Taxa_Conf.csv",header=TRUE,row.names=1)
> any(is.na(a))
[1] FALSE

好像没有NA值。 ConfPlot.R 适用于我的其他文件。 问题是什么??似乎没有任何 na、nan 或 inf 值。 提前谢谢你

检查这一行:

ConfP <- Conf.t/rowSums(Conf.t)

它的计算本质上必须是除以零:

> 0/0
[1] NaN

> 1/0
[1] Inf