petrelharp / context

Context-dependent mutation rate inference machinery.
0 stars 0 forks source link

`getmutpats` errors out #15

Closed matsen closed 10 years ago

matsen commented 10 years ago

Specifically, it seems to have an issue when going through the loop at k=1. Here's what I tried evaluating to isolate that case.

> mutpats <- list()
> patterns <- getpatterns(patlen,bases)
> k <- 1
> kmers <- getpatterns(k,bases)
> mutpats <- c( mutpats,
+         apply(combn(kmers,2),2,list), # make lists of rows (2 = apply over colment lists of kmers 
+         apply(combn(kmers,2)[2:1,],2,list) # and the reverse of the 2-element lists
+         )
Error in apply(combn(kmers, 2)[2:1, ], 2, list) : 
  dim(X) must have a positive length
> 

which is the same result as

> bases <- c("X","O")
> getmutpats(2,bases)
Error in apply(combn(kmers, 2)[2:1, ], 2, list) : 
  dim(X) must have a positive length

It appears to me that this comes from R's implicit casting rule for lists of length 1.

petrelharp commented 10 years ago

this is a result of the implicit dimension-1-matrix -> vector thing that R does.

Solution: change [2:1,] to [2:1,,drop=FALSE].

grrr.

On Sun, Aug 3, 2014 at 6:12 AM, Erick Matsen notifications@github.com wrote:

Specifically, it seems to have an issue when going through the loop at k=1. Here's what I tried evaluating to isolate that case.

mutpats <- list()> patterns <- getpatterns(patlen,bases)> k <- 1> kmers <- getpatterns(k,bases)> mutpats <- c( mutpats,+ apply(combn(kmers,2),2,list), # make lists of rows (2 = apply over colment lists of kmers + apply(combn(kmers,2)[2:1,],2,list) # and the reverse of the 2-element lists+ ) Error in apply(combn(kmers, 2)[2:1, ], 2, list) : dim(X) must have a positive length>

which is the same result as

bases <- c("X","O")> getmutpats(2,bases) Error in apply(combn(kmers, 2)[2:1, ], 2, list) : dim(X) must have a positive length

It appears to me that this comes from R's implicit casting rule for lists of length 1.

— Reply to this email directly or view it on GitHub https://github.com/petrelharp/context/issues/15.