Description Usage Arguments Details Value Author(s) Examples
The VCF
class from VariantAnnotation stores
genotype data in matrices, with one matrix for each field. Fields such as
AD
, GP
, and GL
can store multiple values, in which case
the matrix is a two-dimensional list of vectors. Where all vectors are the
same length, however, it can be efficient to work with the data as a
three-dimensional array in R.
These two functions convert genotype data between these two formats, to
make it easier for users and package developers to get their data into and
out of VCF
objects.
1 2 3 | array3D_to_matrixList(arr)
matrixList_to_array3D(mat)
|
arr |
A three-dimensional array with samples in the second dimension and loci in the third dimension. The first dimension can represent unique genotypes, alleles, haplotypes, or allele copy number. |
mat |
A matrix with loci as rows and samples as columns. Each item in the matrix is a vector. All vectors must be the same length. |
Sample and locus names are carried over from input to output (dimnames
of arr
and mat
).
array3D_to_matrixList
returns a matrix formatted like mat
.
matrixList_to_array3D
returns an array formatted like arr
. The
names of the first dimension will be integers converted to character, starting
with zero.
Lindsay V. Clark
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 | # create a dummy dataset for this example
dummy <- array(rnorm(30), dim = c(5, 2, 3),
dimnames = list(as.character(0:4), c("sam1", "sam2"),
c("loc1", "loc2", "loc3")))
# convert to matrix
dummy_mat <- array3D_to_matrixList(dummy)
# example of how data are stored differently
dummy[,1,2]
dummy_mat[[2,1]]
# convert to array
dummy_arr <- matrixList_to_array3D(dummy_mat)
identical(dummy, dummy_arr) # TRUE
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.