tidy_chromosomes: Remove odd chromosomes from GRanges objects

View source: R/tidy_chromosomes.R

tidy_chromosomesR Documentation

Remove odd chromosomes from GRanges objects

Description

This convenience function removes non-standard, mitochondrial, and/or sex chromosomes from any GRanges object.

Usage

tidy_chromosomes(
  gr,
  keep.X = TRUE,
  keep.Y = TRUE,
  keep.M = FALSE,
  keep.nonstandard = FALSE,
  genome = NULL
)

Arguments

gr

Any GRanges object, or any another object with associated seqinfo (or a Seqinfo object itself). The object should typically have a standard genome associated with it, e.g. genome(gr) <- "hg38". gr can also be a list of such GRanges objects.

keep.X, keep.Y, keep.M, keep.nonstandard

Logicals indicating which non-autosomes should be kept. By default, sex chromosomes are kept, but mitochondrial and non-standard chromosomes are removed.

genome

An optional string that, if supplied, will be used to set the genome of gr.

Details

This function is adapted from tidyChromosomes in the BRGenomics package licensed under the Artistic License 2.0. Original author: Mike DeBerardine <https://github.com/mdeber>

Standard chromosomes are defined using the standardChromosomes function from the GenomeInfoDb package.

Value

A GRanges object in which both ranges and seqinfo associated with trimmed chromosomes have been removed.

Author(s)

Mike DeBerardine

See Also

GenomeInfoDb::standardChromosomes

Examples

# make a GRanges
chrom <- c("chr2", "chr3", "chrX", "chrY", "chrM", "junk")
gr <- GenomicRanges::GRanges(seqnames = chrom,
              ranges = IRanges::IRanges(start = 2*(1:6), end = 3*(1:6)),
              strand = "+",
              seqinfo = GenomeInfoDb::Seqinfo(chrom))
GenomeInfoDb::genome(gr) <- "hg38"

gr

tidy_chromosomes(gr)

tidy_chromosomes(gr, keep.M = TRUE)

tidy_chromosomes(gr, keep.M = TRUE, keep.Y = FALSE)

tidy_chromosomes(gr, keep.nonstandard = TRUE)


neurogenomics/EpiCompare documentation built on Oct. 18, 2024, 11:04 p.m.