"for loop" and AUTOPLOT function
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
• 4,180 views
•
link
2 answers
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()
}
• 0 views
•
link
thanks .. that works !
• 0 views
•
link
Log in to answer this question.
Yeah? What seems to be the problem? What happens?
It looks like youre going to overwrite the file gene.png repeatedly...
https://support.bioconductor.org/p/63439/