These conditions can be checked for a GSP with no inbreeding loops simply by ensuring that the amount of genetic material coming into each individual is the same as the amount going out (either as segregated gametes or as samples). If the amount of material coming out of any individual in the GSP is greater than the amount coming in, then an error is thrown. If the amount coming out is less than the amount coming in, then a warning about the GSP is thrown. Messages printed via message() and warning() indicate which individuals in the GSP are problematic. All problematic individuals are listed before an error is thrown with stop().

check_gsp_for_validity_and_saturation(GP)

Arguments

GP

A gsp in list format as produced by the function prep_gsp_for_hap_dropping(). See the documentation for the return object of prep_gsp_for_hap_dropping() for a description.

Value

This function does not return anything.

Examples

# get the 13 member pedigree in tibble form as the package
# and turn it into a list
GP <- prep_gsp_for_hap_dropping(GSP)

# check it. (This passes)
check_gsp_for_validity_and_saturation(GP)

## The following will show a failure, so we wrap it in tryCatch
## so CRAN check does not flag it as a problem.
# Read in a gsp with errors and then make sure all the
# error in it are caught
bad <- readr::read_csv(system.file("extdata/13-member-ped-with-errors.csv", package = "gscramble"))
#> Rows: 13 Columns: 11
#> ── Column specification ────────────────────────────────────────────────────────
#> Delimiter: ","
#> chr (5): hap1, hap2, hpop1, hpop2, sample
#> dbl (6): ind, par1, par2, ipar1, ipar2, osample
#> 
#>  Use `spec()` to retrieve the full column specification for this data.
#>  Specify the column types or set `show_col_types = FALSE` to quiet this message.

# check_gsp_for_validity_and_saturation() is called internally from
# within prep_gsp_for_hap_dropping(), after creating a list-from GSP.
# This will show the error produced by check_gsp_for_validity_and_saturation().
badL <- tryCatch(
  prep_gsp_for_hap_dropping(bad),
  error = function(x) 0,
  warning = function(x) 0
)
#> Error! Founder with ID 1 missing founder haplotype population information
#> Error! Founder with ID 1 missing valid founder haplotype index
#> Error! Founder with ID 2 cannot also be a sample
#> Warning! Founder with ID 6 is segregating 1 gametes, which is < 2.  This leaves genetic material unused
#> Error! Non-founder with ID 7 has different numbers of gametes coming in from its two parents: from parent ID 2, number of gametes is 1. From parent ID 3, number of gametes is 2
#> Error! Non-founder with ID 7 has 3 incoming gametes, but is requested to use 4 gametes. 2 for its descendants and 2 for its 1 samples.
#> Error! Non-founder with ID 8 has 4 incoming gametes, but is requested to use 6 gametes. 2 for its descendants and 4 for its 2 samples.
#> Warning! Non-founder with ID 12 has 4 incoming gametes, and is requested to use only 2 gametes. 0 for its descendants and 2 for its 1 samples.