Skip to contents

Subset fragments by length

Usage

subset_lengths(fragments, min_len = 0L, max_len = NA_integer_)

Arguments

fragments

Input fragments object

min_len

Minimum bases in fragment (inclusive)

max_len

Maximum bases in fragment (inclusive)

Value

Fragments object

Details

Fragment length is calculated as end-start

Examples

## Prep data
frags <- tibble::tibble(
  chr = "chr1",
  start = seq(10, 260, 50),
  end = start + seq(5, 30, 5),
  cell_id = paste0("cell", c(rep(1, 2), rep(2,2), rep(3,2)))
) 
frags
#> # A tibble: 6 × 4
#>   chr   start   end cell_id
#>   <chr> <dbl> <dbl> <chr>  
#> 1 chr1     10    15 cell1  
#> 2 chr1     60    70 cell1  
#> 3 chr1    110   125 cell2  
#> 4 chr1    160   180 cell2  
#> 5 chr1    210   235 cell3  
#> 6 chr1    260   290 cell3  
frags <- frags %>% convert_to_fragments()

## Subset lengths
subset_lengths(frags, min_len = 10, max_len = 20) %>% as("GRanges")
#> GRanges object with 3 ranges and 1 metadata column:
#>       seqnames    ranges strand |  cell_id
#>          <Rle> <IRanges>  <Rle> | <factor>
#>   [1]     chr1     61-70      * |    cell1
#>   [2]     chr1   111-125      * |    cell2
#>   [3]     chr1   161-180      * |    cell2
#>   -------
#>   seqinfo: 1 sequence from an unspecified genome; no seqlengths