Search code examples
rfor-loopplotsnakemake

Empty pdf with for loop


I have I am trying to save a pdf with path being called via snakemake. I am using vec to loop through each gene in feature plot. I want to make one plot per page and have a list of pages in each pdf that I can look at. However, I keep getting an empty pdf output with zero pages. I am not seeing what is wrong.

pdf(file = snakemake@output[['GeneLabel']], onefile=FALSE)
vec<- c("DKC1", "NOP10", "WRAP53", "POT1", "PARN")
for(i in vec){
  FeaturePlot(cts.seurat.obj, features = c(i))
}
dev.off()
graphics.off()

Solution

  • Not sure about it, but try this:

    pdf(file = snakemake@output[['GeneLabel']], onefile=FALSE)
    vec<- c("DKC1", "NOP10", "WRAP53", "POT1", "PARN")
    for(i in vec){
      gg <- FeaturePlot(cts.seurat.obj, features = c(i))
      print(gg)
    }
    dev.off()
    graphics.off()
    

    I'm also not sure whether you need to set combine=FALSE in FeaturePlot

    As noted by John Polo, you should give quite a bit more detail of what you are doing and a reproducible example.