pneuvial / c3co

Inferring cancer cell clonality from copy-number data
5 stars 1 forks source link

BUG: get.W throws an error when input contains a single subclone #52

Closed pneuvial closed 5 years ago

pneuvial commented 5 years ago
dat <- getToyData(n = 10, len = 20, nbClones = 1, nbSegs = 2, dimension = 1, eps = 0)
Y <- dat$loc$Y
Z <- dat$loc$Z
Zt <- t(Z)
What <- c3co:::get.W(Zt, Y)
## Error: ‘nrow(W) == nrow(Y)’ is not TRUE 

Reason: apply(X, margin, FUN) drops dimensions when FUN returns a scalar. This breaks a sanity check get.W

Example:

> mat <- matrix(rnorm(10), 2, 5)
> apply(mat, 1, function(x) c(mean(x), sd(x), mad(x)))
           [,1]      [,2]
[1,] 0.03065059 0.2783972
[2,] 1.19243633 1.1319516
[3,] 1.45129250 1.4105446
> apply(mat, 1, function(x) c(mean(x)))
[1] 0.03065059 0.27839721
HenrikBengtsson commented 5 years ago

Clarification: The problem is in get.W() and:

    W <- t(apply(Y, MARGIN = 1L, FUN = function(y) {
        lsei(A = Zt, B = y, E = E, F = 1, H = H, G = G, type = 2L)$X
    }))
HenrikBengtsson commented 5 years ago

Fixed for K=1 by doing a workaround in get.W().