acorg / Racmacs

Racmacs R package for performing antigenic cartography
https://acorg.github.io/Racmacs/
GNU Affero General Public License v3.0
20 stars 9 forks source link

moveTrappedPoints crashes R if table distances are all negative for a serum. #147

Open drserajames opened 1 year ago

drserajames commented 1 year ago

Sometimes when I'm adjusting the column bases, the column base is lower than the lowest titre for a serum so that all the table distances for that serum are negative. The map optimises just fine, but then I get an error when I try to use moveTrappedPoints that crashes R.

> library(Racmacs)
> packageVersion("Racmacs")
[1] ‘1.1.40’
> 
> set.seed(123)
> dat2 <- 10*2^round(rbind(cbind(matrix(rep(7, 9), ncol=3), matrix(rep(3, 9), ncol=3)),
+                          cbind(matrix(rep(3, 9), ncol=3), matrix(rep(7, 9), ncol=3))))
> dat2[,1] <- dat2[,1]*8
> dat2
      [,1] [,2] [,3] [,4] [,5] [,6]
[1,] 10240 1280 1280   80   80   80
[2,] 10240 1280 1280   80   80   80
[3,] 10240 1280 1280   80   80   80
[4,]   640   80   80 1280 1280 1280
[5,]   640   80   80 1280 1280 1280
[6,]   640   80   80 1280 1280 1280
> 
> 
> map <- make.acmap(dat2, verbose=F, options=list(report_progress = F))
> mtp <- moveTrappedPoints(map)
Checking for trapped points recursively: no trapped points found.
> 
> cb_map <- optimizeMap(map, 2, 100, fixed_column_bases = rep(5,6))
Discarding previous optimization runs.
Performing 100 optimizations
================================================================================
Optimization runs complete
Took 0.05 secs

> cb_mtp <- moveTrappedPoints(cb_map)
Checking for trapped points recursively:terminate called after throwing an instance of 'std::logic_error'
  what():  Cube::min(): object has no elements
zsh: abort      R

I would prefer that moveTrappedPoints worked as normal. If that's not easy, then for an warning message ("Trapped points not moved due to negative table distances for at least one serum"), rather than a crash.