Skip to content

Commit ace0b25

Browse files
committed
wrapped up omics-tests
1 parent 3c65e1f commit ace0b25

21 files changed

Lines changed: 1637 additions & 161 deletions

DESCRIPTION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
Package: OmicFlow
22
Title: Fast and Efficient (Automated) Analysis of Sparse Omics Data
3-
Version: 1.6.0.9003
3+
Version: 1.6.0.9004
44
Date: 2026-08-03
55
Authors@R: c(
66
person(

NEWS.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,9 @@
1111
- test-omics-ordination.R
1212
- test-omics-feature_merge.R
1313
- test-omics-composition.R
14+
- test-omics-alpha_diversity.R
15+
- test-omics-autoFlow.R [SKIP, finish later with issue #43]
16+
- test-omics-foldchange.R [SKIP, finish later with issue #43]
1417
- test-metagenomics.R
1518
- test-metagenomics-write_biom.R
1619
- test-proteomics.R

R/omics-class.R

Lines changed: 21 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -839,12 +839,12 @@ omics <- R6::R6Class(
839839
#' @description
840840
#' Alpha diversity based on \link{diversity}
841841
#' @param col_name A character variable from the `metaData`.
842-
#' @param metric An alpha diversity metric as input to \link{diversity}.
843-
#' @param group_by A column name to perform grouped statistical test in \link{diversity_plot} (default: NULL).
842+
#' @param metric An alpha diversity metric as input to \link{diversity} (default: \code{"shannon"}).
843+
#' @param group_by A column name to perform grouped statistical test in \link{diversity_plot} (default: \code{NULL}).
844844
#' @param Brewer.palID A character name for the palette set to be applied, see \link[RColorBrewer]{brewer.pal} or \link{colormap}.
845845
#' @param evenness A boolean wether to divide diversity by number of species, see \link[vegan]{specnumber}.
846846
#' @param paired A boolean value to perform paired analysis in \link[stats]{wilcox.test} and samplepair subsetting via [`samplepair_subset()`](#method-samplepair_subset)
847-
#' @param p.adjust.method A character variable to specify the p.adjust.method to be used, default is 'fdr'.
847+
#' @param p.adjust.method A character variable to specify the p.adjust.method to be used (default: \code{'fdr'}).
848848
#' @examples
849849
#' library("OmicFlow")
850850
#'
@@ -868,7 +868,7 @@ omics <- R6::R6Class(
868868
#' }
869869
#' @seealso \link{diversity_plot}
870870
alpha_diversity = function(col_name,
871-
metric = c("shannon", "invsimpson", "simpson"),
871+
metric = "shannon",
872872
Brewer.palID = "Set2",
873873
group_by = NULL,
874874
evenness = FALSE,
@@ -884,6 +884,21 @@ omics <- R6::R6Class(
884884
cli::cli_abort("The specified {.val {col_name}} does not exist in the {.field metaData}.")
885885
}
886886

887+
if (!is.null(group_by)) {
888+
if (!is.character(group_by) || length(group_by) != 1) {
889+
cli::cli_abort("{.val {group_by}} must be a character and of length 1")
890+
} else if (!column_exists(group_by, private$.metaData)) {
891+
cli::cli_abort("The specified {.val {group_by}} does not exist in the {.field metaData}.")
892+
}
893+
combined_cols <- c(col_name, group_by)
894+
} else combined_cols <- col_name
895+
896+
if (!is.logical(evenness))
897+
cli::cli_abort("{.val evenness} can only be a `TRUE` or `FALSE`.")
898+
899+
if (!is.logical(paired))
900+
cli::cli_abort("{.val paired} can only be a `TRUE` or `FALSE`.")
901+
887902
if (!c(p.adjust.method %in% stats::p.adjust.methods))
888903
cli::cli_abort("Specified {.val {p.adjust.method}} is not valid. \nValid options: {.val {p.adjust.methods}}")
889904

@@ -907,15 +922,8 @@ omics <- R6::R6Class(
907922
private$.treeData <- .treeData
908923
}, add = TRUE)
909924

910-
# Remove NAs when col_name is specified
911-
if (!is.null(col_name))
912-
self$removeNAs(col_name)
913-
914-
if (!is.null(group_by)) {
915-
combined_cols <- c(col_name, group_by)
916-
} else {
917-
combined_cols <- col_name
918-
}
925+
# Remove NAs from `col_name`
926+
self$removeNAs(col_name)
919927

920928
# Subset by samplepair completion
921929
if ( paired && column_exists(private$.samplepair_id, private$.metaData) )
@@ -1702,13 +1710,6 @@ omics <- R6::R6Class(
17021710
cli::cli_abort("{.val {feature_contrast}} does not exist in {.field featureData}!")
17031711
}
17041712

1705-
if (!is.null(distmat) && !is.character(distmat) || length(distmat) != 1) {
1706-
cli::cli_abort("{.arg distmat} needs to be a character with a length of 1")
1707-
1708-
if (!file.exists(distmat))
1709-
cli::cli_abort("{.arg distmat} does not exists!")
1710-
}
1711-
17121713
## MAIN
17131714
#--------------------------------------------------------------------#
17141715
is_empty = function(obj) {

man/omics.Rd

Lines changed: 4 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

tests/testthat.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ counts_dense_file <- system.file("extdata", "counts_dense.tsv", package = "OmicF
1818
features_file <- system.file("extdata", "features.tsv", package = "OmicFlow")
1919

2020
## Start tests per section
21-
# test_check("OmicFlow", filter = "omics")
21+
test_check("OmicFlow", filter = "omics")
2222
test_check("OmicFlow", filter = "metagenomics")
2323
test_check("OmicFlow", filter = "proteomics")
2424
# test_check("OmicFlow", filter = "metrics")

tests/testthat/_snaps/metagenomics-write_biom.md

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,3 @@
1414
Error in `taxa$write_biom()`:
1515
! file1.biom and file2.biom Needs to contain characters and be length of 1.
1616

17-
---
18-
19-
Code
20-
taxa$write_biom(filename = output_file)
21-
Condition
22-
Error in `taxa$write_biom()`:
23-
! C:\Users\Z289224\AppData\Local\Temp\Rtmp0MhSOc/test.biom Already exists!
24-
Lines changed: 130 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,130 @@
1+
# `omics$alpha_diversity()` -- Argument checks
2+
3+
Code
4+
taxa$alpha_diversity(col_name = 1)
5+
Condition
6+
Error in `taxa$alpha_diversity()`:
7+
! 1 must be a character and of length 1
8+
9+
---
10+
11+
Code
12+
taxa$alpha_diversity(col_name = "1")
13+
Condition
14+
Error in `taxa$alpha_diversity()`:
15+
! The specified "1" does not exist in the metaData.
16+
17+
---
18+
19+
Code
20+
taxa$alpha_diversity(col_name = c("1", "2"))
21+
Condition
22+
Error in `taxa$alpha_diversity()`:
23+
! "1" and "2" must be a character and of length 1
24+
25+
---
26+
27+
Code
28+
taxa$alpha_diversity(col_name = "CONTRAST_sex", group_by = 1)
29+
Condition
30+
Error in `taxa$alpha_diversity()`:
31+
! 1 must be a character and of length 1
32+
33+
---
34+
35+
Code
36+
taxa$alpha_diversity(col_name = "CONTRAST_sex", group_by = "1")
37+
Condition
38+
Error in `taxa$alpha_diversity()`:
39+
! The specified "1" does not exist in the metaData.
40+
41+
---
42+
43+
Code
44+
taxa$alpha_diversity(col_name = "CONTRAST_sex", group_by = c("1", "2"))
45+
Condition
46+
Error in `taxa$alpha_diversity()`:
47+
! "1" and "2" must be a character and of length 1
48+
49+
---
50+
51+
Code
52+
taxa$alpha_diversity(col_name = "CONTRAST_sex", evenness = "FALSE")
53+
Condition
54+
Error in `taxa$alpha_diversity()`:
55+
! "evenness" can only be a `TRUE` or `FALSE`.
56+
57+
---
58+
59+
Code
60+
taxa$alpha_diversity(col_name = "CONTRAST_sex", paired = "FALSE")
61+
Condition
62+
Error in `taxa$alpha_diversity()`:
63+
! "paired" can only be a `TRUE` or `FALSE`.
64+
65+
---
66+
67+
Code
68+
taxa$alpha_diversity(col_name = "CONTRAST_sex", p.adjust.method = "nothing")
69+
Condition
70+
Error in `taxa$alpha_diversity()`:
71+
! Specified "nothing" is not valid. Valid options: "holm", "hochberg", "hommel", "bonferroni", "BH", "BY", "fdr", and "none"
72+
73+
# `omics$alpha_diversity()` -- Behavioral checks
74+
75+
Code
76+
adiv$data
77+
Output
78+
V1 CONTRAST_sex
79+
<num> <char>
80+
1: 3.403898 male
81+
2: 3.776849 female
82+
3: 3.682609 female
83+
4: 3.686005 male
84+
85+
---
86+
87+
Code
88+
adiv$stats
89+
Output
90+
.y. group1 group2 n1 n2 statistic p p.adj p.adj.signif y.position
91+
1 V1 female male 2 2 3 0.6666667 0.6666667 ns 3.78792
92+
groups xmin xmax
93+
1 female, male 1 2
94+
95+
---
96+
97+
Code
98+
taxa
99+
Message
100+
101+
-- <metagenomics> object
102+
metaData: 9 variables x 4 samples
103+
countData: 4 samples x 242 features
104+
featureData: 7 attributes x 242 features
105+
treeData: 242 tips x 241 nodes
106+
107+
---
108+
109+
Code
110+
adiv$data
111+
Output
112+
V1 CONTRAST_sex group_col
113+
<num> <char> <char>
114+
1: 3.403898 male tumor
115+
2: 3.776849 female tumor
116+
3: 3.682609 female healthy
117+
4: 3.686005 male healthy
118+
119+
---
120+
121+
Code
122+
adiv$stats
123+
Output
124+
treatment .y. group1 group2 n1 n2 statistic p p.adj p.adj.signif y.position
125+
1 tumor V1 female male 1 1 1 1 1 ns 3.82176
126+
2 healthy V1 female male 1 1 0 1 1 ns 3.68636
127+
groups xmin xmax
128+
1 female, male NA NA
129+
2 female, male NA NA
130+

0 commit comments

Comments
 (0)