setwd("some_folder_path/my_working_directory")Install R and required packages
R and RStudio
To work in R, you’ll need to install R and RStudio. Both programs are free and easy to download. For an easy step by step, follow the procedure described here.
TipSet working directory
In each of your script, always start with setting the working directory to avoid issues with folder structure and ensure that your RData is saved in the proper location.
Required packages
Some packages from the CRAN are required to run the examples on this website.
Download the script 001_required_packages.R, or copy the codes below into your own script.
Install packages
# Install packages
# installed from BiocManager ---------------------------------------------------
if (!requireNamespace("BiocManager", quietly = TRUE))
install.packages("BiocManager")
# decontam
if (!require("decontam", quietly = TRUE))
BiocManager::install("decontam")
# phyloseq
if (!require("phyloseq", quietly = TRUE))
BiocManager::install("phyloseq")
# installed from R Universe ----------------------------------------------------
if (!require("microViz", quietly = TRUE))
install.packages(
"microViz",
repos = c(davidbarnett = "https://david-barnett.r-universe.dev", getOption("repos"))
)
# CRAN packages ----------------------------------------------------------------
if (!require("openxlsx", quietly = TRUE))
install.packages("openxlsx")
if (!require("tidyr", quietly = TRUE))
install.packages("tidyr")
if (!require("plyr", quietly = TRUE))
install.packages("plyr")
if (!require("ggplot2", quietly = TRUE))
install.packages("ggplot2")
if (!require("ggpubr", quietly = TRUE))
install.packages("ggpubr")
if (!require("dplyr", quietly = TRUE))
install.packages("dplyr")Load packages
# Load packages
library(decontam)
library(phyloseq)
library(microViz)
library(openxlsx)
library(tidyr)
library(plyr)
library(ggplot2)
library(ggpubr)
library(dplyr) # always load dplyr last to avoid conflicts between packagesHomemade functions
Some additional functions used in this workflow are not part of any R package. These functions are listed below. Make sure to add them to your scripts!
# Homemade functions -----------------------------------------------------------
# Remove taxa from phyloseq objects
remove_taxa <- function(badTaxa, physeq){
allTaxa <- taxa_names(physeq)
cleanTaxa <- allTaxa[!(allTaxa %in% badTaxa)]
return(prune_taxa(cleanTaxa, physeq))
}