GithubHelp home page GithubHelp logo

natverse / fafbseg Goto Github PK

View Code? Open in Web Editor NEW
6.0 6.0 4.0 51.29 MB

Support functions for analysis of Drosophila connectomes especially the FAFB-FlyWire whole brain

Home Page: https://natverse.org/fafbseg/

License: GNU General Public License v3.0

R 100.00%
connectomics neuroanatomy-toolbox neuroscience r

fafbseg's Introduction

natverse

natverse GitHub Docs Travis build status Coveralls test coverage

The natverse package is a wrapper for all of the commonly used NeuroAnatomy Toolbox packages. This is convenient both for package installation and for loading/attaching these packages without many calls to library().

See http://natverse.org for more details.

Installation

The recommended approach to install the full natverse is to use a helper package natmanager, which is available on CRAN. You can therefore do:

install.packages("natmanager")
natmanager::install("natverse")

See http://natverse.org/install for more details.

Use

Once installed, you can load the natverse package:

library(natverse)
#> Loading required package: elmr
#> Loading required package: catmaid
#> Loading required package: httr
#> Warning: package 'httr' was built under R version 3.6.2
#> Loading required package: nat
#> Loading required package: rgl
#> Warning: package 'rgl' was built under R version 3.6.2
#> Registered S3 method overwritten by 'nat':
#>   method             from
#>   as.mesh3d.ashape3d rgl
#> 
#> Attaching package: 'nat'
#> The following object is masked from 'package:rgl':
#> 
#>     wire3d
#> The following objects are masked from 'package:base':
#> 
#>     intersect, setdiff, union
#> Loading required package: nat.flybrains
#> Loading required package: nat.templatebrains
#> Loading required package: nat.nblast
# example 3D plot of some neurons
plot(kcs20, col=type)

Installation Details

Conflicts and Dependencies

The natverse package contains many packages and it is possible that there could be conflicts where functions in the natverse have the same name as another package.

natverse_conflicts()
#> ── Conflicts ─────────────────────────────────────────────────────────────── natverse_conflicts() ──
#> x nat::intersect() masks base::intersect()
#> x nat::setdiff()   masks base::setdiff()
#> x nat::union()     masks base::union()
#> x nat::wire3d()    masks rgl::wire3d()

You can always choose the correct version by prepending the specific package name e.g. nat::flip() will select the nat version rather than any other.

Updates

Once installed, you check the status of all natverse packages and their dependencies like so:

natverse_update()
#> 
#> The following packages are either locally installed or information about them is missing!
#> 
#>   blob, formattable, import, mockr, nycflights13, pingr, fafbsegdata, reticulate, nat
#> 
#> Please install them manually from their appropriate source locations
#> 
#> The following natverse dependencies are out-of-date, see details below:
#> 
#> We recommend updating them by running:
#> natverse_update(update=TRUE)
#> 
#> package         remote         local          source   repo                        status 
#> --------------  -------------  -------------  -------  --------------------------  -------
#> bit64           0.9-7.1        0.9-7          CRAN     https://cran.rstudio.com/   x      
#> data.table      1.13.0         1.12.8         CRAN     https://cran.rstudio.com/   x      
#> elmr            deb0e27df...   7a2be4537...   GitHub   natverse                    x      
#> ff              2.2-14.2       2.2-14         CRAN     https://cran.rstudio.com/   x      
#> flycircuit      1b7b48e29...   cc4594f47...   GitHub   natverse                    x      
#> git2r           0.27.1         0.26.1         CRAN     https://cran.rstudio.com/   x      
#> insectbrainr    6331b4df6...   8fef94a05...   GitHub   natverse                    x      
#> mouselightr     9c2ce1c31...   8e26b7702...   GitHub   natverse                    x      
#> nat.flybrains   28ff33213...   36c622a15...   GitHub   natverse                    x      
#> nat.jrcbrains   85ed4a791...   44c95667e...   GitHub   natverse                    x      
#> neuprintr       7403d3ce2...   8ab03b744...   GitHub   natverse                    x      
#> RCurl           1.98-1.2       1.98-1.1       CRAN     https://cran.rstudio.com/   x      
#> tibble          b4eec19dd...   3f4e5dfae...   GitHub   tidyverse                   x      
#> tidyr           1.1.0          1.0.3          CRAN     https://cran.rstudio.com/   x      
#> xfun            0.16           0.15           CRAN     https://cran.rstudio.com/   x      
#> XML             NA             3.99-0.3       CRAN     https://cran.rstudio.com/   x

You can then update like so:

natverse_update(update = TRUE)

However, if you are in a hurry and want to save time from the questions use like below:

natverse_update(update=TRUE, upgrade = 'always')

If want to upgrade the natverse package itself:

remotes::update_packages('natverse')

fafbseg's People

Contributors

alexanderbates avatar emilkind avatar jefferis avatar mmc46 avatar perlman avatar siqifang avatar sridharjagannathan avatar yijieyin avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

fafbseg's Issues

basic manipulation of `ngscene` objects

  • as.character method to turn into URL as an alternative to ngl_encode_url
  • ngl_segments<- to replace existing segments
  • + to add segment ids (when character or integer64?)
  • - to add segment ids (when character or integer64?)
  • xyzmatrix.ngscene<- to replace position
  • xform.ngscene<- to transform the position (e.g. between flywire/fafb, but not sure really worth it since other work required to make the scene usable)

