Stutter model where the expected stutter rate depends on the allele and locus
allele_specific_stutter_model.Rd
Stutter model where the expected stutter rate depends on the allele and locus
Arguments
- stutter_types
List. See stutter_type.
- size_regression
Function, see read_size_regression.
- sex_locus_name
Character vector, defaults to "AMEL".
Value
Object of class stutter_model
to be used by e.g. log_normal_model.
Details
When a pg_model is constructed (see gamma_model), a stutter model can optionally be applied. The allele specific stutter model is commonly used with a log normal model. The expected stutter ratio for a parent allele at a locus is obtained from a linear regression of observed stutter ratios against allele length. For some loci or alleles the linear model may not be satisfactory. To override the expected stutter rates for specific alleles, a list of exceptions can be used. See stutter_type for more detail.
See also
global_stutter_model for a stutter model where the expected stutter ratio does not depend on the locus or parent allele.
Examples
# we will define an allele specific stutter model for back stutter only
# prepare stutter regression
filename_bs_regression <- system.file("extdata",
"GlobalFiler_Stutter_3500.txt",package = "simDNAmixtures")
bs_regression <- read_stutter_regression(filename_bs_regression)
# prepare exceptions, i.e. where does the regression not apply?
filename_bs_exceptions <- system.file("extdata",
"GlobalFiler_Stutter_Exceptions_3500.csv",package = "simDNAmixtures")
bs_exceptions <- read_stutter_exceptions(filename_bs_exceptions)
# prepare a stutter type
backstutter <- stutter_type(name = "BackStutter", delta = -1,
stutter_regression = bs_regression,
stutter_exceptions = bs_exceptions)
# assign stutter model
size_regression <- read_size_regression(system.file("extdata",
"GlobalFiler_SizeRegression.csv",package = "simDNAmixtures"))
bs_model <- allele_specific_stutter_model(list(backstutter), size_regression)
bs_model
#> $stutter_types
#> $stutter_types[[1]]
#> $name
#> [1] "BackStutter"
#>
#> $delta
#> [1] -1
#>
#> $applies_to_all_loci
#> [1] TRUE
#>
#> $regression
#> function (locus, allele)
#> {
#> regression_locus <- regression_df_by_locus[[locus]]
#> if (is.null(regression_locus)) {
#> stop("No stutter regression available for locus ", locus)
#> }
#> intercept <- regression_locus$Intercept
#> slope <- regression_locus$Slope
#> max(min_stutter_ratio, intercept + slope * as.numeric(allele))
#> }
#> <bytecode: 0x55ce0edc0388>
#> <environment: 0x55ce0c44ae68>
#>
#> $exceptions
#> $exceptions$D8S1179
#> 8 10 11 12 13 14 15 16 18
#> 0.03152 0.04864 0.05584 0.06524 0.05913 0.06564 0.07019 0.07451 0.08698
#>
#> $exceptions$D21S11
#> 27 28 29 30 30.2 31 31.2 32 32.2 33.2
#> 0.04241 0.05957 0.05909 0.07504 0.05746 0.07995 0.06253 0.08734 0.07836 0.08319
#>
#> $exceptions$D2S441
#> 10 11 12 13 14 15 16
#> 0.03342 0.05468 0.06129 0.04058 0.03950 0.04500 0.05982
#>
#> $exceptions$D19S433
#> 6.2 8 9 10 11 11.1 11.2 12 12.1 12.2
#> 0.00005 0.00876 0.00876 0.02618 0.03489 0.02618 0.04360 0.04360 0.00005 0.05231
#> 13 13.2 14 14.2 15 15.2 16 16.2 17 17.2
#> 0.05231 0.06102 0.06102 0.06973 0.06973 0.07844 0.07844 0.08715 0.08715 0.09151
#> 18 18.2 19.2
#> 0.09586 0.10457 0.11328
#>
#> $exceptions$TH01
#> 4 5 6 7 8 8.3 9 9.3 10 10.3
#> 0.00223 0.00799 0.01375 0.01951 0.02527 0.00799 0.03103 0.01375 0.03679 0.01375
#> 11 12 13.3
#> 0.04255 0.04831 0.02527
#>
#> $exceptions$SE33
#> 13 14 15 16 17 18 19 20 21 22.2
#> 0.05466 0.05775 0.06570 0.07151 0.07849 0.08581 0.08929 0.09947 0.10593 0.06981
#> 23.2 24.2 25.2 26.2 27.2 28.2 29.2 30.2 31.2 32.2
#> 0.06975 0.08019 0.08294 0.08884 0.09311 0.09721 0.10606 0.11024 0.11982 0.11991
#>
#> $exceptions$D1S1656
#> 8 9 10 11 12 13 13.3 14 14.3 15
#> 0.02644 0.03559 0.04017 0.05389 0.05847 0.06304 0.05389 0.07677 0.03559 0.08134
#> 15.3 16 16.3 17 17.3 18 18.3 19.3
#> 0.04932 0.09351 0.05389 0.09964 0.06304 0.10879 0.07219 0.08134
#>
#> $exceptions$D2S1338
#> 16 17 18 19 20 21 22 23 24 25
#> 0.04892 0.05731 0.06614 0.06862 0.07423 0.08291 0.06979 0.07556 0.08495 0.09530
#> 26
#> 0.10131
#>
#>
#> $get_expected_stutter_ratio
#> function (locus, allele)
#> {
#> exception <- NULL
#> if (!is.null(stutter$exceptions[[locus]])) {
#> if (as.character(allele) %in% names(stutter$exceptions[[locus]])) {
#> exception <- stutter$exceptions[[locus]][[as.character(allele)]]
#> }
#> }
#> if (isTRUE(exception > 0)) {
#> return(exception)
#> }
#> else {
#> return(stutter$regression(locus, allele))
#> }
#> }
#> <bytecode: 0x55ce0ef7cbd0>
#> <environment: 0x55ce0d8a5ae8>
#>
#> attr(,"class")
#> [1] "stutter_type"
#>
#>
#> $size_regression
#> function (locus, allele)
#> {
#> if (has_exceptions) {
#> locus_exceptions <- exceptions[[locus]]
#> if (!is.null(locus_exceptions)) {
#> if (allele %in% names(locus_exceptions)) {
#> size <- locus_exceptions[[allele]]
#> return(size)
#> }
#> }
#> }
#> regression_locus <- regression_df_by_locus[[locus]]
#> if (is.null(regression_locus)) {
#> stop("No size regression available for locus ", locus)
#> }
#> intercept <- regression_locus$Intercept
#> slope <- regression_locus$Slope
#> allele_numeric <- as.numeric(allele)
#> if (has_repeat_length_by_marker) {
#> repeat_length <- repeat_length_by_marker[[locus]]
#> if (!is.null(repeat_length)) {
#> allele_numeric <- repeats_to_decimals(allele_numeric,
#> repeat_length)
#> }
#> }
#> intercept + slope * allele_numeric
#> }
#> <bytecode: 0x55ce0eb8eb40>
#> <environment: 0x55ce0d8f2820>
#>
#> $sex_locus_name
#> [1] "AMEL"
#>
#> $add_expected_stutter
#> function (...)
#> allele_specific_stutter_model_add_expected_stutter(stutter_model,
#> ...)
#> <bytecode: 0x55ce0f5f01c0>
#> <environment: 0x55ce0da7b110>
#>
#> attr(,"class")
#> [1] "stutter_model"