"for loop" and AUTOPLOT function
2
0
Entering edit mode
Bogdan ▴ 670
@bogdan-2367
Last seen 6 months ago
Palo Alto, CA, USA

Dear all,

I would appreciate a help with writing for a "for loop" with "autoplot" function :

I read a list of genes (chr, start, end) from a file, and would like to use the AUTOPLOT function to display each of these genes (in ggbio package) : but I am not obtaining any result  . Any insights ? thank you,

-- bogdan

the R script is the following :

g <- read.delim("list_GENES",header=TRUE, stringsAsFactors=FALSE)

for (j in 1:nrow(g))
{
   chr <- g[j,]$chr ;
   start <- g[j,]$start ;
   end <- g[j,]$end ;
   gene <- g[j,]$gene ;

   region <- GRanges(chr, IRanges(start,end)) ;

    png("gene.png")

autoplot(Homo.sapiens, which = region, stat = "reduce", color = "blue", fill = "blue", names.expr="SYMBOL")
    dev.off()
 
}

 

where the file "list_GENES" is in the format :

 

chr    start    end    gene
chr16    8663964    8855703    ABAT
chr11    77484160    77741533    ALG8
chr11    69024132    69186057    CCND1
chr1    109424543    109642035    CELSR2
chr15    99517335    99748326    CHSY1
chr6    151733634    152220321    ESR1

 

 

ggbio granges • 1.4k views
ADD COMMENT
0
Entering edit mode
@james-w-macdonald-5106
Last seen 59 minutes ago
United States

You need to wrap your call to autoplot() with a call to print(), and you need to have different file names for each png:

png(paste0(gene, ".png"))

print(autoplot(Homo.sapiens, which = region, stat = "reduce", color = "blue", fill = "blue", names.expr="SYMBOL"))

dev.off()

 

ADD COMMENT
0
Entering edit mode
Bogdan ▴ 670
@bogdan-2367
Last seen 6 months ago
Palo Alto, CA, USA

Dear James,

thanks for the prompt help. It works nicely ;) happy weekend !

-- bogdan

ADD COMMENT

Login before adding your answer.

Traffic: 916 users visited in the last hour
Help About
FAQ
Access RSS
API
Stats

Use of this site constitutes acceptance of our User Agreement and Privacy Policy.

Powered by the version 2.3.6