-
Notifications
You must be signed in to change notification settings - Fork 18
Open
Description
Hello,
I was wondering if it would be useful to add a flip_strand() function to switch strand from "+" to "-" and viceversa, leaving "*" if unstranded. I am not aware of a function that does this in GenomicRanges.
I adapted the flip_strand_info() function from TranscriptomeReconstructoR. It does not cover the "*" case.
Probably there is a more elegant/efficient way of doing this:
#' Flip strand orientation of a GenomicRanges object
#'
#' @param gr \code{GRanges} or \code{GRangesList} object
#' @return Object of the same class as input with positive and negative strands flipped
#' @export
flip_strand <- function(gr) {
stopifnot(class(gr) == "GRanges" || BiocGenerics::grepl("GRangesList", class(gr)))
if (class(gr) == "GRanges") {
BiocGenerics::strand(gr) <- ifelse(BiocGenerics::strand(gr) == "*", "*",
ifelse(BiocGenerics::strand(gr) == "+", "-", "+"))
} else {
unl <- BiocGenerics::unlist(gr, use.names = FALSE)
BiocGenerics::strand(unl) <- ifelse(BiocGenerics::strand(unl) == "*", "*",
ifelse(BiocGenerics::strand(unl) == "+", "-", "+"))
gr <- BiocGenerics::relist(unl, gr)
}
return(gr)
}
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels