This is a test version of Biostars. For the public version, visit https://www.biostars.org.
error in density plot - methylation EPIC data

I am creating densityplot for methylation EPIC data using minfi package in R

Below is my code for plotting density plot

rgsetAll <- read.metharray.exp(targets = Targets, force=TRUE)
densityPlot(preprocessRaw(rgsetAll), main = "Methylation")

However i'm getting this error:

Error in density.default(newX[, i], ...) : 
  need at least 2 points to select a bandwidth automatically
Calls: densityPlot -> apply -> FUN -> FUN -> density.default

I checked beta values and there is a lot of missing values (NA) for couple of samples. Could missing values be causing error?

Did anyone face this problem while dealing with methylation array data.

Any help is appreciated

r bioconductor

1 answer

Hey Mate it may be too little too late but I had the same issue while analyzing EPIC arrays and this is what I did (In hope that someone having the same issue and this could help): I got the following error

"Error in density.default(as.vector(x), na.rm = TRUE) : need at least 2 points to select a bandwidth automatically"

while running this line of code

qcReport(rgSet, sampNames=targets$ID, sampGroups=targets$Sample_Group, pdf="qcReport.pdf").

This ment that one of the samples used in plot does not have enough values to do density plot. Since I was doing Density plot of Beta values I extracted the Beta values for a closer look.

bv<-getBeta(rgSet)

head(bv)

revelaed that one sample has NaN vlues "NOPTSD_N.202908540170_R06C01". To look into that all Beta values in the sample are NaN, I ran the code colMeans(bv,na.rm=TRUE). This output values for all the samples expect our trouble sample "NOPTSD_N.202908540170_R06C01". That has value NaN. So decided to remove the sample from analysis by using the the code

keep<-colMeans(bv,na.rm=TRUE)>0

All samples have TRUE value and our troubled friend has NA. To change from NA to FALSE to help subset dataset.

keep["NOPTSD_N.202908540170_R06C01"]=FALSE

rgSet<-rgSet[,keep] targets <- targets[keep,]

The last 2 line of code updated my dataset by removing the problem sample. After this plots ran like dream.

Thanks, removing the NA worked for me :)

Log in to answer this question.