Skip to contents

Return QC information to assess loci (MAF, missingness and HWE test). For pseudohaploid data, HWE test is not calculated.

Usage

qc_report_loci(.x, hwe = TRUE, n_cores = bigstatsr::nb_cores(), ...)

# S3 method for class 'gen_tbl'
qc_report_loci(.x, hwe = TRUE, n_cores = bigstatsr::nb_cores(), ...)

# S3 method for class 'grouped_gen_tbl'
qc_report_loci(.x, hwe = TRUE, n_cores = bigstatsr::nb_cores(), ...)

Arguments

.x

a gen_tibble object.

hwe

boolean, whether to compute the HWE exact test (the default). It is never computed for pseudohaploid data.

n_cores

number of cores to be used, it defaults to bigstatsr::nb_cores()

...

currently unused

Value

either a tibble with 3 elements (maf, missingness and hwe_p). For pseudohaploid data, or if hwe = FALSE, a tibble with 2 elements (maf and missingness).

Details

The MAF and the missingness are always computed across all individuals: grouping only affects the HWE test, which is computed within each group. When genotypes are coded as 0, 1, 2 or missing (raw or imputed calls), all statistics are computed in a single pass over the genotypes. With hwe = FALSE, qc_report_loci() thus gives both the MAF and the missingness of each locus, identical to loci_maf() and loci_missingness() on the ungrouped data, reading the genotypes once rather than twice (e.g. to filter loci on both with select_loci_if()).

Examples

# Create a gen_tibble of lobster genotypes
bed_file <-
  system.file("extdata", "lobster", "lobster.bed", package = "tidypopgen")
example_gt <- gen_tibble(bed_file,
  backingfile = tempfile("lobsters"),
  quiet = TRUE
)

# Get a QC report for the loci
example_gt %>% qc_report_loci()
#> This gen_tibble is not grouped. For Hardy-Weinberg equilibrium, `qc_report_loci()` will assume individuals are part of the same population and HWE test p-values will be calculated across all individuals. If you wish to calculate HWE p-values within populations or groups, please use`group_by()` before calling `qc_report_loci()`.
#> # A tibble: 79 × 4
#>    snp_id    maf missingness       hwe_p
#>    <chr>   <dbl>       <dbl>       <dbl>
#>  1 rs3441  0.328      0.0227 0.440      
#>  2 rs4173  0.424      0.0341 0.584      
#>  3 rs6157  0.278      0.0284 0.00293    
#>  4 rs7502  0.423      0.0455 0.479      
#>  5 rs7892  0.101      0.0170 0.305      
#>  6 rs9441  0.307      0.0739 0.784      
#>  7 rs11071 0.123      0.0284 0.00299    
#>  8 rs11183 0.458      0.0568 0.102      
#>  9 rs11291 0.244      0.0455 0.000000944
#> 10 rs12971 0.312      0.0625 0.0242     
#> # ℹ 69 more rows

# Only MAF and missingness (in a single pass over the genotypes), e.g. to
# filter loci on both
loci_qc <- example_gt %>% qc_report_loci(hwe = FALSE)
example_gt %>%
  select_loci_if(loci_qc$maf >= 0.05 & loci_qc$missingness <= 0.2)
#> # A gen_tibble: 79 loci
#> # A tibble:     176 × 3
#>    id    population  genotypes
#>    <chr> <chr>      <vctr_SNP>
#>  1 Ale04 Ale         [0,.,...]
#>  2 Ale05 Ale         [1,0,...]
#>  3 Ale06 Ale         [.,0,...]
#>  4 Ale08 Ale         [.,2,...]
#>  5 Ale13 Ale         [0,.,...]
#>  6 Ale15 Ale         [1,0,...]
#>  7 Ale16 Ale         [0,.,...]
#>  8 Ale17 Ale         [1,.,...]
#>  9 Ale18 Ale         [0,0,...]
#> 10 Ale19 Ale         [2,.,...]
#> # ℹ 166 more rows

# Group by population to calculate HWE within populations
example_gt <- example_gt %>% group_by(population)
example_gt %>% qc_report_loci()
#> # A tibble: 79 × 4
#>    snp_id    maf missingness  hwe_p
#>    <chr>   <dbl>       <dbl>  <dbl>
#>  1 rs3441  0.328      0.0227 0.850 
#>  2 rs4173  0.424      0.0341 0.546 
#>  3 rs6157  0.278      0.0284 0.0834
#>  4 rs7502  0.423      0.0455 1     
#>  5 rs7892  0.101      0.0170 0.298 
#>  6 rs9441  0.307      0.0739 1     
#>  7 rs11071 0.123      0.0284 0.0143
#>  8 rs11183 0.458      0.0568 1     
#>  9 rs11291 0.244      0.0455 0.391 
#> 10 rs12971 0.312      0.0625 0.112 
#> # ℹ 69 more rows