kgori / sigfit

Flexible Bayesian inference of mutational signatures
GNU General Public License v3.0
33 stars 8 forks source link

build_catalogues fails if a sample only has one row in a variants table #38

Closed kgori closed 5 years ago

kgori commented 5 years ago

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 5 years ago

Fixed in dev using this nice trick: https://www.r-bloggers.com/design-flaws-in-r-2-%e2%80%94-dropped%c2%a0dimensions/