The chipseq Package

BiocManager::install('chipseq')

GRanges objects

For storing and manipulating genomic intervals and variables defined along a genome

library(GenomicRanges)

GRanges objects

gr = GRanges(
    seqnames = c("chr1", "chr1", "chr2", "chr3"),
    ranges = IRanges(start = 1:4, 
                     end = 10:13, 
                    names = head(letters,4)),
    strand = c("-", "+", "+", "-"))
gr
GRanges object with 4 ranges and 0 metadata columns:
    seqnames    ranges strand
       <Rle> <IRanges>  <Rle>
  a     chr1      1-10      -
  b     chr1      2-11      +
  c     chr2      3-12      +
  d     chr3      4-13      -
  -------
  seqinfo: 3 sequences from an unspecified genome; no seqlengths

Accessing entries in GRanges objects

gr[2]
GRanges object with 1 range and 0 metadata columns:
    seqnames    ranges strand
       <Rle> <IRanges>  <Rle>
  b     chr1      2-11      +
  -------
  seqinfo: 3 sequences from an unspecified genome; no seqlengths

Accessing entries in GRanges objects

gr[2]
GRanges object with 1 range and 0 metadata columns:
    seqnames    ranges strand
       <Rle> <IRanges>  <Rle>
  b     chr1      2-11      +
  -------
  seqinfo: 3 sequences from an unspecified genome; no seqlengths
gr[2:4]
GRanges object with 3 ranges and 0 metadata columns:
    seqnames    ranges strand
       <Rle> <IRanges>  <Rle>
  b     chr1      2-11      +
  c     chr2      3-12      +
  d     chr3      4-13      -
  -------
  seqinfo: 3 sequences from an unspecified genome; no seqlengths

Functions for GRanges objects

start(gr[2])
[1] 2
end(gr[2])
[1] 11
strand(gr[2])
factor-Rle of length 1 with 1 run
  Lengths: 1
  Values : +
Levels(3): + - *

Accessing entries in GRanges objects

gr[seqnames(gr)=="chr1"]
GRanges object with 2 ranges and 0 metadata columns:
    seqnames    ranges strand
       <Rle> <IRanges>  <Rle>
  a     chr1      1-10      -
  b     chr1      2-11      +
  -------
  seqinfo: 3 sequences from an unspecified genome; no seqlengths

Functions for GRanges objects

length(gr)
[1] 4

Functions for GRanges objects

length(gr)
[1] 4
names(gr)
[1] "a" "b" "c" "d"

Functions for GRanges objects

length(gr)
[1] 4
names(gr)
[1] "a" "b" "c" "d"
width(gr)
[1] 10 10 10 10

Functions for GRanges objects

coverage(gr)
RleList of length 3
$chr1
integer-Rle of length 11 with 3 runs
  Lengths: 1 9 1
  Values : 1 2 1

$chr2
integer-Rle of length 12 with 2 runs
  Lengths:  2 10
  Values :  0  1

$chr3
integer-Rle of length 13 with 2 runs
  Lengths:  3 10
  Values :  0  1

Rle objects

run length encoding: a way of condensing ordered values into a smaller package

gum = c(T,T,T,T,F,F,F,T,T,T)
gum
 [1]  TRUE  TRUE  TRUE  TRUE FALSE FALSE FALSE  TRUE  TRUE  TRUE

Rle objects

run length encoding: a way of condensing ordered values into a smaller package

gum = c(T,T,T,T,F,F,F,T,T,T)
gum
 [1]  TRUE  TRUE  TRUE  TRUE FALSE FALSE FALSE  TRUE  TRUE  TRUE
rle.gum = rle(gum)
rle.gum
Run Length Encoding
  lengths: int [1:3] 4 3 3
  values : logi [1:3] TRUE FALSE TRUE

Functions for GRanges objects

coverage(gr)
RleList of length 3
$chr1
integer-Rle of length 11 with 3 runs
  Lengths: 1 9 1
  Values : 1 2 1

$chr2
integer-Rle of length 12 with 2 runs
  Lengths:  2 10
  Values :  0  1

$chr3
integer-Rle of length 13 with 2 runs
  Lengths:  3 10
  Values :  0  1

GRanges Object

gr
GRanges object with 4 ranges and 0 metadata columns:
    seqnames    ranges strand
       <Rle> <IRanges>  <Rle>
  a     chr1      1-10      -
  b     chr1      2-11      +
  c     chr2      3-12      +
  d     chr3      4-13      -
  -------
  seqinfo: 3 sequences from an unspecified genome; no seqlengths

GRangesLists

gr2 = GRanges(
    seqnames = c("chr1", "chr1", "chr2", "chr3"),
    ranges = IRanges(start = 1:4, 
                     end = 10:13, 
                    names = tail(letters,4)),
    strand = c("-", "+", "+", "-"))

GRangesLists

gr2 = GRanges(
    seqnames = c("chr1", "chr1", "chr2", "chr3"),
    ranges = IRanges(start = 1:4, 
                     end = 10:13, 
                    names = tail(letters,4)),
    strand = c("-", "+", "+", "-"))
gr2
GRanges object with 4 ranges and 0 metadata columns:
    seqnames    ranges strand
       <Rle> <IRanges>  <Rle>
  w     chr1      1-10      -
  x     chr1      2-11      +
  y     chr2      3-12      +
  z     chr3      4-13      -
  -------
  seqinfo: 3 sequences from an unspecified genome; no seqlengths

GRangesLists

gr_list = GRangesList("gr1" = gr,"gr2" = gr2)

GRangesLists

gr_list
GRangesList object of length 2:
$gr1
GRanges object with 4 ranges and 0 metadata columns:
    seqnames    ranges strand
       <Rle> <IRanges>  <Rle>
  a     chr1      1-10      -
  b     chr1      2-11      +
  c     chr2      3-12      +
  d     chr3      4-13      -
  -------
  seqinfo: 3 sequences from an unspecified genome; no seqlengths

$gr2
GRanges object with 4 ranges and 0 metadata columns:
    seqnames    ranges strand
       <Rle> <IRanges>  <Rle>
  w     chr1      1-10      -
  x     chr1      2-11      +
  y     chr2      3-12      +
  z     chr3      4-13      -
  -------
  seqinfo: 3 sequences from an unspecified genome; no seqlengths

GRangesLists

gr_list$gr2
GRanges object with 4 ranges and 0 metadata columns:
    seqnames    ranges strand
       <Rle> <IRanges>  <Rle>
  w     chr1      1-10      -
  x     chr1      2-11      +
  y     chr2      3-12      +
  z     chr3      4-13      -
  -------
  seqinfo: 3 sequences from an unspecified genome; no seqlengths

GRangesLists

gr_list[2]
GRangesList object of length 1:
$gr2
GRanges object with 4 ranges and 0 metadata columns:
    seqnames    ranges strand
       <Rle> <IRanges>  <Rle>
  w     chr1      1-10      -
  x     chr1      2-11      +
  y     chr2      3-12      +
  z     chr3      4-13      -
  -------
  seqinfo: 3 sequences from an unspecified genome; no seqlengths

Poisson distribution

  • ppois
  • dpois