LSMA

LONDON SCHOOL OF MULTIOMICS & AI

LSMA

LONDON SCHOOL OF MULTIOMICS & AI

Free course

Free course

0 of 31 lessons

Multi-omics integration with MOFA2 and DIABLO

Multi-omics integration with MOFA2 and DIABLO

Multi-omics integration with MOFA2 and DIABLO

Three measurements of the same tumours: mRNA, miRNA and protein. This lesson finds what they share, first with DIABLO, which is told the subtypes, then with MOFA2, which is not.

This lesson follows DNA methylation with methylKit.

Why integrate several omics at once

So far in this course each analysis has used one kind of measurement: RNA counts, single-cell counts, peaks or methylation. Real studies increasingly measure several on the same samples. The breast cancer data in this lesson, from The Cancer Genome Atlas (TCGA), has three for each tumour: messenger RNA (mRNA) expression, microRNA (miRNA) expression and protein levels. Each of these is called a view, block or layer; the words mean the same thing here.

You could analyse each block on its own and compare the lists afterwards. Integration asks a different question: what patterns are shared across blocks? A signal that appears in mRNA, miRNA and protein together is more likely to be real biology than one seen in a single noisy assay, and the links between blocks (this miRNA goes with that protein) are themselves of interest.

There are two broad approaches, and the difference between them is the same as between PCA and a classifier in Module 5.

  • Unsupervised integration looks for the main sources of variation across all blocks without being told anything about the samples. MOFA (Multi-Omics Factor Analysis) is the best-known method. It finds a small number of factors, hidden variables that each sample has a value for, and reports how much of each block's variation every factor explains. A factor might be active in all three blocks, or in only one. You then ask what the factors mean, for example by comparing them with known subtypes.
  • Supervised integration is given the outcome and looks for the features, across blocks, that separate the groups. DIABLO, in the mixOmics package, does this. It is a multi-block version of sparse partial least squares discriminant analysis (sPLS-DA): it picks a few features from each block that both separate the groups and agree with each other between blocks.

The trade-off is familiar. A supervised method will always find something that separates your groups, so it needs honest validation. An unsupervised method shows you what is really driving the data, which may be a batch effect rather than the biology you care about.

The breast.TCGA data

mixOmics ships a small, pre-filtered version of the TCGA breast cancer data. The training set has 150 tumours of three subtypes; the test set has 70 more, measured for mRNA and miRNA only.

R
library(mixOmics)
data(breast.TCGA)
X <- list(mrna    = breast.TCGA$data.train$mrna,
          mirna   = breast.TCGA$data.train$mirna,
          protein = breast.TCGA$data.train$protein)
Y <- breast.TCGA$data.train$subtype
sapply(X, dim)
table(Y)
all(rownames(X$mrna) == rownames(X$protein))
all(rownames(X$mrna) == rownames(X$mirna))
mrna mirna protein [1,] 150 150 150 [2,] 200 184 142 Y Basal Her2 LumA 45 30 75 [1] TRUE [1] TRUE

What this does

  • X is a named list of three matrices, one per block. mixOmics wants samples in rows and features in columns, the opposite of the gene-by-sample layout used by DESeq2.
  • Each block has 150 rows, one per tumour, and its own number of features: 200 genes, 184 miRNAs and 142 proteins. These were already filtered down from many thousands by the package authors to keep the example small.
  • Y is the subtype of each tumour: Basal, Her2 or LumA (luminal A). The groups are unequal, with half the tumours LumA.
  • The two all(... == ...) checks confirm that row i is the same tumour in every block. Integration methods match samples by position, so this check matters as much as the sample-sheet check in RNA-seq counts and exploration.

DIABLO: supervised integration

DIABLO needs two choices before it runs. keepX says how many features to keep from each block on each component, which makes the result short enough to read. The design matrix says how strongly each pair of blocks should be linked: 0 means "do not try to make these agree", 1 means "agreement between them matters as much as separating the groups". The mixOmics authors suggest values around 0.1 as a compromise when the aim is mainly to predict the outcome.

R
design <- matrix(0.1, ncol = length(X), nrow = length(X),
                 dimnames = list(names(X), names(X)))
diag(design) <- 0
design

