natverse / nat

NeuroAnatomy Toolbox: An R package for the (3D) visualisation and analysis of biological image data, especially tracings of single neurons.
https://natverse.org/nat/
64 stars 28 forks source link

Strahler order fails on a simplified neuron with no branches #464

Closed dokato closed 3 years ago

dokato commented 3 years ago

For a neuron with a single branch (e.g. attached) I'd expect Strahler's order to return 1 per each node. Instead it errors out:

> nn
'neuron' with 403 vertices in 1 tree
> plot3d(nn,soma=T)
> summary(nn)
  root nodes segments branchpoints endpoints cable.length
1    1   403        1            0         2     206.8101
> strahler_order(nn)
Error in idxs[i, ] : incorrect number of dimensions

single_branch_neuron.rds.zip

dokato commented 3 years ago

idea for a quick win:

  if (summary(x)$branchpoints == 0)
    return(list(points=rep(1, summary(x)$nodes),
                segments=rep(1, length(x$SegList))))

at the beginning of strahler_order function.

jefferis commented 3 years ago

summary(x)$branchpoints is actually sort of slow because it does some other stuff.

branchpoints=length(object$BranchPoints)

is the relevant bit, so you could use that. I forget how it handles neurons with multiple trees though.

jefferis commented 3 years ago

Closed by #465