Bioconductor / RaggedExperiment

Matrix-like representations of mutation and CN data
https://bioconductor.org/packages/RaggedExperiment
4 stars 3 forks source link

qreduceAssay: simplifyReduce #10

Closed lgeistlinger closed 7 years ago

lgeistlinger commented 7 years ago

The vignette, Section 6.4 qreduceAssay currently says:

First we define our summary function that calculates a weighted average score per query range. Note that there are three arguments to this function.

weightedmean <- function(scores, ranges, qranges)
    sum(scores * width(ranges)) / sum(width(ranges))

However, the given example only uses two arguments in its body (scores and ranges). Is this intended? How would an example using all three arguments look like?

As far as I understand the procedure underlying qreduceAssay, it first identifies overlapping rowRanges for each given query range and then accordingly summarizes across these ranges by applying simplifyReduce.

Thus, simplifyReduce actually only needs to know about the ranges and associated scores it summarizes over, doesn't it?

lgeistlinger commented 7 years ago

No, it actually makes sense that simplifyReduce also has knowledge about the query ranges, e.g. in case of a weighted average score per query range, where the weight is proportional to the overlap widths between overlapping ranges and a query range.

weightedmean2 <- function(scores, ranges, qranges)
{
    isects <- pintersect(ranges, qranges)
    sum(scores * width(isects)) / sum(width(isects))
}

Perhaps this is even a better example as it illustrates usage with all three arguments.