Skip to content

Commit

Permalink
ran tangle.R
Browse files Browse the repository at this point in the history
  • Loading branch information
lcolladotor committed Jul 4, 2023
1 parent 401e502 commit c09e031
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 54 deletions.
16 changes: 8 additions & 8 deletions 04_smokingMouse_RSE.R
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
## ----download_data_biocfilecache-----------------------------
## ----download_data_biocfilecache-------------------------
## 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


## ----explore_assays------------------------------------------
## ----explore_assays--------------------------------------
## Explore main assay (of raw counts)
assay(rse_gene)[1:3, 1:3] ## counts for first 3 genes and 3 samples
## Access the same raw data with assays()
Expand All @@ -29,35 +29,35 @@ assays(rse_gene)$counts[1:3, 1:3]
assays(rse_gene)$logcounts[1:3, 1:3]


## ----explore_colData-----------------------------------------
## ----explore_colData-------------------------------------
## Data for first 3 samples and 5 variables
colData(rse_gene)[1:3, 1:5]


## ----explore_rowData-----------------------------------------
## ----explore_rowData-------------------------------------
## Data for first 3 genes and 5 variables
rowData(rse_gene)[1:3, 1:5]


## ----exercise1_data, eval=FALSE, echo=FALSE------------------
## ----exercise1_data, eval=FALSE, echo=FALSE--------------
## ## Solution
## head(rse_gene_nic$flowcell)


## ----extract_nicotine_data-----------------------------------
## ----extract_nicotine_data-------------------------------
## Original dimensions of the data
dim(rse_gene)
rse_gene_nic <- rse_gene[, which(rse_gene$Expt == "Nicotine")]
## New dimensions
dim(rse_gene_nic)


## ----exercise2_data, eval=FALSE, echo=FALSE------------------
## ----exercise2_data, eval=FALSE, echo=FALSE--------------
## ## Solution
## table(rse_gene_nic$Expt)


## ----exercise3_data, eval=FALSE, echo=FALSE------------------
## ----exercise3_data, eval=FALSE, echo=FALSE--------------
## ## Solution
## table(rse_gene$Age)
## pup_samples <- rse_gene[, which(rse_gene$Age == "Pup")]
Expand Down
46 changes: 23 additions & 23 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,23 +254,23 @@ 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")


Expand All @@ -280,7 +280,7 @@ multiple_QC_scatterplots("detected", "totalAssignedGene")
## ## 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,21 +432,21 @@ 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"))
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
Loading

0 comments on commit c09e031

Please sign in to comment.