我的数据看起来像this:
Probes Gene.symbol some.kk.06 some.sp.06 some.ln.06 some.kk.06 some.sp.06
1419083_at Tnfsf11 0 1.273 0.976 0 0.964
1419318_at Saa4 1.134 0 0 1.916 0
1442255_at --- 0 1.104 1.417 0 0.761
1421025_at Agpat1 0 1.058 0.976 0 1.02
1427071_at Fbxo42 1.094 1.012 1.137 1.589 1.308
我想要做的是使用以下代码绘制树形图:
#!/u21/neversaint/.r/bin/Rscript
library(gplots);
plot.hclust <- function(inputfile,clust.height) {
dat.some <- read.table(inputfile,na.strings=NA, sep="\t",header=TRUE);
print(head(dat.some))
rownames(dat.some) <- do.call(paste,c(dat.some[c("Probes","Gene.symbol")],sep=" "))
dat.some <- dat.some[,!names(dat.some) %in% c("Probes","Gene.symbol")]
dat.some <- dat.some
# Clustering and distance function
hclustfunc <- function(x) hclust(x, method="complete")
distfunc <- function(x) dist(x,method="maximum")
# Select based on FC, as long as any of them >= anylim
dat.some <- dat.some[ apply(dat.some, 1,function(x) any (x >= anylim)), ]
nrow(dat.some);
# Clustering functions
height <- clust.height;
# Define output file name
dendoout <- paste("some.pafc.dendo.",anylim,".h",height,".default.pdf",sep="");
# Compute distance and clusteirn function
d.some <- distfunc(dat.some)
fit.some <- hclustfunc(d.some)
str(fit.some)
# Plot the hierarchical dendogram without heatmap
pdf(file=dendoout,width=120,height=27);
plot(fit.some)
dev.off()
}
plot.hclust("http://pastebin.com/raw.php?i=i8XXxUu0",clust.height=3);
但它打印出这个错误:
Error in read.table(inputfile, na.strings = NA, sep = "\t", header = TRUE) :
'file' must be a character string or connection
我该如何解决?
答案 0 :(得分:3)
您通过命名函数hclust
来覆盖绘制plot.hclust
对象的通用方法,这样当您在函数的倒数第二行调用plot(fit.some)
时,您实际上是从内部递归调用函数,但使用fit.some
作为输入文件而不是url或文件名。
将您的函数命名为plot.hclust
之外的其他内容应解决您遇到的问题,因为plot(fit.some)
应具有预期的行为。