keepX <- list(mrna = c(20, 10), mirna = c(10, 5), protein = c(10, 5))
diablo <- block.splsda(X, Y, ncomp = 2, keepX = keepX, design = design)
lapply(diablo$prop_expl_var, round, 3)
selectVar(diablo, comp = 1)$protein$name
mrna mirna protein mrna 0.0 0.1 0.1 mirna 0.1 0.0 0.1 protein 0.1 0.1 0.0 Design matrix has changed to include Y; each block will be linked to Y. $mrna comp1 comp2 0.176 0.039 $mirna comp1 comp2 0.199 0.029 $protein comp1 comp2 0.107 0.035 … [1] "ER-alpha" "GATA3" "ASNS" "Cyclin_B1" "AR" "JNK2" [7] "Cyclin_E1" "PR" "INPP4B" "CDK1"

What this does

  • The design matrix has a row and column per block, 0.1 between every pair and 0 on the diagonal (a block is not linked with itself). The message says DIABLO also links every block to the outcome Y, which it always does.
  • keepX asks for 20 genes, 10 miRNAs and 10 proteins on component 1, and half as many on component 2. These numbers are a choice made here for illustration. In a real analysis you would choose them with tune.block.splsda(), which tries several values with cross-validation and picks those with the lowest error.
  • block.splsda() fits the model with two components. Each component is a weighted combination of the selected features in one block, one score per tumour, as in PCA, but chosen to separate the subtypes.
  • prop_expl_var gives the share of each block's variance captured by each component: about 18% of the mRNA variance, 20% of the miRNA and 11% of the protein on component 1. These are modest because only a few features are used.
  • selectVar() lists the features chosen on a component.

The proteins chosen on component 1 make biological sense. Oestrogen receptor alpha (ER-alpha), GATA3 and the progesterone receptor (PR) are high in luminal tumours and low in basal ones; they are the markers pathologists use to classify breast cancers. Cyclin B1, Cyclin E1 and CDK1 are cell-cycle proteins, typically higher in the fast-dividing basal tumours. A list that makes sense is encouraging, though not proof: the model was told the subtypes and asked to separate them, and these are the features that do it.

Because the blocks were linked, the components should agree across blocks. The correlation between blocks' first components shows how far they do.

R
cor(diablo$variates$mrna[, 1], diablo$variates$protein[, 1])
cor(diablo$variates$mrna[, 1], diablo$variates$mirna[, 1])
cor(diablo$variates$mirna[, 1], diablo$variates$protein[, 1])

okabe <- c("#E69F00", "#56B4E9", "#009E73")
plotIndiv(diablo, ind.names = FALSE, legend = TRUE, col = okabe,
          title = "DIABLO, components 1 and 2")
circosPlot(diablo, cutoff = 0.7, color.blocks = okabe,
           color.cor = c("#0072B2", "#D55E00"), size.labels = 1.2)
[1] 0.9221228 [1] 0.8459996 [1] 0.763221

The first components of mRNA and protein correlate at 0.92, so the tumours are ordered almost identically by both. miRNA agrees less well, at 0.85 with mRNA and 0.76 with protein.

plotIndiv() draws one panel per block, with each tumour placed by its scores on the two components. In the plot from this run, component 1 runs from Basal on the left to LumA on the right in all three blocks, and component 2 lifts the Her2 tumours above the rest, most clearly in the protein block. The miRNA panel shows the three subtypes overlapping more, which matches its lower correlations. col sets the group colours, here three of the Okabe–Ito colours.

circosPlot() draws the selected features around a circle, grouped by block, with a line between any two features from different blocks whose correlation is stronger than the cutoff of 0.7: red-orange lines for positive correlations and blue for negative ones (color.cor takes the colour for negative correlations first). It is a compact picture of the links between blocks, such as an mRNA that rises with a protein. Read it as a map of correlations among the selected features, not of regulation: a line does not say which feature affects the other, or that either does.

Is the classifier any good?

As in Random forests and cross-validation, the error on the data used to fit a model is too optimistic. DIABLO has two checks: cross-validation with perf(), and prediction on the test tumours the model has never seen.

R
set.seed(42)
perf_d <- perf(diablo, validation = "Mfold", folds = 5, nrepeat = 5, progressBar = FALSE)
perf_d$WeightedVote.error.rate$centroids.dist

