Skip to content

Commit

Permalink
Break up a long line into multiple ones, to make it easier to read. R…
Browse files Browse the repository at this point in the history
…enee used this line for an example
  • Loading branch information
lcolladotor committed Jul 5, 2023
1 parent 6d0c001 commit 5b8d01f
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 37 deletions.
50 changes: 25 additions & 25 deletions 06_smokingMouse_plotting_basics.R
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
## ----download_data_biocfilecache_repeat------------------
## ----download_data_biocfilecache_repeat------------------------------------------------------------
## Load the container package for this type of data
library("SummarizedExperiment")

Expand All @@ -20,7 +20,7 @@ load(cached_rse_gene, verbose = TRUE)
rse_gene_nic <- rse_gene[, which(rse_gene$Expt == "Nicotine")]


## ----Data preparation, message=FALSE, warning=FALSE------
## ----Data preparation, message=FALSE, warning=FALSE------------------------------------------------
library("ggplot2")

## Histogram and density plot of read counts before and after normalization
Expand All @@ -43,7 +43,7 @@ plot <- ggplot(logcounts_data, aes(x = logcounts)) +
plot + theme(plot.margin = unit(c(2, 4, 2, 4), "cm"))


## ---- message=FALSE, warning=FALSE----------------------
## ---- message=FALSE, warning=FALSE----------------------------------------------------------------
## Retain genes that passed filtering step
rse_gene_filt <- rse_gene_nic[rowData(rse_gene_nic)$retained_after_feature_filtering == TRUE, ]

Expand All @@ -59,7 +59,7 @@ plot <- ggplot(filt_logcounts_data, aes(x = logcounts)) +
plot + theme(plot.margin = unit(c(2, 4, 2, 4), "cm"))


## ----QC_boxplots, message=FALSE, warning=FALSE----------
## ----QC_boxplots, message=FALSE, warning=FALSE----------------------------------------------------
library("Hmisc")
library("stringr")
library("cowplot")
Expand Down Expand Up @@ -156,31 +156,31 @@ multiple_QC_boxplots <- function(sample_var) {
}


## ----message=FALSE, warning=FALSE------------------------
## ----message=FALSE, warning=FALSE------------------------------------------------------------------
multiple_QC_boxplots("Age")


## ----message=FALSE, warning=FALSE------------------------
## ----message=FALSE, warning=FALSE------------------------------------------------------------------
multiple_QC_boxplots("Sex")


## ----message=FALSE, warning=FALSE------------------------
## ----message=FALSE, warning=FALSE------------------------------------------------------------------
multiple_QC_boxplots("Group")


## ----message=FALSE, warning=FALSE------------------------
## ----message=FALSE, warning=FALSE------------------------------------------------------------------
multiple_QC_boxplots("Pregnancy")


## ----message=FALSE, warning=FALSE------------------------
## ----message=FALSE, warning=FALSE------------------------------------------------------------------
multiple_QC_boxplots("plate")


## ----message=FALSE, warning=FALSE------------------------
## ----message=FALSE, warning=FALSE------------------------------------------------------------------
multiple_QC_boxplots("flowcell")


## ----"QC scatterplots", message=FALSE, warning=FALSE-----
## ----"QC scatterplots", message=FALSE, warning=FALSE-----------------------------------------------
## Scatterplots for a pair of QC metrics

