xia-lab / MetaboAnalystR

R package for MetaboAnalyst
Other
318 stars 157 forks source link

PlotSubHeatMap: Error in hclust(d, method = method) : must have n >= 2 objects to cluster #278

Open jessieolough opened 1 year ago

jessieolough commented 1 year ago

Hi,

I am trying to use the MetaboAnalystR package functions within an R Markdown file to easily create metabolomics reports using the code provided by MetaboAnalyst when you use the website for initial analyses. I have been able to make a heatmap where all the compounds are present. However: when I use the code provided to make a heatmap showing only the top 30 most significant compounds I get an "Error in hclust(d, method = method) : must have n >= 2 objects to cluster" message when I use the PlotSubHeatMap function. This is despite me being able to get the desired output when using the MetaboAnalyst website. Here is a shortened version of my code:

library(MetaboAnalystR)

# Construct mSetObj
mSet<-InitDataObjects("pktable", "stat", FALSE)
# Read raw csv file
mSet<-Read.TextData(mSet, "annotations.csv", "colu", "disc");
# Check that the data is in the correct format for further analysis
mSet<-SanityCheckData(mSet)
# Replace zero/missing values with half of the smallest positive values in the original dataset
mSet<-ReplaceMin(mSet);
mSet<-SanityCheckData(mSet)
# Filter dataset (filter out 5% based on Interquantile range, IQR)
mSet<-FilterVariable(mSet, "none", -1, "F", 25, F)
# Normalise data
mSet<-PreparePrenormData(mSet)
mSet<-Normalization(mSet, "NULL", "LogNorm", "ParetoNorm", ratio=FALSE, ratioNum=20)

#Plot heat map (all compounds, this code works)
mSet <- MetaboAnalystR::PlotHeatMap(mSet, "heatmap_0_", "png", 300, width=NA, "norm", "row", "euclidean", "ward.D","bwm", 4, "overview", T, T, NULL, T, F, T, T, T)
#Plot heat map (top 30 most significant compounds, this code does NOT work)
mSet<-MetaboAnalystR::PlotSubHeatMap(mSet, "heatmap_1_", "png", 72, width=NA, "norm", "row", "euclidean", "ward.D","bwm", 8, "tanova", 30, "overview", T, T, T, F, T, T, T)

Any help would be much appreciated. Many thanks!

lumin2003 commented 1 year ago

I have some issue to make a top50 with the code from MetaboAnalyst. But if you look into the code:mSet2 <- PlotHeatMap( mSetObj = mSet, imgName = "heatmap1", format = "png", dpi = 72, width = NA, dataOpt = "norm", scaleOpt = "row", smplDist = "euclidean", clstDist = "ward.D", palette = "bwm", font.size = 8, viewOpt ="tanova", rowV =30, colV = T, var.inx = T, border = T, grp.ave = F, show.legend = T, show.annot.legend = T, includeRowNames = T ), we probably need to correctly set the parameters (viewOpt and rowV) up with "tanova", 30, "overview".

jessieolough commented 1 year ago

Hi lumin2003, thanks for your response! I will give that a try :)