8000 Adding link to cheatsheet in 19.1.3.2 & removed some verbose messages by ElySeraidarian · Pull Request #457 · microbiome/OMA · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Adding link to cheatsheet in 19.1.3.2 & removed some verbose messages #457

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 15 commits into from
May 24, 2024
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
6 changes: 4 additions & 2 deletions inst/pages/95_resources.qmd
Original file line number Diff line number Diff line change
Expand Up @@ -91,8 +91,10 @@ material can be used to familiarize with such alternative methods:
* [List of R tools for microbiome analysis](https://microsud.github.io/Tools-Microbiome-Analysis/)
* phyloseq [@McMurdie2013]
* [microbiome tutorial](http://microbiome.github.io/tutorials/)
* [microbiomeutilities](https://microsud.github.io/microbiomeutilities/)
* Bioconductor Workflow for Microbiome Data Analysis: from raw reads to community analyses [@Callahan2016].
* [microbiomeutilities](https://microsud.github.io/microbiomeutilities/)
* [phyloseq/TreeSE cheatsheet](https://microbiome.github.io/OMA/docs/devel/pages/97_extra_materials.html#cheatsheet)
* Bioconductor Workflow for Microbiome Data Analysis: from raw reads to community analyses [@Callahan2016].



## R programming resources
Expand Down
45 changes: 22 additions & 23 deletions inst/pages/97_extra_materials.qmd
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# Extra material {#sec-extras}

```{r}
knitr::opts_chunk$set(eval=TRUE)
knitr::opts_chunk$set(eval=TRUE, warning=FALSE, message=FALSE)
```


Expand All @@ -17,7 +17,7 @@ Here we present two possible uses of the `adonis2` function which performs PERMA
optional argument `by` has an effect on the statistical outcome, so its two options are
compared here.

```{r permanova_import, warning = FALSE, message = FALSE}
```{r permanova_import}
# import necessary packages
library(gtools)
library(purrr)
Expand All @@ -31,7 +31,7 @@ different orders of three variables with two different approaches:
`by = "margin"` or `by = "terms"`.


```{r permanova_prep, message = FALSE, warning = FALSE}
```{r permanova_prep}
# load and prepare data
library(mia)
data("enterotype", package="mia")
Expand All @@ -55,7 +55,7 @@ margin_df <- data.frame("Formula" = formulas,



```{r permanova_loop, message = FALSE, warning = FALSE}
```{r permanova_loop}
for (row_idx in 1:nrow(var_perm)) {

# generate temporary formula (i.e. "assay ~ ClinicalStatus + Nationality + Gender")
Expand Down Expand Up @@ -104,7 +104,7 @@ ClinicalStatus, Gender and Nationality obtained by PERMANOVA with
formula when `by = "terms"` (default).


```{r permanova_table, message = FALSE, warning = FALSE}
```{r permanova_table}

df <- terms_df %>%
dplyr::inner_join(margin_df, by = "Formula", suffix = c(" (terms)", " (margin)"))
Expand All @@ -127,22 +127,22 @@ data of @Sprockett2020 available
through `microbiomeDataSets` package.


```{r, message=FALSE, warning=FALSE}
```{r}
library(fido)
```

Loading the libraries and importing data:

```{r, message=FALSE, warning=FALSE}
```{r}
library(fido)
```

```{r, message=FALSE, warning=FALSE, eval=FALSE}
```{r, eval=FALSE}
library(microbiomeDataSets)
tse <- SprockettTHData()
```

```{r, message=FALSE, warning=FALSE, echo=FALSE}
```{r, echo=FALSE}
# saveRDS(tse, file="data/SprockettTHData.Rds")
# Hidden reading of the saved data
tse <- readRDS("../extdata/SprockettTHData.Rds")
Expand All @@ -154,7 +154,7 @@ We pick three covariates ("Sex","Age_Years","Delivery_Mode") during this
analysis as an example, and beforehand we check for missing data:


```{r, message=FALSE, warning=FALSE}
```{r}
library(mia)
cov_names <- c("Sex","Age_Years","Delivery_Mode")
na_counts <- apply(is.na(colData(tse)[,cov_names]), 2, sum)
Expand All @@ -163,21 +163,21 @@ na_summary<-as.data.frame(na_counts,row.names=cov_names)

We drop missing values of the covariates:

```{r, message=FALSE, warning=FALSE}
```{r}
tse <- tse[ , !is.na(colData(tse)$Delivery_Mode) ]
tse <- tse[ , !is.na(colData(tse)$Age_Years) ]
```

We agglomerate microbiome data to Phylum:

```{r, message=FALSE, warning=FALSE}
```{r}
tse_phylum <- mergeFeaturesByRank(tse, "Phylum")
```

We extract the counts assay and covariate data to build the model
matrix:

```{r, message=FALSE, warning=FALSE}
```{r}
Y <- assays(tse_phylum)$counts
# design matrix
# taking 3 covariates
Expand All @@ -187,7 +187,7 @@ X <- t(model.matrix(~Sex+Age_Years+Delivery_Mode,data=sample_data))

Building the parameters for the `pibble` call to build the model; see more at [vignette](https://jsilve24.github.io/fido/articles/introduction-to-fido.html):

```{r, message=FALSE, warning=FALSE}
```{r}
n_taxa<-nrow(Y)
upsilon <- n_taxa+3
Omega <- diag(n_taxa)
Expand All @@ -199,7 +199,7 @@ Gamma <- diag(nrow(X))

Automatically initializing the priors and visualizing their distributions:

```{r, message=FALSE, warning=FALSE}
```{r}
priors <- pibble(NULL, X, upsilon, Theta, Gamma, Xi)
names_covariates(priors) <- rownames(X)
plot(priors, pars="Lambda") + ggplot2::xlim(c(-5, 5))
Expand All @@ -209,47 +209,47 @@ Estimating the posterior by including our response data `Y`.
Note: Some computational failures could occur (see [discussion](https://github-wiki-see.page/m/jsilve24/fido/wiki/Frequently-Asked-Questions))
the arguments `multDirichletBoot` `calcGradHess` could be passed in such case.

```{r, message=FALSE, warning=FALSE}
```{r}
priors$Y <- Y
posterior <- refit(priors, optim_method="adam", multDirichletBoot=0.5) #calcGradHess=FALSE
```

Printing a summary about the posterior:

```{r, message=FALSE, warning=FALSE}
```{r}
ppc_summary(posterior)
```
Plotting the summary of the posterior distributions of the regression parameters:

```{r, message=FALSE, warning=FALSE}
```{r}
names_categories(posterior) <- rownames(Y)
plot(posterior,par="Lambda",focus.cov=rownames(X)[2:4])
```

Taking a closer look at "Sex" and "Delivery_Mode":

```{r, message=FALSE, warning=FALSE}
```{r}
plot(posterior, par="Lambda", focus.cov = rownames(X)[c(2,4)])
```


## Interactive 3D Plots

```{r, message=FALSE, warning=FALSE}
```{r}
# Load libraries
library(rgl)
library(plotly)
```

```{r setup2, warning=FALSE, message=FALSE}
```{r setup2}
library(knitr)
knitr::knit_hooks$set(webgl = hook_webgl)
```


In this section we make a 3D version of the earlier Visualizing the most dominant genus on PCoA (see \@ref(quality-control)), with the help of the plotly [@Sievert2020].

```{r, message=FALSE, warning=FALSE, eval=FALSE}
```{r, eval=FALSE}
# Importing necessary libraries
library(curatedMetagenomicData)
library(dplyr)
Expand Down Expand Up @@ -614,7 +614,6 @@ Ok, let's plot.
#| label = "plot_red_dim"
# Plot
plotReducedDim(tse, "MDS_bray", color_by = "SampleType")

# The sign is given arbitrarily. We can change it to match the plot_ordination
reducedDim(tse)[, 1] <- -reducedDim(tse)[, 1]
reducedDim(tse)[, 2] <- -reducedDim(tse)[, 2]
Expand Down
Loading
0