DT2Mat_genos | R Documentation |
Takes a data table of genotypes in long format and converts it into
a matrix in wide format (loci in columns and individuals in rows). The reverse
can also be done. See also DT2Mat_freqs
for converting matrix of frequencies.
DT2Mat_genos(
dat,
sampCol = "SAMPLE",
locusCol = "LOCUS",
genoCol = "GT",
flip = FALSE
)
dat |
Data table or Matrix: The object to transform. If this is a long data table of genotypes coded as per VCF specifications ('0/0', '0/1', '1/1'), or counts of the Alt alleles (0, 1, 2, repsectively). Three columns are required:
The sampled individual ID column serves as the pivot point to convert the long data table into a wide matrix.
If converting from a genotypes matrix to a data table, see argument |
sampCol |
Character: The column name with the sampled individual information. Default is 'SAMPLE'. |
locusCol |
Character: The column name with the locus information. Default is 'LOCUS'. |
genoCol |
Character: The column name with the genotype information. Default is 'GT'. |
flip |
Logical: Instead of converting a (long) data table to a (wide) matrix,
should a (wide) matrix be converted into a (long) data table? Default = |
When flip=FALSE
, converts a data table into a genotype matrix. When
flip=TRUE
, converts a matrix into a data table with three columns: (1) $SAMPLE
,
the sample ID; (2) $LOCUS
, the locus ID; and (3) $GT
,
the Ref allele frequency.
library(genomalicious)
data(data_Genos)
# Convert a long data table to a wide matrix
genoMat <- DT2Mat_genos(
data_Genos,
sampCol='SAMPLE',
locusCol='LOCUS',
genoCol='GT',
flip=FALSE)
genoMat
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.