From 8514ec105d2d8d38fb7783d7c0b20ab07374a10e Mon Sep 17 00:00:00 2001 From: David Barnett Date: Mon, 12 Apr 2021 13:20:43 +0200 Subject: [PATCH] more tests for comp_barplot --- tests/testthat/_snaps/comp_barplot.md | 72 +++++++++++ .../_snaps/comp_barplot/SAMPLE_order-lean.csv | 39 ++++++ .../comp_barplot/SAMPLE_order-obese.csv | 39 ++++++ .../comp_barplot/SAMPLE_order-overweight.csv | 39 ++++++ .../_snaps/comp_barplot/SAMPLE_order.csv | 39 ++++++ .../comp_barplot/unique_taxa_order-lean.csv | 10 ++ .../comp_barplot/unique_taxa_order-obese.csv | 10 ++ .../unique_taxa_order-overweight.csv | 10 ++ .../_snaps/comp_barplot/unique_taxa_order.csv | 120 ++++++++++++++++++ tests/testthat/test-comp_barplot.R | 55 ++++++++ 10 files changed, 433 insertions(+) create mode 100644 tests/testthat/_snaps/comp_barplot/SAMPLE_order-lean.csv create mode 100644 tests/testthat/_snaps/comp_barplot/SAMPLE_order-obese.csv create mode 100644 tests/testthat/_snaps/comp_barplot/SAMPLE_order-overweight.csv create mode 100644 tests/testthat/_snaps/comp_barplot/SAMPLE_order.csv create mode 100644 tests/testthat/_snaps/comp_barplot/unique_taxa_order-lean.csv create mode 100644 tests/testthat/_snaps/comp_barplot/unique_taxa_order-obese.csv create mode 100644 tests/testthat/_snaps/comp_barplot/unique_taxa_order-overweight.csv create mode 100644 tests/testthat/_snaps/comp_barplot/unique_taxa_order.csv diff --git a/tests/testthat/_snaps/comp_barplot.md b/tests/testthat/_snaps/comp_barplot.md index 5fb94cad..be5400a9 100644 --- a/tests/testthat/_snaps/comp_barplot.md +++ b/tests/testthat/_snaps/comp_barplot.md @@ -1,3 +1,75 @@ +# comp_barplot doesn't change + + Code + levels(p$data$top) + Output + [1] "other" + [2] "Allistipes et rel." + [3] "Clostridium symbiosum et rel." + [4] "Clostridium cellulosi et rel." + [5] "Faecalibacterium prausnitzii et rel." + [6] "Prevotella oralis et rel." + [7] "Oscillospira guillermondii et rel." + [8] "Bacteroides vulgatus et rel." + [9] "Prevotella melaninogenica et rel." + +# list of plots generated by group_by works + + Code + print(p) + Output + [1] "overweight" + Code + levels(plots[[p]]$data$top) + Output + [1] "other" + [2] "Allistipes et rel." + [3] "Clostridium symbiosum et rel." + [4] "Clostridium cellulosi et rel." + [5] "Faecalibacterium prausnitzii et rel." + [6] "Prevotella oralis et rel." + [7] "Oscillospira guillermondii et rel." + [8] "Bacteroides vulgatus et rel." + [9] "Prevotella melaninogenica et rel." + +--- + + Code + print(p) + Output + [1] "lean" + Code + levels(plots[[p]]$data$top) + Output + [1] "other" + [2] "Allistipes et rel." + [3] "Clostridium symbiosum et rel." + [4] "Clostridium cellulosi et rel." + [5] "Faecalibacterium prausnitzii et rel." + [6] "Prevotella oralis et rel." + [7] "Oscillospira guillermondii et rel." + [8] "Bacteroides vulgatus et rel." + [9] "Prevotella melaninogenica et rel." + +--- + + Code + print(p) + Output + [1] "obese" + Code + levels(plots[[p]]$data$top) + Output + [1] "other" + [2] "Allistipes et rel." + [3] "Clostridium symbiosum et rel." + [4] "Clostridium cellulosi et rel." + [5] "Faecalibacterium prausnitzii et rel." + [6] "Prevotella oralis et rel." + [7] "Oscillospira guillermondii et rel." + [8] "Bacteroides vulgatus et rel." + [9] "Prevotella melaninogenica et rel." + # tt_add_topN_var helper works as expected Code diff --git a/tests/testthat/_snaps/comp_barplot/SAMPLE_order-lean.csv b/tests/testthat/_snaps/comp_barplot/SAMPLE_order-lean.csv new file mode 100644 index 00000000..d8997f0d --- /dev/null +++ b/tests/testthat/_snaps/comp_barplot/SAMPLE_order-lean.csv @@ -0,0 +1,39 @@ +"","x" +"1","Sample-208" +"2","Sample-212" +"3","Sample-210" +"4","Sample-209" +"5","Sample-207" +"6","Sample-213" +"7","Sample-214" +"8","Sample-38" +"9","Sample-69" +"10","Sample-182" +"11","Sample-61" +"12","Sample-57" +"13","Sample-50" +"14","Sample-58" +"15","Sample-51" +"16","Sample-60" +"17","Sample-52" +"18","Sample-59" +"19","Sample-204" +"20","Sample-181" +"21","Sample-183" +"22","Sample-35" +"23","Sample-34" +"24","Sample-40" +"25","Sample-37" +"26","Sample-33" +"27","Sample-203" +"28","Sample-32" +"29","Sample-71" +"30","Sample-179" +"31","Sample-68" +"32","Sample-36" +"33","Sample-73" +"34","Sample-39" +"35","Sample-180" +"36","Sample-211" +"37","Sample-178" +"38","Sample-56" diff --git a/tests/testthat/_snaps/comp_barplot/SAMPLE_order-obese.csv b/tests/testthat/_snaps/comp_barplot/SAMPLE_order-obese.csv new file mode 100644 index 00000000..d8997f0d --- /dev/null +++ b/tests/testthat/_snaps/comp_barplot/SAMPLE_order-obese.csv @@ -0,0 +1,39 @@ +"","x" +"1","Sample-208" +"2","Sample-212" +"3","Sample-210" +"4","Sample-209" +"5","Sample-207" +"6","Sample-213" +"7","Sample-214" +"8","Sample-38" +"9","Sample-69" +"10","Sample-182" +"11","Sample-61" +"12","Sample-57" +"13","Sample-50" +"14","Sample-58" +"15","Sample-51" +"16","Sample-60" +"17","Sample-52" +"18","Sample-59" +"19","Sample-204" +"20","Sample-181" +"21","Sample-183" +"22","Sample-35" +"23","Sample-34" +"24","Sample-40" +"25","Sample-37" +"26","Sample-33" +"27","Sample-203" +"28","Sample-32" +"29","Sample-71" +"30","Sample-179" +"31","Sample-68" +"32","Sample-36" +"33","Sample-73" +"34","Sample-39" +"35","Sample-180" +"36","Sample-211" +"37","Sample-178" +"38","Sample-56" diff --git a/tests/testthat/_snaps/comp_barplot/SAMPLE_order-overweight.csv b/tests/testthat/_snaps/comp_barplot/SAMPLE_order-overweight.csv new file mode 100644 index 00000000..d8997f0d --- /dev/null +++ b/tests/testthat/_snaps/comp_barplot/SAMPLE_order-overweight.csv @@ -0,0 +1,39 @@ +"","x" +"1","Sample-208" +"2","Sample-212" +"3","Sample-210" +"4","Sample-209" +"5","Sample-207" +"6","Sample-213" +"7","Sample-214" +"8","Sample-38" +"9","Sample-69" +"10","Sample-182" +"11","Sample-61" +"12","Sample-57" +"13","Sample-50" +"14","Sample-58" +"15","Sample-51" +"16","Sample-60" +"17","Sample-52" +"18","Sample-59" +"19","Sample-204" +"20","Sample-181" +"21","Sample-183" +"22","Sample-35" +"23","Sample-34" +"24","Sample-40" +"25","Sample-37" +"26","Sample-33" +"27","Sample-203" +"28","Sample-32" +"29","Sample-71" +"30","Sample-179" +"31","Sample-68" +"32","Sample-36" +"33","Sample-73" +"34","Sample-39" +"35","Sample-180" +"36","Sample-211" +"37","Sample-178" +"38","Sample-56" diff --git a/tests/testthat/_snaps/comp_barplot/SAMPLE_order.csv b/tests/testthat/_snaps/comp_barplot/SAMPLE_order.csv new file mode 100644 index 00000000..0f692018 --- /dev/null +++ b/tests/testthat/_snaps/comp_barplot/SAMPLE_order.csv @@ -0,0 +1,39 @@ +"","x" +"1","Sample-180" +"2","Sample-37" +"3","Sample-36" +"4","Sample-73" +"5","Sample-211" +"6","Sample-178" +"7","Sample-203" +"8","Sample-179" +"9","Sample-71" +"10","Sample-68" +"11","Sample-32" +"12","Sample-33" +"13","Sample-39" +"14","Sample-40" +"15","Sample-34" +"16","Sample-35" +"17","Sample-52" +"18","Sample-56" +"19","Sample-59" +"20","Sample-60" +"21","Sample-57" +"22","Sample-58" +"23","Sample-214" +"24","Sample-51" +"25","Sample-69" +"26","Sample-50" +"27","Sample-61" +"28","Sample-207" +"29","Sample-208" +"30","Sample-213" +"31","Sample-210" +"32","Sample-209" +"33","Sample-212" +"34","Sample-182" +"35","Sample-38" +"36","Sample-183" +"37","Sample-181" +"38","Sample-204" diff --git a/tests/testthat/_snaps/comp_barplot/unique_taxa_order-lean.csv b/tests/testthat/_snaps/comp_barplot/unique_taxa_order-lean.csv new file mode 100644 index 00000000..eabee2a8 --- /dev/null +++ b/tests/testthat/_snaps/comp_barplot/unique_taxa_order-lean.csv @@ -0,0 +1,10 @@ +"","x" +"1","other" +"2","Allistipes et rel." +"3","Clostridium symbiosum et rel." +"4","Clostridium cellulosi et rel." +"5","Faecalibacterium prausnitzii et rel." +"6","Prevotella oralis et rel." +"7","Oscillospira guillermondii et rel." +"8","Bacteroides vulgatus et rel." +"9","Prevotella melaninogenica et rel." diff --git a/tests/testthat/_snaps/comp_barplot/unique_taxa_order-obese.csv b/tests/testthat/_snaps/comp_barplot/unique_taxa_order-obese.csv new file mode 100644 index 00000000..eabee2a8 --- /dev/null +++ b/tests/testthat/_snaps/comp_barplot/unique_taxa_order-obese.csv @@ -0,0 +1,10 @@ +"","x" +"1","other" +"2","Allistipes et rel." +"3","Clostridium symbiosum et rel." +"4","Clostridium cellulosi et rel." +"5","Faecalibacterium prausnitzii et rel." +"6","Prevotella oralis et rel." +"7","Oscillospira guillermondii et rel." +"8","Bacteroides vulgatus et rel." +"9","Prevotella melaninogenica et rel." diff --git a/tests/testthat/_snaps/comp_barplot/unique_taxa_order-overweight.csv b/tests/testthat/_snaps/comp_barplot/unique_taxa_order-overweight.csv new file mode 100644 index 00000000..eabee2a8 --- /dev/null +++ b/tests/testthat/_snaps/comp_barplot/unique_taxa_order-overweight.csv @@ -0,0 +1,10 @@ +"","x" +"1","other" +"2","Allistipes et rel." +"3","Clostridium symbiosum et rel." +"4","Clostridium cellulosi et rel." +"5","Faecalibacterium prausnitzii et rel." +"6","Prevotella oralis et rel." +"7","Oscillospira guillermondii et rel." +"8","Bacteroides vulgatus et rel." +"9","Prevotella melaninogenica et rel." diff --git a/tests/testthat/_snaps/comp_barplot/unique_taxa_order.csv b/tests/testthat/_snaps/comp_barplot/unique_taxa_order.csv new file mode 100644 index 00000000..2dbe089d --- /dev/null +++ b/tests/testthat/_snaps/comp_barplot/unique_taxa_order.csv @@ -0,0 +1,120 @@ +"","x" +"1","Gemella" +"2","Aeromonas" +"3","Pseudomonas" +"4","Actinomycetaceae" +"5","Uncultured Chroococcales" +"6","Atopobium" +"7","Staphylococcus" +"8","Lactobacillus catenaformis et rel." +"9","Wissella et rel." +"10","Granulicatella" +"11","Brachyspira" +"12","Aquabacterium" +"13","Leminorella" +"14","Moraxellaceae" +"15","Burkholderia" +"16","Corynebacterium" +"17","Bacillus" +"18","Xanthomonadaceae" +"19","Megamonas hypermegale et rel." +"20","Eubacterium limosum et rel." +"21","Propionibacterium" +"22","Lactococcus" +"23","Bilophila et rel." +"24","Oceanospirillum" +"25","Peptostreptococcus micros et rel." +"26","Helicobacter" +"27","Eubacterium cylindroides et rel." +"28","Yersinia et rel." +"29","Clostridium ramosum et rel." +"30","Vibrio" +"31","Catenibacterium mitsuokai et rel." +"32","Uncultured Selenomonadaceae" +"33","Weissella et rel." +"34","Bulleidia moorei et rel." +"35","Eubacterium siraeum et rel." +"36","Uncultured Bacteroidetes" +"37","Coprobacillus catenaformis et rel." +"38","Peptococcus niger et rel." +"39","Eggerthella lenta et rel." +"40","Campylobacter" +"41","Lactobacillus salivarius et rel." +"42","Prevotella ruminicola et rel." +"43","Desulfovibrio et rel." +"44","Fusobacteria" +"45","Haemophilus" +"46","Proteus et rel." +"47","Streptococcus intermedius et rel." +"48","Enterococcus" +"49","Veillonella" +"50","Clostridium stercorarium et rel." +"51","Ruminococcus lactaris et rel." +"52","Collinsella" +"53","Lactobacillus gasseri et rel." +"54","Serratia" +"55","Alcaligenes faecalis et rel." +"56","Anaerovorax odorimutans et rel." +"57","Lactobacillus plantarum et rel." +"58","Bacteroides intestinalis et rel." +"59","Roseburia intestinalis et rel." +"60","Klebisiella pneumoniae et rel." +"61","Eubacterium ventriosum et rel." +"62","Eubacterium hallii et rel." +"63","Clostridium difficile et rel." +"64","Clostridium (sensu stricto)" +"65","Oxalobacter formigenes et rel." +"66","Clostridium colinum et rel." +"67","Ruminococcus gnavus et rel." +"68","Eubacterium biforme et rel." +"69","Megasphaera elsdenii et rel." +"70","Mitsuokella multiacida et rel." +"71","Enterobacter aerogenes et rel." +"72","Papillibacter cinnamivorans et rel." +"73","Bacteroides stercoris et rel." +"74","Tannerella et rel." +"75","Clostridium nexile et rel." +"76","Ruminococcus bromii et rel." +"77","Uncultured Clostridiales II" +"78","Outgrouping clostridium cluster XIVa" +"79","Eubacterium rectale et rel." +"80","Streptococcus mitis et rel." +"81","Lachnobacillus bovis et rel." +"82","Uncultured Mollicutes" +"83","Bacteroides plebeius et rel." +"84","Coprococcus eutactus et rel." +"85","Bifidobacterium" +"86","Phascolarctobacterium faecium et rel." +"87","Anaerostipes caccae et rel." +"88","Sutterella wadsworthia et rel." +"89","Lachnospira pectinoschiza et rel." +"90","Escherichia coli et rel." +"91","Prevotella tannerae et rel." +"92","Streptococcus bovis et rel." +"93","Anaerotruncus colihominis et rel." +"94","Bacteroides splachnicus et rel." +"95","Clostridium leptum et rel." +"96","Dorea formicigenerans et rel." +"97","Akkermansia" +"98","Ruminococcus callidus et rel." +"99","Bacteroides uniformis et rel." +"100","Clostridium sphenoides et rel." +"101","Bacteroides ovatus et rel." +"102","Bryantella formatexigens et rel." +"103","Parabacteroides distasonis et rel." +"104","Uncultured Clostridiales I" +"105","Bacteroides fragilis et rel." +"106","Butyrivibrio crossotus et rel." +"107","Dialister" +"108","Ruminococcus obeum et rel." +"109","Clostridium orbiscindens et rel." +"110","Subdoligranulum variable at rel." +"111","Sporobacter termitidis et rel." +"112","Allistipes et rel." +"113","Clostridium symbiosum et rel." +"114","Clostridium cellulosi et rel." +"115","Faecalibacterium prausnitzii et rel." +"116","Prevotella oralis et rel." +"117","Oscillospira guillermondii et rel." +"118","Bacteroides vulgatus et rel." +"119","Prevotella melaninogenica et rel." diff --git a/tests/testthat/test-comp_barplot.R b/tests/testthat/test-comp_barplot.R index f8b2acc9..92d328d8 100644 --- a/tests/testthat/test-comp_barplot.R +++ b/tests/testthat/test-comp_barplot.R @@ -22,6 +22,61 @@ test_that("fixing tax order of comp_barplot works", { ) }) +test_that("comp_barplot doesn't change", { + local_edition(3) + p <- dietswap %>% + ps_filter(timepoint == 1) %>% + comp_barplot( + tax_level = "Genus", n_taxa = 8, + sample_order = "aitchison", + merge_other = FALSE + ) + coord_flip() + + expect_snapshot_csv( + name = "unique_taxa_order", + object = levels(p$data$unique) + ) + expect_snapshot_csv( + name = "SAMPLE_order", + object = levels(p$data$SAMPLE) + ) + expect_snapshot(levels(p$data$top)) + +}) + +test_that("list of plots generated by group_by works", { + local_edition(3) + plots <- dietswap %>% + ps_filter(timepoint == 1) %>% + comp_barplot( + tax_level = "Genus", + sample_order = "bray", + group_by = "bmi_group" + ) + expect_equal( + object = names(plots), + expected = c("overweight", "lean", "obese") + ) + + for (p in names(plots)){ + expect_snapshot_csv( + name = paste0("unique_taxa_order-", p), + object = levels(plots[[p]]$data$unique) + ) + expect_snapshot_csv( + name = paste0("SAMPLE_order-", p), + object = levels(plots[[p]]$data$SAMPLE) + ) + expect_snapshot( + { + print(p) + levels(plots[[p]]$data$top) + } + ) + } + +}) + test_that("tt_add_topN_var helper works as expected", { local_edition(3) tt <- microViz:::tt_add_topN_var(