plotGenomeBrowser {chromstaR} | R Documentation

## #' Plot a genome browser view #' #' Plot a simple genome browser view. This is useful for scripted genome browser snapshots. #' #' @param counts A `GRanges-class` object with meta-data column 'counts'. #' @param peaklist A named list() of `GRanges-class` objects containing peak coordinates. #' @param chr,start,end Chromosome, start and end coordinates for the plot. #' @param countcol A character giving the color for the counts. #' @param peakcols A character vector with colors for the peaks in `peaklist`. #' @param style One of `c('peaks', 'density')`. #' @param peakTrackHeight Relative height of the tracks given in `peaklist` compared to the `counts`. #' @return A `ggplot` object. #' @examples #'## Get an example multiHMM ## #'file <- system.file("data","multivariate_mode-combinatorial_condition-SHR.RData", #' package="chromstaR") #'model <- get(load(file)) #'## Plot genome browser snapshot #'bins <- model$bins #'bins$counts <- model$bins$counts.rpkm[,1] #'plotGenomeBrowser(counts=bins, peaklist=model$peaks, #' chr='chr12', start=1, end=1e6) #' plotGenomeBrowser2 <- function(counts, peaklist=NULL, chr, start, end, countcol='black', peakcols=NULL, style='peaks', peakTrackHeight=5) ## Select ranges to plot ranges2plot <- reduce(counts[counts@seqnames == chr & start(counts) >= start & start(counts) <= end]) ## Counts counts <- subsetByOverlaps(counts, ranges2plot) if (style == 'peaks') df <- data.frame(x=(start(counts)+end(counts))/2, counts=counts$counts) # plot triangles centered at middle of the bin ggplt <- ggplot(df) + geom_area(aes_string(x='x', y='counts')) + theme(panel.grid = element_blank(), panel.background = element_blank(), axis.text.x = element_blank(), axis.title = element_blank(), axis.ticks.x = element_blank(), axis.line = element_blank()) maxcounts <- max(counts$counts) ggplt <- ggplt + scale_y_continuous(breaks=c(0, maxcounts)) else if (style == 'density') df <- data.frame(xmin=start(counts), xmax=end(counts), counts=counts$counts) ggplt <- ggplot(df) + geom_rect(aes_string(xmin='xmin', xmax='xmax', ymin=0, ymax=4, alpha='counts')) + theme(panel.grid = element_blank(), panel.background = element_blank(), axis.text = element_blank(), axis.title = element_blank(), axis.ticks = element_blank(), axis.line = element_blank()) else stop("Unknown value '", style, "' for parameter 'style'. Must be one of c('peaks', 'density').") ## Peaks if (!is.null(peaklist)) if (is.null(peakcols)) peakcols <- getDistinctColors(length(peaklist)) for (i1 in 1:length(peaklist)) p <- peakTrackHeight peaks <- subsetByOverlaps(peaklist[[i1]], ranges2plot) if (length(peaks) > 0) df <- data.frame(start=start(peaks), end=end(peaks), ymin=-p*i1, ymax=-p*i1+0.9*p) ggplt <- ggplt + geom_rect(data=df, mapping=aes_string(xmin='start', xmax='end', ymin='ymin', ymax='ymax'), col=peakcols[i1], fill=peakcols[i1]) trackname <- names(peaklist)[i1] df <- data.frame(x=start(counts)[1], y=-p*i1+0.5*p, label=trackname) ggplt <- ggplt + geom_text(data=df, mapping=aes_string(x='x', y='y', label='label'), vjust=0.5, hjust=0.5, col=peakcols[i1]) return(ggplt) Plot a genome browser view

### Description

Plot a simple genome browser view of `chromstaR-objects`. This is useful for scripted genome browser snapshots.

### Usage

    plotGenomeBrowser(model, chr, start, end, style = "peaks", peakHeight = 0.2,
      peakColor = "blue", same.yaxis = TRUE)

### Arguments

`model` | A `uniHMM`, `multiHMM` or `combinedMultiHMM` object or file that contains such an object.
`chr, start, end` | Chromosome, start and end coordinates for the plot.
`style` | One of `c('peaks', 'density')`.
`peakHeight` | Height of the peak track relative to the count track.
`peakColor` | Color for the peak track.
`same.yaxis` | Whether or not the plots for the same mark have the same y-axis.

### Value

A `list()` of `ggplot` objects.

### Examples

    ## Get an example uniHMM ##
    file <- system.file("data","H3K27me3-BN-rep1.RData", package="chromstaR")
    model <- get(load(file))
    plotGenomeBrowser(model, chr='chr12', start=1, end=1e6, style='peaks',
                     peakHeight=0.1)

    ## Get an example multiHMM ##
    file <- system.file("data","multivariate_mode-combinatorial_condition-SHR.RData",
                        package="chromstaR")
    model <- get(load(file))
    plotGenomeBrowser(model, chr='chr12', start=1, end=1e6, style='peaks',
                     peakHeight=0.1)

    ## Get an example combinedMultiHMM ##
    file <- system.file("data","combined_mode-differential.RData",
                        package="chromstaR")
    model <- get(load(file))
    plotlist <- plotGenomeBrowser(model, chr='chr12', start=1, end=1e6, style='peaks',
                     peakHeight=0.1)

[Package chromstaR version 1.10.0 Index]