QC_scatterplots <- function(sample_var, qc_metric1, qc_metric2) {
Expand Down Expand Up @@ -254,33 +254,33 @@ multiple_QC_scatterplots <- function(qc_metric1, qc_metric2) {
}


## ----message=FALSE, warning=FALSE------------------------
## ----message=FALSE, warning=FALSE------------------------------------------------------------------
multiple_QC_scatterplots("mitoRate", "rRNA_rate")


## ----message=FALSE, warning=FALSE------------------------
## ----message=FALSE, warning=FALSE------------------------------------------------------------------
multiple_QC_scatterplots("mitoRate", "totalAssignedGene")


## ----message=FALSE, warning=FALSE------------------------
## ----message=FALSE, warning=FALSE------------------------------------------------------------------
multiple_QC_scatterplots("sum", "detected")


## ----message=FALSE, warning=FALSE------------------------
## ----message=FALSE, warning=FALSE------------------------------------------------------------------
multiple_QC_scatterplots("sum", "totalAssignedGene")


## ----message=FALSE, warning=FALSE------------------------
## ----message=FALSE, warning=FALSE------------------------------------------------------------------
multiple_QC_scatterplots("detected", "totalAssignedGene")


## ----exercise1_EDA, message=FALSE, warning=FALSE, eval=FALSE, echo=FALSE----
## ----exercise1_EDA, message=FALSE, warning=FALSE, eval=FALSE, echo=FALSE--------------------------
## ## Solution
## multiple_QC_scatterplots("subsets_Mito_sum", "mitoMapped")
## ## Because in mitoMapped you take reads that mapped to the whole mt chr, in subsets_Mito_sum only reads that were aligned to mt genes. But there's almost a perfect correlation between these two metrics.


## ----"QC sample filtering", message=FALSE, warning=FALSE----
## ----"QC sample filtering", message=FALSE, warning=FALSE-------------------------------------------
library("scater")
library("rlang")
library("ggrepel")
Expand Down Expand Up @@ -368,7 +368,7 @@ rse_gene_pups$Retention_after_QC_filtering <- as.vector(sapply(rse_gene_pups$SAM
}))


## ----message=FALSE, warning=FALSE------------------------
## ----message=FALSE, warning=FALSE------------------------------------------------------------------
## Boxplots of QC metrics after sample filtering

## Boxplots
Expand Down Expand Up @@ -432,27 +432,27 @@ boxplots_after_QC_filtering <- function(rse_gene, qc_metric, sample_var) {
}


## ----message=FALSE, warning=FALSE------------------------
## ----message=FALSE, warning=FALSE------------------------------------------------------------------
## Plots

## All samples together
p <- boxplots_after_QC_filtering(rse_gene_filt, "mitoRate", "Age")
p + theme(plot.margin = unit(c(2, 4, 2, 4), "cm"))


## ----message=FALSE, warning=FALSE------------------------
## ----message=FALSE, warning=FALSE------------------------------------------------------------------
## Adult samples
p <- boxplots_after_QC_filtering(rse_gene_adults, "mitoRate", "Group")
p + theme(plot.margin = unit(c(2, 4, 2, 4), "cm"))


## ----message=FALSE, warning=FALSE------------------------
## ----message=FALSE, warning=FALSE------------------------------------------------------------------
## Pup samples
p <- boxplots_after_QC_filtering(rse_gene_pups, "rRNA_rate", "Group")
p + theme(plot.margin = unit(c(2, 4, 2, 4), "cm"))


## ----exercise2_EDA, message=FALSE, warning=FALSE, eval=FALSE, echo=FALSE----
## ----exercise2_EDA, message=FALSE, warning=FALSE, eval=FALSE, echo=FALSE---------------------------
## ## Solution
## p <- boxplots_after_QC_filtering(rse_gene_adults, "mitoRate", "Pregnancy")
## p + theme(plot.margin = unit(c(2, 4, 2, 4), "cm"))
Expand All @@ -467,7 +467,7 @@ p + theme(plot.margin = unit(c(2, 4, 2, 4), "cm"))
## p + theme(plot.margin = unit(c(2, 4, 2, 4), "cm"))


## --------------------------------------------------------
## --------------------------------------------------------------------------------------------------
## Why do we see log(CPM + 0.5) values smaller than -1?
log2(0.5)

Expand Down Expand Up @@ -497,7 +497,7 @@ log2(0.01578469)
1 / 0.03156938


## --------------------------------------------------------
## --------------------------------------------------------------------------------------------------
## Check the documentation
## ?edgeR::cpm
## > If log-values are computed, then a small count, given by prior.count but scaled to be proportional to the library size, is added to y to avoid taking the log of zero.
Expand Down
25 changes: 14 additions & 11 deletions 13_expression_heatmaps.R
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
## ---- include = FALSE-----------------------------------------------------------------------
## ---- include = FALSE------------------------------------------------------------------------------
knitr::opts_chunk$set(
collapse = TRUE,
comment = "#>"
)