Fix ngl_encode_url for a range of (more) complex scenes

Many flywire scenes could not be properly encoded back into URLs that flywire.ai could open. The key issue turned out to be the handling of segment ids wherever they appear. Neuroglancer expects them to be in an array, even when length 1, but other fields must be a scalar when length 1. This causes problems for jsonlite::toJSON because auto_unbox must be set to TRUE to cope with the large number of scalars, but must be false for segments. This can be achieved by marking segments in the ngscene list with I(), which prevents them from being simplified by toJSON.

ngl_segments needs to be able to expand flywire URLs

See

https://github.com/jefferis/fafbseg/blob/9bd4bd990a4c89da54c763d88efb1bbd808b8b7d/R/ids.R#L95

The problem is that they will normally need to be expanded from flywire short form (the default) to long form (like other neuroglancer instances use)

e.g. from

short="https://ngl.flywire.ai/?json_url=https://globalv1.flywire-daf.com/nglstate/5747205470158848"

to

https://ngl.flywire.ai/#!%7B%22layers%22:%5B%7B%22source%22:%22precomputed://gs://microns-seunglab/drosophila_v0/alignment/image_rechunked%22%2C%22type%22:%22image%22%2C%22blend%22:%22default%22%2C%22shaderControls%22:%7B%7D%2C%22name%22:%22Production-image%22%7D%2C%7B%22tab%22:%22graph%22%2C%22source%22:%22graphene://https://prodv1.flywire-daf.com/segmentation/1.0/fly_v31%22%2C%22type%22:%22segmentation_with_graph%22%2C%22selectedAlpha%22:0.62%2C%22colorSeed%22:1358768360%2C%22segments%22:%5B%22720575940619527173%22%2C%22720575940628130268%22%2C%22720575940630484179%22%5D%2C%22hiddenSegments%22:%5B%22720575940634222734%22%2C%22720575940636364870%22%5D%2C%22skeletonRendering%22:%7B%22mode2d%22:%22lines_and_points%22%2C%22mode3d%22:%22lines%22%7D%2C%22graphOperationMarker%22:%5B%7B%22annotations%22:%5B%5D%2C%22tags%22:%5B%5D%7D%2C%7B%22annotations%22:%5B%5D%2C%22tags%22:%5B%5D%7D%5D%2C%22pathFinder%22:%7B%22color%22:%22#ffff00%22%2C%22pathObject%22:%7B%22annotationPath%22:%7B%22annotations%22:%5B%5D%2C%22tags%22:%5B%5D%7D%2C%22hasPath%22:false%7D%7D%2C%22name%22:%22Production-segmentation_with_graph%22%7D%5D%2C%22navigation%22:%7B%22pose%22:%7B%22position%22:%7B%22voxelSize%22:%5B4%2C4%2C40%5D%2C%22voxelCoordinates%22:%5B115198%2C55453%2C1537%5D%7D%7D%2C%22zoomFactor%22:4.145162302892657%7D%2C%22perspectiveOrientation%22:%5B-0.22566604614257812%2C-0.034010399132966995%2C-0.07959923148155212%2C0.97035151720047%5D%2C%22perspectiveZoom%22:4888.123757966904%2C%22showSlices%22:false%2C%22jsonStateServer%22:%22https://globalv1.flywire-daf.com/nglstate/post%22%2C%22selectedLayer%22:%7B%22layer%22:%22Production-segmentation_with_graph%22%2C%22visible%22:true%7D%2C%22layout%22:%22xy-3d%22%7D

This requires an authenticated all to the flywire server. I have some code that already does this in #15 (see https://github.com/jefferis/fafbseg/blob/2dc800ff191ace8de5d2ced6997834f6f492457c/R/flywire-fetch.R#L26-L28)

colouring ngscene objects

more advanced addition to #55

  • colour_segments How should this work? Need to associate segments with a colour / function. Would be nice if we could do this by nblast results easily

Error: lexical error: invalid char in json text for invalid locations

library(fafbseg)
p.flywire.raw <- cbind(118865, 71338, -2267)
p.flywire.nm <- p.flywire.raw * c(4,4,40)
fafbseg:::mapmany(p.flywire.nm)

produces,

