Learn R Programming

GenomicRanges (version 1.22.0)

strand-utils: Strand utilities

Description

Some useful strand methods.

Usage

"strand"(x) "strand"(x) "strand"(x) "strand"(x) "strand"(x) "strand"(x) "strand"(x) "strand"(x) <- value

Arguments

x
The object from which to obtain a strand factor, can be missing.
value
Replacement value for the strand.

Value

A factor (or factor-Rle) with the "standard strand levels" (i.e. +, -, and *) and no NAs.

Details

If x is missing, returns an empty factor with the "standard strand levels" i.e. +, -, and *.

If x is a character vector or factor, it is coerced to a factor with the levels listed above. NA values in x are not accepted.

If x is an integer vector, it is coerced to a factor with the levels listed above. 1, -1, and NA values in x are mapped to the +, -, and * levels respectively.

If x is a logical vector, it is coerced to a factor with the levels listed above. FALSE, TRUE, and NA values in x are mapped to the +, -, and * levels respectively.

If x is a character-, factor-, integer-, or logical-Rle, it is transformed with runValue(x) <- strand(runValue(x)) and returned.

If x inherits from DataTable, the "strand" column is passed thru strand() and returned. If x has no "strand" column, this return value is populated with *s.

See Also

strand

Examples

Run this code
strand()

x1 <- c("-", "*", "*", "+", "-", "*")
x2 <- factor(c("-", "-", "+", "-"))
x3 <- c(-1L, NA, NA, 1L, -1L, NA)
x4 <- c(TRUE, NA, NA, FALSE, TRUE, NA)

strand(x1)
strand(x2)
strand(x3)
strand(x4)

strand(Rle(x1))
strand(Rle(x2))
strand(Rle(x3))
strand(Rle(x4))

strand(DataFrame(score=2:-3))
strand(DataFrame(score=2:-3, strand=x3))
strand(DataFrame(score=2:-3, strand=Rle(x3)))

## Sanity checks:
target <- strand(x1)
stopifnot(identical(target, strand(x3)))
stopifnot(identical(target, strand(x4)))

stopifnot(identical(Rle(strand(x1)), strand(Rle(x1))))
stopifnot(identical(Rle(strand(x2)), strand(Rle(x2))))
stopifnot(identical(Rle(strand(x3)), strand(Rle(x3))))
stopifnot(identical(Rle(strand(x4)), strand(Rle(x4))))

Run the code above in your browser using DataLab