Question: "for loop" and AUTOPLOT function
1
gravatar for Bogdan
6.2 years ago by
Bogdan1.1k
Palo Alto, CA, USA
Bogdan1.1k wrote:

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 • 2.1k views
ADD COMMENTlink modified 6.2 years ago • written 6.2 years ago by Bogdan1.1k

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

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

ADD REPLYlink written 6.2 years ago by karl.stamm3.9k

https://support.bioconductor.org/p/63439/

ADD REPLYlink written 6.0 years ago by zx87549.9k
2
gravatar for komal.rathi
6.2 years ago by
komal.rathi3.7k
Children's Hospital of Philadelphia, Philadelphia, PA
komal.rathi3.7k wrote:

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 COMMENTlink written 6.2 years ago by komal.rathi3.7k
0
gravatar for Bogdan
6.2 years ago by
Bogdan1.1k
Palo Alto, CA, USA
Bogdan1.1k wrote:

thanks .. that works !

ADD COMMENTlink written 6.2 years ago by Bogdan1.1k
Please log in to add an answer.

Help
Access

Use of this site constitutes acceptance of our User Agreement and Privacy Policy.
Powered by Biostar version 2.3.0
Traffic: 1133 users visited in the last hour
_