Error: lexical error: invalid char in json text.
                                [{"dx":NaN,"dy":NaN,"x":NaN,"y":NaN,"z
                     (right here) ------^ 

The mapmany function should handle NaN and produce warnings for invalid locations.

The usual usage from the end-user perspective is:

flywire2fafb(p.flywire.nm, method = "mapmany")

produces,

      X  Y      Z
[1,] NA NA -90680
Warning message:
In mapmany(xyzraw, ...) : Internal Server Error (HTTP 500).

switch flywire to 8 x 8 x 40 nm (or more specifically to flexible voxel size)

Probably means

  • switching to new scene URL
  • using that to set voxel size
https://ngl.flywire.ai/#!%7B%22layers%22:%5B%7B%22source%22:%22precomputed://gs://microns-seunglab/drosophila_v0/alignment/image_rechunked%22%2C%22type%22:%22image%22%2C%22blend%22:%22default%22%2C%22shaderControls%22:%7B%7D%2C%22name%22:%22Production-image%22%7D%2C%7B%22source%22:%22graphene://https://prodv1.flywire-daf.com/segmentation/1.0/fly_v31%22%2C%22type%22:%22segmentation_with_graph%22%2C%22segments%22:%5B%22720575940626877799%22%5D%2C%22skeletonRendering%22:%7B%22mode2d%22:%22lines_and_points%22%2C%22mode3d%22:%22lines%22%7D%2C%22graphOperationMarker%22:%5B%7B%22annotations%22:%5B%5D%2C%22tags%22:%5B%5D%7D%2C%7B%22annotations%22:%5B%5D%2C%22tags%22:%5B%5D%7D%5D%2C%22pathFinder%22:%7B%22color%22:%22#ffff00%22%2C%22pathObject%22:%7B%22annotationPath%22:%7B%22annotations%22:%5B%5D%2C%22tags%22:%5B%5D%7D%2C%22hasPath%22:false%7D%7D%2C%22name%22:%22Production-segmentation_with_graph%22%7D%5D%2C%22navigation%22:%7B%22pose%22:%7B%22position%22:%7B%22voxelSize%22:%5B8%2C8%2C40%5D%2C%22voxelCoordinates%22:%5B79290.5%2C36113%2C2189%5D%7D%7D%2C%22zoomFactor%22:8%7D%2C%22perspectiveZoom%22:79%2C%22jsonStateServer%22:%22https://globalv1.flywire-daf.com/nglstate/post%22%2C%22selectedLayer%22:%7B%22layer%22:%22Production-segmentation_with_graph%22%7D%2C%22layout%22:%22xy-3d%22%7D

Error in fafb2flywire during xform_brain

Thank you for developing tools for analyzing FlyWire data in the natverse environment!

I got the following warning when transforming a FlyWire skeleton from 'FlyWire' to 'JFRC2' template.
neuron_JFRC2 <- xform_brain(neuron_fw, sample = 'FlyWire', reference = 'JFRC2')

Transforming neurons using the sequence: FlyWire->FAFB14->JFRC2013->JFRC2
Warning message:
In mapmany(xyzraw, baseurl = baseurl, ...) :
Internal Server Error (HTTP 500).

While neuron_JFRC2 is created, summary(neuron_JFRC2) shows that the cable.length is 0, and plot3d(neuron_JFRC2) does not show anything.

wrong graphene URL for some flywire calls

The URL has changed at some point and API calls like get_leaves fail with the old URL. There may also be an interaction with the version of cloudvolume (see e.g. this slack discussion). This may make it necessary to check the compatibility of the installed cloudvolume and URL.

Bug when fetching data for multiple partners

> partners=flywire_partners(segs)
  |                                                  | 0 % ~calculating  Fetching supervoxel ids for id: 720575940619073968
Finding synapses for supervoxels
Error in dplyr::inner_join(flywireids, df, by = ifelse(partners == "outputs",  : 
  object 'flywireids' not found

Support for Google ffn1 20200412 segmentation.

This is the latest release from Peter Li. See http://fafb-ffn1.storage.googleapis.com/landing.html.

Main thing is to add a new sample url in choose_segmentation
most of the lines are commented out because don't yet know or we need to check but the key one is fafbseg.sampleurl.

this should not yet be the default release given that no catmaid exists yet

 } else if (release == '20200412') {
    list(
      fafbseg.sampleurl = "https://neuroglancer-demo.appspot.com/fafb.html#!%7B%22dimensions%22:%7B%22x%22:%5B4e-9%2C%22m%22%5D%2C%22y%22:%5B4e-9%2C%22m%22%5D%2C%22z%22:%5B4e-8%2C%22m%22%5D%7D%2C%22position%22:%5B108405.96875%2C42452.015625%2C5328.5%5D%2C%22crossSectionScale%22:0.6742069283637876%2C%22projectionOrientation%22:%5B0.849229633808136%2C0.34033116698265076%2C-0.38500097393989563%2C0.12148263305425644%5D%2C%22projectionScale%22:124522.29008158288%2C%22layers%22:%5B%7B%22type%22:%22image%22%2C%22source%22:%22precomputed://gs://neuroglancer-fafb-data/fafb_v14/fafb_v14_orig%22%2C%22tab%22:%22source%22%2C%22name%22:%22fafb_v14%22%2C%22visible%22:false%7D%2C%7B%22type%22:%22image%22%2C%22source%22:%22precomputed://gs://neuroglancer-fafb-data/fafb_v14/fafb_v14_clahe%22%2C%22tab%22:%22source%22%2C%22name%22:%22fafb_v14_clahe%22%7D%2C%7B%22type%22:%22segmentation%22%2C%22source%22:%7B%22url%22:%22precomputed://gs://fafb-ffn1-20200412/segmentation%22%2C%22subsources%22:%7B%22default%22:true%2C%22bounds%22:true%2C%22mesh%22:true%2C%22skeletons%22:true%7D%2C%22enableDefaultSubsources%22:false%7D%2C%22selectedAlpha%22:0.52%2C%22segments%22:%5B%2210088799207%22%2C%2210088799228%22%2C%224870190129%22%2C%2249815370240%22%2C%2249815370259%22%2C%2249815370269%22%2C%2250602257279%22%2C%22710435991%22%2C%229829049855%22%2C%229958285060%22%2C%229958922750%22%2C%229959562422%22%5D%2C%22name%22:%22fafb-ffn1-20200412%22%7D%2C%7B%22type%22:%22annotation%22%2C%22source%22:%22precomputed://gs://neuroglancer-20191211_fafbv14_buhmann2019_li20190805%22%2C%22annotationColor%22:%22#cecd11%22%2C%22shader%22:%22#uicontrol%20vec3%20preColor%20color%28default=%5C%22blue%5C%22%29%5Cn#uicontrol%20vec3%20postColor%20color%28default=%5C%22red%5C%22%29%5Cn#uicontrol%20float%20scorethr%20slider%28min=0%2C%20max=1000%29%5Cn#uicontrol%20int%20showautapse%20slider%28min=0%2C%20max=1%29%5Cn%5Cnvoid%20main%28%29%20%7B%5Cn%20%20setColor%28defaultColor%28%29%29%3B%5Cn%20%20setEndpointMarkerColor%28%5Cn%20%20%20%20vec4%28preColor%2C%200.5%29%2C%5Cn%20%20%20%20vec4%28postColor%2C%200.5%29%29%3B%5Cn%20%20setEndpointMarkerSize%285.0%2C%205.0%29%3B%5Cn%20%20setLineWidth%282.0%29%3B%5Cn%20%20if%20%28int%28prop_autapse%28%29%29%20%3E%20showautapse%29%20discard%3B%5Cn%20%20if%20%28prop_score%28%29%3Cscorethr%29%20discard%3B%5Cn%7D%5Cn%5Cn%22%2C%22shaderControls%22:%7B%22scorethr%22:80%7D%2C%22linkedSegmentationLayer%22:%7B%22pre_segment%22:%22fafb-ffn1-20200412%22%2C%22post_segment%22:%22fafb-ffn1-20200412%22%7D%2C%22filterBySegmentation%22:%5B%22post_segment%22%2C%22pre_segment%22%5D%2C%22name%22:%22synapses_buhmann2019%22%7D%2C%7B%22type%22:%22image%22%2C%22source%22:%7B%22url%22:%22n5://gs://fafb-v14-synaptic-clefts-heinrich-et-al-2018-n5/synapses_dt_reblocked%22%2C%22transform%22:%7B%22matrix%22:%5B%5B1%2C0%2C0%2C0%5D%2C%5B0%2C1%2C0%2C0%5D%2C%5B0%2C0%2C1%2C1%5D%5D%2C%22outputDimensions%22:%7B%22x%22:%5B4e-9%2C%22m%22%5D%2C%22y%22:%5B4e-9%2C%22m%22%5D%2C%22z%22:%5B4e-8%2C%22m%22%5D%7D%7D%7D%2C%22opacity%22:0.73%2C%22shader%22:%22void%20main%28%29%20%7BemitRGBA%28vec4%280.0%2C0.0%2C1.0%2CtoNormalized%28getDataValue%28%29%29%29%29%3B%7D%22%2C%22name%22:%22clefts_Heinrich_etal%22%2C%22visible%22:false%7D%2C%7B%22type%22:%22segmentation%22%2C%22source%22:%22precomputed://gs://neuroglancer-fafb-data/elmr-data/FAFBNP.surf/mesh#type=mesh%22%2C%22tab%22:%22segments%22%2C%22segments%22:%5B%221%22%2C%2210%22%2C%2211%22%2C%2212%22%2C%2213%22%2C%2214%22%2C%2215%22%2C%2216%22%2C%2217%22%2C%2218%22%2C%2219%22%2C%222%22%2C%2220%22%2C%2221%22%2C%2222%22%2C%2223%22%2C%2224%22%2C%2225%22%2C%2226%22%2C%2227%22%2C%2228%22%2C%2229%22%2C%223%22%2C%2230%22%2C%2231%22%2C%2232%22%2C%2233%22%2C%2234%22%2C%2235%22%2C%2236%22%2C%2237%22%2C%2238%22%2C%2239%22%2C%224%22%2C%2240%22%2C%2241%22%2C%2242%22%2C%2243%22%2C%2244%22%2C%2245%22%2C%2246%22%2C%2247%22%2C%2248%22%2C%2249%22%2C%225%22%2C%2250%22%2C%2251%22%2C%2252%22%2C%2253%22%2C%2254%22%2C%2255%22%2C%2256%22%2C%2257%22%2C%2258%22%2C%2259%22%2C%226%22%2C%2260%22%2C%2261%22%2C%2262%22%2C%2263%22%2C%2264%22%2C%2265%22%2C%2266%22%2C%2267%22%2C%2268%22%2C%2269%22%2C%227%22%2C%2270%22%2C%2271%22%2C%2272%22%2C%2273%22%2C%2274%22%2C%2275%22%2C%228%22%2C%229%22%5D%2C%22name%22:%22neuropil-regions-surface%22%2C%22visible%22:false%7D%2C%7B%22type%22:%22mesh%22%2C%22source%22:%22vtk://https://storage.googleapis.com/neuroglancer-fafb-data/elmr-data/FAFB.surf.vtk.gz%22%2C%22shader%22:%22void%20main%28%29%20%7BemitRGBA%28vec4%281.0%2C%200.0%2C%200.0%2C%200.5%29%29%3B%7D%22%2C%22name%22:%22neuropil-full-surface%22%2C%22visible%22:false%7D%2C%7B%22type%22:%22segmentation%22%2C%22source%22:%22precomputed://gs://fafb-ffn1/fafb-public-skeletons%22%2C%22segments%22:%5B%2242%22%5D%2C%22name%22:%22public_skeletons%22%2C%22visible%22:false%7D%5D%2C%22showAxisLines%22:false%2C%22showSlices%22:false%2C%22selectedLayer%22:%7B%22layer%22:%22fafb-ffn1-20200412%22%2C%22visible%22:true%7D%2C%22layout%22:%22xy-3d%22%7D",
     # fafbseg.skeletonuri = "precomputed://gs://fafb-ffn1-20190521/segmentation/skeletons_32nm",
     # fafbseg.brainmaps.volume = "772153499790:fafb_v14:fafb-ffn1-20190521",
     # fafbseg.brainmaps.meshName = "mcws_quad1e6",
      # fafbseg.catmaid = "https://neuropil.janelia.org/tracing/fafb/v14seg-Li-190411.0/",
      # fafbseg.skelziproot = "fafb_ffn_20190522_flat_skeleton32nm512_nnconn215_mc10000_e250_prune10_thresh1000_sparse250"
    )
  }

support for fetching hemibrain dataset

  • this would allow 1. fetching hemibrain meshes using read_cloudvolume_meshes()
    • the github released version of cloudvolume has support for these meshes based on seung-lab/cloud-volume#340 (I'm not sure if this is on pypi)
  • jumping to hemibrain neuroglancer locations (by specifying appropriate coordinates, likely using the sample and reference brains to transform)

Output of dr_fafbseg() points to wrong token helper function

library(fafbseg)
#> Loading required package: nat
#> Loading required package: rgl
#> Registered S3 method overwritten by 'nat':
#>   method             from
#>   as.mesh3d.ashape3d rgl
#> 
#> Attaching package: 'nat'
#> The following object is masked from 'package:rgl':
#> 
#>     wire3d
#> The following objects are masked from 'package:base':
#> 
#>     intersect, setdiff, union
#> Run dr_fafbseg() for a status report on your installation
dr_fafbseg()
#> FlyWire
#> ----
#> ● No valid FlyWire token found. Set your token by doing:
#>   `set_chunkedgraph_token()`
#> Google FFN1 segmentation
set_chunkedgraph_token()
#> Error in set_chunkedgraph_token(): could not find function "set_chunkedgraph_token"

The documentation lists a flywire_set_token function instead.Does the name of the function need editing in the output of dr_fafbseg()?

batch flywire_rootid lookups for faster synaptic partner finding

e.g. in flywire_partners

bench::mark(post=flywire_rootid(synapses$post_svid), pre=flywire_rootid(synapses$pre_svid), joint=flywire_rootid(unique(c(synapses$post_svid, synapses$pre_svid))), check = F)
# A tibble: 3 x 13
  expression   min median `itr/sec` mem_alloc `gc/sec` n_itr  n_gc total_time
  <bch:expr> <bch> <bch:>     <dbl> <bch:byt>    <dbl> <int> <dbl>   <bch:tm>
1 post       2.23s  2.23s     0.448  558.33KB        0     1     0      2.23s
2 pre        2.35s  2.35s     0.426  558.33KB        0     1     0      2.35s
3 joint      2.97s  2.97s     0.337    1.13MB        0     1     0      2.97s

This is for 5865 pre/post lookups or 8738 in joint and indicates that there is a large fixed cost for each query

we may also need to offer the option to chunk when there are very many (>1e5? 1e6?) and should ensure that we are using 64 bit ints rather than character vector input.

Running skeletor example throws error

Running the example in R in http://natverse.org/fafbseg/articles/articles/installing-cloudvolume-meshparty.html, after installing skeletor.

Blender is a requirement, though it is not currently mentioned in docs. It is installed in /Applications/blender.app. For python to see it, I added a symlink to a path reticulate was looking at, /usr/local/bin.

ln -s /Applications/blender.app/Contents/MacOS/Blender /usr/local/bin/blender
# Checking that reticulate finds Blender
reticulate::py_run_string("import os")
reticulate::py_run_string("from distutils.spawn import find_executable")
reticulate::py_run_string("blender_executable = find_executable('blender')")
reticulate::py_run_string("print('Blender executable:', blender_executable)")
Blender executable: /usr/local/bin/blender

# running example in docs
library(natverse)
#> Loading required package: elmr
#> Loading required package: catmaid
#> Loading required package: httr
#> Loading required package: nat
#> Loading required package: rgl
#> Registered S3 method overwritten by 'nat':
#>   method             from
#>   as.mesh3d.ashape3d rgl
#> 
#> Attaching package: 'nat'
#> The following object is masked from 'package:rgl':
#> 
#>     wire3d
#> The following objects are masked from 'package:base':
#> 
#>     intersect, setdiff, union
#> Loading required package: nat.flybrains
#> Loading required package: nat.templatebrains
#> Loading required package: nat.nblast
library(fafbseg)
#> Run dr_fafbseg() for a status report on your installation
choose_segmentation("flywire")
nx=xform_brain(elmr::dense_core_neurons, ref="FlyWire", sample="FAFB14")
xyz =xyzmatrix(nx)
ids = unique(flywire_xyz2id(xyz[sample(1:nrow(xyz),100),]))
neurons = skeletor(ids)
#> Failed: 720575940634367221
#> Error in py_run_string_impl(code, local, convert): CalledProcessError: Command '['/usr/local/bin/blender', '--background', '--python', '/var/folders/by/vvm2pb4s4vlgp5bgqqny8kdm0000gn/T/tmpymlc5rct']' died with <Signals.SIGABRT: 6>.
#> 
#> Detailed traceback: 
#>   File "<string>", line 1, in <module>
#>   File "/opt/miniconda3/envs/flywire_env/lib/python3.8/site-packages/skeletor/preprocessing.py", line 230, in simplify
#>     result = blend.run(_blender_executable
#>   File "/opt/miniconda3/envs/flywire_env/lib/python3.8/site-packages/trimesh/interfaces/generic.py", line 87, in run
#>     check_call(command_run,
#>   File "/opt/miniconda3/envs/flywire_env/lib/python3.8/subprocess.py", line 364, in check_call
#>     raise CalledProcessError(retcode, cmd)
#> Failed: 720575940637192819
#> Error in py_run_string_impl(code, local, convert): CalledProcessError: Command '['/usr/local/bin/blender', '--background', '--python', '/var/folders/by/vvm2pb4s4vlgp5bgqqny8kdm0000gn/T/tmpov7cq59r']' died with <Signals.SIGABRT: 6>.
#> 
#> Detailed traceback: 
#>   File "<string>", line 1, in <module>
#>   File "/opt/miniconda3/envs/flywire_env/lib/python3.8/site-packages/skeletor/preprocessing.py", line 230, in simplify
#>     result = blend.run(_blender_executable
#>   File "/opt/miniconda3/envs/flywire_env/lib/python3.8/site-packages/trimesh/interfaces/generic.py", line 87, in run
#>     check_call(command_run,
#>   File "/opt/miniconda3/envs/flywire_env/lib/python3.8/subprocess.py", line 364, in check_call
#>     raise CalledProcessError(retcode, cmd)
#> Warning in skeletor(ids): 2 ids could not be read and converted to skeletons

With the error, I also get a prompt that Blender has crashed
Screenshot 2020-10-29 at 15 35 38

I can run the python skeletor example without problems.

From dr_fafbseg()

Python
----
python:         /opt/miniconda3/envs/flywire_env/bin/python
libpython:      /opt/miniconda3/envs/flywire_env/lib/libpython3.8.dylib
pythonhome:     /opt/miniconda3/envs/flywire_env:/opt/miniconda3/envs/flywire_env
version:        3.8.5 (default, Sep  4 2020, 02:22:02)  [Clang 10.0.0 ]
numpy:          /opt/miniconda3/envs/flywire_env/lib/python3.8/site-packages/numpy
numpy_version:  1.19.2

NOTE: Python version was forced by RETICULATE_PYTHON

                     module available version
1               cloudvolume      TRUE   3.2.1
2                   DracoPy      TRUE        
3                 meshparty      TRUE   1.8.0
4                  skeletor      TRUE  0.2.10
5                  pykdtree      TRUE        
6                  pyembree      TRUE   0.1.6
7 annotationframeworkclient      TRUE   2.0.1
8            PyChunkedGraph     FALSE        
9                   igneous      TRUE        
                                                                                    path
1               /opt/miniconda3/envs/flywire_env/lib/python3.8/site-packages/cloudvolume
2                                                                                       
3                 /opt/miniconda3/envs/flywire_env/lib/python3.8/site-packages/meshparty
4                  /opt/miniconda3/envs/flywire_env/lib/python3.8/site-packages/skeletor
5                  /opt/miniconda3/envs/flywire_env/lib/python3.8/site-packages/pykdtree
6                  /opt/miniconda3/envs/flywire_env/lib/python3.8/site-packages/pyembree
7 /opt/miniconda3/envs/flywire_env/lib/python3.8/site-packages/annotationframeworkclient
8                                                                                       
9                                                           /Users/mmc46/igneous/igneous

Any ideas on how to fix this?

more informative error for flywire_xyz2id when coordinate space might be wrong

This works:

# get ID
flywire.xyz = "108847.975,62454.2775,3811"
flywire.id = fafbseg::flywire_xyz2id(nat::xyzmatrix(flywire.xyz), rawcoords = TRUE)

However, earlier today I forgot that the default was not rawcoords = TRUE. If I do it with FALSE, I get this error:

flywire.xyz = "108847.975,62454.2775,3811"
flywire.id = fafbseg::flywire_xyz2id(nat::xyzmatrix(flywire.xyz), rawcoords = FALSE)
> Error in parse_url(url) : length(url) == 1 is not TRUE

And didn't immediately realise what was wrong. I also happened to get two separate inquiries over the last few days about why this function was not working, both times it was the same issue.

More informative error message needed?

Installation issues: 'there is no package called memo'

Downloading GitHub repo natverse/fafbseg@HEAD
✔  checking for file ‘/tmp/RtmpDA38AF/remotes3e6f3eb36878/natverse-fafbseg-eba061a/DESCRIPTION’
─  preparing ‘fafbseg’:
✔  checking DESCRIPTION meta-information
─  checking for LF line-endings in source and make files and shell scripts
─  checking for empty or unneeded directories
   Removed empty directory ‘fafbseg/vignettes’
─  building ‘fafbseg_0.9.0.9000.tar.gz’
   
Installing package into ‘/home/travis/R/Library’
(as ‘lib’ is unspecified)
* installing *source* package ‘fafbseg’ ...
** using staged installation
** R
** inst
** byte-compile and prepare package for lazy loading
Error in loadNamespace(name) : there is no package called ‘memo’
Error: unable to load R code in package ‘fafbseg’
Execution halted
ERROR: lazy loading failed for package ‘fafbseg’
* removing ‘/home/travis/R/Library/fafbseg’
* restoring previous ‘/home/travis/R/Library/fafbseg’
Error: Failed to install 'fafbseg' from GitHub:
  (converted from warning) installation of package ‘/tmp/RtmpDA38AF/file3e6f32222185/fafbseg_0.9.0.9000.tar.gz’ had non-zero exit status
Execution halted
The command "Rscript -e 'deps <- remotes::dev_package_deps(dependencies = NA);remotes::install_deps(dependencies = TRUE);if (!all(deps$package %in% installed.packages())) { message("missing: ", paste(setdiff(deps$package, installed.packages()), collapse=", ")); q(status = 1, save = "no")}'" failed and exited with 1 during .

manipulate annotations from ngscene

  • Ideally would allow annotations to set and retrieved using the same interface as the csv in the neuroglancer interface i.e. with a data.frame intermediate
  • some columns may need to be compound

an easy to use edgelist for flywire neurons

I would like to build an easy to use edgelist for flywire neurons. With hemibrainr, you can access one I have made for the hemibrainr google drive:

elist = hemibrainr::hemibrain_elist()

And you get:

# Source:   lazy query [?? x 7]
# Database: sqlite 3.33.0 [/Volumes/GoogleDrive/Shared drives/hemibrainr/hemibrain_neurons/hemibrainr_data.sqlite]
        post        pre post.Label pre.Label count    norm connection       
       <dbl>      <dbl> <chr>      <chr>     <dbl>   <dbl> <chr>            
1  425790257 5813105172 dendrite   dendrite   4296 0.0339  dendrite-dendrite
2 5813105172  425790257 dendrite   dendrite   1739 0.0225  dendrite-dendrite
3  424767514 1196854070 dendrite   axon        987 0.0377  axon-dendrite    
4  424767514  393766777 dendrite   axon        951 0.0363  axon-dendrite    
5  425790257 5813022424 dendrite   axon        829 0.00654 axon-dendrite    
6  425790257 1048172314 dendrite   axon        742 0.00585 axon-dendrite

It is broken down by axon/dendrite. I could make something similar for the flywire neurons that are 'processed' on FlyEM1 each night and put it on the currently private 'hemibrain' google drive, at hemibrain/fafbsynapses.

Keep the same column names? Also add transmitter as top.nt?

Retire fafbseg.zipdivisor option

In the spirit of simplifying setup (like #6), remove the fafbseg.zipdivisor package option and look after this detail transparently for the user. The obvious way to do this is to use a memoised version of the find_zip_divisor() function inside segmentid2zip(). This will be a bit slower than reading a package option (~50µs vs 500 ns) (mostly because of the serialise/digest time inherent in memoisation), but since segmentid2zip() is vectorised this shouldn't be a problem. A specialised memoisastion strategy could be developed if it ever were using an environment.

fix `ngl_encode_url` when only one segment

  • complex error when only one segment due to the fact that neuroglancer insists on getting an
    array for segments but scalar for other fields.
  • R only has vector primitives so the jsonlite provides an option to turn length one vectors into json scalars
  • however this cannot cope with the case where some length 1 vectors must be json scalars and others must be json arrays

Make it easier to choose default segmentations

Should simplify support for the biorxiv segmentation and the latest one out of the box. This means setting the default sample urls appropriately. Perhaps also having a function that returns a url for one or both. While at it, might be a good idea to provide support for skeletons at the most typical locations.

options(fafbseg.sampleurl = "https://neuroglancer-demo.appspot.com/#!%7B%22layers%22:%5B%7B%22source%22:%22precomputed://gs://neuroglancer-fafb-data/fafb_v14/fafb_v14_clahe_sharded%22%2C%22type%22:%22image%22%2C%22name%22:%22fafb_v14_clahe%22%7D%2C%7B%22source%22:%22precomputed://gs://fafb-ffn1-20190521/segmentation%22%2C%22type%22:%22segmentation%22%2C%22segments%22:%5B%220%22%2C%221366959786%22%5D%2C%22skeletonRendering%22:%7B%22mode2d%22:%22lines_and_points%22%2C%22mode3d%22:%22lines%22%7D%2C%22name%22:%22fafb-ffn1-20190521%22%7D%5D%2C%22navigation%22:%7B%22pose%22:%7B%22position%22:%7B%22voxelSize%22:%5B4%2C4%2C40%5D%2C%22voxelCoordinates%22:%5B132181.4375%2C44958.3515625%2C1586.5582275390625%5D%7D%7D%2C%22zoomFactor%22:8%7D%2C%22perspectiveOrientation%22:%5B-0.14806526899337769%2C0.06667085736989975%2C0.30171263217926025%2C0.9394685626029968%5D%2C%22perspectiveZoom%22:1693.2813601504033%2C%22showSlices%22:false%2C%22layout%22:%22xy-3d%22%7D")

options(fafbseg.sampleurl = "https://neuroglancer-demo.appspot.com/#!%7B%22layers%22:%7B%22fafb_v14_clahe%22:%7B%22source%22:%22brainmaps://772153499790:fafb_v14:fafb_v14_clahe%22,%22type%22:%22image%22%7D,%22fafb_v14_16nm_v00c_split3xfill2%22:%7B%22source%22:%22brainmaps://772153499790:fafb_v14:fafb_v14_16nm_v00c_split3xfill2%22,%22type%22:%22segmentation%22%7D%7D,%22navigation%22:%7B%22pose%22:%7B%22position%22:%7B%22voxelSize%22:[8,8,40],%22voxelCoordinates%22:[53323.1017,21251.8736,3282]%7D%7D,%22zoomFactor%22:8%7D,%22showAxisLines%22:false,%22perspectiveOrientation%22:[0.0214,0.4873,-0.505,-0.7121],%22perspectiveZoom%22:1024,%22showSlices%22:false%7D")

consider caching expensive flywire id lookups

rootid->supervoxels

this can be cached essentially permanently since rootids mutate whenever the mapping changes

however they are quite large, so the object store could quickly start taking a lot of space. For example this fairly large neuron

> system.time(fl <- flywire_leaves('720575940619073968'), gcFirst = F)
   user  system elapsed 
  0.278   0.074   4.431 

generates ~ 270000 svids occupying ~ 20 Mb as character vector. This could be reduced to ~ 0.7 Mb by compression of binary data.

Define seed points for (all) neurons within a region of interest

  • ideally would have nice evenly spaced point locations as output
  • could do this by "throwing darts" at the location and using flywire_xyz2id()
  • this is pretty fast (hundreds per second) but doing this exhaustively might still be expensive.
  • could perhaps do it exhaustively by fetching all of the supervoxels within the roi by fetching the segmentation image itself
    • then making sure that we have at least one xyz location for each supervoxel id.
  • there might be efficient ways to use e.g. a 2D voronoi diagram to get nice evenly spaced points

Support for fetching flywire meshes without python

Python dependencies are a problem on Windows. See e.g. DracoPy

  • I have a new package dracor that should enable direct fetching for flywire meshes from R without using the python cloudvolume package. However this method does not yet handle vertex deduplication that cloudvolume does for you when meshes have been encoded as separate fragments

Example with flywire_xyz2id in doc 'The natverse and flywire meshes' returns an error

In http://natverse.org/fafbseg/articles/articles/installing-cloudvolume-meshparty.html, section The natverse and flywire meshes.
In flywire_xyz2id with argument rawcoords = TRUE. In the example, the points should be in nm, so not raw voxel coordinates.

library(natverse)
#> Loading required package: elmr
#> Loading required package: catmaid
#> Loading required package: httr
#> Loading required package: nat
#> Loading required package: rgl
#> Registered S3 method overwritten by 'nat':
#>   method             from
#>   as.mesh3d.ashape3d rgl
#> 
#> Attaching package: 'nat'
#> The following object is masked from 'package:rgl':
#> 
#>     wire3d
#> The following objects are masked from 'package:base':
#> 
#>     intersect, setdiff, union
#> Loading required package: nat.flybrains
#> Loading required package: nat.templatebrains
#> Loading required package: nat.nblast
library(fafbseg)
#> Run dr_fafbseg() for a status report on your installation
choose_segmentation("flywire")
# Points in FAFBv14 (nm) to flywire coordinates (also nm)
points = matrix(c(723086,200499,90960),ncol=3)
flywire.fafb = xform_brain(points, sample='FAFB14', ref="FlyWire")

# Get mesh
id = flywire_xyz2id(flywire.fafb, rawcoords = TRUE)
#> Loading required namespace: reticulate
#> Error in py_call_impl(callable, dots$args, dots$keywords): OutOfBoundsError: Bbox([5100, 1440, 16],[59200, 29600, 7062], dtype=int32) did not fully contain the specified bounding box Bbox([180938, 50173, 90960],[180939, 50174, 90961], dtype=int64).
#> 
#> Detailed traceback: 
#>   File "<string>", line 8, in py_flywire_xyz2id
#>   File "/opt/miniconda3/envs/flywire_env/lib/python3.8/site-packages/cloudvolume/frontends/graphene.py", line 119, in download_point
#>     return self.download(bbox, mip, parallel=parallel, **kwargs)
#>   File "/opt/miniconda3/envs/flywire_env/lib/python3.8/site-packages/cloudvolume/frontends/graphene.py", line 172, in download
#>     bbox = Bbox.create(
#>   File "/opt/miniconda3/envs/flywire_env/lib/python3.8/site-packages/cloudvolume/lib.py", line 372, in create
#>     raise OutOfBoundsError(

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.