plyranges select() when a metadata column is shared with core variable
0
1
Entering edit mode
@mikelove
Last seen 7 hours ago
United States

I'm using ensembldb to construct some ranges, and then was using select() to select some metadata columns.

I noticed that the transcripts I was working with have a metadata column width, not the same as the width of the range. This then interferes with select():

> gr <- GRanges("chr1",IRanges(1:3,width=10))
> mcols(gr)$width <- 7
> mcols(gr)$test <- 0
> mcols(gr)$test2 <- "a"
> gr
GRanges object with 3 ranges and 3 metadata columns:
      seqnames    ranges strand |     width      test       test2
         <Rle> <IRanges>  <Rle> | <numeric> <numeric> <character>
  [1]     chr1      1-10      * |         7         0           a
  [2]     chr1      2-11      * |         7         0           a
  [3]     chr1      3-12      * |         7         0           a
  -------
  seqinfo: 1 sequence from an unspecified genome; no seqlengths
> gr %>% select(test2)
GRanges object with 3 ranges and 1 metadata column:
      seqnames    ranges strand |     test2
         <Rle> <IRanges>  <Rle> | <numeric>
  [1]     chr1      1-10      * |         0
  [2]     chr1      2-11      * |         0
  [3]     chr1      3-12      * |         0
  -------
  seqinfo: 1 sequence from an unspecified genome; no seqlengths

This is using current release/devel branch.

I wonder if select() should complain about metadata columns with names shared with core variables at the outset to avoid this issue?

plyranges • 889 views
ADD COMMENT
0
Entering edit mode

Another select() issue, I think the error here could be instead about the missing metadata column:

> gr <- as_granges(data.frame(seqnames=1,start=1,end=100,foo=7))
> gr
GRanges object with 1 range and 1 metadata column:
      seqnames    ranges strand |       foo
         <Rle> <IRanges>  <Rle> | <numeric>
  [1]        1     1-100      * |         7
  -------
  seqinfo: 1 sequence from an unspecified genome; no seqlengths
> gr %>% select(bar)
Error in select_rng(.data, .drop_ranges, ...) :
  Cannot select/rename the following columns: seqnames, start, end, width, strand
Calls: %>% -> select -> select.Ranges -> select_rng
ADD REPLY

Login before adding your answer.

Traffic: 794 users visited in the last hour
Help About
FAQ
Access RSS
API
Stats

Use of this site constitutes acceptance of our User Agreement and Privacy Policy.

Powered by the version 2.3.6