You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I only just discovered your package - I'm excited to start being tidy with my GRanges!
Apologies if I missed something, but I think I am requesting an enhancement.
With tibbles, when I'm grouping on a factor, there's a way to summarize and make sure I include empty groups, by using the .drop=FALSE argument. But for GRanges, I don't see a way to include the empty groups. Again, sorry if I missed it - I have tried searching but didn't see anything.
I've provided code below that I think is a nice small example.
thanks very much,
Janet Young
Malik lab,
Fred Hutch Cancer Research Center,
Seattle, WA
## here's how I include empty groups when summarizing a tibble
library(tidyverse)
fruit_tbl <- data.frame(fruit=factor( c("apple","apple","orange","pear"),
levels=c("apple","orange","pear","banana")),
weight=c(3,4,5,3)) %>%
as_tibble()
# we DO get output for 'banana', the empty group:
fruit_tbl %>%
group_by(fruit, .drop=FALSE) %>%
summarise(numFruits=n(),
mean=mean(weight))
# A tibble: 4 × 3
# fruit numFruits mean
# <fct> <int> <dbl>
# 1 apple 2 3.5
# 2 orange 1 5
# 3 pear 1 3
# 4 banana 0 NaN
But I don't see a way to include empty groups in plyranges. Is that true? Sorry if I missed it. I am using plyranges_1.14.0 (release version). Here's what I tried (after restarting R to make sure tidyverse packages aren't loaded):
library(plyranges)
## make GRanges where not all factor levels are represented (for seqnames, also for regionType)
grng2 <- data.frame(seqnames = sample(c("chr1", "chr2"), 7, replace = TRUE),
strand = sample(c("+", "-"), 7, replace = TRUE),
gc = runif(7),
start = 1:7,
width = 10) %>%
mutate(seqnames=factor(seqnames, levels=c("chr1", "chr2", "chr3"))) %>%
mutate(regionType=factor( sample(c("a", "b"), 7, replace = TRUE),
levels=c("a", "b", "c"))) %>%
as_granges()
## works, but we don't get summaries for the empty levels of seqlevel (chr3) or regionType (c):
grng2 %>%
group_by(seqnames) %>%
summarize(numRegions=n(),
meanGC=mean(gc))
# DataFrame with 2 rows and 3 columns
# seqnames numRegions meanGC
# <Rle> <integer> <numeric>
# 1 chr1 6 0.592756
# 2 chr2 1 0.664616
grng2 %>%
group_by(regionType) %>%
summarize(numRegions=n(),
meanGC=mean(gc))
# DataFrame with 2 rows and 3 columns
# regionType numRegions meanGC
# <factor> <integer> <numeric>
# 1 a 6 0.646677
# 2 b 1 0.341085
## can't use .drop like I would with a tibble
grng2 %>%
group_by(regionType, .drop=FALSE) %>%
summarize(numRegions=n(),
meanGC=mean(gc))
# Error in new_grouping(.data, ...) : Column `.drop` is unknown
Hi there,
I only just discovered your package - I'm excited to start being tidy with my GRanges!
Apologies if I missed something, but I think I am requesting an enhancement.
With tibbles, when I'm grouping on a factor, there's a way to summarize and make sure I include empty groups, by using the .drop=FALSE argument. But for GRanges, I don't see a way to include the empty groups. Again, sorry if I missed it - I have tried searching but didn't see anything.
I've provided code below that I think is a nice small example.
thanks very much,
Janet Young
Malik lab,
Fred Hutch Cancer Research Center,
Seattle, WA
But I don't see a way to include empty groups in plyranges. Is that true? Sorry if I missed it. I am using plyranges_1.14.0 (release version). Here's what I tried (after restarting R to make sure tidyverse packages aren't loaded):
and here's my R session information
The text was updated successfully, but these errors were encountered: