mutate.Ranges {plyranges} | R Documentation

## Modify a Ranges object

### Description

Modify a Ranges object

### Usage

    ## 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

    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)

[Package plyranges version 1.6.10 Index]