DOSE icon indicating copy to clipboard operation
DOSE copied to clipboard

Saving separate dotplots with for loop

Open mirkocelii opened this issue 4 years ago • 1 comments

hello, I want to create several PDF files with Functional_enrichment Doplot as Chipseeker vignette with a for loop. http://bioconductor.org/packages/devel/bioc/vignettes/ChIPseeker/inst/doc/ChIPseeker.html but the PDF are empty with no pages.

If I avoid the for loop e run the commands one by one, it works. am I doing something wrong? this is the code

library(ReactomePA)
library(ChIPseeker)
library(TxDb.Hsapiens.UCSC.hg19.knownGene)
txdb <- TxDb.Hsapiens.UCSC.hg19.knownGene
library(clusterProfiler)

files <- getSampleFiles()
peakList         <- lapply(files, readPeakFile)
peakAnnoList <- lapply(files, annotatePeak, TxDb=txdb, tssRegion=c(-3000, 3000), verbose=FALSE)


for( i in names(peakAnnoList))
{
    cat(i)
    peak         = peakList[[i]]
    peakAnno = peakAnnoList[[i]]
    
    pathway1 <- enrichPathway(as.data.frame(peakAnno)$geneId)
    head(pathway1, 2)
    
    gene <- seq2gene(peak, tssRegion = c(-1000, 1000), flankDistance = 3000, TxDb=txdb)
    pathway2 <- enrichPathway(gene)
    head(pathway2, 2)
    
    pdf( paste("Functional_enrichment",i,"pathway1.pdf",sep="."),10,10)
    dotplot( pathway1,title = paste("Functional enrichment", sam))
    dev.off()  
    
    pdf( paste("Functional_enrichment",i,"pathway2.pdf",sep="."),10,10)
    dotplot( pathway2,title = paste("Functional enrichment", sam))
    dev.off()  
    
    }

mirkocelii avatar Mar 18 '21 15:03 mirkocelii

try print the dotplot.

pdf(file)
print(dotplot())
dev.off()

GuangchuangYu avatar Sep 18 '21 15:09 GuangchuangYu