Xtest <- list(mrna = breast.TCGA$data.test$mrna, mirna = breast.TCGA$data.test$mirna)
pred <- predict(diablo, newdata = Xtest)
pred_class <- pred$WeightedVote$centroids.dist[, 2]
table(predicted = pred_class, truth = breast.TCGA$data.test$subtype)
mean(pred_class == breast.TCGA$data.test$subtype)
comp1 comp2 Basal 0.02666667 0.02666667 Her2 0.12666667 0.13333333 LumA 0.06400000 0.01600000 Overall.ER 0.06533333 0.04266667 Overall.BER 0.07244444 0.05866667 truth predicted Basal Her2 LumA Basal 20 0 0 Her2 1 14 1 LumA 0 0 34 [1] 0.9714286 Warning message: In predict.block.spls(diablo, newdata = Xtest) : Some blocks are missing in 'newdata'; the prediction is based on the following blocks only: mrna, mirna

What this does

  • perf() runs 5-fold cross-validation five times: it refits the model on four-fifths of the tumours and predicts the rest. set.seed() fixes the random split so the numbers repeat.
  • Each block makes its own prediction, and the weighted vote combines them, giving more weight to blocks whose components agree best with the outcome. centroids.dist is one of three distance rules for turning scores into a class: each tumour is assigned to the subtype whose average position it is closest to.
  • The balanced error rate (BER) averages the error of each subtype, so the large LumA group cannot hide poor performance on Her2. With two components it is 0.059, about 6%. Most errors are in Her2, the smallest and most varied group (13% error).
  • predict() places the test tumours on the fitted components. The test set has no protein data, and DIABLO predicts from the blocks it has, as the warning says. Column 2 of the result is the prediction using both components.
  • 68 of 70 test tumours are classified correctly, 97%. The two errors are both called Her2.

That the model works without the protein block is useful in practice: proteins are the hardest of the three to measure, and a model trained on all three can still be applied to new samples with fewer.

Worked example · overall versus balanced error

From the cross-validation table, component 2: Basal 0.027, Her2 0.133, LumA 0.016. The groups have 45, 30 and 75 tumours.

balanced error = (0.0267 + 0.1333 + 0.0160) ÷ 3 = 0.1760 ÷ 3 = 0.0587
overall error ≈ (45 × 0.0267 + 30 × 0.1333 + 75 × 0.0160) ÷ 150
= (1.2 + 4.0 + 1.2) ÷ 150 = 6.4 ÷ 150 = 0.0427

Step by step. The balanced error gives each subtype one third of the weight, whatever its size. The overall error counts tumours, so LumA, with half of them and the lowest error, pulls it down. Both numbers match the table's Overall.BER and Overall.ER rows.

What the answer means. When groups are unequal, the overall error flatters a classifier that does well on the big group. Report the balanced error, and the per-group errors, so a reader sees that Her2 is the hard case.

MOFA2: unsupervised integration

Now the same three blocks without the subtypes. MOFA2 fits its model in Python, through the mofapy2 package. With use_basilisk = FALSE, the default in the version used here (MOFA2 1.18), it uses the Python that the reticulate package points to, which must have mofapy2 installed (pip install mofapy2); change the path below to your own Python. With use_basilisk = TRUE, MOFA2 instead downloads and builds its own Python environment the first time, which takes a while.

R
library(MOFA2)
reticulate::use_python("/Users/you/miniconda3/bin/python3", required = TRUE)

views <- lapply(X, t)
mofa <- create_mofa(views)
model_opts <- get_default_model_options(mofa)
model_opts$num_factors <- 5
train_opts <- get_default_training_options(mofa)
train_opts$seed <- 42
mofa <- prepare_mofa(mofa, model_options = model_opts, training_options = train_opts)
mofa <- run_mofa(mofa, outfile = tempfile(fileext = ".hdf5"), use_basilisk = FALSE)

ve <- get_variance_explained(mofa)
round(ve$r2_per_factor[[1]], 1)
… Converged! … mrna mirna protein Factor1 20.5 16.7 20.2 Factor2 11.9 6.2 1.8 Factor3 0.2 1.2 11.3 Factor4 0.8 11.7 0.1 Factor5 4.7 4.6 1.0 Warning message: … Factor(s) 2, 4 are strongly correlated with the total number of expressed features for at least one of your omics. …

What this does

  • MOFA2 wants the opposite orientation to mixOmics, features in rows and samples in columns, so lapply(X, t) transposes each block.
  • create_mofa() builds the model object; the default options are fetched, the number of factors set to 5 and the random seed fixed, then prepare_mofa() checks everything and run_mofa() trains the model, saving it to a file. Training stops when the fit no longer improves ("Converged!"), here after 86 iterations.
  • get_variance_explained() gives, for every factor and view, the percentage of that view's variance the factor explains. plot_variance_explained(mofa) draws the same table as a heatmap.

