20  Cross-association

Cross-association analysis is a straightforward approach that can reveal the strength and type of associations between datasets. For instance, we can analyze if higher presence of a specific taxon relates to higher levels of a biomolecule. Correlation analyses within a dataset were already discussed in Chapter 17.

In this chapter, we continue from where we left off in the previous section (Chapter 19). There, we tested whether the microbiome and the metabolite profiles of the Hintikka et al. (2021) dataset are globally associated. Next, we investigate associations between individual features.

Xylo-oligosaccharides in prevention of hepatic steatosis and adipose tissue inflammation: Associating taxonomic and metabolomic patterns in fecal microbiomes with biclustering. Hintikka et al. (2021). Int J Environ Res Public Health 18:4049. doi:10.3390/ijerph18084049.
# Load the data
data(HintikkaXOData, package = "mia")
mae <- HintikkaXOData

We agglomerate the data into prevalent bacterial families and apply a logarithmic transformation.

# Agglomerate microbiome data at family level
mae[[1]] <- agglomerateByRank(mae[[1]], rank = "Family", na.rm = TRUE)
mae[[1]] <- addPrevalence(mae[[1]])
mae[[1]] <- subsetBy(
    mae[[1]],
    rows = prevalence > 0.5, collapse = TRUE
)
# Apply log10 transformation to microbiome data
mae[[1]] <- transformAssay(mae[[1]], method = "log10", pseudocount = TRUE)

Next we can perform a cross-association analysis. Let us analyze if individual bacterial families are correlated with concentrations of individual metabolites. This helps to answer the following question: “If bacterium X is present, is the concentration of metabolite Y lower or higher?”

res <- getCrossAssociation(
    mae,
    experiment1 = 1,
    experiment2 = 2,
    assay.type1 = "log10",
    assay.type2 = "nmr",
    method = "spearman",
    test.signif = TRUE,
    p.adj.threshold = NULL,
    cor.threshold = NULL,
    mode = "matrix",
    sort = TRUE,
    show.warnings = FALSE
)

Next, we create a heatmap depicting all cross-correlations between bacterial families and metabolite concentrations (Figure 20.1).

library(ComplexHeatmap)
library(shadowtext)

# Function for marking significant correlations with "X"
add_signif <- function(j, i, x, y, width, height, fill) {
    # If the p-value is under threshold
    if (!is.na(res$p_adj[i, j]) & res$p_adj[i, j] < 0.05) {
        # Print "X"
        grid.shadowtext(
            sprintf("%s", "X"), x, y,
            gp = gpar(fontsize = 8, col = "#f5f5f5")
        )
    }
}

# Create a heatmap
p <- Heatmap(res$cor,
    # Print values to cells
    cell_fun = add_signif,
    heatmap_legend_param = list(
        title = "correlation", legend_height = unit(5, "cm")
    ),
    column_names_rot = 45
)
p
Clustered heatmap with bacterial families as rows and metabolites as columns, filled by Spearman correlation on a color scale, with an X in the cells of significant correlations.
Figure 20.1: Heatmap of Spearman correlations between log10-transformed abundances of prevalent bacterial families (rows) and NMR metabolite concentrations (columns) in the Hintikka et al. (2021) data. Color shows the correlation and X marks correlations with adjusted p-value below 0.05.

Testing all feature pairs quickly leads to a large number of tests. Other tools address this in different ways. anansi restricts the analysis to biologically plausible feature pairs based on prior knowledge, such as functional annotations (Bastiaanssen et al. 2023). OmniCorr, on the other hand, first clusters co-varying features into modules and then correlates these modules across omic layers (Gupta et al. 2026).

Knowledge-based integration of multi-omic datasets with Anansi: Annotation-based analysis of specific interactions. Bastiaanssen et al. (2023). arXiv. doi:10.48550/arXiv.2305.10832.
OmniCorr: An R-package for visualizing putative host-microbiome interactions using multi-omics data. Gupta et al. (2026). Bioinform Adv 6:vbag057. doi:10.1093/bioadv/vbag057.

20.1 Exercises

We use the HintikkaXOData dataset. Unlike in this chapter, we compare the microbiota with the biomarkers.

Solve the exercises in order, as each exercise continues from the previous one. Try to solve each exercise yourself before opening the solution.

Exercise 1: Cross-association and multiple testing

Goal: Explain what cross-association analysis tells us and why the number of tests matters.

Answer the following questions without writing any code. The beginning and the end of this chapter will help you.

  1. What kind of question can be answered with cross-association analysis between bacterial taxa and metabolites?

  2. Suppose that the microbiota data has 38 families and the biomarker data has 39 biomarkers. How many correlations are tested if every family is tested against every biomarker?

  3. Why does a large number of tests cause a problem, and how is it taken into account?

  1. For example: “If bacterium X is abundant, is the concentration of metabolite Y lower or higher?” Cross-association analysis tells the strength and direction of the association between each feature of one omic and each feature of the other omic.

  2. 38 x 39 = 1482 correlations.

  3. When many tests are done, some of them are significant just by chance. Therefore, the p-values are adjusted for multiple testing, and the adjusted p-values (p_adj) are used to decide which associations are significant. Another approach is to test only biologically plausible pairs of features, as is done in the anansi package.

