
Filter individuals based on genotyping/missingness rate, heterozygosity and total coverage
Source:R/filter_individuals.R
filter_individuals.RdRemove individuals with bad QC based on:
missingness (genotyping rate)
heterozygosity
coverage (total, median, iqr)
Filter target: Individuals.
Statistics: Missingness, heterozygosity and coverage
Used internally in radr and might be of interest for users who wants to blacklist individuals.
Usage
filter_individuals(
data,
interactive.filter = TRUE,
filter.individuals.missing = NULL,
filter.individuals.heterozygosity = NULL,
filter.individuals.coverage.total = NULL,
filter.individuals.coverage.median = NULL,
filter.individuals.coverage.iqr = NULL,
parallel.core = parallel::detectCores() - 1,
verbose = TRUE,
...
)Arguments
- data
(2 options) A Genomic Data Structure (GDS) file or object generated by radr.
How to get GDS? Use
read_genometo import supported formats.- interactive.filter
Logical indicating whether an interactive filtering session may display diagnostics and ask for thresholds. Default:
interactive.filter = TRUE.- filter.individuals.missing
(optional, double) A proportion above which the individuals are blacklisted and removed from the dataset. Default:
filter.individuals.missing = NULL.- filter.individuals.heterozygosity
(optional, string of doubles) A proportion below and above which the individuals are blacklisted and removed from the dataset. Default:
filter.individuals.heterozygosity = NULL.- filter.individuals.coverage.total
Optional numeric threshold(s) or
"outliers"targeting total coverage per sample. A single numeric value is the minimum accepted total coverage. Two numeric values specify the accepted lower and upper limits."outliers"derives both limits from the coverage distribution. Default:filter.individuals.coverage.total = NULL.- filter.individuals.coverage.median
(optional, string of integers) Target the median coverage per samples. Integers, below and above, that blacklist individuals (removed from the dataset) Default:
filter.individuals.coverage.median = NULL.- filter.individuals.coverage.iqr
(optional, string of integers) Target the IQR (Interquartile Range) coverage per samples. Integers, below and above, that blacklist individuals (removed from the dataset) Default:
filter.individuals.coverage.iqr = NULL.- parallel.core
Number of workers available for parallel operations. Default:
parallel.core = parallel::detectCores() - 1.- verbose
Logical indicating whether progress messages are emitted. Default:
verbose = TRUE.- ...
Additional arguments passed to lower-level screening or filtering functions.
Value
The filtered GDS connection. Individual metadata and active samples are updated in place, so the underlying GDS file is modified. Diagnostic files, individual blacklists, and filtering parameters are written to the function output folder.
Interactive version
The function first displays sample-level missingness, heterozygosity, and coverage diagnostics. It then proceeds through the following branches:
Missingness: asks whether to blacklist samples. If yes, choose the boxplot-outlier statistic or enter the maximum tolerated missing proportion.
Heterozygosity: asks whether to blacklist samples. If yes, choose the outlier limits or enter the minimum and maximum tolerated heterozygosity.
Coverage, when available: separately asks whether to filter total, median, and IQR coverage. For every selected statistic, choose the outlier limits or enter minimum and maximum tolerated values.
The initial yes/no prompts are, respectively,
"Do you want to blacklist samples based on missingness?",
"... based on heterozygosity?", and
"... based on TOTAL/MEDIAN/IQR coverage?". Choosing custom values
leads to the corresponding minimum and maximum threshold questions. Use
interactive.filter = FALSE and explicit arguments for a reproducible
analysis.
Author
Thierry Gosselin thierrygosselin@icloud.com
Examples
if (FALSE) { # \dontrun{
genome <- genometranslator::read_genome("my_genome.gds")
# Inspect all available sample QC statistics interactively.
genome <- radr::filter_individuals(data = genome)
# Alternatively, start from a separate unfiltered GDS for a scripted run.
scripted_genome <- genometranslator::read_genome("my_genome_scripted.gds")
scripted_genome <- radr::filter_individuals(
data = scripted_genome,
interactive.filter = FALSE,
filter.individuals.missing = "outliers",
filter.individuals.heterozygosity = "outliers",
filter.individuals.coverage.total = "outliers"
)
# Project-specific limits can be supplied instead of outlier rules.
another_genome <- genometranslator::read_genome("my_genome_limits.gds")
another_genome <- radr::filter_individuals(
data = another_genome,
interactive.filter = FALSE,
filter.individuals.missing = 0.50,
filter.individuals.heterozygosity = c(0.02, 0.06),
filter.individuals.coverage.total = c(9e5, 5e6)
)
} # }