countBug counts the frequency of the most commonly identified bug in a simulated signature. getCriticalN performs a Monte Carlo simulation to estimate the number of times the most frequent taxon is expected to be observed in a list of signatures

getCriticalN(relevant.sigs, siglengths, alpha = 0.05, nsim = 1000)

Arguments

relevant.sigs

a list of signatures that form the "background" from which taxa for simulated signatures will be drawn. These are used to estimate how frequently taxa occur

siglengths

The sizes of signatures found in a set of related studies. Simulated signatures will match these in number and size.

alpha

Probability at which a critical threshold will be calculated (default: 0.05)

nsim

Number of simulations (default: 1000)

Value

The 1 - alpha quantile of Monte Carlo simulated values for the maximum number of times any taxon is identified.

Details

E.g. for alpha = 0.05, we expect only a 5

Examples

full.dat <- bugsigdbr::importBugSigDB()
#> Using cached version from 2025-01-30 21:57:36
my.dat <- full.dat[full.dat$Curator == "Mst Afroza Parvin", ]
relevant.dat <- full.dat[full.dat$`Body site` %in% my.dat$`Body site`, ]
relevant.sigs <- bugsigdbr::getSignatures(my.dat)
my.sigs.increased <- relevant.sigs[grep("UP", names(relevant.sigs))]
(my.siglengths <- sapply(my.sigs.increased, length))
#>                                         bsdb:304/1/1_Antimicrobial-agent:oral-intake-of-vancomycin-(directed-against-Gram-positive-bacteria)_vs_or-placebo-(microcrystalline-cellulose)_UP 
#>                                                                                                                                                                                         18 
#>                                                                                       bsdb:307/1/1_Antimicrobial-agent:moxifloxacin-treated-group-(MXF)_vs_Negative-control-group-(CLT)_UP 
#>                                                                                                                                                                                          2 
#>                                                                     bsdb:307/2/1_Antimicrobial-agent:DAV132+moxifloxacin-treated-group-(MXF+DAV132)_vs_moxifloxacin-treated-group-(MXF)_UP 
#>                                                                                                                                                                                         34 
#>                                                                         bsdb:307/3/1_Antimicrobial-agent:DAV132+moxifloxacin-treated-group-(MXF+DAV132)_vs_Negative-control-group-(CLT)_UP 
#>                                                                                                                                                                                          2 
#>                                                                               bsdb:315/1/1_Antimicrobial-agent:Infants-to-mothers-received-IAP_vs_Infants-to-mothers-didn't-receive-IAP_UP 
#>                                                                                                                                                                                          5 
#>                                                         bsdb:315/2/1_Antimicrobial-agent:Breast-fed-Infants-to-mothers-received-IAP_vs_breast-fed-Infants-to-mothers-didn't-receive-IAP_UP 
#>                                                                                                                                                                                          2 
#>                                                       bsdb:315/3/1_Antimicrobial-agent:Formula-fed-Infants-to-mothers-received-IAP_vs_Formula-fed-Infants-to-mothers-didn't-receive-IAP_UP 
#>                                                                                                                                                                                          1 
#>                                                              bsdb:316/1/1_Premature-birth:2-day-old-Pre-term-infants_vs_2-day-old-Full-term-infants(born-after-uncomplicated-pregnancy)_UP 
#>                                                                                                                                                                                          7 
#>                                                                    bsdb:316/2/1_Premature-birth:10-day-old-Pre-term_vs_10-day-old-Full-term-infants(born-after-uncomplicated-pregnancy)_UP 
#>                                                                                                                                                                                          3 
#>                                                                                  bsdb:316/3/1_Premature-birth:30-and-90-day-old-Pre-term-infants_vs_30-and-90-day-old-Full-term-infants_UP 
#>                                                                                                                                                                                          1 
#>      bsdb:316/9/1_Antimicrobial-agent:30-day-old-pre-tem-neonates-with-mothers-exposed-to-antibiotics-(IAP)_vs_30-day-old-full-term-neonates-not-exposed-to-antibiotics-(IAP/postnatal)_UP 
#>                                                                                                                                                                                          1 
#>                     bsdb:320/1/1_Antimicrobial-agent:infants(6-weeks)-to-mothers-exposed-to-intrapartum-antibiotic_vs_infants-(6-weeks)-to-mothers-unexposed-to--intrapartum-antibiotic_UP 
#>                                                                                                                                                                                          4 
#>                       bsdb:320/2/1_Antimicrobial-agent:infants(1-year)-to-mothers-exposed-to-intrapartum-antibiotic_vs_infants-(1-year)-to-mothers-unexposed-to--intrapartum-antibiotic_UP 
#>                                                                                                                                                                                          4 
#>                                     bsdb:320/4/1_Antimicrobial-agent:infants(1-year)-to-mothers-exposed-to-the-penicillin-group_vs_infants-(1-year)-to-mothers-unexposed-to--antibiotic_UP 
#>                                                                                                                                                                                          2 
#>                                bsdb:320/5/1_Antimicrobial-agent:infants(6-weeks)-to-mothers-exposed-to-multi-class-antibiotics_vs_infants-(6-weeks)-to-mothers-unexposed-to--antibiotic_UP 
#>                                                                                                                                                                                          1 
#>                                          bsdb:327/1/1_Antimicrobial-agent:infants-who-received-short-term-or-long-term-antibiotic-treatment---week-1_vs_control-(no-treatment)---week-1_UP 
#>                                                                                                                                                                                          1 
#>                                                     bsdb:327/2/1_Antimicrobial-agent:infants-received-long-term(>5days)-antibiotic-treatment---week-2_vs_control(no-treatment)---week-2_UP 
#>                                                                                                                                                                                          1 
#>                                                                                         bsdb:329/1/1_Antimicrobial-agent:Postnatal-antibiotic-group-(2-day-old-infant)_vs_control-group_UP 
#>                                                                                                                                                                                          2 
#>                                                                                                        bsdb:329/3/1_Antimicrobial-agent:IAP-group-(6-month-old-infant)_vs_control-group_UP 
#>                                                                                                                                                                                          2 
#>                                                                                     bsdb:329/4/1_Antimicrobial-agent:IAP+postnatal-antibiotic-group-(2-day-old-infant)_vs_control-group_UP 
#>                                                                                                                                                                                          1 
#>                                                                                   bsdb:329/6/1_Antimicrobial-agent:IAP+postnatal-antibiotic-group-(6-month-old-infant)_vs_control-group_UP 
#>                                                                                                                                                                                          1 
#>                                     bsdb:334/1/1_Antimicrobial-agent:infants(14-d-old)-exposed-to-prenatal-antibiotic-therapy-(PAT-group)_vs_prenatal-antibiotic-free-group-(PAF-group)_UP 
#>                                                                                                                                                                                          3 
#>                                                        bsdb:334/2/1_Antimicrobial-agent:infants-exposed-to-antibiotic->7day-(H-group)_vs_infants-exposed-to-antibiotic-<=7day-(L-group)_UP 
#>                                                                                                                                                                                          1 
#>                                            bsdb:336/1/1_Antimicrobial-agent:combination-of-penicillin-and-moxalactam-group-(postnatal-day-3)_vs_Antibiotic-free-group-(postnatal-day-3)_UP 
#>                                                                                                                                                                                          5 
#>                                                             bsdb:336/2/1_Antimicrobial-agent:piperacillin-tazobactam-group-(postnatal-day-3)_vs_Antibiotic-free-group-(postnatal-day-3)_UP 
#>                                                                                                                                                                                          2 
#>                                            bsdb:336/3/1_Antimicrobial-agent:combination-of-penicillin-and-moxalactam-group-(postnatal-day-7)_vs_Antibiotic-free-group-(postnatal-day-7)_UP 
#>                                                                                                                                                                                          2 
#>                                                             bsdb:336/4/1_Antimicrobial-agent:piperacillin-tazobactam-group-(postnatal-day-7)_vs_Antibiotic-free-group-(postnatal-day-7)_UP 
#>                                                                                                                                                                                          2 
#>       bsdb:337/1/1_Antimicrobial-agent:3-month-old-infants-exposed-to-antibiotics-in-the-second-trimester_vs_3-month-old-infants-not-exposed-to-antibiotics-during-the-second-trimester_UP 
#>                                                                                                                                                                                          2 
#> bsdb:337/3/1_Antimicrobial-agent:12-month-old-infants-exposed-to-antibiotics-during-the-second-trimester_vs_12-month-old-infants-not-exposed-to-antibiotics-during-the-second-trimester_UP 
#>                                                                                                                                                                                          4 
#>                                                                                                                           bsdb:338/1/1_Obesity:obese-children_vs_normal-weight-children_UP 
#>                                                                                                                                                                                          5 
#>                                                                                                                           bsdb:338/2/1_Obesity:obese-children_vs_normal-weight-children_UP 
#>                                                                                                                                                                                         44 
#>                                                                                                                                         bsdb:347/1/1_Obesity:obese-children_vs_controls_UP 
#>                                                                                                                                                                                         10 
#>                                                                                                                                    bsdb:348/1/1_Obesity:obese-children_vs_lean-children_UP 
#>                                                                                                                                                                                          2 
#>                                                                                                                               bsdb:348/2/1_Obesity:overweight-children_vs_lean-children_UP 
#>                                                                                                                                                                                          2 
#>                                                                                                                                    bsdb:348/3/1_Obesity:obese-children_vs_lean-children_UP 
#>                                                                                                                                                                                          1 
#>                                                                                                                               bsdb:348/4/1_Obesity:overweight-children_vs_lean-children_UP 
#>                                                                                                                                                                                          1 
#>                                                                                                                           bsdb:350/1/1_Obesity:Obese-children-(O)_vs_Normal-weight-(NW)_UP 
#>                                                                                                                                                                                          3 
#>                                                                                                        bsdb:350/2/1_Obesity:Obesity-with-metabolic-syndrome-(OMS)_vs_Normal-weight-(NW)_UP 
#>                                                                                                                                                                                         13 
#>                                                                                                                                       bsdb:351/1/1_Obesity:overweight/obesity_vs_normal_UP 
#>                                                                                                                                                                                          1 
#>                                                                                                                                                 bsdb:353/1/1_Obesity:obese_vs_non-obese_UP 
#>                                                                                                                                                                                          1 
#>                                                                                                                  bsdb:354/1/1_Obesity:overweight/obese_vs_control-(BMI-at-normal-range)_UP 
#>                                                                                                                                                                                          1 
#>                                                                                            bsdb:355/1/1_Obesity:obese-(obese/overweight/morbidly-obese)_vs_control-(lean/normal-weight)_UP 
#>                                                                                                                                                                                          1 
#>                                                                                                                                    bsdb:362/1/1_Obesity:obese_vs_normal-weight-children_UP 
#>                                                                                                                                                                                          1 
#>                                                                                                                                             bsdb:367/1/1_Obesity:obese_vs_normal-weight_UP 
#>                                                                                                                                                                                          6 
#>                                                                                                                                             bsdb:369/1/1_Obesity:obese_vs_normal-weight_UP 
#>                                                                                                                                                                                          4 
#>                                                                                                                  bsdb:369/2/1_Obesity:after-onset-of-obesity_vs_before-onset-of-obesity_UP 
#>                                                                                                                                                                                          4 
#>                                                                                                                               bsdb:371/4/1_Obesity:overweight-subjects_vs_lean-subjects_UP 
#>                                                                                                                                                                                          1 
#>                                                                                                                      bsdb:373/1/1_Obesity:overweight-children_vs_normal-weight-children_UP 
#>                                                                                                                                                                                          6 
#>                                                                                                                                      bsdb:373/2/1_Obesity:Overweight-children_vs_Adults_UP 
#>                                                                                                                                                                                         18 
#>                                                                                                                                             bsdb:375/1/1_Obesity:obese_vs_normal-weight_UP 
#>                                                                                                                                                                                          2 
getCriticalN(relevant.sigs, my.siglengths)
#> 95% 
#>   9 
# Compare to observed
frequencySigs(my.sigs.increased)
#>   1239   1578 186803    543    976 135858   1591  39778    853   1224 
#>      6      6      5      5      5      4      4      4      4      3