Exercise 2: Prepare the data

Goal: Explore a MultiAssayExperiment and prepare the microbiota data for cross-association analysis.

  1. Load the HintikkaXOData dataset from the mia package and store it in a variable called mae.

  2. Show the experiments of mae. Check the names of the assays in the microbiota and biomarkers experiments.

  3. Agglomerate the microbiota experiment to the Family rank with na.rm = TRUE. Then add the prevalence, and combine the families with a prevalence of 0.5 or less into “Other”. How many families are left (including “Other”)?

  4. Apply the log10 transformation to the counts assay of the microbiota experiment with pseudocount = TRUE.

Useful functions: data(), MultiAssayExperiment::experiments(), SummarizedExperiment::assayNames(), mia::agglomerateByRank(), mia::addPrevalence(), mia::subsetBy(), nrow(), mia::transformAssay()

library(mia)

# 1. Load the data
data("HintikkaXOData", package = "mia")
mae <- HintikkaXOData

# 2. Experiments and their assays
experiments(mae)
##  ExperimentList class object of length 3:
##   [1] microbiota: TreeSummarizedExperiment with 12706 rows and 40 columns
##   [2] metabolites: TreeSummarizedExperiment with 38 rows and 40 columns
##   [3] biomarkers: TreeSummarizedExperiment with 39 rows and 40 columns
assayNames(mae[["microbiota"]])
##  [1] "counts"
assayNames(mae[["biomarkers"]])
##  [1] "signals"

# 3. Agglomerate microbiota to prevalent families
mae[["microbiota"]] <- agglomerateByRank(
    mae[["microbiota"]],
    rank = "Family", na.rm = TRUE
)
mae[["microbiota"]] <- addPrevalence(mae[["microbiota"]])
mae[["microbiota"]] <- subsetBy(
    mae[["microbiota"]],
    rows = prevalence > 0.5, collapse = TRUE
)
nrow(mae[["microbiota"]])
##  [1] 38

# 4. log10 transformation
mae[["microbiota"]] <- transformAssay(
    mae[["microbiota"]],
    assay.type = "counts", method = "log10", pseudocount = TRUE
)
Exercise 3: Calculate cross-associations

Goal: Calculate correlations between the features of two experiments.

  1. Calculate the Spearman correlations between the families in the log10 assay of the microbiota experiment and the biomarkers in the signals assay of the biomarkers experiment with getCrossAssociation(). Test the significance of the correlations, keep all results (p.adj.threshold = NULL, cor.threshold = NULL), return them as matrices, sort them (sort = TRUE) and set show.warnings = FALSE. Store the result in res.

  2. Check the dimensions of the correlation matrix res$cor. What do the rows and columns represent?

  3. Count how many correlations have an adjusted p-value below 0.05.

Useful functions: mia::getCrossAssociation(), dim(), sum()

# 1. Cross-associations between microbiota and biomarkers
res <- getCrossAssociation(
    mae,
    experiment1 = "microbiota",
    experiment2 = "biomarkers",
    assay.type1 = "log10",
    assay.type2 = "signals",
    method = "spearman",
    test.signif = TRUE,
    p.adj.threshold = NULL,
    cor.threshold = NULL,
    mode = "matrix",
    sort = TRUE,
    show.warnings = FALSE
)

# 2. Dimensions of the correlation matrix
dim(res$cor)
##  [1] 38 39

# 3. Number of correlations with adjusted p-value below 0.05
sum(res$p_adj < 0.05, na.rm = TRUE)
##  [1] 54
  1. The rows are the families of the first experiment (microbiota) and the columns are the biomarkers of the second experiment (biomarkers). Each cell is the correlation between one family and one biomarker.
Exercise 4: Visualize cross-associations

Goal: Visualize cross-associations with a heatmap.

  1. Visualize the correlation matrix res$cor from Exercise 3 with a heatmap. Rotate the column names by 45 degrees (column_names_rot = 45).

  2. How do you read the heatmap? What does a positive and a negative correlation between a family and a biomarker mean?

Useful functions: ComplexHeatmap::Heatmap()

library(ComplexHeatmap)

# 1. Heatmap of the correlations
Heatmap(res$cor, column_names_rot = 45)

  1. Each row is a family and each column a biomarker, and the color of a cell shows the Spearman correlation between them. A positive correlation means that in rats with a higher abundance of the family, the biomarker tends to have higher values. A negative correlation means that the biomarker tends to have lower values. Blocks of cells with the same color show groups of families and biomarkers that are associated in a similar way. To see which correlations are significant, check the adjusted p-values in res$p_adj. A correlation does not tell whether the bacteria affect the biomarker, or the other way around.
Back to top