filter-ranges: Subset a 'Ranges' object

Description Usage Arguments Details Value See Also Examples

Description

Subset a Ranges object

Usage

1
2
## S3 method for class 'Ranges'
filter(.data, ..., .preserve = FALSE)

Arguments

.data

A Ranges object

...

valid logical predictates to subset .data by. These are determined by variables in .data. If more than one condition is supplied, the conditions are combined with &. Only rows where the condition evaluates to TRUE are kept.

.preserve

when FALSE (the default) grouping structure is recalculated, TRUE is currently not implemented.

Details

For any Ranges objects filter can act on all core components of the class including start, end, width (for IRanges) or seqnames and strand (for GRanges) in addition to metadata columns. If the Ranges object is grouped, filter will act seperately on each parition of the data.

Value

a Ranges object

See Also

dplyr::filter()

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
set.seed(100)
df <- data.frame(start = 1:10,
                 width = 5,
                 seqnames = "seq1",
                 strand = sample(c("+", "-", "*"), 10, replace = TRUE),
                 gc = runif(10))

rng <- as_granges(df)

filter(rng, strand == "+")
filter(rng, gc > 0.5)

# multiple criteria
filter(rng, strand == "+" | start > 5)
filter(rng, strand == "+" & start > 5)

# multiple conditions are the same as and
filter(rng, strand == "+", start > 5)

# grouping acts on each subset of the data
rng %>%
  group_by(strand) %>%
  filter(gc > 0.5)

plyranges documentation built on Nov. 8, 2020, 7:36 p.m.