SVG: The SVG class for storing annotated SVG (aSVG) instances

View source: R/svg.R

SVG-classR Documentation

The SVG class for storing annotated SVG (aSVG) instances

Description

The SVG class is designed to represent annotated SVG (aSVG) instances.

Usage

SVG(
  coordinate = list(),
  attribute = list(),
  dimension = list(),
  svg = list(),
  raster = list(),
  angle = list()
)

Arguments

coordinate

A named list of x-y coordinates parsed from one or multile aSVG files respectively. Coordinates are represented in three columns x, y, and feature in form of data.frame or tbl, corresponding to x, y coordinates, and spatial features (cellular compartments, tissues, organs, etc.) in aSVGs respectively. The list name slots refer to aSVG instances respectively, e.g. list(SVGInstance1=coordinate1, SVGInstance2=coordinate2).

attribute

A named list of attributes of coordinates in coordinate. Attributes are represented in at least four columns feature, id, fill and stroke in form of data.frame or tbl, corresponding to feature in coordinate, ids of feature, fill colors of feature, and line widths of feature respectively. id can be the same as feature or ontology ids. The list name slots refer to aSVG instances respectively and must match those in coordinate, e.g. list(SVGInstance1=attribute1, SVGInstance2=attribute2).

dimension

A named list of width/height parsed from one or multile aSVG files respectively, which is calculated from coordinate automatically. Each pair of width/height is stored in a named vector. The list name slots refer to aSVG instances respectively and must match those in coordinate, e.g. list(SVGInstance1=c(with=100, height=8), SVGInstance2=c(with=20, height=15)).

svg

A named list of one or multile aSVG instances, each in form of an 'raw' object returned by xml_serialize. The list name slots refer to aSVG files respectively and must match those in coordinate, e.g. list(SVGInstance1=svg1, SVGInstance2=svg2).

raster

A named list of directory path(s) of one or multile raster image files (jpg, png) respectively. This argument is relevant only when superimposing raster images with spatial heatmap plots that are created from aSVG images. The default is NULL for each aSVG instance. aSVG images are usually created by using these raster images as templates, otherwise spatial features between the two will not match. The list name slots refer to aSVG instances respectively and must match those in coordinate, e.g. list(SVGInstance1=raster.path1, SVGInstance2=raster.path2).

angle

Applicable in the case of spatially resolved single-cell data. A named list of one or multiple rotation degrees of the shapes with the identifier 'overlay' in one or muptiple aSVGs respectively. The list name slots refer to aSVG instances respectively and must be the same with coordinate, e.g. list(SVGInstance1=90, SVGInstance2=45).

Value

A SVG object.

Author(s)

Jianhai Zhang jzhan067@ucr.edu
Dr. Thomas Girke thomas.girke@ucr.edu

Examples


# The first raste image used as a template to create an aSVG. 
raster.pa1 <- system.file('extdata/shinyApp/data/maize_leaf_shm1.png',
package='spatialHeatmap')
# The first aSVG created with the first template. 
svg.pa1 <- system.file('extdata/shinyApp/data/maize_leaf_shm1.svg',
package='spatialHeatmap')
# The second raster image used as a template to create an aSVG. 
raster.pa2 <- system.file('extdata/shinyApp/data/maize_leaf_shm2.png',
package='spatialHeatmap')
# The second aSVG created with the second template. 
svg.pa2 <- system.file('extdata/shinyApp/data/maize_leaf_shm2.svg',
package='spatialHeatmap')

# Parse these two aSVGs without association with raster images.
svgs <- read_svg(svg.path=c(svg.pa1, svg.pa2), raster.path=NULL)

# Parse these two aSVGs. The raster image paths are provide so as to 
# be associated with respective aSVGs, which will be used when 
# superimposing raster images with SHM plots.
svgs <- read_svg(svg.path=c(svg.pa1, svg.pa2), raster.path=c(raster.pa1, raster.pa2))

# Two aSVG instances are stored in a "SVG" object of "svgs".
names(svgs)
# Access content of "svgs".
svgs[1, ] # The first aSVG instance
svgs[, 'coordinate'][1]; coordinate(svgs)[1] # The coordinates of the first aSVG instance
# Combine two "SVG" objects.
x <- svgs[1, ]; y <- svgs[2, ]; cmb(x, y)
# Extract slots from "svgs" and create a new "SVG" object.
lis <- list(cordn=coordinate(svgs), attrb=attribute(svgs), svg=svg_obj(svgs), raster=raster_pa(svgs))
new.svgs <- SVG(coordinate=lis$cordn, attribute=lis$attrb, svg=lis$svg, raster=lis$raster)
# Change aSVG instance names.
names(new.svgs) <- c('aSVG1', 'aSVG2')

jianhaizhang/spatialHeatmap documentation built on July 31, 2024, 2:59 a.m.