Learn R Programming

MutableRanges (version 0.6.2)

MutableGRanges-class: MutableGRanges objects

Description

MutableGRanges is a virtual GenomicRanges derivative that has mutable state, the implementation of which is left to subclasses, like SimpleMutableGRanges. There is no copying when replacing the ranges, element metadata, strand or seqnames. This is useful for graphical user interfaces and visualization. See the documentation of GenomicRanges for most of the behaviors of this class.

Arguments

See Also

GenomicRanges-class

Examples

Run this code
gr <-
    MutableGRanges(seqnames =
            Rle(c("chr1", "chr2", "chr1", "chr3"), c(1, 3, 2, 4)),
            ranges =
            IRanges(1:10, width = 10:1, names = head(letters,10)),
            strand =
            Rle(strand(c("-", "+", "*", "+", "-")),
                c(1, 2, 2, 3, 2)),
            score = 1:10,
            GC = seq(1, 0, length=10))
  gr

  # Changing 'gr2' also changes 'gr'
  gr2 <- gr
  s <- start(gr)
  start(gr2) <- 1
  gr
  start(gr) <- s

  # Summarizing elements
  table(seqnames(gr))
  sum(width(gr))
  summary(elementMetadata(gr)[,"score"]) # or values(gr)
  coverage(gr)

  # Changing sequence name
  unique(seqnames(gr))
  seqnames(gr) <- sub("chr", "Chrom", seqnames(gr))
  gr

  # Intra-interval operations
  flank(gr, 10)
  resize(gr, 10)
  shift(gr, 1)

  # Inter-interval operations
  disjoin(gr)
  gaps(gr, start = 1, end = 10)
  range(gr)
  reduce(gr)
  
  # Combining objects
  gr2 <- MutableGRanges(seqnames=Rle(c('Chrom1', 'Chrom2', 'Chrom3'),
                                     c(3, 3, 4)),
                        IRanges(1:10, width=5), strand='-',
                        score=101:110, GC = runif(10))
  gr3 <- MutableGRanges(seqnames=Rle(c('Chrom1', 'Chrom2', 'Chrom3'),
                                     c(3, 4, 3)),
                        IRanges(101:110, width=10), strand='-',
                        score=21:30)
  some.gr <- c(gr, gr2)
  
  ## all.gr <- c(gr, gr2, gr3) ## (This would fail)
  all.gr <- c(gr, gr2, gr3, .ignoreElementMetadata=TRUE)

Run the code above in your browser using DataLab