build_catalogues fails if a sample only has one row in a variants table
kgori opened this issue · 1 comments
kgori commented
When idx
only pulls out a single row, then variants[idx, ]
is interpreted as a character vector, and it breaks the apply
.
Arguably not a big issue as we don't expect anyone to use samples with a single mutation, it's more of an annoyance.
# Example of the bug
variants <- data.frame(sample = c("sample1", "sample1", "sample1", "sample2"),
ref = c("T", "G", "A", "G"),
alt = c("G", "T", "C", "C"),
trinuc = c("TTG", "TGC", "TAT", "AGA"))
build_catalogues(variants) # breaks
# Error in apply(variants[idx, ], 1, function(var) { :
# dim(X) must have a positive length
variants <- data.frame(sample = c("sample1", "sample1", "sample2", "sample2"),
ref = c("T", "G", "A", "G"),
alt = c("G", "T", "C", "C"),
trinuc = c("TTG", "TGC", "TAT", "AGA"))
build_catalogues(variants) # works
baezortega commented
Fixed in dev using this nice trick: https://www.r-bloggers.com/design-flaws-in-r-2-%e2%80%94-dropped%c2%a0dimensions/