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 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 or a dense/sparse Matrix format.
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)
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.
Displays parameters of the omics class via stdout.
Examples
library("OmicFlow")
metadata_file <- system.file("extdata", "metadata.tsv", package = "OmicFlow")
counts_file <- system.file("extdata", "counts.tsv", package = "OmicFlow")
obj <- omics$new(
metaData = metadata_file,
countData = counts_file
)
# method 1 to call print function
obj
# method 2 to call print function
obj$print()
Method reset()
Upon creation of a new omics object a small backup of the original data is created.
Since modification of the object is done by reference and duplicates are not made, it is possible to reset changes to the class.
The methods from the abstract class omics also contains a private method to prevent any changes to the original object when using methods such as ordination alpha_diversity or $DFE.
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")
taxa <- omics$new(
metaData = metadata_file,
countData = counts_file,
featureData = features_file
)
# Performs modifications
taxa$transform(log2)
# resets
taxa$reset()
# An inbuilt reset function prevents unwanted modification to the taxa object.
taxa$rankstat(feature_ranks = c("Kingdom", "Phylum", "Family", "Genus", "Species"))
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 data synchronization.
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 == "Pseudomonas")
Method sample_subset()
Sample subset (based on metaData), automatically applies synchronization.
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 synchronization.
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 synchronization.
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",
group_by = NULL,
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.
group_by
A column name to perform grouped statistical test in diversity_plot (default: NULL).
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,
logfold.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).
logfold.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 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_. If the data is from the class omics or proteomics than FDR adjusted p-values are computed for the volcano plots.
Usage
omics$autoFlow(
feature_contrast = "FEATURE_ID",
feature_filter = NULL,
feature_ranks = NULL,
distance_metrics = c("unifrac"),
beta_div_table = NULL,
alpha_div_table = NULL,
normalize = TRUE,
weighted = TRUE,
pvalue.threshold = 0.05,
logfold.threshold = 1,
abundance.threshold = 0.01,
perm = 999,
threads = 1,
report = TRUE,
filename = paste0(getwd(), "/report.html")
)
Arguments
feature_contrast
A character vector of feature columns in the featureData to aggregate via feature_merge() (default: "FEATURE_ID").
feature_filter
A character vector to filter unwanted features, (default: NULL).
feature_ranks
A character vector as input to rankstat() (default: NULL).
distance_metrics
A character vector specifying what (dis)similarity metrics to use (default: c("unifrac")).
beta_div_table
A path to an existing file or a dense/sparse Matrix format (default: NULL).
alpha_div_table
A path to pre-computed alpha diversity table, with columns: alpha_div (containing diversity values) and the same CONTRAST columns from metaData (default: NULL).
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).
logfold.threshold
A numeric value used as a fold-change threshold to label and color significantly expressed features, see DFE() (Default: 1).
abundance.threshold
A numeric value used as an abundance threshold to size the scatter dots based on their mean abundance, see DFE() (default: 0.01).
perm
A wholenumber, number of permutations to compare against the null hypothesis of adonis2 or anosim (default: 999).
threads
Number of threads to use, only used in distance() when beta_div_table is not supplied (default: 1).
report
A boolean value to create a HTML markdown report (default: FALSE). If FALSE a nested list of the plots and data is returned.
filename
A character to name the HTML report to be saved in the current working directory (default: paste0(getwd(), "/report.html")). The getwd() is required for rmarkdown to save it in the right path.
Returns
List of plots/data or rendered HTML report
Method clone()
The objects of this class are cloneable with this method.
Usage
omics$clone(deep = FALSE)
Arguments
deep
Whether to make a deep clone.