natverse / malevnc

Support for working with Janelia FlyEM Male VNC dataset
https://natverse.org/malevnc/
GNU General Public License v3.0
1 stars 0 forks source link

symmetric_manc drops body position #16

Open dokato opened 3 years ago

dokato commented 3 years ago

What is?

After calling symmetric_manc soma coordinates become NA:

> before
      bodyid       X       Y       Z     n                from                  to nside
10004  10004 20958.5 39272.5 41095.5  6249 20958, 39292, 40809 20959, 39253, 41382     L
10010  10010 21441.0 39443.5 59953.0  6724 21441, 39725, 60635 21441, 39162, 59271     L
10011  10011 31054.5 39992.0 40853.5 12686 30141, 39992, 39865 31968, 39992, 41842     R
10013  10013 13448.5 37048.5 41536.0  1259 13448, 38253, 41587 13449, 35844, 41485     L
10014  10014 10637.0 31555.5 46236.0   103 10640, 32351, 46195 10634, 30760, 46277     L
10016  10016 17567.0 21542.0 50313.0  2999 17102, 21542, 49816 18032, 21542, 50810     L
> after #symmetric_manc
      bodyid  X  Y  Z     n                from                  to nside 
10004  10004 NA NA NA  6249 20958, 39292, 40809 20959, 39253, 41382     L 
10010  10010 NA NA NA  6724 21441, 39725, 60635 21441, 39162, 59271     L          
10011  10011 NA NA NA 12686 30141, 39992, 39865 31968, 39992, 41842     R     
10013  10013 NA NA NA  1259 13448, 38253, 41587 13449, 35844, 41485     L     
10014  10014 NA NA NA   103 10640, 32351, 46195 10634, 30760, 46277     L   
10016  10016 NA NA NA  2999 17102, 21542, 49816 18032, 21542, 50810     L

Expected behaviour

Soma positions become symmetrised too.

jefferis commented 3 years ago

Thanks for pointing this out. It is a units problem. symmetric_manc wants coordinates in microns but these coords are in raw voxels. Given how different they are I think we could probably add some logic inside symmetric_manc to guess. Even better would be a reusable function that did this any time we wanted to use xyzmatrix. Perhaps something like this:

manc_xyzmatrix<-function(x, inunits=c("guess", "raw", "microns"), outunits=c("in", "raw", "microns"), ...) {
}

Better still would be general units support for nat!

dokato commented 3 years ago

Actually, what happened here is

after <- symmetric_manc(before/125)

but indeed, the division does not apply to X,Y,Z. As I always forget what data you need to divide by what, I'll have a look at units support soon.

jefferis commented 3 years ago

There is special handling for attached metadata data.frames for xform.neuronlist

https://github.com/natverse/nat/blob/master/R/xform.R#L209-L228

however it is controlled by an argument since it would be possible to have XYZ metadata columns that you didn't want to be touched.

*.neuronlist is much simpler:

https://github.com/natverse/nat/blob/2da55fa227666471d0231b90dde0fe565a519860/R/neuronlist.R#L945

it should probably be translated to Ops.neuronlist but implement Ops is slightly more complicated. Here is the implementation for Ops.neuron

https://github.com/natverse/nat/blob/88507a819c2b4b4f16ada74a79560abc4d260fc5/R/neuron.R#L345

we would either need to