Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

Table of Contents

...

a. In windows explorer, go to: H:\workshop\RNAseq

b. In this folder, create a new folder called ‘functional_annotation’ (case-sensitive)

c. Open RStudio and create a new R script (‘File’ → “New File” → “R script”). Now hit ‘File’ → ‘Save’ and save the script in the H:\workshop\RNAseq\functional_annotation folder you created. Save the script file as ‘functional_annotation.R

In the following sections you will be copying and running the R code into your functional_annotation.R script.

5. Installing packages

IMPORTANT: don’t run this code in this rVDI session, the packages are already installed. This code is only here if you need to run the analysis on your computer.

#### 5. Installing required packages ####

 

bioconductor_packages <- c("clusterProfiler", "pathview", "AnnotationHub", "org.Mm.eg.db")

cran_packages <- c("tidyverse", "ggplot2", "plyr", "readxl", "scales")

# Compares installed packages to above packages and returns a vector of missing packages

new_packages <- bioconductor_packages[!(bioconductor_packages %in% installed.packages()[,"Package"])]

new_cran_packages <- cran_packages[!(cran_packages %in% installed.packages()[,"Package"])]

# Install missing bioconductor packages

if (!requireNamespace("BiocManager", quietly = TRUE))

  install.packages("BiocManager")

BiocManager::install(new_packages)

# Install missing cran packages

if (length(new_cran_packages)) install.packages(new_cran_packages, repos = http://cran.us.r-project.org)

# Update all installed packages to the latest version

update.packages(bioconductor_packages, ask = FALSE)

update.packages(cran_packages, ask = FALSE, repos = http://cran.us.r-project.org)

...

NOTE: You need to have the correct path for your DE_genes_Basal_cells_Vs_Differentiated_cells.csv file, that you generated in session 3. It should be in H:/workshop/RNAseq/DE_analysis_workshop/Tables for most people. If not, change this to the correct path containing your DE genes table.

If you’ve deleted your DE_genes_Basal_cells_Vs_Differentiated_cells.csv file or didn’t attend section 3, you can download the file here

View file
nameDE_genes_Basal_cells_Vs_Differentiated_cells.csv
, create the H:/workshop/RNAseq/DE_analysis_workshop/Tables folders and put the file in the Tables folder.

Code Block
#### 7. Convert to Entrez gene IDs ####

# Set your working directory
setwd("H:/workshop/RNAseq/functional_annotation")

# Import your DE genes data:
# NOTE: THE DIRECTORY THAT CONTAINS YOUR RESULTS DATA MAY VARY. YOU NEED TO LOOK IN 'H:/workshop/RNAseq' TO SEE WHERE YOUR 'Tables' SUBDIRECTORY IS, AND CHANGE THE BELOW PATH TO REFLECT THAT.
dat <- read.csv("H:/workshop/RNAseq/DE_analysis_workshop/Tables/DE_genes_Basal_cells_Vs_Differentiated_cells.csv", row.names = 1)

# Convert the gene symbol column to Entrez IDs
# NOTE: 'OrgDb=' needs to be your organism database. We're using mouse here, so we're using 'OrgDb=org.Mm.eg.db' if your species was human you'd use 'OrgDb=org.Hs.eg.db', etc
gene_list <- bitr(gene = dat$SYMBOL, fromType="SYMBOL", toType="ENTREZID", OrgDb=org.Mm.eg.db, drop=TRUE)

...

Code Block
#### 8. KEGG pathway enrichment #######

# Use clusterProfiler's enrichKEGG() function to match your genes list to KEGG pathways
kk <- enrichKEGG(gene = gene_list$ENTREZID, organism = "mmu", pvalueCutoff = 0.05, qvalueCutoff = 0.2)

# Now you can save this as a table of enriched KEGG pathways
# Create a 'results' subdirectory where all figures will be output
dir.create("results", showWarnings = FALSE)
write.csv(as.data.frame(kk), "./results/Enriched_KEGG_pathways.csv")

...

NOTE: this only plots one of your enriched pathways at a time. You’ll need to enter one of these KEGG pathways IDs into into the keggpath <- .. line. You can see your set of enriched pathways in the H:\workshop\RNAseq\functional_annotation\results\Enriched_KEGG_pathways.csv or type as.data.frame(kk)$ID into the RStudio console.

...