Method new()
Wrapper function that is inherited and adapted for each omics class.
The omics classes requires a metadata samplesheet, that is validated by the metadata_schema.json.
It requires a column SAMPLE_ID and optionally a SAMPLEPAIR_ID or FEATURE_ID can be supplied.
The SAMPLE_ID will be used to link the metaData to the countData, and will act as the key during subsetting of other columns.
To create a new object use new() method. Do notice that the abstract class only checks if the metadata is valid!
The countData and featureData will not be checked, these are handled by the sub-classes.
Using the omics class to load your data is not supported and still experimental.
Usage
omics$new(countData = NULL, featureData = NULL, metaData = NULL)
Arguments
countData
A path to an existing file, data.table, data.frame, matrix or sparseMatrix with zero values.
featureData
A path to an existing file, data.table or data.frame.
metaData
A path to an existing file, data.table or data.frame.
Returns
A new omics object.
Method validate()
Validates an input metadata against the JSON schema. The metadata should look as follows and should not contain any empty spaces.
For example; 'sample 1' is not allowed, whereas 'sample1' is allowed!
Acceptable column headers:
SAMPLE_ID (required)
SAMPLEPAIR_ID (optional)
FEATURE_ID (optional)
CONTRAST_ (optional), used for autoFlow().
VARIABLE_ (optional), not supported yet.
This function is used during the creation of a new object via new() to validate the supplied metadata
via a filepath or existing data.table or data.frame.
Method removeZeros()
Removes empty (zero) values by row and column from the countData.
This method is performed automatically during subsetting of the object.
Usage
omics$removeZeros()
Examples
library("OmicFlow")
metadata_file <- system.file("extdata", "metadata.tsv", package = "OmicFlow")
counts_file <- system.file("extdata", "counts.tsv", package = "OmicFlow")
features_file <- system.file("extdata", "features.tsv", package = "OmicFlow")
obj <- metagenomics$new(
metaData = metadata_file,
countData = counts_file,
featureData = features_file,
)
obj$removeZeros()
Method removeNAs()
Remove NAs from metaData and updates the countData.
Usage
omics$removeNAs(column)
Arguments
column
The column from where NAs should be removed, this can be either a wholenumbers or characters. Vectors are also supported.
Examples
library("OmicFlow")metadata_file <- system.file("extdata", "metadata.tsv", package = "OmicFlow")
counts_file <- system.file("extdata", "counts.tsv", package = "OmicFlow")
features_file <- system.file("extdata", "features.tsv", package = "OmicFlow")
obj <- metagenomics$new(
metaData = metadata_file,
countData = counts_file,
featureData = features_file,
)
obj$removeNAs(column = "treatment")
Method feature_subset()
Feature subset (based on featureData), automatically applies removeZeros().
Usage
omics$feature_subset(...)
Arguments
...
Expressions that return a logical value, and are defined in terms of the variables in featureData.
Only rows for which all conditions evaluate to TRUE are kept.
Examples
library("OmicFlow")metadata_file <- system.file("extdata", "metadata.tsv", package = "OmicFlow")
counts_file <- system.file("extdata", "counts.tsv", package = "OmicFlow")
features_file <- system.file("extdata", "features.tsv", package = "OmicFlow")
obj <- metagenomics$new(
metaData = metadata_file,
countData = counts_file,
featureData = features_file,
)
obj$feature_subset(Genus == "Streptococcus")
Method sample_subset()
Sample subset (based on metaData), automatically applies removeZeros().
Usage
omics$sample_subset(...)
Arguments
...
Expressions that return a logical value, and are defined in terms of the variables in metaData.
Only rows for which all conditions evaluate to TRUE are kept.
Examples
library("OmicFlow")metadata_file <- system.file("extdata", "metadata.tsv", package = "OmicFlow")
counts_file <- system.file("extdata", "counts.tsv", package = "OmicFlow")
features_file <- system.file("extdata", "features.tsv", package = "OmicFlow")
obj <- metagenomics$new(
metaData = metadata_file,
countData = counts_file,
featureData = features_file,
)
obj$sample_subset(treatment == "tumor")
Method samplepair_subset()
Samplepair subset (based on metaData), automatically applies removeZeros().
Usage
omics$samplepair_subset(num_unique_pairs = NULL)
Arguments
num_unique_pairs
An integer value to define the number of pairs to subset. The default is NULL,
meaning the maximum number of unique pairs will be used to subset the data.
Let's say you have three samples for each pair, then the num_unique_pairs will be set to 3.
Method feature_merge()
Agglomerates features by column, automatically applies removeZeros().
Usage
omics$feature_merge(feature_rank, feature_filter = NULL)
Arguments
feature_rank
A character value or vector of columns to aggregate from the featureData.
feature_filter
A character value or vector of characters to remove features via regex pattern.
Examples
library("OmicFlow")metadata_file <- system.file("extdata", "metadata.tsv", package = "OmicFlow")
counts_file <- system.file("extdata", "counts.tsv", package = "OmicFlow")
features_file <- system.file("extdata", "features.tsv", package = "OmicFlow")
obj <- metagenomics$new(
metaData = metadata_file,
countData = counts_file,
featureData = features_file,
)
obj$feature_merge(feature_rank = c("Kingdom", "Phylum"))
obj$feature_merge(feature_rank = "Genus", feature_filter = c("uncultured", "metagenome"))
Arguments
FUN
A function such as log2, log
Examples
library("OmicFlow")metadata_file <- system.file("extdata", "metadata.tsv", package = "OmicFlow")
counts_file <- system.file("extdata", "counts.tsv", package = "OmicFlow")
features_file <- system.file("extdata", "features.tsv", package = "OmicFlow")
obj <- metagenomics$new(
metaData = metadata_file,
countData = counts_file,
featureData = features_file,
)
obj$transform(log2)
Method normalize()
Relative abundance computation by column sums on the countData.
Examples
library("OmicFlow")
metadata_file <- system.file("extdata", "metadata.tsv", package = "OmicFlow")
counts_file <- system.file("extdata", "counts.tsv", package = "OmicFlow")
features_file <- system.file("extdata", "features.tsv", package = "OmicFlow")
obj <- metagenomics$new(
metaData = metadata_file,
countData = counts_file,
featureData = features_file,
)
obj$normalize()
Method rankstat()
Rank statistics based on featureData
Usage
omics$rankstat(feature_ranks, unique = FALSE)
Arguments
feature_ranks
A vector of characters or integers that match the featureData.
unique
A boolean value to display only unique entries in feature_ranks.
Details
Counts the number of features identified for each column, for example in case of 16S metagenomics it would be the number of OTUs or ASVs on different taxonomy levels.
Examples
library("ggplot2")
library("OmicFlow")
metadata_file <- system.file("extdata", "metadata.tsv", package = "OmicFlow")
counts_file <- system.file("extdata", "counts.tsv", package = "OmicFlow")
features_file <- system.file("extdata", "features.tsv", package = "OmicFlow")
obj <- metagenomics$new(
metaData = metadata_file,
countData = counts_file,
featureData = features_file,
)
plt <- obj$rankstat(feature_ranks = c("Kingdom", "Phylum", "Family", "Genus", "Species"))
plt
Method alpha_diversity()
Alpha diversity based on diversity
Usage
omics$alpha_diversity(
col_name,
metric = c("shannon", "invsimpson", "simpson"),
Brewer.palID = "Set2",
evenness = FALSE,
paired = FALSE,
p.adjust.method = "fdr"
)
Arguments
col_name
A character variable from the metaData.
metric
An alpha diversity metric as input to diversity.
Brewer.palID
A character name for the palette set to be applied, see brewer.pal or colormap.
evenness
A boolean wether to divide diversity by number of species, see specnumber.
paired
A boolean value to perform paired analysis in wilcox.test and samplepair subsetting via samplepair_subset()
p.adjust.method
A character variable to specify the p.adjust.method to be used, default is 'fdr'.
Examples
library("ggplot2")
library("OmicFlow")metadata_file <- system.file("extdata", "metadata.tsv", package = "OmicFlow")
counts_file <- system.file("extdata", "counts.tsv", package = "OmicFlow")
features_file <- system.file("extdata", "features.tsv", package = "OmicFlow")
obj <- metagenomics$new(
metaData = metadata_file,
countData = counts_file,
featureData = features_file,
)
plt <- obj$alpha_diversity(col_name = "treatment",
metric = "shannon")
Method composition()
Creates a table most abundant compositional features. Also assigns a color blind friendly palette for visualizations.
Usage
omics$composition(
feature_rank,
feature_filter = NULL,
col_name = NULL,
normalize = TRUE,
feature_top = c(10, 15),
Brewer.palID = "RdYlBu"
)
Arguments
feature_rank
A character variable in featureData to aggregate via feature_merge().
feature_filter
A character or vector of characters to removes features by regex pattern.
col_name
Optional, a character or vector of characters to add to the final compositional data output.
normalize
A boolean value, whether to normalize() by total sample sums (Default: TRUE).
feature_top
A wholenumber of the top features to visualize, the max is 15, due to a limit of palettes.
Brewer.palID
A character name for the palette set to be applied, see brewer.pal or colormap.
Examples
library("ggplot2")
library("OmicFlow")metadata_file <- system.file("extdata", "metadata.tsv", package = "OmicFlow")
counts_file <- system.file("extdata", "counts.tsv", package = "OmicFlow")
features_file <- system.file("extdata", "features.tsv", package = "OmicFlow")
obj <- metagenomics$new(
metaData = metadata_file,
countData = counts_file,
featureData = features_file,
)
result <- obj$composition(feature_rank = "Genus",
feature_filter = c("uncultured"),
feature_top = 10)
plt <- composition_plot(data = result$data,
palette = result$palette,
feature_rank = "Genus")
Method distance()
Compute a distance metric from countData
Usage
omics$distance(metric, normalized = TRUE, weighted = TRUE, threads = 1)
Arguments
metric
A dissimilarity metric to be applied on the countData,
thus far supports 'bray', 'jaccard', 'cosine', 'manhattan', 'jsd' (jensen-shannon divergence), 'canberra' and 'unifrac' when a tree is provided via treeData, see distance().
normalized
A boolean value, whether to normalize() by total sample sums (Default: TRUE).
weighted
A boolean value, to use abundances (weighted = TRUE) or absence/presence (weighted=FALSE) (default: TRUE).
threads
A wholenumber, indicating the number of threads to use (Default: 1).
Returns
A column x column dist object.
Examples
library("OmicFlow")metadata_file <- system.file("extdata", "metadata.tsv", package = "OmicFlow")
counts_file <- system.file("extdata", "counts.tsv", package = "OmicFlow")
features_file <- system.file("extdata", "features.tsv", package = "OmicFlow")
obj <- metagenomics$new(
metaData = metadata_file,
countData = counts_file,
featureData = features_file
)
obj$feature_subset(Kingdom == "Bacteria")
dist <- obj$distance(metric = "bray")
Method ordination()
Ordination of countData with statistical testing.
Usage
omics$ordination(
metric = "bray",
method = c("pcoa", "nmds"),
group_by,
distmat = NULL,
weighted = TRUE,
normalize = TRUE,
threads = 1,
perm_design = NULL,
perm = 999
)
Arguments
metric
A dissimilarity or similarity metric to be applied on the countData,
thus far supports 'bray', 'jaccard', 'cosine', 'manhattan', 'jsd' (jensen-shannon divergence), 'canberra' and 'unifrac' when a tree is provided via treeData, see distance().
method
Ordination method, supports "pcoa" and "nmds", see wcmdscale.
group_by
A character variable in metaData to be used for the pairwise_adonis or pairwise_anosim statistical test.
distmat
A custom distance matrix in either dist or Matrix format.
weighted
A boolean value, whether to compute weighted or unweighted dissimilarities (Default: TRUE).
normalize
A boolean value, whether to normalize() by total sample sums (Default: TRUE).
threads
A wholenumber, indicating the number of threads to use (Default: 1).
perm_design
A function that takes metaData and constructs a permutation design with how (default: NULL).
perm
A wholenumber, number of permutations to compare against the null hypothesis of adonis2 and anosim (default: perm=999).
Examples
library("ggplot2")
library("OmicFlow")metadata_file <- system.file("extdata", "metadata.tsv", package = "OmicFlow")
counts_file <- system.file("extdata", "counts.tsv", package = "OmicFlow")
features_file <- system.file("extdata", "features.tsv", package = "OmicFlow")
obj <- metagenomics$new(
metaData = metadata_file,
countData = counts_file,
featureData = features_file,
)
pcoa_plots <- obj$ordination(metric = "bray",
method = "pcoa",
group_by = "treatment",
weighted = TRUE,
normalize = TRUE)
pcoa_plots
Method DFE()
Differential feature expression (DFE) using the foldchange for both paired and non-paired test.
Usage
omics$DFE(
feature_rank,
feature_filter = NULL,
paired = FALSE,
normalize = TRUE,
condition.group,
condition_A,
condition_B,
pvalue.threshold = 0.05,
foldchange.threshold = 0.06,
abundance.threshold = 0
)
Arguments
feature_rank
A character or vector of characters in the featureData to aggregate via feature_merge().
feature_filter
A character or vector of characters to remove features via regex pattern (Default: NULL).
paired
A boolean value, the paired is only applicable when a SAMPLEPAIR_ID column exists within the metaData. See wilcox.test and samplepair_subset().
normalize
A boolean value, whether to normalize() by total sample sums (Default: TRUE).
condition.group
A character variable of an existing column name in metaData, wherein the conditions A and B are located.
condition_A
A character value or vector of characters.
condition_B
A character value or vector of characters.
pvalue.threshold
A numeric value used as a p-value threshold to label and color significant features (Default: 0.05).
foldchange.threshold
A numeric value used as a fold-change threshold to label and color significantly expressed features (Default: 0.06).
abundance.threshold
A numeric value used as an abundance threshold to size the scatter dots based on their mean relative abundance (default: 0.01).
Examples
library("ggplot2")
library("OmicFlow")metadata_file <- system.file("extdata", "metadata.tsv", package = "OmicFlow")
counts_file <- system.file("extdata", "counts.tsv", package = "OmicFlow")
features_file <- system.file("extdata", "features.tsv", package = "OmicFlow")
obj <- metagenomics$new(
metaData = metadata_file,
countData = counts_file,
featureData = features_file,
)
unpaired <- obj$DFE(feature_rank = "Genus",
paired = FALSE,
condition.group = "treatment",
condition_A = c("healthy"),
condition_B = c("tumor"))
Method autoFlow()
Automated Omics Analysis based on the metaData, see validate().
For now only works with headers that start with prefix CONTRAST_.
Usage
omics$autoFlow(
feature_ranks = c("Kingdom", "Phylum", "Class", "Order", "Family", "Genus", "Species"),
feature_contrast = c("Phylum", "Family", "Genus"),
feature_filter = c("uncultured"),
distance_metrics = c("unifrac"),
beta_div_table = NULL,
alpha_div_table = NULL,
normalize = TRUE,
weighted = TRUE,
pvalue.threshold = 0.05,
perm = 999,
threads = 1,
filename = paste0(getwd(), "/report.html")
)
Arguments
feature_ranks
A character vector as input to rankstat().
feature_contrast
A character vector of feature columns in the featureData to aggregate via feature_merge().
feature_filter
A character vector to filter unwanted features, default: c("uncultured")
distance_metrics
A character vector specifying what (dis)similarity metrics to use, default c("unifrac")
beta_div_table
A path to pre-computed distance matrix, expects tsv/csv/txt file.
alpha_div_table
A path to pre-computed alpha diversity with rarefraction depth, expects tsv/csv/txt from qiime2, see read_rarefraction_qiime.
normalize
A boolean value, whether to normalize() by total sample sums (Default: TRUE).
weighted
A boolean value, whether to compute weighted or unweighted dissimilarities (Default: TRUE).
pvalue.threshold
A numeric value, the p-value is used to include/exclude composition and foldchanges plots coming from alpha- and beta diversity analysis (Default: 0.05).
perm
A wholenumber, number of permutations to compare against the null hypothesis of adonis2 or anosim (default: perm=999).
threads
Number of threads to use, only used in ordination() when beta_div_table is not supplied (default: 1).
filename
A character to name the HTML report, it can also be a filepath (e.g. "/path/to/report.html"). Default: "report.html" in your current work directory.
Returns
A report in HTML format