[Bioc-devel] Collapsing a GRangesList into a GRanges without loosing names(GRangesList)
Bhagwat, Aditya
Ad|ty@@Bh@gw@t @end|ng |rom mp|-bn@mpg@de
Wed Sep 11 14:47:17 CEST 2019
Dear bioc-devel,
When using unlist to collapse a GRangesList into a GRanges<https://support.bioconductor.org/p/83599> one looses names(GRangesList).
Since I need a name-preserving collapser, I defined the following in multicrispr<https://gitlab.gwdg.de/loosolab/software/multicrispr>.
My feedback request is: did I overlook existing similar functionality?
#' Collapse a GRangesList
#' @param grangeslist GenomicRanges::GRangesList
#' @examples
#' # Consider a GRangesList
#' grlist <- GenomicRanges::GRangesList(
#' gr1 = GenomicRanges::GRanges('chr1', '1-100', strand = '-'),
#' gr2 = GenomicRanges::GRanges('chr1', '101-200', strand = '-'))
#'
#' # unlist() drops names(grlist)
#' unlist(grlist)
#'
#' # collapse() preserves them
#' collapse(grlist)
#'
#' # in a way similar to as.data.frame()
#' as.data.frame(grlist)
#' @export
collapse <- function(grangeslist){
add_series <- function(granges, group_name){
granges$group_name <- group_name;
granges }
S4Vectors::mendoapply(add_series, grangeslist, names(grangeslist)) %>%
unlist() %>%
sort()
}
Aditya
[[alternative HTML version deleted]]
More information about the Bioc-devel
mailing list