knitr::opts_chunk$set(echo = TRUE, warning=FALSE, message = FALSE)
library(readr) # library(knitr) # for function kable
countfile_url <- "https://raw.githubusercontent.com/PacktPublishing/R-Bioinformatics-Cookbook/master/datasets/ch1/modencodefly_count_table.txt" countfile <- "modencodefly_count_table.txt" if (!file.exists(countfile)) { download.file(countfile_url,countfile) } count_dataframe <- readr::read_tsv(countfile) head(count_dataframe)
genes <- count_dataframe[['gene']] count_dataframe[['gene']] <- NULL # keep only numbers or matrix will not work count_matrix <- as.matrix(count_dataframe) rownames(count_matrix) <- genes head(count_matrix)
count_matrix
?typeof
# typeof(count_matrix) # count_matrix <- as.numeric(count_matrix) # typeof(count_matrix)
phenofile_url <- "https://raw.githubusercontent.com/PacktPublishing/R-Bioinformatics-Cookbook/master/datasets/ch1/modencodefly_phenodata.txt" phenofile <- "modencodefly_phenodata.txt" if (!file.exists(phenofile)) { download.file(phenofile_url,phenofile) } pheno_data <- readr::read_table2(phenofile)
kable(pheno_data)
experiments_of_interest <- c("L1Larvae","L2Larvae") columns_of_interest <- which(pheno_data[['stage']] %in% experiments_of_interest) columns_of_interest
library(magrittr) grouping <- pheno_data[['stage']][columns_of_interest] %>% forcats::as_factor() grouping
counts_of_interest <- count_matrix[,columns_of_interest]
counts_of_interest
library(edgeR) count_dge <- edgeR::DGEList(counts=counts_of_interest,group=grouping) count_dge
count_dge
For a simple Poisson process we expect the variance to be equal to the mean:
$$Var(count) = \mu$$
Variation in biological high-throughput experiments tends to be larger. One can model this using a square term and the "dispersion":
$$Var(count) = \mu + dispersion * \mu^2$$
citation("edgeR")
design <- model.matrix(~ grouping) eset_dge <- edgeR::estimateDisp(count_dge, design) fit <- edgeR::glmQLFit(eset_dge, design) result <- edgeR::glmQLFTest(fit, coef=2)
topTags(result)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.