## ----vignetteSetup_expheatmap, echo=FALSE, message=FALSE, warning = FALSE-------------------
## ----vignetteSetup_expheatmap, echo=FALSE, message=FALSE, warning = FALSE--------------------------
## For links
library(BiocStyle)

Expand All @@ -22,20 +22,20 @@ bib <- c(
options(max.print = 50)


## ---- echo=FALSE----------------------------------------------------------------------------
## ---- echo=FALSE-----------------------------------------------------------------------------------
suppressPackageStartupMessages(library("SummarizedExperiment"))
suppressPackageStartupMessages(data(airway, package = "airway"))
suppressPackageStartupMessages(library("ComplexHeatmap"))
suppressPackageStartupMessages(library("circlize"))


## -------------------------------------------------------------------------------------------
## --------------------------------------------------------------------------------------------------
library("SummarizedExperiment")
library("ComplexHeatmap")
library("circlize")


## ----download_data_biocfilecache_expheatmap-------------------------------------------------
## ----download_data_biocfilecache_expheatmap--------------------------------------------------------
## Download and cache the file
library("BiocFileCache")
bfc <- BiocFileCache::BiocFileCache()
Expand All @@ -54,9 +54,12 @@ load(cached_rse_gene, verbose = TRUE)
rse_gene


## -------------------------------------------------------------------------------------------
## --------------------------------------------------------------------------------------------------
## Extract genes and samples of interest
rse_gene_pup_nic <- rse_gene[rowData(rse_gene)$DE_in_pup_brain_nicotine == TRUE, rse_gene$Age == "Pup" & rse_gene$Expt == "Nicotine"]
rse_gene_pup_nic <- rse_gene[
rowData(rse_gene)$DE_in_pup_brain_nicotine == TRUE,
rse_gene$Age == "Pup" & rse_gene$Expt == "Nicotine"
]

## Extract logcounts and add name columns
logs_pup_nic <- assay(rse_gene_pup_nic, 2)
Expand Down Expand Up @@ -86,7 +89,7 @@ logs_pup_nic <- cleaningY(logs_pup_nic, model, P = 2)
logs_pup_nic <- (logs_pup_nic - rowMeans(logs_pup_nic)) / rowSds(logs_pup_nic)


## -------------------------------------------------------------------------------------------
## --------------------------------------------------------------------------------------------------
## Prepare annotation for our heatmap
## For this heatmap I want to be able to see the Group to which each sample belongs
## as well as the Sex of the pup
Expand Down Expand Up @@ -115,7 +118,7 @@ left_ans <- rowAnnotation(
)


## ---- out.width = "1000px"------------------------------------------------------------------
## ---- out.width = "1000px"-------------------------------------------------------------------------
## Finally, let's plot!
Heatmap(logs_pup_nic,
name = "logcounts",
Expand All @@ -131,7 +134,7 @@ Heatmap(logs_pup_nic,
)


## -------------------------------------------------------------------------------------------
## --------------------------------------------------------------------------------------------------
## For a) we need to use he function anno_barplot() to generate the barplot and gpar() to fill the bars

top_ans <- HeatmapAnnotation(
Expand Down Expand Up @@ -167,7 +170,7 @@ left_ans <- rowAnnotation(
)


## ---- out.width = "1000px"------------------------------------------------------------------
## ---- out.width = "1000px"-------------------------------------------------------------------------
Heatmap(logs_pup_nic,
name = " ",
show_row_names = FALSE,
Expand Down
5 changes: 4 additions & 1 deletion 13_expression_heatmaps.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,10 @@ rse_gene

```{r}
## Extract genes and samples of interest
rse_gene_pup_nic <- rse_gene[rowData(rse_gene)$DE_in_pup_brain_nicotine == TRUE, rse_gene$Age == "Pup" & rse_gene$Expt == "Nicotine"]
rse_gene_pup_nic <- rse_gene[
rowData(rse_gene)$DE_in_pup_brain_nicotine == TRUE,
rse_gene$Age == "Pup" & rse_gene$Expt == "Nicotine"
]
## Extract logcounts and add name columns
logs_pup_nic <- assay(rse_gene_pup_nic, 2)
Expand Down

0 comments on commit 5b8d01f

Please sign in to comment.