Helper function to turn diverse inputs into neuroglancer segment ids
Source:R/ids.R
ngl_segments.Rd
ngl_segments<-
replaces neuroglancer segments in a
neuroglancer scene parsed by ngl_decode_scene
.
Usage
ngl_segments(
x,
as_character = TRUE,
include_hidden = FALSE,
must_work = TRUE,
unique = FALSE,
...
)
ngl_segments(x) <- value
Arguments
- x
Neuroglancer ids either as a vector of ids (character vector or
integer64
recommended) OR a scene specification as raw JSON. format (character vector), the path to a file on disk, a neuroglancer scene URL (which embeds a JSON scene specification in a single URL), or an R list generated by parsing one of the above.- as_character
Whether to return segments as character rather than numeric vector (the default is character for safety).
Whether to include
hiddenSegments
(typically for flywire scenes).- must_work
if
TRUE
, the default, then an error will be generated if the scene has no segments or if invalid ids are present. Explicit NAs will trigger this error whenmust_work=T
, but will be returned as id 0 without error whenmust_work=F
.- unique
When
TRUE
drops any duplicated ids with a warning- ...
Additional arguments passed to
ngl_decode_scene
- value
Segment ids in any form understandable by
ngl_segments
. This can include character/numeric/int64 ids, a URL, parsed neuroglancer scene etc.
Value
Numeric (or character) vector of segment ids, taken from the first segmentation layer (with a warning) if the scene contains more than one.
Details
For simple vector inputs, ngl_segments
will treat the values
"NA", "NAN", "NULL"
(all case insensitive) and ""
as NA.
ngl_segments<-
chooses the FlyWire style
segmentation_with_graph
layer if it exists otherwise the first
visible segmentation layer. Note that hiddenSegment will be removed
in this process
.
See also
Other neuroglancer-urls:
flywire_ids()
,
flywire_scene()
,
ngl_blank_scene()
,
ngl_decode_scene()
,
ngl_encode_url()
,
open_fafb_ngl()
Examples
# -> character
ngl_segments(c(10950626347, 10952282491, 13307888342))
#> [1] "10950626347" "10952282491" "13307888342"
# turns these into numeric
ngl_segments(c("10950626347", "10952282491", "13307888342"), as_character=FALSE)
#> [1] 10950626347 10952282491 13307888342
# \donttest{
u="https://ngl.flywire.ai/?json_url=https://globalv1.flywire-daf.com/nglstate/5409525645443072"
ngl_segments(u, as_character = TRUE)
#> [1] "720575940621039145" "720575940626877799"
sc=ngl_decode_scene(u)
# set segments
ngl_segments(sc) <- c("720575940621039145")
# or a shortcut to add ids
sc=sc+c("720575940621039145", "720575940626877799")
sc
#> neuroglancer scene with 2 layers and 2 segments (of which 2 shown)
#> name type visible nsegs
#> 1 Production-image image TRUE 0
#> 2 Production-segmentation_with_graph segmentation_with_graph TRUE 2
#> nhidden
#> 1 0
#> 2 0
#> source
#> 1 precomputed://gs://microns-seunglab/drosophila_v0/alignment/image_rechunked
#> 2 graphene://https://prodv1.flywire-daf.com/segmentation/1.0/fly_v31
if (FALSE) { # \dontrun{
# paste resultant URL to clipboard to use in neuroglancer
clipr::write_clip(as.character(sc))
} # }
# you can also modify the URL directly
ngl_segments(u)=c("720575940621039145", "720575940626877799")
# }
if (FALSE) { # \dontrun{
browseURL(u)
## Summary of different classes of input
# from clipboard
ngl_segments(clipr::read_clip())
# URL
ngl_segments("<ngl-scene-url>")
# path to file on disk
ngl_segments("/path/to/scene.json")
# R list
ngl_segments(scenelist)
} # }