Gviz - Plot genes and data from - strand (3'-5') in 5'-3' direction
1
0
Entering edit mode
@jager-dominik-6134
Last seen 9.6 years ago
Hi, I'm using the Gviz package to visualize some RNA-seq data. Everything works great so far, however I was wondering if there is a simple way to display genes (and corresponding datatracks) which are encoded on the - strand of the genome on the + strand? I really would like to plot a certain set of genes all in 5'-> 3' direction independently on which strand they are encoded... Thanks for your help! Dominik [The Ohio State University] Dr. Dominik Jäger Biological Sciences Department of Microbiology 405 Biological Science Building | 484 West 12th Avenue Columbus, OH 43210 (614)-682-6890 Office jager.9@osu.edu<mailto:jager.9@osu.edu> osu.edu<http: osu.edu=""> [[alternative HTML version deleted]]
Gviz Gviz • 2.1k views
ADD COMMENT
0
Entering edit mode
Robert Ivanek ▴ 730
@robert-ivanek-5892
Last seen 5 months ago
Switzerland
Hi Dominik, You can achieve that by changing the strand in corresponding track objects. You did not provide any code so I can only suggest a solution based on example from vignette: library(Gviz) from <- 65921878 to <- 65980988 knownGenes <- UcscTrack(genome = "mm9", chromosome = "chrX", track = "knownGene", from = from, to = to, trackType = "GeneRegionTrack", rstarts = "exonStarts", rends = "exonEnds", gene = "name", symbol = "name", transcript = "name", strand = "strand", fill = "#8282d2", name = "UCSC Genes") ## by running ploTracks now you can see that some gene(s) ## are on minus strand plotTracks(knownGenes) ## change the strand of knowGenes (which is UcscTrack object) strand(knownGenes) <- "+" ## by calling the plotTracks again you can see all genes ## are now on plus strand plotTracks(knownGenes) Best Robert On 12/09/13 13:30, Jager, Dominik wrote: > Hi, > > I'm using the Gviz package to visualize some RNA-seq data. Everything works great so far, however > I was wondering if there is a simple way to display genes (and corresponding datatracks) which are encoded on the - strand of the genome on the + strand? I really would like to plot a certain set of genes all in 5'-> 3' direction independently on which strand they are encoded... > > > Thanks for your help! > > Dominik > > > > [The Ohio State University] > Dr. Dominik J?ger > Biological Sciences Department of Microbiology > 405 Biological Science Building | 484 West 12th Avenue Columbus, OH 43210 > (614)-682-6890 Office > jager.9 at osu.edu<mailto:jager.9 at="" osu.edu=""> osu.edu<http: osu.edu=""> > > [[alternative HTML version deleted]] > > > > _______________________________________________ > Bioconductor mailing list > Bioconductor at r-project.org > https://stat.ethz.ch/mailman/listinfo/bioconductor > Search the archives: http://news.gmane.org/gmane.science.biology.informatics.conductor >
ADD COMMENT
0
Entering edit mode
Hi, On Thu, Sep 12, 2013 at 6:14 AM, Robert Ivanek <robert.ivanek at="" unibas.ch=""> wrote: > Hi Dominik, > > You can achieve that by changing the strand in corresponding track > objects. [snip] While this might change the strand of a gene, I do not think this is what the OP is really after -- as I have previously been keen to try to implement the approach that (I think) the OP wants. I believe the OP would like to plot "the mirror image" of the plot that Gviz would "normally" show given the start/stop coordinates that the plotting functionality infers (or is given). The approach you suggest wouldn't properly "flip" my gene models and the data associated with them -- it would only show them on the positive strand. The 5'utr of the gene that was originally on the negative strand would look as if it were the 3'utr of the gene on the (now annotated) positive strand, and vice versa, and if I were (say) plotting ChIP-seq data over this locus, the TF would appear to be binding the 3'utr of a gene on the positive strand (or downstream of it), when that's not really the case. -steve -- Steve Lianoglou Computational Biologist Bioinformatics and Computational Biology Genentech
ADD REPLY
0
Entering edit mode
...yes, thats correct. So what I really want is to plot my data (see attached PNG) flipped by 180 degrees. So now the genes and the data were plotted in 3' to 5' direction, but I want in 5' to 3'/ Here some code: > setwd("~/WORKING/") > library(Gviz) > options(ucscChromosomeNames = FALSE) > tkgff <- import.gff3("~/WORKING/NC_006624.gff", format = "gff3", genome= "NC_06624.1", asRangedData = FALSE) >atrack <- AnnotationTrack(tkgff, strand = "*", chromosome = chr, genome = gen, name = TK) >gtrack <- GenomeAxisTrack() > WIG <- import.wig("~/S0_20min_reverse.wig", asRangedData = FALSE) > dtrack <- DataTrack(WIG, name = "S0+") >from <- 1049512 > to <- 1052176 >plotTracks(list(gtrack,atrack, dtrack), from = from, to = to, cex = 1, type = "h") I also attached the plot as PNG. Dominik Dr. Dominik J?ger Biological Sciences Department of Microbiology 405 Biological Science Building | 484 West 12th Avenue Columbus, OH 43210 (614)-682-6890 Office jager.9 at osu.edu osu.edu ________________________________________ Von: bioconductor-bounces at r-project.org [bioconductor-bounces at r-project.org]" im Auftrag von "Steve Lianoglou [lianoglou.steve at gene.com] Gesendet: Donnerstag, 12. September 2013 09:57 An: Robert Ivanek Cc: bioconductor at r-project.org list Betreff: Re: [BioC] Gviz - Plot genes and data from - strand (3'-5') in 5'-3' direction Hi, On Thu, Sep 12, 2013 at 6:14 AM, Robert Ivanek <robert.ivanek at="" unibas.ch=""> wrote: > Hi Dominik, > > You can achieve that by changing the strand in corresponding track > objects. [snip] While this might change the strand of a gene, I do not think this is what the OP is really after -- as I have previously been keen to try to implement the approach that (I think) the OP wants. I believe the OP would like to plot "the mirror image" of the plot that Gviz would "normally" show given the start/stop coordinates that the plotting functionality infers (or is given). The approach you suggest wouldn't properly "flip" my gene models and the data associated with them -- it would only show them on the positive strand. The 5'utr of the gene that was originally on the negative strand would look as if it were the 3'utr of the gene on the (now annotated) positive strand, and vice versa, and if I were (say) plotting ChIP-seq data over this locus, the TF would appear to be binding the 3'utr of a gene on the positive strand (or downstream of it), when that's not really the case. -steve -- Steve Lianoglou Computational Biologist Bioinformatics and Computational Biology Genentech _______________________________________________ Bioconductor mailing list Bioconductor at r-project.org https://stat.ethz.ch/mailman/listinfo/bioconductor Search the archives: http://news.gmane.org/gmane.science.biology.informatics.conductor
ADD REPLY
0
Entering edit mode
I see, sorry I got it wrong. It cannot be done automatically in Gviz but maybe following can help you: library(GenomicRanges) library(Gviz) genes.gr <- GRanges("chr1", IRanges(c(10,20,30,40), width=8), strand=c("+","-","+","-")) aT <- AnnotationTrackgenes.gr) reads.gr <- GRanges("chr1", IRanges(seq(1,50,2), width=1), strand="+", count=seq(1,50,2)) dT1 <- DataTrackreads.gr) ## this function expects DataTrack in which you would like to flip the points and AnnotationTrack with genes which would define regions you would like to flip, those regions (genes) have to be on minus strand reverseCounts <- function(reads, genes) { genes <- genes[strand(genes)=="-"] strand(genes) <- "*" ## ov <- findOverlaps(ranges(reads), ranges(genes)) indx <- split(queryHits(ov), subjectHits(ov)) indx <- lapply(indx, rev) indx <- unlist(indx) values(reads)[,queryHits(ov)] <- values(reads)[,indx] ## return(reads) } ## dT2 <- reverseCounts(dT1, aT) ## plotTracks(list(aT, dT1, dT2)) Is that what you want? Best Robert On 12/09/13 16:21, Jager, Dominik wrote: > ...yes, thats correct. > > So what I really want is to plot my data (see attached PNG) flipped by 180 degrees. So now the genes and the data were plotted in 3' to 5' direction, but I want in 5' to 3'/ > > Here some code: > >> setwd("~/WORKING/") >> library(Gviz) >> options(ucscChromosomeNames = FALSE) >> tkgff <- import.gff3("~/WORKING/NC_006624.gff", format = "gff3", genome= "NC_06624.1", asRangedData = FALSE) >> atrack <- AnnotationTrack(tkgff, strand = "*", chromosome = chr, genome = gen, name = TK) >> gtrack <- GenomeAxisTrack() >> WIG <- import.wig("~/S0_20min_reverse.wig", asRangedData = FALSE) >> dtrack <- DataTrack(WIG, name = "S0+") >>from <- 1049512 >> to <- 1052176 >> plotTracks(list(gtrack,atrack, dtrack), from = from, to = to, cex = 1, type = "h") > > I also attached the plot as PNG. > > > Dominik > > Dr. Dominik J?ger > Biological Sciences Department of Microbiology > 405 Biological Science Building | 484 West 12th Avenue Columbus, OH 43210 > (614)-682-6890 Office > jager.9 at osu.edu osu.edu > > ________________________________________ > Von: bioconductor-bounces at r-project.org [bioconductor-bounces at r-project.org]" im Auftrag von "Steve Lianoglou [lianoglou.steve at gene.com] > Gesendet: Donnerstag, 12. September 2013 09:57 > An: Robert Ivanek > Cc: bioconductor at r-project.org list > Betreff: Re: [BioC] Gviz - Plot genes and data from - strand (3'-5') in 5'-3' direction > > Hi, > > On Thu, Sep 12, 2013 at 6:14 AM, Robert Ivanek <robert.ivanek at="" unibas.ch=""> wrote: >> Hi Dominik, >> >> You can achieve that by changing the strand in corresponding track >> objects. > [snip] > > While this might change the strand of a gene, I do not think this is > what the OP is really after -- as I have previously been keen to try > to implement the approach that (I think) the OP wants. > > I believe the OP would like to plot "the mirror image" of the plot > that Gviz would "normally" show given the start/stop coordinates that > the plotting functionality infers (or is given). > > The approach you suggest wouldn't properly "flip" my gene models and > the data associated with them -- it would only show them on the > positive strand. The 5'utr of the gene that was originally on the > negative strand would look as if it were the 3'utr of the gene on the > (now annotated) positive strand, and vice versa, and if I were (say) > plotting ChIP-seq data over this locus, the TF would appear to be > binding the 3'utr of a gene on the positive strand (or downstream of > it), when that's not really the case. > > -steve > > -- > Steve Lianoglou > Computational Biologist > Bioinformatics and Computational Biology > Genentech > > _______________________________________________ > Bioconductor mailing list > Bioconductor at r-project.org > https://stat.ethz.ch/mailman/listinfo/bioconductor > Search the archives: http://news.gmane.org/gmane.science.biology.informatics.conductor > > > _______________________________________________ > Bioconductor mailing list > Bioconductor at r-project.org > https://stat.ethz.ch/mailman/listinfo/bioconductor > Search the archives: http://news.gmane.org/gmane.science.biology.informatics.conductor >
ADD REPLY
0
Entering edit mode
I realized it is better to change the coordinates than the actual values: reverseCounts <- function(reads, genes) { genes <- genes[strand(genes)=="-"] strand(genes) <- "*" ## ov <- findOverlaps(ranges(reads), ranges(genes)) ww <- width(reads)[queryHits(ov)] start(reads)[queryHits(ov)] <- start(genes)[subjectHits(ov)] + (end(genes)[subjectHits(ov)] - start(reads)[queryHits(ov)]) width(reads)[queryHits(ov)] <- ww ## return(reads) } Best Robert On 12/09/13 17:01, Robert Ivanek wrote: > I see, sorry I got it wrong. > It cannot be done automatically in Gviz but maybe following can help you: > > library(GenomicRanges) > library(Gviz) > > genes.gr <- GRanges("chr1", IRanges(c(10,20,30,40), width=8), > strand=c("+","-","+","-")) > aT <- AnnotationTrackgenes.gr) > > reads.gr <- GRanges("chr1", IRanges(seq(1,50,2), width=1), > strand="+", count=seq(1,50,2)) > dT1 <- DataTrackreads.gr) > > ## this function expects DataTrack in which you would like to flip the > points and AnnotationTrack with genes which would define regions you > would like to flip, those regions (genes) have to be on minus strand > > reverseCounts <- function(reads, genes) { > genes <- genes[strand(genes)=="-"] > strand(genes) <- "*" > ## > ov <- findOverlaps(ranges(reads), ranges(genes)) > indx <- split(queryHits(ov), subjectHits(ov)) > indx <- lapply(indx, rev) > indx <- unlist(indx) > values(reads)[,queryHits(ov)] <- values(reads)[,indx] > ## > return(reads) > } > ## > dT2 <- reverseCounts(dT1, aT) > ## > plotTracks(list(aT, dT1, dT2)) > > Is that what you want? > Best > Robert > > > On 12/09/13 16:21, Jager, Dominik wrote: >> ...yes, thats correct. >> >> So what I really want is to plot my data (see attached PNG) flipped by 180 degrees. So now the genes and the data were plotted in 3' to 5' direction, but I want in 5' to 3'/ >> >> Here some code: >> >>> setwd("~/WORKING/") >>> library(Gviz) >>> options(ucscChromosomeNames = FALSE) >>> tkgff <- import.gff3("~/WORKING/NC_006624.gff", format = "gff3", genome= "NC_06624.1", asRangedData = FALSE) >>> atrack <- AnnotationTrack(tkgff, strand = "*", chromosome = chr, genome = gen, name = TK) >>> gtrack <- GenomeAxisTrack() >>> WIG <- import.wig("~/S0_20min_reverse.wig", asRangedData = FALSE) >>> dtrack <- DataTrack(WIG, name = "S0+") >> >from <- 1049512 >>> to <- 1052176 >>> plotTracks(list(gtrack,atrack, dtrack), from = from, to = to, cex = 1, type = "h") >> >> I also attached the plot as PNG. >> >> >> Dominik >> >> Dr. Dominik J?ger >> Biological Sciences Department of Microbiology >> 405 Biological Science Building | 484 West 12th Avenue Columbus, OH 43210 >> (614)-682-6890 Office >> jager.9 at osu.edu osu.edu >> >> ________________________________________ >> Von: bioconductor-bounces at r-project.org [bioconductor-bounces at r-project.org]" im Auftrag von "Steve Lianoglou [lianoglou.steve at gene.com] >> Gesendet: Donnerstag, 12. September 2013 09:57 >> An: Robert Ivanek >> Cc: bioconductor at r-project.org list >> Betreff: Re: [BioC] Gviz - Plot genes and data from - strand (3'-5') in 5'-3' direction >> >> Hi, >> >> On Thu, Sep 12, 2013 at 6:14 AM, Robert Ivanek <robert.ivanek at="" unibas.ch=""> wrote: >>> Hi Dominik, >>> >>> You can achieve that by changing the strand in corresponding track >>> objects. >> [snip] >> >> While this might change the strand of a gene, I do not think this is >> what the OP is really after -- as I have previously been keen to try >> to implement the approach that (I think) the OP wants. >> >> I believe the OP would like to plot "the mirror image" of the plot >> that Gviz would "normally" show given the start/stop coordinates that >> the plotting functionality infers (or is given). >> >> The approach you suggest wouldn't properly "flip" my gene models and >> the data associated with them -- it would only show them on the >> positive strand. The 5'utr of the gene that was originally on the >> negative strand would look as if it were the 3'utr of the gene on the >> (now annotated) positive strand, and vice versa, and if I were (say) >> plotting ChIP-seq data over this locus, the TF would appear to be >> binding the 3'utr of a gene on the positive strand (or downstream of >> it), when that's not really the case. >> >> -steve >> >> -- >> Steve Lianoglou >> Computational Biologist >> Bioinformatics and Computational Biology >> Genentech >> >> _______________________________________________ >> Bioconductor mailing list >> Bioconductor at r-project.org >> https://stat.ethz.ch/mailman/listinfo/bioconductor >> Search the archives: http://news.gmane.org/gmane.science.biology.informatics.conductor >> >> >> _______________________________________________ >> Bioconductor mailing list >> Bioconductor at r-project.org >> https://stat.ethz.ch/mailman/listinfo/bioconductor >> Search the archives: http://news.gmane.org/gmane.science.biology.informatics.conductor >> > > _______________________________________________ > Bioconductor mailing list > Bioconductor at r-project.org > https://stat.ethz.ch/mailman/listinfo/bioconductor > Search the archives: http://news.gmane.org/gmane.science.biology.informatics.conductor >
ADD REPLY
0
Entering edit mode
Since Gviz track objects are essentially GRanges, one could use the reflect method to archive this. Not thoroughly tested, but something along the lines of this: library(GenomicFeatures) samplefile <- system.file("extdata", "UCSC_knownGene_sample.sqlite", package = "GenomicFeatures") txdb <- loadDb(samplefile) txTr <- GeneRegionTrack(txdb, chromosome="chr6", start=300000, end=350000) plotTracks(txTr) txTr2 <- txTr rr <- ranges(txTr2) rrByChrom <- split(rr, seqnames(rr)) rrNew <- unlist(endoapply(rrByChrom, function(x){ ranges(x) <- reflect(ranges(x), range(ranges(x))) x })) ranges(txTr2) <- rrNew dev.new() plotTracks(txTr2) Not quite sure why one would like to do this, because the resulting coordinates are no longer genomic coordinates, but you guys may have a convincing use case I am sure. Florian On 9/12/13 3:57 PM, "Steve Lianoglou" <lianoglou.steve at="" gene.com=""> wrote: >Hi, > >On Thu, Sep 12, 2013 at 6:14 AM, Robert Ivanek <robert.ivanek at="" unibas.ch=""> >wrote: >> Hi Dominik, >> >> You can achieve that by changing the strand in corresponding track >> objects. >[snip] > >While this might change the strand of a gene, I do not think this is >what the OP is really after -- as I have previously been keen to try >to implement the approach that (I think) the OP wants. > >I believe the OP would like to plot "the mirror image" of the plot >that Gviz would "normally" show given the start/stop coordinates that >the plotting functionality infers (or is given). > >The approach you suggest wouldn't properly "flip" my gene models and >the data associated with them -- it would only show them on the >positive strand. The 5'utr of the gene that was originally on the >negative strand would look as if it were the 3'utr of the gene on the >(now annotated) positive strand, and vice versa, and if I were (say) >plotting ChIP-seq data over this locus, the TF would appear to be >binding the 3'utr of a gene on the positive strand (or downstream of >it), when that's not really the case. > >-steve > >-- >Steve Lianoglou >Computational Biologist >Bioinformatics and Computational Biology >Genentech > >_______________________________________________ >Bioconductor mailing list >Bioconductor at r-project.org >https://stat.ethz.ch/mailman/listinfo/bioconductor >Search the archives: >http://news.gmane.org/gmane.science.biology.informatics.conductor
ADD REPLY
0
Entering edit mode
Hi, On Fri, Sep 13, 2013 at 12:39 AM, Hahne, Florian <florian.hahne at="" novartis.com=""> wrote: > Since Gviz track objects are essentially GRanges, one could use the > reflect method to archive this. Indeed -- I felt like a few judicially placed reflect calls would do the trick. > Not quite sure why one would like to do this, because the resulting > coordinates are no longer genomic coordinates, but you guys may have a > convincing use case I am sure. Imagine you want to show several examples of binding of <whatever> to some landmark within the gene -- for instance, something binding close to the transcript start site. If I want to single out a few examples to show during a presentation on a slide and I have a mix of (+) and (-) strand genes, not only do I have to explain the main idea of the slide -- that there is some spatial preference for XXX -- but I also have to remind the audience that these genes are on the (+) and these are on the (-) "so filp the coords for examples 2, 5, and 7 in your head and imagine you see the spatial bias I am explaining because once flipped, the peaks will end up (pretty much) on top of each other ... trust me." There are times when the strand is irrelevant and what I really want to show is something as a function of the direction of transcription. Know what I mean? -steve -- Steve Lianoglou Computational Biologist Bioinformatics and Computational Biology Genentech
ADD REPLY
0
Entering edit mode
I think I get the point of what you are trying to do, but I am not quite sure how exactly that translates to the way things are done in Gviz. If I take your example, would you want to flip only the transcripts on the minus strand? Or would you also want to flip the peaks on the minus strand? Just flipping transcripts, or groups of elements in an AnnotationTrack, is not hard. We have a somewhat natural inflection point for each transcript to do that operation. However, the locations that you are plotting in this case are no longer genomic locations. They are artificial coordinates that just happen to overlap with the original gene region. The locations of the peaks that you are seeing in a second DataTrack are still genomic locations, so you wouldn't actually get your peaks to align if all you are flipping are the transcripts on the minus strand. Now how would you go about flipping the data in the DataTrack? What are your inflection points? The same ones that you used for the genes? In this case we should need some cross-talk between several tracks, but the current Gviz implementation is that tracks are separate from one another and can be drawn without knowing about other tracks. Also how would you deal with region between genes? If your data are continuos and not distinct peaks that would look really weird... Maybe I am getting you all wrong, and a simple graphical example could help me show what exactly you want to archive. On 9/13/13 9:51 AM, "Steve Lianoglou" <lianoglou.steve at="" gene.com=""> wrote: >Hi, > >On Fri, Sep 13, 2013 at 12:39 AM, Hahne, Florian ><florian.hahne at="" novartis.com=""> wrote: >> Since Gviz track objects are essentially GRanges, one could use the >> reflect method to archive this. > >Indeed -- I felt like a few judicially placed reflect calls would do the >trick. > >> Not quite sure why one would like to do this, because the resulting >> coordinates are no longer genomic coordinates, but you guys may have a >> convincing use case I am sure. > >Imagine you want to show several examples of binding of <whatever> to >some landmark within the gene -- for instance, something binding close >to the transcript start site. > >If I want to single out a few examples to show during a presentation >on a slide and I have a mix of (+) and (-) strand genes, not only do I >have to explain the main idea of the slide -- that there is some >spatial preference for XXX -- but I also have to remind the audience >that these genes are on the (+) and these are on the (-) "so filp the >coords for examples 2, 5, and 7 in your head and imagine you see the >spatial bias I am explaining because once flipped, the peaks will end >up (pretty much) on top of each other ... trust me." > >There are times when the strand is irrelevant and what I really want >to show is something as a function of the direction of transcription. > >Know what I mean? > >-steve > >-- >Steve Lianoglou >Computational Biologist >Bioinformatics and Computational Biology >Genentech
ADD REPLY

Login before adding your answer.

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