Skip to contents

Helper function to parse the number of causal SNPs with percentage and average modifiers.

Usage

parse_num_causal_snps(value)

Arguments

value

Character string representing the number of causal SNPs.

Value

A list containing the parsed number of causal SNPs and the type (percent or count).

Examples

parse_num_causal_snps(10)       # 10 SNPs
#> $value
#> [1] 10
#> 
#> $is_pct
#> [1] FALSE
#> 
parse_num_causal_snps("10")     # can also accept string format
#> $value
#> [1] 10
#> 
#> $is_pct
#> [1] FALSE
#> 
parse_num_causal_snps("50pct")    # 50% of observed SNPs
#> $value
#> [1] 0.5
#> 
#> $is_pct
#> [1] TRUE
#> 
parse_num_causal_snps("5avg")     # Average of 5 SNPs, sampled from truncated Poisson distribution
#> $value
#> [1] 5
#> 
#> $is_pct
#> [1] FALSE
#> 
parse_num_causal_snps("0avg")     # Invalid: Average number of causal SNPs must be at least 1
#> Error in parse_num_causal_snps("0avg"): Average number of causal SNPs must be at least 1
parse_num_causal_snps("101pct")   # Invalid: Percentage must be in (0, 100]
#> Error in parse_num_causal_snps("101pct"): Percentage of causal SNPs must be in (0, 100].
parse_num_causal_snps("invalid")  # Invalid format
#> Error in if (num_tmp < 1) {    stop("Number of causal SNPs must be at least 1")}: missing value where TRUE/FALSE needed