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
library(plyranges)
set.seed(2018)
n<-10r<- GRanges(seqnames= rep("chr1", n),
ranges= IRanges(start= sample(20, n, replace=T),
width= sample(6, n, replace=T))
)
mcols(r) <-data.frame(score= runif(n, 0, 100), condition= rep_len(c("One","Two"), n))
r
## GRanges object with 10 ranges and 2 metadata columns:
## seqnames ranges strand | score condition
## <Rle> <IRanges> <Rle> | <numeric> <factor>
## [1] chr1 7-9 * | 26.0100793326274 One
## [2] chr1 10-13 * | 56.8360368022695 Two
## [3] chr1 2-7 * | 15.1498265331611 One
## [4] chr1 4-8 * | 9.49368453584611 Two
## [5] chr1 10-14 * | 76.191659620963 One
## [6] chr1 7-10 * | 53.5928548080847 Two
## [7] chr1 13-14 * | 32.7880936674774 One
## [8] chr1 3-6 * | 92.4356027971953 Two
## [9] chr1 20-24 * | 59.8311740672216 One
## [10] chr1 11-15 * | 6.46366507280618 Two
## -------
## seqinfo: 1 sequence from an unspecified genome; no seqlengths
These work:
r %>% group_by(condition) %>% summarize(score= mean(score))
## DataFrame with 2 rows and 2 columns
## condition score
## <factor> <numeric>
## 1 One 41.9941666442901
## 2 Two 43.7643688032404
r %>% group_by(condition) %>% summarize(score= mean(width))
## DataFrame with 2 rows and 2 columns
## condition score
## <factor> <numeric>
## 1 One 4.2
## 2 Two 4.4
r %>% group_by(condition) %>% reduce_ranges(score= weighted.mean(score, width))
## GRanges object with 3 ranges and 2 metadata columns:
## seqnames ranges strand | condition score
## <Rle> <IRanges> <Rle> | <factor> <numeric>
## [1] chr1 2-14 * | One 38.4664801647887
## [2] chr1 20-24 * | One 59.8311740672216
## [3] chr1 3-15 * | Two 40.5111238942482
## -------
## seqinfo: 1 sequence from an unspecified genome; no seqlengths
... but this doesn't:
r %>% group_by(condition) %>% summarize(score= weighted.mean(score, width))
## Error in as.vector(x, mode): coercing an AtomicList object to an atomic vector is supported only for
## objects with top-level elements of length <= 1
This is to do with some issues we've been talking about in #30 - I need to handle the case when there is not "fast" method for dispatching the grouped object better.
@lawremi I'm surprised there is no List method for weighted.mean?
These work:
... but this doesn't:
The text was updated successfully, but these errors were encountered: