"for loop" and AUTOPLOT function
2
1
Entering edit mode
9.4 years ago
Bogdan ★ 1.4k

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
granges ggbio • 3.4k views
ADD COMMENT
0
Entering edit mode

Yeah? What seems to be the problem? What happens?

It looks like youre going to overwrite the file gene.png repeatedly...

ADD REPLY
0
Entering edit mode
ADD REPLY
2
Entering edit mode
9.4 years ago
komal.rathi ★ 4.1k

You may want to change your for loop to accommodate for

1. different name for each file and

2. use the print function to print it out to the file.

for(i in 1:nrow(g))
{
  ...
  png(filename=paste(gene,".png"),width=800,height=600) 
  p = autoplot(...)
  print(p)
  dev.off()
}
ADD COMMENT
0
Entering edit mode
9.4 years ago
Bogdan ★ 1.4k

thanks .. that works !

ADD COMMENT

Login before adding your answer.

Traffic: 2946 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