ngl_layers: Extract and manipulate layers in a neuroglancer scene

View source: R/ids.R

ngl_layersR Documentation

Extract and manipulate layers in a neuroglancer scene

Description

ngl_layers extract the neuroglancer layers with convenience options for selecting layers by characteristics such as visibility, type etc.

ngl_layers<- sets the layers element of a ngscene object, taking care of name/class details.

+.ngscene adds segments or layers to a neuroglancer scene

-.ngscene removes segments or whole layers from a neuroglancer scene. It does not complain if the segment is not present.

Usage

ngl_layers(x, subset = NULL)

ngl_layers(x) <- value

## S3 method for class 'ngscene'
x + y

## S3 method for class 'ngscene'
x - y

Arguments

x

a neuroglancer scene object (see ngscene) or an existing nglayers object (which you probably want to subset).

subset

an expression (evaluated in the style of subset.dataframe) which defined

value

a list specifying one or more neuroglancer layers. This will usually come from a json fragment or another parsed neuroglancer scene. See examples.

y

Segments or layers to add or remove from a neuroglancer scene. Segments are provided as character vectors or by applying ngl_segments to a more complex object. Layers to remove should be the layer name. Layers to add should be in the form of an R list returned by ng_layers or a JSON fragment copied from neuroglancer.

Value

A list of layers with additional class nglayers

Using + and -

There are shortcut methods that allow you to add or subtract segments or layers from neuroglancer scenes. These are designed for convenience in interactive use, but may be a bit fragile for unusual inputs.

See Also

ngl_decode_scene, ngl_layers, ngl_segments, ngl_encode_url

Examples


u="https://ngl.flywire.ai/?json_url=https://globalv1.flywire-daf.com/nglstate/5409525645443072"
sc=ngl_decode_scene(u)
sc
names(ngl_layers(sc))
str(ngl_layers(sc))

str(ngl_layers(sc, nsegs>0))
str(ngl_layers(sc, visible==TRUE))
str(ngl_layers(sc, !visible))
# flywire segmentation
str(ngl_layers(sc, type=="segmentation_with_graph"))
# image or segmentation
str(ngl_layers(sc, type %in% c("image", "segmentation_with_graph")))

# get a sample flywire neuroglancer scene
sc=ngl_decode_scene(system.file("flywire-annotations.json" ,
  package = 'fafbseg'))
sc
# save a copy
sc.orig <- sc
# remove a layer
ngl_layers(sc)=ngl_layers(sc)[-3]
# or using convenient - notation
sc.noann <- sc.orig - "annotation"

# reverse layer order
ngl_layers(sc)=ngl_layers(sc)[2:1]

# keep visible only
ngl_layers(sc) <- ngl_layers(sc, visible)
# visible + multiple segments
ngl_layers(sc) <- ngl_layers(sc, visible & nsegs>0)
# flywire segmentation
ngl_layers(sc) <- ngl_layers(sc, type=="segmentation_with_graph")

# combine layers using + convenience method
sc.noann + ngl_layers(sc.orig)['annotation']
## Not run: 
# combine layers from two scenes
ngl_layers(sc) <- c(ngl_layers(sc), ngl_layers(sc2))
ngl_layers(sc) <- c(ngl_layers(sc)[-(3:4)], ngl_layers(sc2)[3:4])
ngl_layers(sc) <- c(ngl_layers(sc), ngl_layers(sc2)[-1])
ngl_layers(sc) <- c(ngl_layers(sc), ngl_layers(sc2)['annotation'])
sc

# another way to add a single scene
ngl_layers(sc)[[4]] <- ngl_layers(sc2)[[4]]

# add a new layer to a scene by parsing some JSON from the clipboard
# note the double brackets are essential here
ngl_layers(sc)[['jfrc_mesh']] <- jsonlite::fromJSON(clipr::read_clip())

## End(Not run)

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