mutate-ranges: Modify a Ranges object

Description Usage Arguments Value Examples

Description

Modify a Ranges object

Usage

1
2
## S3 method for class 'Ranges'
mutate(.data, ...)

Arguments

.data

a Ranges object

...

Pairs of name-value expressions. The name-value pairs can either create new metadata columns or modify existing ones.

Value

a Ranges object

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
df <- data.frame(start = 1:10,
                 width = 5,
                 seqnames = "seq1",
                 strand = sample(c("+", "-", "*"), 10, replace = TRUE),
                 gc = runif(10))
rng <- as_granges(df)

# mutate adds new columns
rng %>%
    mutate(avg_gc = mean(gc), row_id = 1:n())
# can also compute on newly created columns
rng %>%
    mutate(score = gc * width, score2 = score + 1)
# group by partitions the data and computes within each group
rng %>%
    group_by(strand) %>%
    mutate(avg_gc = mean(gc), row_id = 1:n())

# mutate can be used in conjuction with anchoring to resize ranges
rng %>%
    mutate(width = 10)
# by default width modfication fixes by start
rng %>%
    anchor_start() %>%
    mutate(width = 10)
# fix by end or midpoint
rng %>%
    anchor_end() %>%
    mutate(width = width + 1)
rng %>%
    anchor_center() %>%
    mutate(width = width + 1)
# anchoring by strand
rng %>%
    anchor_3p() %>%
    mutate(width = width * 2)
rng %>%
    anchor_5p() %>%
    mutate(width = width * 2)

sa-lee/plyranges documentation built on June 29, 2021, 1:12 p.m.