Skip to contents

Subset, translate, or reorder chromosome IDs

Usage

select_chromosomes(fragments, chromosome_selection)

Arguments

fragments

Input fragments object

chromosome_selection

List of chromosme IDs (numeric), or names (character), or logical mask.

Details

Numeric chromosome IDs will be re-assigned in the order of chromosome_selection. The output chromosome ID n will be taken from the input chromosome with ID/name chromosome_selection[n].

Examples

## Prep data
frags <- tibble::tibble(
  chr = c(rep("chr1", 2), rep("chrX", 2), rep("chr3", 2)),
  start = seq(10, 260, 50),
  end = start + 30,
  cell_id = paste0("cell1")
) %>% as("GRanges")
frags <- frags %>% convert_to_fragments()
frags
#> IterableFragments object of class "UnpackedMemFragments"
#> 
#> Cells: 1 cells with names cell1
#> Chromosomes: 3 chromosomes with names chr1, chr3, chrX
#> 
#> Queued Operations:
#> 1. Read uncompressed fragments from memory

## Selecting by chromosome IDs
select_chromosomes(frags, c(1, 3))
#> IterableFragments object of class "ChrSelectIndex"
#> 
#> Cells: 1 cells with names cell1
#> Chromosomes: 2 chromosomes with names chr1, chrX
#> 
#> Queued Operations:
#> 1. Read uncompressed fragments from memory
#> 2. Select 2 chromosomes by index: 1, 3

## Selecting by name
select_chromosomes(frags, c("chrX"))
#> IterableFragments object of class "ChrSelectName"
#> 
#> Cells: 1 cells with names cell1
#> Chromosomes: 1 chromosomes with names chrX
#> 
#> Queued Operations:
#> 1. Read uncompressed fragments from memory
#> 2. Select 1 chromosomes by name: chrX