Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
94 changes: 66 additions & 28 deletions inst/pages/example_solutions.qmd
Original file line number Diff line number Diff line change
Expand Up @@ -412,26 +412,6 @@ These example solutions are related to exercises in [@sec-mediation].
#| code-summary: "Show the solution"
```

## Network learning & analysis

These example solutions are related to exercises in [@sec-network-learning].

```{r}
#| label: network1
#| code-fold: true
#| code-summary: "Show the solution"
```

## Network comparison

These example solutions are related to exercises in [@sec-network-comparison].

```{r}
#| label: network2
#| code-fold: true
#| code-summary: "Show the solution"
```

## Cross-association

These example solutions are related to exercises in [@sec-cross-correlation].
Expand All @@ -440,6 +420,37 @@ These example solutions are related to exercises in [@sec-cross-correlation].
#| label: cross-corr
#| code-fold: true
#| code-summary: "Show the solution"

# Load the example dataset
library(mia)
data(HintikkaXOData)
mae <- HintikkaXOData

# Agglomerate microbiome data
mae[[1]] <- agglomerateByPrevalence(mae[[1]], rank = "Phylum")

# Apply CLR
mae[[1]] <- transformAssay(mae[[1]], assay.type = "counts", method = "rclr")

# Apply relative and log10
mae[[2]] <- transformAssay(mae[[2]], assay.type = "nmr", method = "relabundance")
mae[[2]] <- transformAssay(mae[[2]], assay.type = "relabundance", method = "log10", pseudocount = TRUE)

# Cross correlates data sets
res <- getCrossAssociation(
mae,
experiment1 = 1,
experiment2 = 2,
assay.type1 = "rclr",
assay.type2 = "log10",
method = "spearman",
mode = "matrix"
)

# Create a heatmap
library(ComplexHeatmap)
p <- Heatmap(res)
p
```

## Ordination-based multiassay analysis
Expand All @@ -451,17 +462,44 @@ These example solutions are related to exercises in
#| label: mofa
#| code-fold: true
#| code-summary: "Show the solution"
```

## Multi-omics prediction and classification
# Load the example dataset
library(mia)
data(HintikkaXOData)
mae <- HintikkaXOData

These example solutions are related to exercises in
[@sec-multi-omics-integration].
# Select only microbiome and metabolites
mae <- mae[, , c(1, 2)]

```{r}
#| label: integratedlearner
#| code-fold: true
#| code-summary: "Show the solution"
# Agglomerate microbiome data
mae[[1]] <- agglomerateByPrevalence(mae[[1]], rank = "Phylum")

# Apply CLR
mae[[1]] <- transformAssay(mae[[1]], assay.type = "counts", method = "rclr")

# Apply relative and log10 transformations
mae[[2]] <- transformAssay(mae[[2]], assay.type = "nmr", method = "relabundance")
mae[[2]] <- transformAssay(mae[[2]], assay.type = "relabundance", method = "log10", pseudocount = TRUE)

# Scale features
mae[[1]] <- transformAssay(mae[[1]], assay.type = "rclr", method = "standardize", MARGIN = "rows")
mae[[2]] <- transformAssay(mae[[2]], assay.type = "log10", method = "standardize", MARGIN = "rows")

# Removing the assays no longer needed
assays(mae[[1]]) <- assays(mae[[1]])["standardize"]
assays(mae[[2]]) <- assays(mae[[2]])["standardize"]

# Create a MOFA object
library(MOFA2)
model <- create_mofa_from_MultiAssayExperiment(mae)

# Run MOFA
model <- prepare_mofa(object = model)
model <- run_mofa(model, use_basilisk = TRUE)

# Visualize variance explained
p <- plot_variance_explained(model, x = "view", y = "factor")
p
```

## Machine learning
Expand Down
13 changes: 8 additions & 5 deletions inst/pages/multiassay_ordination.qmd
Original file line number Diff line number Diff line change
Expand Up @@ -224,17 +224,20 @@ interpret MOFA results.
4. Apply relative transformation and log10 transformation to other metabolite or
other omic.

5. Create a MOFA2 object from the `MultiAssayExperiment`.
5. Standardize each feature (within each dataset) by centering to mean 0 and
scaling to unit variance so that all variables are on a comparable scale.

6. Run MOFA.
6. Create a MOFA2 object from the `MultiAssayExperiment`.

7. Visualize the explained variance. How much variance is explained in total,
7. Run MOFA.

8. Visualize the explained variance. How much variance is explained in total,
and which omic accounts the most variance?

8. For each omic, visualize the features with the largest weights. Can you
9. For each omic, visualize the features with the largest weights. Can you
identify features that are co-varying?

9. If you completed exercises in [@sec-cross-correlation], did you get similar
10. If you completed exercises in [@sec-cross-correlation], did you get similar
results? Do the co-varying features also exhibited correlation?

Useful functions:
Expand Down
Loading