This function takes a GRanges object with genomic coordinates in one genome assembly and lifts them to target genome assembly using a chain file.
Arguments
- x
A GRanges object with genomic coordinates in the original assembly.
- to
The target genome assembly (e.g., "hg38").
- chain
The path to the chain file containing the liftover mapping. Can be provided in gzipped or non-gzipped format. If omitted, the function will look in the default BiocFileCache for a properly named chain file.
- bfc
A BiocFileCache object (optional), if not provided (most typically) the default location will be used.
See also
liftOver
function from the rtracklayer
package,
which is the basis for easylift
.
Examples
# Lift over the coordinates of the first 10 genes in the hg19 assembly
# to the hg38 assembly
library(easylift)
gr <- GRanges(
seqname = Rle(c("chr1", "chr2"), c(100000, 100000)),
ranges = IRanges(start = 1, end = 200000)
)
# Here, "hg19" is the source genome
genome(gr) <- "hg19"
# Here, we use the `system.file()` function because the chain file is in the
# package (however if you need to point to any other file on your machine,
# just do 'chain <- "path/to/your/hg19ToHg38.over.chain.gz"'):
chain <- system.file("extdata", "hg19ToHg38.over.chain.gz", package = "easylift")
# Here, "hg38" is the target genome
easylift(gr, "hg38", chain)
#> GRanges object with 300000 ranges and 0 metadata columns:
#> seqnames ranges strand
#> <Rle> <IRanges> <Rle>
#> [1] chr1 10001-177376 *
#> [2] chr19 242824-242864 *
#> [3] chr1 10001-177376 *
#> [4] chr19 242824-242864 *
#> [5] chr1 10001-177376 *
#> ... ... ... ...
#> [299996] chr2 10001-200000 *
#> [299997] chr2 10001-200000 *
#> [299998] chr2 10001-200000 *
#> [299999] chr2 10001-200000 *
#> [300000] chr2 10001-200000 *
#> -------
#> seqinfo: 25 sequences (1 circular) from hg38 genome
# \donttest{
# To use `BiocFileCache` for the chain file, add it to the cache as follows:
chain_file <- "/path/to/your/hg19ToHg38.over.chain.gz"
bfc <- BiocFileCache()
#> Error in collect(., Inf): Failed to collect lazy table.
#> Caused by error in `db_collect()`:
#> ! Arguments in `...` must be used.
#> ✖ Problematic argument:
#> • ..1 = Inf
#> ℹ Did you misspell an argument name?
# Add chain file to cache if already not available
if (nrow(bfcquery(bfc, basename(chain_file))) == 0)
bfcadd(bfc, chain_file)
#> Error in h(simpleError(msg, call)): error in evaluating the argument 'x' in selecting a method for function 'nrow': error in evaluating the argument 'x' in selecting a method for function 'bfcquery': object 'bfc' not found
# Then, use it in `easylift` like this:
easylift(gr, "hg38")
#> Error in collect(., Inf): Failed to collect lazy table.
#> Caused by error in `db_collect()`:
#> ! Arguments in `...` must be used.
#> ✖ Problematic argument:
#> • ..1 = Inf
#> ℹ Did you misspell an argument name?
# or
gr |> easylift("hg38")
#> Error in collect(., Inf): Failed to collect lazy table.
#> Caused by error in `db_collect()`:
#> ! Arguments in `...` must be used.
#> ✖ Problematic argument:
#> • ..1 = Inf
#> ℹ Did you misspell an argument name?
# }