Skip to contents

Reads a GFF3 or BED annotation file and returns a GRanges object with standardized metadata columns. The result can be passed directly to the annotation argument of commaData.

Usage

loadAnnotation(file, feature_types = NULL, ...)

Arguments

file

Character string. Path to a GFF3 (.gff, .gff3, .gff.gz, .gff3.gz) or BED (.bed) file.

feature_types

Character vector or NULL. If provided, only features with a matching type (GFF3) or name (BED) are retained. Common GFF3 types include "gene", "CDS", "rRNA", "tRNA". NULL retains all features.

...

Additional arguments passed to rtracklayer::import().

Value

A GRanges object. The mcols always include:

feature_type

Character. The feature type (from GFF3 type column, or "region" for BED).

name

Character. Feature name or identifier (from GFF3 Name or ID attribute, or BED name column).

Additional metadata columns from the source file are preserved.

Details

This function requires the rtracklayer package (Bioconductor):


  BiocManager::install("rtracklayer")

Both NCBI-style GFF3 (with gene_biotype, product attributes) and Ensembl-style GFF3 are supported.

Examples

# Load the bundled example GFF3 annotation
gff_file <- system.file("extdata", "example.gff3", package = "comma")
if (requireNamespace("rtracklayer", quietly = TRUE)) {
  ann <- loadAnnotation(gff_file)
  ann <- loadAnnotation(gff_file, feature_types = "gene")
}

if (FALSE) { # \dontrun{
# Load only genes and CDS from your own file
ann <- loadAnnotation("my_genome.gff3", feature_types = c("gene", "CDS"))
} # }