ngl_segments: Helper function to turn diverse inputs into neuroglancer...

View source: R/ids.R

ngl_segmentsR Documentation

Helper function to turn diverse inputs into neuroglancer segment ids

Description

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).

include_hidden

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 when must_work=T, but will be returned as id 0 without error when must_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.

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.

Value

Numeric (or character) vector of segment ids, taken from the first segmentation layer (with a warning) if the scene contains more than one.

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))
# turns these into numeric
ngl_segments(c("10950626347", "10952282491", "13307888342"), as_character=FALSE)


u="https://ngl.flywire.ai/?json_url=https://globalv1.flywire-daf.com/nglstate/5409525645443072"
ngl_segments(u, as_character = TRUE)
sc=ngl_decode_scene(u)
# set segments
ngl_segments(sc) <- c("720575940621039145")
# or a shortcut to add ids
sc=sc+c("720575940621039145", "720575940626877799")
sc
## Not run: 
# paste resultant URL to clipboard to use in neuroglancer
clipr::write_clip(as.character(sc))

## End(Not run)

# you can also modify the URL directly
ngl_segments(u)=c("720575940621039145", "720575940626877799")


## Not run: 
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)

## End(Not run)

natverse/fafbseg documentation built on Nov. 11, 2024, 9:50 p.m.