ae()
provides a handy shortcut to extract a vector of allelic
expression ratios for a DAE SNP on a set of samples.
ae_hom()
and ae_het()
also extract a vector of allelic expression ratios
but for the corresponding homozygous or heterozygous samples of the candidate
SNP, respectively.
Arguments
- dae_snp
A string indicating the identifier of the DAE SNP.
- ae
A data frame of expression values. Each row is for a locus. The locus identity is indicated in the first column. Remaining columns are samples.
- samples
Either a logical or an integer vector indicating which samples in the
ae
data table are to be selected.- drop_na
Whether to drop
NA
values in the returned value.- candidate_snp
A string indicating the identifier of the candidate SNP.
- zygosity
A data frame of zygosity levels:
"hom"
for homozygous or"het"
for heterozygous. Each row is for a locus. The locus identity is indicated in the first column and namedsnp
. Remaining columns are samples.
Examples
# Let us load some dummy data
zygosity <- read_snp_zygosity(file = daeqtlr_example("zygosity.csv"))
ae <- read_ae_ratios(file = daeqtlr_example("ae.csv"))
# Select all allelic expression ratios of rsX019
ae('rsX019', ae = ae, drop_na = FALSE)
#> [1] NA NA NA NA NA NA
#> [7] -0.78121260 NA NA -0.19801280 -0.27931810 NA
#> [13] NA NA NA -0.92423460 -0.03798342 0.03065449
#> [19] NA 0.10446470 NA NA NA NA
#> [25] NA NA NA -0.23169140 NA NA
#> [31] NA NA -0.32567110 NA NA NA
#> [37] NA NA NA -0.15817040 NA -0.44861720
#> [43] NA NA NA 0.09732815 NA NA
#> [49] NA NA
# Select only the first 5 samples
ae('rsX019', ae = ae, samples = 1:10, drop_na = FALSE)
#> [1] NA NA NA NA NA NA
#> [7] -0.7812126 NA NA -0.1980128
ae('rsX019', ae = ae, samples = 1:10, drop_na = TRUE)
#> [1] -0.7812126 -0.1980128
# Use a logical vector to select samples that meet a requirement, e.g.
# heterozygous samples only. Note that `is_het()` is useful here.
(het_samples_for_rsX019 <- is_het(zygosity = zygosity, snp = 'rsX019'))
#> [1] FALSE FALSE FALSE FALSE FALSE FALSE TRUE FALSE FALSE TRUE TRUE FALSE
#> [13] TRUE FALSE FALSE TRUE TRUE TRUE FALSE TRUE FALSE FALSE FALSE FALSE
#> [25] FALSE FALSE FALSE TRUE FALSE FALSE FALSE FALSE TRUE FALSE FALSE FALSE
#> [37] FALSE FALSE FALSE TRUE FALSE TRUE FALSE FALSE FALSE TRUE FALSE FALSE
#> [49] FALSE FALSE
ae('rsX019', ae = ae, samples = het_samples_for_rsX019, drop_na = FALSE)
#> [1] -0.78121260 -0.19801280 -0.27931810 NA -0.92423460 -0.03798342
#> [7] 0.03065449 0.10446470 -0.23169140 -0.32567110 -0.15817040 -0.44861720
#> [13] 0.09732815
# If you want the allelic ratios for samples that are simultaneously:
# - heterozygous for rsX019
# - homozygous for rsX002
(hom_samples_for_rsX002 <- is_hom(zygosity = zygosity, snp = 'rsX002'))
#> [1] TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE FALSE TRUE
#> [13] TRUE TRUE TRUE TRUE TRUE FALSE TRUE TRUE TRUE TRUE TRUE TRUE
#> [25] TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE FALSE
#> [37] TRUE TRUE TRUE TRUE TRUE TRUE TRUE FALSE FALSE TRUE TRUE TRUE
#> [49] TRUE FALSE
ae(
dae_snp = 'rsX019',
ae = ae,
samples = het_samples_for_rsX019 & hom_samples_for_rsX002,
drop_na = FALSE
)
#> [1] -0.78121260 -0.19801280 NA -0.92423460 -0.03798342 0.10446470
#> [7] -0.23169140 -0.32567110 -0.15817040 -0.44861720 0.09732815
# Or more simply:
ae_hom('rsX019', 'rsX002', zygosity, ae, drop_na = FALSE)
#> [1] -0.78121260 -0.19801280 NA -0.92423460 -0.03798342 0.10446470
#> [7] -0.23169140 -0.32567110 -0.15817040 -0.44861720 0.09732815
# Compare with the previous
ae_hom('rsX019', 'rsX002', zygosity, ae, drop_na = TRUE)
#> [1] -0.78121260 -0.19801280 -0.92423460 -0.03798342 0.10446470 -0.23169140
#> [7] -0.32567110 -0.15817040 -0.44861720 0.09732815