| is_hom | R Documentation |
This function determines who are the homozygous or heterozygous samples given
a data table of zygosity levels and a SNP of interest. Samples whose zygosity
level is NA will be returned as FALSE.
is_hom(zygosity, snp, na_as_false = TRUE) is_het(zygosity, snp, na_as_false = TRUE)
zygosity |
A data frame of zygosity levels: |
snp |
String with SNP identifier. |
na_as_false |
Whether to return |
A logical vector.
# Let us start by reading in an example data set with zygosity levels
zygosity <- read_snp_zygosity(file = daeqtlr_example("zygosity.csv"))
# Checking out SNP rsX005
zygosity['rsX005']
is_hom(zygosity, 'rsX005')
is_het(zygosity, 'rsX005')
# Translate the logical vector to sample names
# Note that first column is excluded because it is the SNP identifier col
# Homozygous samples
(homs <- colnames(zygosity)[-1][is_hom(zygosity, 'rsX005')])
# Heterozygous samples
(hets <- colnames(zygosity)[-1][is_het(zygosity, 'rsX005')])
# Some samples are neither homozygous nor heterozygous because of NAs
# Note the `- 1` because the first column of `zygosity` is the SNP identifier.
(ncol(zygosity) - 1) - length(c(homs, hets))
# The samples whose zygosity is NA are:
setdiff(colnames(zygosity)[-1], c(homs, hets))
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.