ngl_decode_scene: Decode and manipulate Neuroglancer scenes (from URLs or JSON...

View source: R/urls.R

ngl_decode_sceneR Documentation

Decode and manipulate Neuroglancer scenes (from URLs or JSON blocks)

Description

ngl_decode_scene takes a Neuroglancer scene from your web browser and turns it into an R list object that can be programmatically manipulated e.g. to add/remove segments. Manipulate these scenes with ngl_segments, ngl_layers. See ngl_encode_url to turn a scene back into a URL to open in your browser.

Usage

ngl_decode_scene(
  x,
  return.json = FALSE,
  simplifyVector = TRUE,
  simplifyDataFrame = FALSE,
  ...
)

Arguments

x

Character vector containing single Neuroglancer URL or a json block

return.json

When TRUE extracts the JSON block in a URL does not parse it to an R list

simplifyVector

coerce JSON arrays containing only primitives into an atomic vector

simplifyDataFrame

coerce JSON arrays containing only records (JSON objects) into a data frame

...

additional arguments passed to jsonlite::fromJSON

Value

An R list with additional class ngscene describing the scene, or, when return.json=TRUE, a character vector.

See Also

URLdecode, fromJSON

Other neuroglancer-urls: flywire_ids(), flywire_scene(), ngl_blank_scene(), ngl_encode_url(), ngl_segments(), open_fafb_ngl()

Examples



# get sample FlyWire URL
fw_url=with_segmentation('flywire31', getOption('fafbseg.sampleurl'))
# only a 0 (dummy) segment id present
ngl_segments(fw_url)
#
fw_sc=ngl_decode_scene(fw_url)
fw_sc
# add two segments
fw_sc=fw_sc+c("720575940621039145", "720575940626877799")
ngl_segments(fw_sc)
# remove that 0 segment
fw_sc=fw_sc-0
ngl_segments(fw_sc)
# repeated segments are ignored i.e. no duplicates
ngl_segments(fw_sc+"720575940621039145")
# convert back to a URL, nb this depends on choose_segmentation
ngl_encode_url(fw_sc)

## Not run: 
# open in your default browser
browseURL(ngl_encode_url(fw_sc))

## End(Not run)


## Not run: 
ngl_decode_scene("<someneuroglancerurl>")

# decode scene from URL currently on clipboard
scene=ngl_decode_scene(clipr::read_clip())

# open a Neuroglancer URL in CATMAID
ngu="<someurl>"
library(elmr)
open_fafb(ngl_decode_scene(ngu))
# Or store the URL rather than opening it
cmu=open_fafb(ngl_decode_scene(ngu), open=FALSE)

## End(Not run)

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