array3D_to_matrixList: Convert Between Two-Dimensional Lists and Three-Dimensional...

Description Usage Arguments Details Value Author(s) Examples

View source: R/utilities.R

Description

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.

Usage

1
2
3

Arguments

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.

Details

Sample and locus names are carried over from input to output (dimnames of arr and mat).

Value

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.

Author(s)

Lindsay V. Clark

Examples

 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

ploidyverse/ploidyverseClasses documentation built on May 25, 2019, 2:21 p.m.