Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Option to prune small twigs before nblast #19

Closed
jefferis opened this issue Oct 5, 2016 · 10 comments
Closed

Option to prune small twigs before nblast #19

jefferis opened this issue Oct 5, 2016 · 10 comments

Comments

@jefferis
Copy link
Collaborator

jefferis commented Oct 5, 2016

By combining strahler order and segment length we could probably remove a large number of small terminal branches without any impact on nblast results.

@jefferis
Copy link
Collaborator Author

jefferis commented Dec 7, 2016

maybe reverse Strahler order

@jefferis
Copy link
Collaborator Author

Could also remove anything tagged as not a branch

@jefferis
Copy link
Collaborator Author

Here is a first attempt at this. Trials on some DA1 PNs show a reduction in the number of nodes of about 25%, which seems useful though not huge. It may have a greater impact on neurons with very extensive arbours.

prune_terminals <- function(x, maxorder=1, maxlength=2000,...) {
  badsegs = strahler_order(x)$segments <= maxorder &
    seglengths(x) <= maxlength
  goodids = unlist(x$SegList[!badsegs])
  prune_vertices(x, goodids, invert = T)
}
> da1s.p=nlapply(da1s, prune_terminals)
> da1s.p.dps=dotprops(da1s.p/1e3, k=5, resample=1)
> da1s.dps=dotprops(da1s/1e3, k=5, resample=1)

> summary(da1s.p.dps)/summary(da1s.dps)
            nodes cable.length
27295   0.6759853    0.6759853
57311   0.7644979    0.7644979
57323   0.7818021    0.7818021
57353   0.8527709    0.8527709
57381   0.6872659    0.6872659
61221   0.7637326    0.7637326
755022  0.7949153    0.7949153
2863104 0.7189805    0.7189805

> summary(summary(da1s.p.dps)/summary(da1s.dps))
     nodes         cable.length   
 Min.   :0.6760   Min.   :0.6760  
 1st Qu.:0.7111   1st Qu.:0.7111  
 Median :0.7641   Median :0.7641  
 Mean   :0.7550   Mean   :0.7550  
 3rd Qu.:0.7851   3rd Qu.:0.7851  
 Max.   :0.8528   Max.   :0.8528  
> 

@jefferis
Copy link
Collaborator Author

mvp2=read.neuron.catmaid(2333007)
mvp2.orig=dotprops(mvp2/1e3, k=5, resample=1)
mvp2.p=dotprops(prune_terminals(mvp2)/1e3, k=5, resample=1)
> nvertices(mvp2.orig)
[1] 29513
> nvertices(mvp2.p)
[1] 10959

So more significant, but it actually takes 30 s to do the whole dotprops and strahler order thing. More than 20s of that is dotprops, with much of the time spent rbinding.

@jefferis
Copy link
Collaborator Author

NB have been having a problem where neurons have cycles

> prune_terminals(da1s[[1]])
Error in as.seglist.igraph(masterg <- x, origin = origin, Verbose = Verbose) : 
  Graph has cycles!
Called from: as.seglist.igraph(masterg <- x, origin = origin, Verbose = Verbose)

@jefferis
Copy link
Collaborator Author

Looks like this relates to a bug introduced into nat when trying to speed up resampling of neurons in natverse/nat@77ca3e5.

@jefferis
Copy link
Collaborator Author

We now have a good implementation of this in prune_twigs:
https://github.com/jefferis/elmr/blob/e34dc5e4dadc93160dba7889031501462bf9b966/R/prune_twigs.R#L1-L20

(good enough that we may move to nat).

@jefferis
Copy link
Collaborator Author

So we can update nblast_fafb to use this by default. @schlegelp would this have any impact on CATBOT?

@schlegelp
Copy link

No. Catbot uses the basic nblast function and does all the preprocessing itself. It currently uses the pre-processed simp10.dps overnight dump. If you are changing nblast_fafb, should I change that behaviour to using the twigs5.dps to match nblast_fafb?

@jefferis
Copy link
Collaborator Author

I think twigs5 is def better than simp10 although it might take longer.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants