Skip to main content

Using GRanges with ExonR

GRanges is a very useful package for working with genomic ranges in R.

Loading the Data

To get started we need something to work with, and that's where we see ExonR for the first time. We can load an example gzip GFF file from S3 with as such:

> library(exonr)

# Load the GFF file
> rdr <- read_gff_file("s3://wtt-01-dist-prd/gffs/Ga0604745_crt.gff")
> df <- as.data.frame(rdr)

Creating a GRanges Object

Now that there's a data frame, we can create a GRanges object from it.

> library(GenomicRanges)

> gr <- GRanges(seqnames = df$seqname,
ranges = IRanges(start = df$start, end = df$end))

> gr
GRanges object with 17289 ranges and 0 metadata columns:
seqnames ranges strand
<Rle> <IRanges> <Rle>
[1] Ga0604745_000026 1 *
[2] Ga0604745_000026 1 *
[3] Ga0604745_000026 73 *
[4] Ga0604745_000026 147 *
[5] Ga0604745_000026 219 *
... ... ... ...
[17285] Ga0604745_216712 159 *
[17286] Ga0604745_216719 10 *
[17287] Ga0604745_216719 10 *
[17288] Ga0604745_216719 84 *
[17289] Ga0604745_216719 157 *
-------
seqinfo: 1664 sequences from an unspecified genome; no seqlengths