kuwisdelu / Cardinal

Mass spectrometry imaging toolbox
http://www.cardinalmsi.org
Artistic License 2.0
42 stars 14 forks source link

spatialFastMaps types spatial neighbors as numerics instead of matrices #10

Closed gtluu closed 4 years ago

gtluu commented 4 years ago

Hi Kylie,

As mentioned in the help group:

When running spatialFastMaps in Cardinal 2.4.0, there seems to be a possible bug (unless this was intentional) in the functions .spatialFastmap2 and .findDistantObjects2 when iterating over FastMap components. It appears that xa and xb (spatial neighbors?), which should be matrices, are typed as numeric if there is only one column. It seems that adding these lines of code (highlighted in red) seems to fix the issue, though I am curious if this behavior is intentional.

Additionally, I'd like to add that this issue was originally found when running spatialShrunkenCentroids, thought it seems to persist when calling spatialFastMaps on my dataset:

ssc <- spatialShrunkenCentroids(data, r=c(1,2,3), k=c(2,4,6,8,10,12,14,16,18,20), s=c(0,3,6,9,12,15))

It seems that adding an if statement to check if xa and xb are numerics followed by converting them to matrices fixes the issue:

if (class(xa) == 'numeric') { xa <- as.matrix(xa) }

kuwisdelu commented 4 years ago

This should now be fixed by 4cf89e0