This class represents a RNA sequencing dataset containing the following information:
expression values (raw count) of expressed tags (genes or transcripts) for all samples.
effective lengths of expressed tags (genes or transcripts) for all samples.
normalization factors for expressed tags (genes or transcripts) for all samples.
design and annotation information; see PairwiseDesignWith for details.
By convention, the dataset is represented as a matrix:
A column represents the expression values for one sample.
A row represents the expression values for one expression tag. Column names are the sample names, and row names are the expression tag names.
Methods
Method show_etags_summary()
This function computes a summary per tax_id, tax_name and rna type for selected expressed tags, and returns a list of tables per feature.
Usage
ExprData$show_etags_summary(
in_batch = NULL,
tr_fn = NULL,
sum_fn = sum,
intra_norm = FALSE,
inter_norm = FALSE
)Arguments
in_batch(optional) A character vector specifying the batch(es) to include.
tr_fnA function to transform the expression values before summarizing. Default is identity function (no transformation).
sum_fnA function to aggregate the transformed values. Default is "sum", but can be "sum_fn = function(x) sum(as.integer(x > 0))" to count non zero genes for example.
intra_normA boolean indicating whether to apply intra-sample normalization. Only used when type="norm".
inter_normA boolean indicating whether to apply inter-sample normalization. Only used when type="norm".
Method plot_etags_summary()
Usage
ExprData$plot_etags_summary(
in_batch = NULL,
tr_fn = NULL,
sum_fn = sum,
intra_norm = FALSE,
inter_norm = FALSE
)Arguments
in_batch(optional) A character vector specifying the batch(es) to include.
tr_fnA function to transform the expression values before summarizing. Default is identity function (no transformation).
sum_fnA function to aggregate the transformed values. Default is "sum", but can be "sum_fn = function(x) sum(as.integer(x > 0))" to count non zero genes for example.
intra_normA boolean indicating whether to apply intra-sample normalization. Only used when type="norm".
inter_normA boolean indicating whether to apply inter-sample normalization. Only used when type="norm".
Method filter_and_set_selected_ids()
Select expressed tags based on filtering on taxon or rna type. The results will be an intersect with the previous selection. You can reset the object if it's not desired.
Arguments
valuesA list of values used for filtering. e.g c("mRNA", "transcript")
filtered_varThe variable being filtered. Possible values are
"tax_id" for filtering based on taxon id
"tax_name" for filtering based on taxon name
"type" for filtering based on rna type (default)
filter_typeThe filtering method. Possible values are:
"keep" to keep only an expression tag if its value for the variable designated with
filtered_varis invalues"excl" to keep only an expression tag if its value for the variable designated with
filtered_varis not invalues. Compute and set inter normalization factors
Method compute_and_set_inter_norm_fact()
Compute and set inter normalization factors
This function computes scaling factors using a ratio-based
method to correct for systematic technical biases between samples, such
as differences in sequencing depth or library composition. By default, it
performs Median Ratio Normalization (MRN), as norm_mean is "median"
and M-value trimming is disabled (m_trim_prop = 0). It can be
configured to perform TMM-style normalization by setting m_trim_prop
and norm_mean="geometric"ornorm_mean="mod.geometric"`. Note that the
weigthed mean for TMM is not available yet.
The normalization process is as follows:
Reference Selection: A reference expression profile is created from samples chosen via
ref_typeandref_samples. Gene expression values are averaged using theref_meanmethod.Target Processing: For each target sample or group (
norm_by), a target expression profile is created usingtgt_mean.M and A Vector Calculation:
The A-vector (average expression) is used to filter out low-expression genes, which can be noisy.
The M-vector (expression ratio: target/reference) is used to derive the normalization factor from its central tendency.
Trimming Process: A sequential trimming process refines the set of genes used for normalization:
A-vector trimming: Genes with average expression below
a_trim_valueare removed.M-vector trimming: A proportion (
m_trim_prop) of genes with the most extreme expression ratios are removed. This is disabled by default (m_trim_prop = 0).Extreme ratio trimming: If
trim_extremeisTRUE, genes with infinite or zero ratios are removed. This is advised whennorm_meanis not"median"or whenm_trim_propis too small to remove these values.
Factor Calculation: The final normalization factor is computed by applying
norm_meanto the ratio (M-vector) of the remaining genes.Normalization Scope (
norm_scale): This parameter determines the scope and reference for normalization.design: Normalization is performed across all samples at once This is the generally recommended approach as it makes all samples comparable across the entire experiment.batchorgroup: Normalization is performed independently within each context. This can mitigate biases if a particular batch or group is compositionally very different. However, it renders data comparable only within that same context (e.g., within a batch), not across the entire design.
Usage
ExprData$compute_and_set_inter_norm_fact(
norm_scale = "design",
norm_by = "sample",
ref_type = "all",
ref_samples = NULL,
ref_mean = "arithmetic",
norm_mean = "median",
tgt_mean = "arithmetic",
a_mean = "arithmetic",
a_trim_value = 1,
m_trim_prop = 0,
trim_extreme = FALSE
)Arguments
norm_scaleScale to apply the normalization:
"design" for all samples in one go
"batch" for applying norm_factors per batch
"group" for applying norm factors per batch per group. The scale will have an impact on the reference selection if ref type is "ctrl" or "all". In consequences the same sample can be associated with different scaling factor if it appears in different batch/group. Therefore data normalized at the "batch" or "group" level can not be analyzed at the design level. (and group scale not at the batch level either). Indeed at group/batch levels the inter_norm can only be applied at group/batch level.
norm_bylevel by which M and A vector are computed followed by. the scaling factor for normalization.
ref_typeType of reference samples to use for normalization.
"all" for using all samples as reference
"ctrl" for using only control samples as reference
"specified" for using specific samples
ref_samplesas reference
ref_samplesSamples to use as reference for normalization.
ref_meanMethod for averaging gene expression across reference samples. It is recommended to use the same method for
ref_mean,tgt_mean, anda_mean."arithmetic": Recommended when using library size-scaled intra-normalization (e.g., "tpm", "fpkm", "fpm"). This preserves the sum of proportions."geometric": Recommended when intra-normalization does not account for library size (e.g., "none", "fpk"). The library size effect is then absorbed into the inter-sample normalization factor. This approach, with "none" intra-normalization, mirrors the default behavior in DESeq2. Note that this can be problematic if normalization is performed per group (norm_by = "group").Other options:
"median","nz.geometric","mod.geometric".
norm_meanMethod for the mean of ratios between the target and the reference. See
ref_meanfor possible values.tgt_meanMethod for averaging gene expression across target samples. See
ref_meanfor recommended usage and available options.a_meanMethod for averaging gene expression between target and reference samples to calculate the A-vector. See
ref_meanfor recommended usage and available options.a_trim_valueValue for trimming the A vector.
m_trim_propProportion of values to trim from the M vector.
trim_extremeWhether to trim extreme values from the M vector, before calculating the mean. If the mean function
norm_meanis not "median", extreme values will causes issues with the calculation of the mean.
Method compute_and_set_intra_norm_fact()
Set intra normalization factors. This function replaces any NaN values in the intra normalization factors with 1. NaN values may occur when the denominator in the calculations is 0. Replacing NaN values with 1 ensures that the normalization factors do not have missing or undefined values, which can cause issues in further analyses.
Method reset()
Reset object, this affects:
expression tags selection (as initially)
samples selection (as initially)
normalization (No norm)
Method filter_and_get_raw()
Filter and get raw count matrix
Method filter_and_get_len()
filter and get effective length matrix
Method compute_norm_fact()
Get normalization factors matrix
Usage
ExprData$compute_norm_fact(
in_batch = NULL,
in_group = NULL,
inter_norm = FALSE,
intra_norm = TRUE,
include_ctrl = FALSE,
rescale_inter_norm = TRUE
)Arguments
in_batch(optional) A character vector specifying the batch(es) to include.
in_group(optional) A character vector specifying the group(s) to include.
inter_normA boolean indicating whether to apply inter-sample normalization.
intra_normA boolean indicating whether to apply intra-sample normalization.
include_ctrlif TRUE and if
in_batchandin_groupare specified, control samples from the specified batch will be included.rescale_inter_normRescale inter-sample normalization factors so that their geometric mean is 1. Default is TRUE.
Method compute_norm()
Compute the normalized expression data from raw and norm matrices.
IMPORTANT: Default is no normalization. Please use the function below beforehand.
"compute_and_set_intra_norm_fact"
"compute_and_set_inter_norm_fact" Note that intra normalization is always applied, however inter norm is optional. Depending on the
norm_scaleused for inter normalization, thein_batchargument might be mandatory.
Usage
ExprData$compute_norm(
in_batch = NULL,
in_group = NULL,
intra_norm = TRUE,
inter_norm = FALSE,
include_ctrl = FALSE,
rescale_inter_norm = TRUE
)Arguments
in_batch(optional) A character vector specifying the batch(es) to include.
in_group(optional) A character vector specifying the group(s) to include.
intra_normA boolean indicating whether to apply intra-sample normalization.
inter_normA boolean indicating whether to apply inter-sample normalization.
include_ctrlinclude control samples in the normalization
rescale_inter_normRescale inter-sample normalization factors so that their geometric mean is 1. Default is TRUE.
Method get_intra_norm_fact()
Get the intra normalization factor
Method get_main_etag()
Get the main expression tag id. The tag id corresponds to the unique id linked with a expression point. It can be tx_id (for transcript id) or "tgid" for "typed gene id". Why typed gene ID ? because some genes have transcripts from different types. As it would not be biologically relevant to aggregate different typse during the sum, a new id is create that is gene and type specific.
Method get_design()
Extract the PairwiseDesign instance that were used to build the expression data object.
Method get_annotation()
Extract the Annotation instance that were used to build the expression data object.
Method plot_dist_per_sample()
Plot the distribution of count or normalized values per RNA type for each sample.
Arguments
intra_normA boolean indicating whether to apply intra-sample normalization.
inter_normA boolean indicating whether to apply inter-sample normalization.
include_ctrlA boolean indicating whether to include the control group. This argument is only valid when specifying only one argument for 'in_group' and 'in_batch'.
rescale_inter_normRescale inter-sample normalization factors so that their geometric mean is 1. Default is TRUE.
geomsCharacter vector, types of plot to draw, can be a combination of:
"boxplot": draw a box plot (fast)
"violin": draw a violin plot (slow)
"histo": draw an hiostogram (slow)
tr_fnfunction to transform expression values before plot.
mean_fun(Optional) Function to plot the mean per sample. Can be one of the following:
"median"
"geometric"
"nz.geometric" geometric without zero
"mod.geometric" modified geometric with epsilon = 1e-05 (see https://arxiv.org/abs/1806.06403)
"arithmetic"
...Additional arguments passed to
$compute_norm
Method extract_pairwise_data_with_design()
Get formatted data for a group with its matching control within a batch
Arguments
in_batch(optional) A character vector specifying the batch(es) to include.
in_group(optional) A character vector specifying the group(s) to include.
rescale_inter_normRescale inter-sample normalization factors so that their geometric mean is 1. Default is TRUE.
Returns
list with selected attributes:
"raw" : matrix of raw values for test and control samples specified as column names
"len" : matrix of tag lenght values for test and control samples specified as column names
"intra_norm_fact" : matrix intra normalization factors
"inter_norm_fact" : vector of inter normalization factors
"norm_fact" : vector of inter normalization factors
"test_samples" : vector with test sample names
"ctrl_samples" : vector with control sample names
"design_table" : design table only for those samples
"ctrl_group" : the control group
Method clean_id_versions()
Clean version suffixes from expression tag IDs.
This method applies the remove_id_version_suffix utility to the
row names of internal data matrices (raw, len, intra_norm_fact)
and to selected_ids.
Method plot_prcomp()
Function to draw PCA plots
Usage
ExprData$plot_prcomp(
in_batch = NULL,
in_group = NULL,
intra_norm = TRUE,
inter_norm = TRUE,
tr_fn = (function(x) log2(x + 2)),
plot_scale = "group",
ggplot_mod = NULL,
color_palette = "Paired",
prcomp_args = list(),
include_ctrl_at_group_scale = FALSE,
tags = NULL,
tag_type = NULL,
pca_plot_dims = c(1L, 2L),
mshape = setNames("b_label", "Batch"),
mcolor = setNames("g_label", "Group"),
point_size = 5
)Arguments
in_batch(optional) A character vector specifying the batch(es) to include.
in_group(optional) A character vector specifying the group(s) to include.
intra_normA boolean indicating whether to apply intra-sample normalization.
inter_normA boolean indicating whether to apply inter-sample normalization.
tr_fndata transformation function
plot_scaleAt which scale are the samples correlated.
ggplot_modggplot modifier that will be added to the graph.
color_palettename of the palette of color to use
prcomp_argsargs to be used with prcomp.
include_ctrl_at_group_scalewhether to include the controls at group scale
tagsvector of tag ids to use for the plot
tag_typename of the tag type to use
pca_plot_dimsinteger id the the principal component to plot
mshapeWhich variable to use for shape mapping
mcolorWhich variable to use for color mapping
point_sizepoint size for geom plot
prcomp_autoplot_argslist of argument that are used with autoplot.
Method plot_corr()
Function to draw correlation plots
Usage
ExprData$plot_corr(
in_batch = NULL,
in_group = NULL,
intra_norm = TRUE,
inter_norm = TRUE,
tr_fn = (function(x) log2(x + 2)),
plot_scale = "group",
ggplot_mod = NULL,
include_ctrl_at_group_scale = FALSE,
tags = NULL,
tag_type = NULL
)Arguments
in_batch(optional) A character vector specifying the batch(es) to include.
in_group(optional) A character vector specifying the group(s) to include.
intra_normA boolean indicating whether to apply intra-sample normalization.
inter_normA boolean indicating whether to apply inter-sample normalization.
tr_fndata transformation function
plot_scaleAt which scale are the samples correlated.
ggplot_modggplot modifier that will be added to the graph.
include_ctrl_at_group_scalewhether to include the controls at group scale
tagsvector of tag ids to use for the plot
tag_typename of the tag type to use
Method plot_hclust()
Function to draw hierarchical clustering plots
Usage
ExprData$plot_hclust(
in_batch = NULL,
in_group = NULL,
intra_norm = TRUE,
inter_norm = TRUE,
tr_fn = (function(x) log2(x + 2)),
plot_scale = "group",
ggplot_mod = NULL,
color_palette = "BrBG",
dist_method = "euclidean",
hclust_method = "ward.D2",
dim_reduce = NULL,
clust_bar_var = c(),
height_main = 10,
width_main = 4,
prcomp_args = list(),
include_ctrl_at_group_scale = FALSE,
tags = NULL,
tag_type = NULL
)Arguments
in_batch(optional) A character vector specifying the batch(es) to include.
in_group(optional) A character vector specifying the group(s) to include.
intra_normA boolean indicating whether to apply intra-sample normalization.
inter_normA boolean indicating whether to apply inter-sample normalization.
tr_fndata transformation function
plot_scaleAt which scale are the samples correlated.
ggplot_modggplot modifier that will be added to the graph.
color_palettename of the palette of color to use
dist_methoddistance method
hclust_methodhierarchical clustering method
dim_reducereduction before clustering
clust_bar_varlist of variable to include as legend as a color bar
height_mainheight value for main graph
width_mainwidth value for main graph
prcomp_argsargs to be used with prcomp.
include_ctrl_at_group_scalewhether to include the controls at group scale
tagsvector of tag ids to use for the plot
tag_typename of the tag type to use