Skip to contents

A class representing a nested representation of pairwise comparisons given a pairwise design.

Details

Pairwise Comparison Class

This class serves as a superclass for all methods of pairwise comparisons considered in this package. It defines the shared public and private methods common to all subclass.

Pairwise comparisons are used in experimental designs with test vs control samples, comparing their expression tags to determine deregulation between conditions.

This function filters the results table based on specified groups and batches. Note that the term "filter" in this context does not refer to a statistical filter.

Attributes

  • expr_data: An ExprData object.

  • results: A nested data.frame with columns "batch", "group", and a nested "data" column containing:

    • baseMean: Numeric vector with the base mean of expression value

    • log2FoldChange: Numeric vector with the log2FC

    • lfcSE: Numeric vector with the log2FC standard error

    • pvalue: Numeric vector with the p-values

    • padj: Numeric vector with the adjusted p-values

    • status: Factor vector with four levels: undetected, filtered, outlier, analyzed

    • tag_id: Character vector with the tag id

  • opts: Important options defined during initialization.

Methods


Method get_results()

Get results

Usage

PairwiseComp$get_results()

Returns

A nested dataframe.


Method filter_and_get_results()

Retrieve the results table after filtering for specific groups/batches and with the option to add new columns to extend the tag ID.

Usage

PairwiseComp$filter_and_get_results(
  in_batch,
  in_group,
  verbose = FALSE,
  add_ids = c("gid", "symbol", "uniprot", "protein_names", "type", "tax_name"),
  safe_translate = FALSE
)

Arguments

in_batch

Vector of batch codes; select or report only samples in these batches

in_group

Vector of group codes; select or report only samples in these groups

verbose

If TRUE, the column names are replaced with more meaningful names

add_ids

Character vector; see to argument of method generate_translate_dict from class Annotation Available options are: "gid", "symbol", "uniprot", "protein_names", "type", and "tax_name"

safe_translate

If TRUE, the function will keep original ids if the translation fails

Returns

A data.frame containing filtered results with optional additional ID columns


Method generate_a_list()

Generate a list of deregulated genes for a specific comparison based on given criteria.

Usage

PairwiseComp$generate_a_list(
  in_batch,
  in_group,
  id = "symbol",
  use_padj = TRUE,
  type = "deregulated",
  lfc_abs_lim = 1,
  min_signif = 0.05,
  ranking = "log2FoldChange",
  top_x = NULL
)

Arguments

in_batch

Vector of batch codes; select or report only samples in these batches

in_group

Vector of group codes; select or report only samples in these groups

id

Character vector; see to argument of method generate_translate_dict from class Annotation

use_padj

Whether to use the adjusted p-value or not

type

Type of deregulation: "deregulated", "upregulated", or "downregulated"

lfc_abs_lim

Threshold for log fold change

min_signif

Threshold for significance

ranking

A character string specifying the value to use for ranking. Can be either "log2FoldChange" (default) or "z" for a z-score calculated from the p-value and fold change direction.

top_x

An integer. If not NULL (the default), the list is restricted to the top top_x genes after ranking.

Returns

A character vector


Method cross_args_and_generate_lists()

Generate crossed lists of genes from all comparisons in nested results using multiple filtering criteria.

Usage

PairwiseComp$cross_args_and_generate_lists(
  cross_id = c("symbol", "uniprot"),
  use_padj = TRUE,
  cross_type = c("deregulated", "upregulated", "downregulated"),
  cross_lfc_abs_lim = c(log2(1.5), 1),
  cross_min_signif = c(0.01, 0.05),
  top_x = NULL
)

Arguments

cross_id

Character vector; see id argument in generate_a_list method

use_padj

Whether to use the adjusted p-value or not

cross_type

Vector of deregulation types; see type argument in generate_a_list method Available options are: "deregulated", "upregulated", "downregulated" (default: c("deregulated", "upregulated", "downregulated"))

cross_lfc_abs_lim

Vector of log fold change thresholds; see lfc_abs_lim argument in generate_a_list method

cross_min_signif

Vector of significance thresholds; see min_signif argument in generate_a_list method

top_x

An integer. If not NULL (the default), the list is restricted to the top top_x genes after ranking.

Returns

A nested data.frame containing crossed lists of genes for each combination of filtering criteria


Method write_to_xlsx()

Write comparison results to xlsx

Usage

PairwiseComp$write_to_xlsx(
  file_suffix = "_pairwiseComp.xlsx",
  output_folder = ".",
  in_batch = NULL
)

Arguments

file_suffix

suffix for output file

output_folder

output folder

in_batch

Vector of batch codes; select or report only samples in these batches

Returns

NULL


Method generate_summary()

Get the summary in number of deregulated genes from the comparisons

Usage

PairwiseComp$generate_summary(...)

Arguments

...

passed to cross_args_and_generate_lists method

Returns

tibble with summary stats


Method plot_summary()

Plot the summary in number of deregulated genes from the comparisons

Usage

PairwiseComp$plot_summary(...)

Arguments

...

passed to generate_summary method

Returns

ggplot2 object with summary plot


Method extract_data_for_plot()

Return data for plots

Usage

PairwiseComp$extract_data_for_plot(
  use_padj = TRUE,
  lfc_abs_lim = 1,
  min_signif = 0.05,
  tag_id_select = "symbol",
  tag_id_show = "symbol",
  select_ids = NULL,
  select_batches = NULL,
  max_tags = 15,
  in_batches = NULL,
  hard_select = FALSE,
  safe_translate = TRUE
)

Arguments

use_padj

Whether to use the adjusted p-value or not

lfc_abs_lim

Threshold for log fold change

min_signif

Threshold for significance

tag_id_select

