Skip to content

Commit 0e591c5

Browse files
authored
Merge branch 'dev' into add-parallelism
2 parents 82173dd + 2a4eb71 commit 0e591c5

104 files changed

Lines changed: 5510 additions & 2390 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

DESCRIPTION

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
Package: OmicFlow
22
Title: Fast and Efficient (Automated) Analysis of Sparse Omics Data
3-
Version: 1.6.0.9002
4-
Date: 2026-05-19
3+
Version: 1.6.0.9004
4+
Date: 2026-08-03
55
Authors@R: c(
66
person(
77
"Alem", "Gusinac",
@@ -22,32 +22,34 @@ Description:
2222
which serves as a guide to connect all the pieces together by aligning them into a single object that is defined as an 'omics' class.
2323
Once this unified structure is established, users can perform manual subsetting, visualisation, and statistical analysis, or leverage the automated 'autoFlow' method to generate a comprehensive report.
2424
License: MIT + file LICENSE
25-
URL: https://github.com/agusinac/OmicFlow, https://agusinac.github.io/OmicFlow/
25+
URL: https://agusinac.github.io/OmicFlow/
2626
BugReports: https://github.com/agusinac/OmicFlow/issues
2727
Config/testthat/edition: 3
2828
Encoding: UTF-8
2929
Roxygen: list(markdown = TRUE)
3030
Depends:
3131
R (>= 4.3.0)
3232
Imports:
33-
R6,
34-
data.table,
35-
Matrix,
3633
ape,
34+
cli,
35+
data.table,
3736
ggpubr,
3837
ggrepel,
3938
ggplot2,
4039
jsonvalidate,
4140
methods,
41+
Matrix,
4242
patchwork,
43+
R6,
4344
RColorBrewer,
4445
rhdf5,
4546
rstatix,
4647
Rcpp (>= 0.12.6),
4748
RcppParallel (>= 4.3.20),
49+
stats,
50+
utils,
4851
vegan,
49-
yyjsonr,
50-
cli
52+
yyjsonr
5153
Suggests:
5254
DT,
5355
downloadthis,

NAMESPACE

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
export(bray)
44
export(canberra)
55
export(colormap)
6-
export(column_exists)
76
export(composition_plot)
87
export(cosine)
98
export(diversity)
@@ -13,7 +12,6 @@ export(hill_taxa)
1312
export(jaccard)
1413
export(jsd)
1514
export(manhattan)
16-
export(matrix_to_dtable)
1715
export(metagenomics)
1816
export(omics)
1917
export(ordination_plot)
@@ -29,6 +27,8 @@ import(ggplot2)
2927
import(rhdf5)
3028
importFrom(Matrix,sparseMatrix)
3129
importFrom(Rcpp,sourceCpp)
30+
importFrom(RcppParallel,RcppParallelLibs)
31+
importFrom(RcppParallel,setThreadOptions)
3232
importFrom(ape,read.tree)
3333
importFrom(data.table,":=")
3434
importFrom(data.table,.SD)

NEWS.md

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,9 @@
1-
# OmicFlow 1.6.0.9003
1+
# OmicFlow 1.6.0.9005
22

33
## Changed
4-
- Re-factoring `roxygen2` code & documentation style & error handling.
5-
- Follow order of `tests/testthat.R` file
6-
- Finished:
7-
- test-omics.R
8-
- test-metagenomics.R
4+
- Re-factoring and improving `roxygen2` code, documentation style and error handling.
95
- TODO: Add `tryCatch` where neccessary
6+
- Added `tryCatch` and better error handling in `omics$sample_subset`, `omics$feature_subset` and `omics$samplepair_subset`.
107
- Replaced `jsonlite` by `yyjsonr` functionality, much faster and cleaner code.
118
- Replaced `tests/testthat/input/metagenomics/biom_with_taxonomy_json.biom` with one from BIOM v2 example.
129
- Re-combined `foldchange` into `omics` and option to use different fold-change computations via argument `method`.

R/OmicFlow-package.R

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,10 @@
33

44
## usethis namespace: start
55
#' @importFrom data.table := .SD
6-
#' @importFrom Rcpp sourceCpp
76
#' @useDynLib OmicFlow, .registration = TRUE
7+
#' @importFrom Rcpp sourceCpp
8+
#' @importFrom RcppParallel RcppParallelLibs
9+
#' @importFrom RcppParallel setThreadOptions
810
#' @importFrom utils globalVariables
911
## usethis namespace: end
1012

R/bray.R

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -43,15 +43,24 @@ bray <- function(x, weighted = TRUE, threads = 1) {
4343

4444
## Error handling
4545
#--------------------------------------------------------------------#
46+
if (is.vector(x))
47+
cli::cli_abort("{.val x} must be a {.cls matrix}, {.cls denseMatrix} or {.cls sparseMatrix}, not a {.cls vector}.")
48+
4649
if (inherits(x, "denseMatrix") || inherits(x, "matrix") || inherits(x, "sparseMatrix")) {
4750
x <- methods::as(x, "CsparseMatrix")
48-
} else cli::cli_abort("Input isn't a {.cls matrix}, {.cls denseMatrix} or {.cls sparseMatrix}.")
49-
51+
} else cli::cli_abort("{.val x} isn't a {.cls matrix}, {.cls denseMatrix} or {.cls sparseMatrix}.")
52+
5053
if (!is.numeric(x@x))
51-
cli::cli_abort("Input data must be numeric.")
54+
cli::cli_abort("{.val x} must be numeric.")
55+
56+
if (!is.logical(weighted))
57+
cli::cli_abort("{.val weighted} needs to be either `TRUE` or `FALSE`.")
5258

53-
if (!is.wholenumber(threads))
54-
cli::cli_abort("{.val {threads}} must be a whole number.")
59+
if (length(threads) != 1) {
60+
cli::cli_abort("{.val threads} must be a single whole number.")
61+
} else if (!is.wholenumber(threads)) {
62+
cli::cli_abort("{.val threads} must be a whole number.")
63+
}
5564

5665
## MAIN
5766
#--------------------------------------------------------------------#

R/canberra.R

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -42,17 +42,23 @@ canberra <- function(x, weighted = TRUE, threads = 1) {
4242
## Error handling
4343
#--------------------------------------------------------------------#
4444
if (is.vector(x))
45-
cli::cli_abort("Input must a matrix of class matrix or Matrix, not a vector.")
46-
45+
cli::cli_abort("{.val x} must be a {.cls matrix}, {.cls denseMatrix} or {.cls sparseMatrix}, not a {.cls vector}.")
46+
4747
if (inherits(x, "denseMatrix") || inherits(x, "matrix") || inherits(x, "sparseMatrix")) {
4848
x <- methods::as(x, "CsparseMatrix")
49-
} else cli::cli_abort("Input isn't a {.cls matrix}, {.cls denseMatrix} or {.cls sparseMatrix}.")
50-
49+
} else cli::cli_abort("{.val x} isn't a {.cls matrix}, {.cls denseMatrix} or {.cls sparseMatrix}.")
50+
5151
if (!is.numeric(x@x))
52-
cli::cli_abort("Input data must be numeric.")
52+
cli::cli_abort("{.val x} must be numeric.")
53+
54+
if (!is.logical(weighted))
55+
cli::cli_abort("{.val weighted} needs to be either `TRUE` or `FALSE`.")
5356

54-
if (!is.wholenumber(threads))
55-
cli::cli_abort("{.val {threads}} must be a whole number.")
57+
if (length(threads) != 1) {
58+
cli::cli_abort("{.val threads} must be a single whole number.")
59+
} else if (!is.wholenumber(threads)) {
60+
cli::cli_abort("{.val threads} must be a whole number.")
61+
}
5662

5763
## MAIN
5864
#--------------------------------------------------------------------#

R/colormap.R

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#' Color map of a variable
22
#'
33
#' @description Creates an object of hexcode colors with names given a vector of characters.
4-
#' This function is built into the \code{ordination} method from the abstract class \link{omics} and inherited by other omics classes, such as;
4+
#' This function is built into the \code{composition} method from the abstract class \link{omics} and inherited by other omics classes, such as;
55
#' \link{metagenomics} and \link{proteomics}.
66
#'
77
#' @param data A \link[base]{data.frame} or \link[data.table]{data.table}.
@@ -29,18 +29,18 @@ colormap <- function(data,
2929
OPTIONS <- rownames(RColorBrewer::brewer.pal.info)
3030

3131
if (!inherits(data, "data.frame") && !inherits(data, "data.table"))
32-
cli::cli_abort("Data must be a {.cls data.frame} or {.cls data.table}.")
32+
cli::cli_abort("{.val data} must be a {.cls data.frame} or {.cls data.table}.")
3333

34-
if (!is.character(col_name) && length(col_name) != 1) {
35-
cli::cli_abort("{.val {col_name}} needs to contain characters with length of 1.")
34+
if (!is.character(col_name) || length(col_name) != 1) {
35+
cli::cli_abort("{.val col_name} needs to contain characters with length of 1.")
3636
} else if (!column_exists(col_name, data)) {
37-
cli::cli_abort("The {.val {col_name}} column does not exist in the provided data.")
37+
cli::cli_abort("The {.val col_name} column does not exist in the provided data.")
3838
}
3939

40-
if (!is.character(Brewer.palID) && length(Brewer.palID) != 1) {
41-
cli::cli_abort("The {.val {Brewer.palID}} needs to contain characters with length of 1.")
40+
if (!is.character(Brewer.palID) || length(Brewer.palID) != 1) {
41+
cli::cli_abort("The {.val Brewer.palID} needs to contain characters with length of 1.")
4242
} else if (!c(Brewer.palID %in% OPTIONS)) {
43-
cli::cli_abort("{.val {Brewer.palID}} is not a valid Brewer pal ID. \nValid options: {.val {OPTIONS}}.")
43+
cli::cli_abort("{.val Brewer.palID} is not a valid Brewer pal ID. \nValid options: {.val {OPTIONS}}.")
4444
}
4545

4646
## MAIN

R/composition_plot.R

Lines changed: 18 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,10 @@
44
#' The function is compatible with the class \link{omics} method \code{composition()}.
55
#'
66
#' @param data A \link[base]{data.frame} or \link[data.table]{data.table}.
7-
#' @param palette An object with names and hexcode or color names, see \link{colormap}.
8-
#' @param feature_rank A character variable of the feature column.
9-
#' @param title_name A character to set the \code{ggtitle} of the \link[ggplot2]{ggplot}, (Default: NULL).
10-
#' @param group_by A character variable to aggregate the stacked bars by group (Default: NULL).
7+
#' @param palette A \link[stats]{setNames}, see \link{colormap}.
8+
#' @param feature_rank A column name containing the feature names.
9+
#' @param title_name A character to set the \code{ggtitle} of the \link[ggplot2]{ggplot}, (default: \code{NULL}).
10+
#' @param group_by A character variable to aggregate the stacked bars by group (default: \code{NULL}).
1111
#' @return A \link[ggplot2]{ggplot2} object to be further modified
1212
#'
1313
#' @examples
@@ -75,30 +75,33 @@ composition_plot <- function(data,
7575
#--------------------------------------------------------------------#
7676

7777
if (!inherits(data, "data.frame") && !inherits(data, "data.table"))
78-
cli::cli_abort("Data must be a {.cls data.frame} or {.cls data.table}.")
78+
cli::cli_abort("{.val data} must be a {.cls data.frame} or {.cls data.table}.")
7979

8080
if (!is.character(palette))
81-
cli::cli_abort("{.val {palette}} needs to contain characters.")
81+
cli::cli_abort("{.val palette} needs to contain characters.")
8282

83-
if (!is.character(feature_rank) && length(feature_rank) != 1) {
84-
cli::cli_abort("{.val {feature_rank}} needs to contain characters with length of 1.")
83+
if (!is.character(feature_rank) || length(feature_rank) != 1) {
84+
cli::cli_abort("{.val feature_rank} needs to contain characters with length of 1.")
8585
} else if (!column_exists(feature_rank, data)) {
86-
cli::cli_abort("The {.val {feature_rank}} column does not exist in the provided {.arg data}.")
86+
cli::cli_abort("The {.val {feature_rank}} column does not exist in the provided {.val data}.")
8787
}
8888

89-
if (!is.null(title_name) && !is.character(title_name))
90-
cli::cli_abort("{.val {title_name}} needs to be of type character.")
89+
if (!is.null(title_name)) {
90+
if (!is.character(title_name) || length(title_name) != 1) {
91+
cli::cli_abort("{.val title_name} must be a character and of length 1")
92+
}
93+
}
9194

9295
if (!is.null(group_by)) {
93-
if (!is.character(group_by) && length(group_by) != 1) {
94-
cli::cli_abort("{.val {group_by}} must be a character and of length 1")
96+
if (!is.character(group_by) || length(group_by) != 1) {
97+
cli::cli_abort("{.val group_by} must be a character and of length 1")
9598
} else if (!column_exists(group_by, data)) {
96-
cli::cli_abort("The specified {.val {group_by}} does not exist in the provided {.arg data}.")
99+
cli::cli_abort("The specified {.val {group_by}} does not exist in the provided {.val data}.")
97100
}
98101
}
99102

100103
if (!column_exists("SAMPLE_ID", data))
101-
cli::cli_abort("{.arg SAMPLE_ID} needs to exist within the provided {.arg data}.")
104+
cli::cli_abort("{.arg SAMPLE_ID} needs to exist within the provided {.val data}.")
102105

103106
## MAIN
104107
#--------------------------------------------------------------------#

R/cosine.R

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -41,15 +41,24 @@ cosine <- function(x, weighted = TRUE, threads = 1) {
4141

4242
## Error handling
4343
#--------------------------------------------------------------------#
44+
if (is.vector(x))
45+
cli::cli_abort("{.val x} must be a {.cls matrix}, {.cls denseMatrix} or {.cls sparseMatrix}, not a {.cls vector}.")
46+
4447
if (inherits(x, "denseMatrix") || inherits(x, "matrix") || inherits(x, "sparseMatrix")) {
4548
x <- methods::as(x, "CsparseMatrix")
46-
} else cli::cli_abort("Input isn't a {.cls matrix}, {.cls denseMatrix} or {.cls sparseMatrix}.")
47-
49+
} else cli::cli_abort("{.val x} isn't a {.cls matrix}, {.cls denseMatrix} or {.cls sparseMatrix}.")
50+
4851
if (!is.numeric(x@x))
49-
cli::cli_abort("Input data must be numeric.")
52+
cli::cli_abort("{.val x} must be numeric.")
53+
54+
if (!is.logical(weighted))
55+
cli::cli_abort("{.val weighted} needs to be either `TRUE` or `FALSE`.")
5056

51-
if (!is.wholenumber(threads))
52-
cli::cli_abort("{.val {threads}} must be a whole number.")
57+
if (length(threads) != 1) {
58+
cli::cli_abort("{.val threads} must be a single whole number.")
59+
} else if (!is.wholenumber(threads)) {
60+
cli::cli_abort("{.val threads} must be a whole number.")
61+
}
5362

5463
## MAIN
5564
#--------------------------------------------------------------------#

R/diversity.R

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -42,31 +42,33 @@
4242
#' @export
4343

4444
diversity <- function(x,
45-
metric = c("shannon", "simpson", "invsimpson"),
45+
metric = "shannon",
4646
normalize = TRUE,
4747
base = exp(1)) {
4848

4949
## Error handling
5050
#--------------------------------------------------------------------#
51-
51+
if (is.vector(x))
52+
cli::cli_abort("{.val x} must be a {.cls matrix}, {.cls denseMatrix} or {.cls sparseMatrix}, not a {.cls vector}.")
53+
5254
if (inherits(x, "denseMatrix") || inherits(x, "matrix") || inherits(x, "sparseMatrix")) {
5355
x <- methods::as(x, "CsparseMatrix")
54-
} else cli::cli_abort("Input isn't a {.cls matrix}, {.cls denseMatrix} or {.cls sparseMatrix}.")
55-
56-
if (!is.numeric(x@x))
57-
cli::cli_abort("Input data must be {.cls numeric} type")
56+
} else cli::cli_abort("{.val x} isn't a {.cls matrix}, {.cls denseMatrix} or {.cls sparseMatrix}.")
5857

5958
if (any(x@x < 0, na.rm = TRUE))
60-
cli::cli_abort("Input data must be non-negative")
59+
cli::cli_abort("{.val x} must be non-negative.")
6160

62-
if (!is.numeric(base))
63-
cli::cli_abort("{.val {base}} needs to be a {.cls numeric} type.")
61+
if (!is.logical(normalize))
62+
cli::cli_abort("{.val normalize} needs to be either `TRUE` or `FALSE`.")
63+
64+
if (!is.numeric(base) || length(base) != 1)
65+
cli::cli_abort("{.val base} needs to be a {.cls numeric} type with length of 1.")
6466

6567
OPTIONS <- c("shannon", "simpson", "invsimpson")
66-
if (!is.character(metric) && length(metric) != 1) {
67-
cli::cli_abort("{.val {metric}} needs to contain characters with length of 1.")
68+
if (!is.character(metric) || length(metric) != 1) {
69+
cli::cli_abort("{.val metric} needs to contain characters with length of 1.")
6870
} else if (!metric %in% OPTIONS) {
69-
cli::cli_abort("{.val {metric}} is not a valid metric. Valid options: <{.val {OPTIONS}}>")
71+
cli::cli_abort("{.val {metric}} is not a valid {.arg metric}.\nValid options: <{.val {OPTIONS}}>")
7072
}
7173

7274
## MAIN

0 commit comments

Comments
 (0)