[Bioc-devel] Collapsing a GRangesList into a GRanges without loosing names(GRangesList)

Shepherd, Lori Lor|@Shepherd @end|ng |rom Ro@we||P@rk@org
Wed Sep 11 14:54:21 CEST 2019


In what way are you feeling they loose names?

> grlist <- GenomicRanges::GRangesList( gr1 = GenomicRanges::GRanges('chr1', '1-100',   strand = '-'), gr2 = GenomicRanges::GRanges('chr1', '101-200', strand = '-'))

> names(grlist)
[1] "gr1" "gr2"

> temp = unlist(grlist)
> names(temp)
[1] "gr1" "gr2"

> temp
GRanges object with 2 ranges and 0 metadata columns:
      seqnames    ranges strand
         <Rle> <IRanges>  <Rle>
  gr1     chr1     1-100      -
  gr2     chr1   101-200      -
  -------
  seqinfo: 1 sequence from an unspecified genome; no seqlengths

> temp["gr1"]
GRanges object with 1 range and 0 metadata columns:
      seqnames    ranges strand
         <Rle> <IRanges>  <Rle>
  gr1     chr1     1-100      -
  -------
  seqinfo: 1 sequence from an unspecified genome; no seqlengths



The names "gr1" and "gr2"  were preserved. You can see them as the first entry in my temp object.



Lori Shepherd

Bioconductor Core Team

Roswell Park Cancer Institute

Department of Biostatistics & Bioinformatics

Elm & Carlton Streets

Buffalo, New York 14263

________________________________
From: Bioc-devel <bioc-devel-bounces using r-project.org> on behalf of Bhagwat, Aditya <Aditya.Bhagwat using mpi-bn.mpg.de>
Sent: Wednesday, September 11, 2019 8:47 AM
To: bioc-devel using r-project.org <bioc-devel using r-project.org>
Subject: [Bioc-devel] Collapsing a GRangesList into a GRanges without loosing names(GRangesList)

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

_______________________________________________
Bioc-devel using r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/bioc-devel


This email message may contain legally privileged and/or confidential information.  If you are not the intended recipient(s), or the employee or agent responsible for the delivery of this message to the intended recipient(s), you are hereby notified that any disclosure, copying, distribution, or use of this email message is prohibited.  If you have received this message in error, please notify the sender immediately by e-mail and delete this email message from your computer. Thank you.
	[[alternative HTML version deleted]]



More information about the Bioc-devel mailing list