Tag ID used for selection. Tag id can be "gid", "tgid", "txid", "symbol" or "uniprot"

tag_id_show

Tag ID used for plots. Tag id can be "gid", "tgid", "txid", "symbol" or "uniprot"

select_ids

Vector of IDs (tag_id_select) to select the genes

select_batches

vector of batch to mark for selection

max_tags

maximum number of tags to show

in_batches

vector of batches code to keep (default all)

hard_select

whether to remove unselected data

safe_translate

If TRUE, the function will keep original ids if the translation fails

Returns

long data frame for plot


Method plot_ma()

Return MA plot(s)

Usage

PairwiseComp$plot_ma(...)

Arguments

...

options passed to plot_de method

Returns

The plot


Method plot_vulcano()

Return VULCANO plot(s)

Usage

PairwiseComp$plot_vulcano(...)

Arguments

...

options passed to plot_de method

Returns

The plot


Method plot_lfc_per_group()

Return LFC per group plot(s)

Usage

PairwiseComp$plot_lfc_per_group(...)

Arguments

...

options passed to plot_de method

Returns

The plot


Method plot_lfc_per_group_facet_tags()

Return LFC per group with tags as facet plot(s)

Usage

PairwiseComp$plot_lfc_per_group_facet_tags(geoms = c("bar", "errorbar"), ...)

Arguments

geoms

vector with geoms see method plot_de

...

options passed to plot_de method

Returns

The plot


Method plot_de()

Return plot(s)

Usage

PairwiseComp$plot_de(
  plot_type,
  lfc_limits = NULL,
  geoms = "point",
  show_selected_ids = TRUE,
  text_in_box = FALSE,
  max_nrow = 5,
  tag_ids_size = 4,
  tag_ids_alpha = 0.5,
  log2_expr = TRUE,
  batch_layout = "facet_grid_x",
  facet_scales = "fixed",
  facet_space = "fixed",
  ...
)

Arguments

plot_type

plot to draw either:

  • "ma" : MA-plot

  • "vulcano" : vulcano-plot

  • "lfc_per_group" : lfc per group

  • "lfc_per_group_facet_tags" : lfc per group with tag facet

lfc_limits

values to draw hline and or vline for lfc

geoms

vector with geoms to add:

  • point : compatible with all

  • bar : only for "lfc_per_group_facet_tags"

  • line : only for "lfc_per_group*"

  • errorbar : only for "lfc_per_group_facet_tags"

show_selected_ids

whether or not to show the selected ids (not compatible with lfc_per_group*)

text_in_box

whether or not to use box to plot text (show_selected_ids)

max_nrow

maximum of facet row for the nested wrap facetting

tag_ids_size

size when tag ids are plotted in plot area

tag_ids_alpha

alpha when tag ids are plotted in plot area

log2_expr

Whether to use log2(x+2) transform for expression data

batch_layout

Define the type of layout for batch

  • "facet_nested_wrap"

  • "facet_grid_x"

  • "facet_grid_y"

  • "color_selected" represent all batch on the same plot with a focus on a selected batch;only with plot_type "lfc_per_group_facet_tags" with color_selected we must use select_batches from extract_data_for_plot

facet_scales

scales = "fixed" by default

facet_space

space = "fixed" by default

...

options passed to extract_data_for_plot method

Returns

The plot


Method build_tag_hclust()

Return tag hclust "NA" values are replaced with 0

Usage

PairwiseComp$build_tag_hclust(
  data = NULL,
  meth_dist = "minkowski",
  meth_value = "z",
  meth_clust = "centroid",
  max_abs_value = 100,
  ...
)

Arguments

data

Optional data similar to extract_data_for_plot output

meth_dist

method to compute distance, see dist() function

meth_value

value to compute distance

  • "z"

  • "log2FoldChange"

meth_clust

method to compute clustering, see hclust() function

max_abs_value

maximum absolute value to consider

...

options passed to extract_data_for_plot method

Returns

The plot


Method plot_heatmap()

Return HEATmap for a batch

Usage

PairwiseComp$plot_heatmap(
  meth_tag_dist = "minkowski",
  meth_tag_clust = "centroid",
  meth_tag_value = "z",
  max_abs_value_hclust = 100,
  plot_value = "z",
  max_abs_value_plot = 5,
  cut_tree_k = NULL,
  show_selected_ids = FALSE,
  meth_tag_dist2 = "minkowski",
  meth_tag_value2 = "z",
  meth_tag_clust2 = "ward.D2",
  max_abs_value_hclust2 = 100,
  ...
)

Arguments

meth_tag_dist

meth_dist for build_tag_hclust()

meth_tag_clust

meth_clust for build_tag_hclust()

meth_tag_value

meth_value for build_tag_hclust()

max_abs_value_hclust

max_abs_value for build_tag_hclust()

plot_value

value to plot

max_abs_value_plot

maximum value for values to plot

cut_tree_k

if provided with cut the heatmap into pieces based on the hclust

  • "log2FoldChange"

  • "z" : z-score

show_selected_ids

whether to show or not the selected ids.

meth_tag_dist2

meth_dist for build_tag_hclust() when finding gene cluster if cut_tree_k is not null

meth_tag_value2

meth_value for build_tag_hclust() when finding gene cluster if cut_tree_k is not null

meth_tag_clust2

meth_clust for build_tag_hclust() when finding gene cluster if cut_tree_k is not null

max_abs_value_hclust2

max_abs_value for build_tag_hclust() when finding gene cluster if cut_tree_k is not null

...

options passed to extract_data_for_plot method

Returns

The plot


Method clone()

The objects of this class are cloneable with this method.

Usage

PairwiseComp$clone(deep = FALSE)

Arguments

deep

Whether to make a deep clone.