Re-implementation of nat
core functions in Rust.
- Clone this repository
- Make sure the Rust toolchain and the R
rextendr
&devtools
packages are installed - In R run:
utils::install.packages("/path/to/repo/fastcore-rs/R/nat.fastcore/", type="source", repos=NULL)
- Clone this repository
- Make sure the Rust toolchain and the R
rextendr
&devtools
packages are installed cd
into this directory- In R run:
library(rextendr) library(devtools) rextendr::document() # compiles Rust code and update the R wrappers devtools::load_all(".")
> library(nat.fastcore)
> # Load a single skeleton
> s = read.neurons('test.swc')[[1]]
> # Generate node indices from node -> parent IDs
> parents = node_indices(s$d$PointNo, s$d$Parent)
> # Find distances to roots
> all_dists_to_root(parents, sources=NULL, weights=NULL)
[1] 0 47 48 49 50 51 ...
> # Calculate child -> parent distances
> weights = child_to_parent_dists(parents, s$d$X, s$d$Y, s$d$Z)
> # Generate all-by-all geodesic distance matrix
> dists = geodesic_distances(parents, sources=NULL, targets=NULL, weights=weights, directed=F)
Currently the following functions have been wrapped:
node_indices
: turn node and parent IDs into parent indicesgeodesic_distances
: calculate geodesic distances between all/subsets of nodesstrahler_index
: calculate the Strahler indexconnected_components
: extract connected componentsall_dist_to_root
: calculate distances from all/subsets of nodes to the rootprune_twigs
: prune twigs under a given size thresholdchild_to_parent_dists
: helper to calculate child -> parent distances