Skip to contents

Checks for overlap between variants and a set of genomic regions provided either as a BED file or a GRanges object. Adds a boolean column to the data. Uses the 1-bp variant anchor parsed from variant_id (format chr:pos:REF>ALT); deduplicates across rows that share a variant before the overlap call and joins the result back.

Usage

av_annotate_regions(obj, regions, label = "in_region")

Arguments

obj

An object of class AlphaVarSet. Must carry a variant_id column in the AlphaGenome format chr:pos:REF>ALT.

regions

Path to a BED file (character) or a GRanges object.

label

Character string. Name of the new column (default: "in_region"). Also registered in obj$meta$custom_regions so downstream consumers (e.g. av_plot_annotation(type = "custom")) can discover the column regardless of its naming convention.

Value

An AlphaVarSet object with a new boolean column indicating overlap.

Examples

example_file <- system.file(
  "extdata", "bcl11a_rs1427407_example.csv",
  package = "AlphaVaR"
)
obj <- av_import_csv(example_file)
#> Reading bcl11a_rs1427407_example.csv ...

# Two windows on chr2; only the first covers the BCL11A intronic variant.
regions <- GenomicRanges::GRanges(
  seqnames = "chr2",
  ranges = IRanges::IRanges(
    start = c(60490000, 60600000),
    end   = c(60491500, 60601500)
  )
)

obj <- av_annotate_regions(obj, regions, label = "in_enhancer")
print(table(obj$data$in_enhancer))
#> 
#> TRUE 
#> 2676 

# The label is registered so downstream plots can discover the column.
print(obj$meta$custom_regions)
#> [1] "in_enhancer"