xyzmatrix
gets coordinates from objects containing 3D vertex data
xyzmatrix.list
will parse a list containing triplets of 3
numeric values.
xyzmatrix<-
assigns xyz elements of neuron or dotprops
object and can also handle matrix like objects with columns named X, Y, Z
or x, y, z.
xyzmatrix2str
will convert the XYZ locations associated
with an object to a character vector (by default comma separated).
xyzmatrix2list
will convert the Nx3 matrix of XYZ
locations associated with an object to a list of length N with each element
a vector of length 3.
xyzmatrix(x, ...)
# S3 method for default
xyzmatrix(x, y = NULL, z = NULL, ...)
# S3 method for list
xyzmatrix(x, empty2na = TRUE, ...)
# S3 method for character
xyzmatrix(x, ...)
# S3 method for neuron
xyzmatrix(x, ...)
# S3 method for neuronlist
xyzmatrix(x, ...)
# S3 method for shapelist3d
xyzmatrix(x, ...)
# S3 method for dotprops
xyzmatrix(x, ...)
# S3 method for hxsurf
xyzmatrix(x, ...)
# S3 method for igraph
xyzmatrix(x, ...)
# S3 method for mesh3d
xyzmatrix(x, ...)
xyzmatrix(x) <- value
# S3 method for character
xyzmatrix(x) <- value
xyzmatrix2str(x, format = "%g,%g,%g", sep = NULL)
xyzmatrix2list(x)
# S3 method for neuron
xyzmatrix(x) <- value
# S3 method for dotprops
xyzmatrix(x) <- value
# S3 method for hxsurf
xyzmatrix(x) <- value
# S3 method for igraph
xyzmatrix(x) <- value
# S3 method for shape3d
xyzmatrix(x) <- value
# S3 method for mesh3d
xyzmatrix(x) <- value
# S3 method for neuronlist
xyzmatrix(x) <- value
# S3 method for shapelist3d
xyzmatrix(x) <- value
object containing 3D coordinates
additional arguments passed to methods
separate y and z coordinates
Whether or not to convert empty elements (NULL
or
list()
) into NAs. Default TRUE
.
Nx3 matrix specifying new xyz coords
A sprintf
compatible format string. The default
will give comma separated values.
A character vector specifying a separator string. Overrides
format
when present. The default value of format
is
equivalent to sep=","
.
For xyzmatrix
: Nx3 matrix containing 3D coordinates
For xyzmatrix<-
: Original object with modified coords
Note that xyzmatrix
can extract or set 3D coordinates in a
matrix
or data.frame
that either has exactly 3 columns
or has 3 columns named X,Y,Z or x,y,z. As of Nov 2020, if these
columns are character vectors, they will be correctly converted to numeric
(with a warning for any NA values). As of Jan 2021 if x
is a numeric
vector containing exactly 3 numbers it will be parsed as a 1x3 matrix.
Support has also been added for setting a list containing 3-vectors in each
element.
xyzmatrix
can also both get and set 3D coordinates from a character
vector (including a single data frame column) in which each string encodes
all 3 coordinates e.g. "-1, 4, 10"
. It should handle a range of
separators such as spaces, tabs, commas, semicolons and ignore extraneous
characters such as brackets. Note that data are rounded by
zapsmall
in the replacement version to try to avoid cases
where rounding errors result in long strings of digits to the right of the
decimal place.
Replacement into character vectors introduces a number of corner cases when there are not exactly 3 numbers to replace in the target vector. We handle them as follows:
0 values in target, >0 in replacement: use a default pattern
1-2 values in target, same number of "good" values in replacement: insert those replacement value
1-2 values in target, different number of values in replacement: use
default pattern, give a warning
The default pattern will be the first entry in x
with 3 numbers.
Should there not be such a value, then the pattern will be "x, y,
z"
.
xyzmatrix
# see all available methods for different classes
methods('xyzmatrix')
#> [1] xyzmatrix.character* xyzmatrix.default* xyzmatrix.dotprops*
#> [4] xyzmatrix.hxsurf* xyzmatrix.igraph* xyzmatrix.list*
#> [7] xyzmatrix.mesh3d* xyzmatrix.neuron* xyzmatrix.neuronlist*
#> [10] xyzmatrix.shapelist3d*
#> see '?methods' for accessing help and source code
# ... and for the assignment method
methods('xyzmatrix<-')
#> [1] xyzmatrix<-.character* xyzmatrix<-.default* xyzmatrix<-.dotprops*
#> [4] xyzmatrix<-.hxsurf* xyzmatrix<-.igraph* xyzmatrix<-.list*
#> [7] xyzmatrix<-.mesh3d* xyzmatrix<-.neuron* xyzmatrix<-.neuronlist*
#> [10] xyzmatrix<-.shape3d* xyzmatrix<-.shapelist3d*
#> see '?methods' for accessing help and source code
# basic usage
xyzmatrix(cbind(-1,2,3))
#> X Y Z
#> [1,] -1 2 3
# character vector - useful e.g. when encoded in 1 column of a table
str123="(-1,+2,3)"
xyzmatrix(str123)
#> X Y Z
#> [1,] -1 2 3
# replace
xyzmatrix(str123) <- xyzmatrix(str123)/3
str123
#> [1] "(-0.333333,0.666667,1)"
xyzmatrix(str123) <- xyzmatrix(str123)*3
str123
#> [1] "(-0.999999,2,3)"
n=Cell07PNs[[1]]
xyzmatrix(n)<-xyzmatrix(n)
stopifnot(isTRUE(
all.equal(xyzmatrix(n),xyzmatrix(Cell07PNs[[1]]))
))
head(xyzmatrix2str(kcs20[[1]]))
#> [1] "343.959,72.5024,23.6374" "344.764,73.1412,23.6184"
#> [3] "345.877,74.3274,23.3508" "337.16,80.5844,24.1932"
#> [5] "343.089,71.1413,24.1765" "343.779,71.8842,24.3607"
head(xyzmatrix2str(kcs20[[1]], format="(%g;%g;%g)"))
#> [1] "(343.959;72.5024;23.6374)" "(344.764;73.1412;23.6184)"
#> [3] "(345.877;74.3274;23.3508)" "(337.16;80.5844;24.1932)"
#> [5] "(343.089;71.1413;24.1765)" "(343.779;71.8842;24.3607)"
# if you want to process the xyz locations (here rounded to nearest nm)
# you must extract them from complex objects yourself
xyzmatrix2str(round(xyzmatrix(kcs20[[1]])*1000), format="%d,%d,%d")[1:3]
#> [1] "343959,72502,23637" "344764,73141,23618" "345877,74327,23351"
xyzmatrix2list(kcs20[[1]])[1:2]
#> [[1]]
#> [1] 343.95865 72.50237 23.63742
#>
#> [[2]]
#> [1] 344.76367 73.14120 23.61839
#>