This table is the heart of a MOFA analysis. Factor 1 explains about a fifth of the variance in all three views: it is a shared axis of variation. Factor 3 is almost entirely protein (11.3%), and Factor 4 almost entirely miRNA (11.7%): signals found in one layer only. Factor 2 is mostly mRNA. Together the five factors explain 38%, 38% and 34% of the three views.

Only now do we bring in the subtypes, to interpret the factors rather than to find them.

R
f <- get_factors(mofa)[[1]]
round(sapply(as.data.frame(f), function(x) tapply(x, Y, mean)), 2)
sapply(as.data.frame(f), function(x) round(summary(aov(x ~ Y))[[1]][["Pr(>F)"]][1], 4))

w <- get_weights(mofa, views = "protein", factors = 1)[[1]]
head(sort(w[, 1]), 4)
tail(sort(w[, 1]), 4)
Factor1 Factor2 Factor3 Factor4 Factor5 Basal -1.47 -0.05 0.08 0.43 -0.10 Her2 -0.30 0.15 -0.15 -0.25 0.14 LumA 1.00 -0.03 0.02 -0.16 0.01 Factor1 Factor2 Factor3 Factor4 Factor5 0.0000 0.6727 0.6184 0.0017 0.6027 Cyclin_B1 ASNS Cyclin_E1 -0.6444731 -0.4021246 -0.3710856 Caspase-7_cleavedD198 -0.3357988 Caveolin-1 GATA3 PR ER-alpha 0.5421492 0.7894885 0.9452152 1.3966975

get_factors() returns each tumour's value on each factor. The mean per subtype and a one-way ANOVA (Linear models with groups and covariates) ask whether a factor differs between subtypes. Factor 1 does, strongly: Basal tumours average −1.47, LumA +1.00. Its protein weights, how much each feature contributes, put ER-alpha, PR and GATA3 at the positive end and Cyclin B1 and Cyclin E1 at the negative end: the same luminal-versus-basal axis DIABLO found, recovered here without being told the subtypes. Factor 4, the miRNA-only factor, also differs between subtypes (p = 0.0017), though less. Factors 2, 3 and 5 do not; they are variation of some other kind.

The warning deserves attention. MOFA2 checks whether any factor tracks the overall level of each sample, and flags factors 2 and 4. Such factors can be real biology, but they are often a sign of a normalisation difference between samples, and they should be checked, for example against sequencing depth or batch, before being interpreted.

That is the strength of the unsupervised approach: when the main shared factor matches the known subtypes, the subtype signal is not something the method was steered towards. And the factors that do not match are leads, or warnings, that a supervised method would never have shown you.

Common mistakes

  • Samples out of order between blocks. Both methods match samples by position or name. Check that every block has the same samples in the same order before fitting.
  • Choosing keepX on the same data you report. Tune with cross-validation, then judge the final model on data it has not seen.
  • Reading a supervised separation as discovery. DIABLO separates the groups it is given, so a clean plotIndiv() is expected; the cross-validated error is the evidence.
  • Unscaled, unfiltered blocks. A block with thousands of noisy features can drown a small, informative one. Filter each block to its most variable features first, as the breast.TCGA authors did.

DIABLO is described in Singh et al. 2019, "DIABLO: an integrative approach for identifying key molecular drivers from multi-omics assays" (Bioinformatics), and mixOmics in Rohart et al. 2017 (PLOS Computational Biology). MOFA is described in Argelaguet et al. 2018, "Multi-Omics Factor Analysis — a framework for unsupervised integration of multi-omics data sets" (Molecular Systems Biology), and MOFA+ in Argelaguet et al. 2020 (Genome Biology). The breast.TCGA data come from The Cancer Genome Atlas Network 2012 (Nature). Cite the packages with citation("mixOmics") and citation("MOFA2") and give their versions.

Further reading · Module 7Singh et al. 2019: DIABLO, with the breast cancer example. · All reading for this course

Check your understanding

1. What is the main difference between DIABLO and MOFA?

2. In the DIABLO design matrix, what does a value of 0.1 between mRNA and protein mean?

3. MOFA Factor 1 explained about 20% of the variance in all three views and separated Basal from LumA tumours. Why is that convincing?

Ask LSMA