diff --git a/01_intro_rstudio.R b/01_intro_rstudio.R index 6d8ac05..fe25529 100644 --- a/01_intro_rstudio.R +++ b/01_intro_rstudio.R @@ -1,4 +1,4 @@ -## ----install_rsthemes, eval = FALSE-------------------------------------------------- +## ----install_rsthemes, eval = FALSE---- ## remotes::install_github(c( ## "gadenbuie/rsthemes" ## )) @@ -6,7 +6,7 @@ ## rsthemes::install_rsthemes(include_base16 = TRUE) -## ----r_profile, eval = FALSE--------------------------------------------------------- +## ----r_profile, eval = FALSE----------- ## usethis::edit_r_profile() ## ## ## From https://www.garrickadenbuie.com/project/rsthemes/ @@ -32,21 +32,21 @@ ## options(repos = c(CRAN = "https://cloud.r-project.org")) -## ----proj, eval = FALSE-------------------------------------------------------------- +## ----proj, eval = FALSE---------------- ## usethis::create_project("~/rnaseq_2024_notas") -## ----create_setup, eval = FALSE------------------------------------------------------ +## ----create_setup, eval = FALSE-------- ## ## Start a setup file ## usethis::use_r("01-notas.R") -## ----create_01-visualizar-mtcars, eval = FALSE--------------------------------------- +## ----create_01-visualizar-mtcars, eval = FALSE---- ## ## Creemos el archivo R/02-visualizar-mtcars.R ## usethis::use_r("02-visualizar-mtcars.R") -## ----vis_mtcars, eval = FALSE-------------------------------------------------------- +## ----vis_mtcars, eval = FALSE---------- ## library("sessioninfo") ## library("here") ## library("ggplot2") @@ -75,29 +75,29 @@ ## sessioninfo::session_info() -## ----use_git_init, eval = FALSE------------------------------------------------------ +## ----use_git_init, eval = FALSE-------- ## ## Para poder conectar tu compu con GitHub ## usethis::create_github_token() ## Abrirá una página web, escoje un nombre único ## ## y luego da click en el botón verde al final. Después copia el token ## ## (son 40 caracteres) -## ----gitcreds_set, eval = FALSE------------------------------------------------------ +## ----gitcreds_set, eval = FALSE-------- ## gitcreds::gitcreds_set() ## Ojo, copia el token, no tu password de git! ## ## Si no, terminaras en la situación descrita en ## ## https://github.com/r-lib/usethis/issues/1347 -## ----edit_r_envir, eval = FALSE------------------------------------------------------ +## ----edit_r_envir, eval = FALSE-------- ## usethis::edit_r_environ() -## ----use_git_cont_parte1, eval = FALSE----------------------------------------------- +## ----use_git_cont_parte1, eval = FALSE---- ## ## Configura tu usuario de GitHub ## usethis::edit_git_config() -## ----use_git_cont_parte2, eval = FALSE----------------------------------------------- +## ----use_git_cont_parte2, eval = FALSE---- ## ## Para inicializar el repositorio de Git ## usethis::use_git() ## @@ -112,7 +112,7 @@ ## ## https://docs.github.com/en/github/authenticating-to-github/generating-a-new-ssh-key-and-adding-it-to-the-ssh-agent ## git clone git@github.com:lcolladotor/rnaseq_LCG-UNAM_2024.git -## ----clone_repo, eval = FALSE-------------------------------------------------------- +## ----clone_repo, eval = FALSE---------- ## ## Opción más nueva: ## library("gert") ## repo <- git_clone( @@ -128,7 +128,7 @@ ## ) -## ----eval=FALSE---------------------------------------------------------------------- +## ----eval=FALSE------------------------ ## ## Puedes instalar Postcards con el siguiente comando: ## install.packages("postcards") ## @@ -136,18 +136,18 @@ ## remotes::install_github("seankross/postcards@main") -## ----eval=FALSE---------------------------------------------------------------------- +## ----eval=FALSE------------------------ ## ## Crearun nuevo proyecto ## usethis::create_project("Su_Usuario.github.io") -## ----eval=FALSE---------------------------------------------------------------------- +## ----eval=FALSE------------------------ ## ## Configurar Git y GitHub ## usethis::use_git() # Reiniciar la sesión ## usethis::use_github() -## ----eval=FALSE---------------------------------------------------------------------- +## ----eval=FALSE------------------------ ## ## Elegir solo una plantilla (la que más te guste) ## postcards::create_postcard(template = "jolla") ## postcards::create_postcard(template = "jolla-blue") @@ -156,7 +156,7 @@ ## postcards::create_postcard(template = "solana") -## ----eval=FALSE---------------------------------------------------------------------- +## ----eval=FALSE------------------------ ## ## Desplegar la página GitHub ## rmarkdown::render("index.Rmd") diff --git a/05_modelos.R b/05_modelos.R index 05dd3eb..d7a2117 100644 --- a/05_modelos.R +++ b/05_modelos.R @@ -1,15 +1,15 @@ -## ----model.matrix-------------------------------------------------------------------- +## ----model.matrix---------------------- ## ?model.matrix mat <- with(trees, model.matrix(log(Volume) ~ log(Height) + log(Girth))) mat colnames(mat) -## ----lm_example---------------------------------------------------------------------- +## ----lm_example------------------------ summary(lm(log(Volume) ~ log(Height) + log(Girth), data = trees)) -## ----EMM_example1-------------------------------------------------------------------- +## ----EMM_example1---------------------- ## Datos de ejemplo (sampleData <- data.frame( genotype = rep(c("A", "B"), each = 4), @@ -27,7 +27,7 @@ vd <- ExploreModelMatrix::VisualizeDesign( cowplot::plot_grid(plotlist = vd$plotlist) -## ----EMM_example1_interactive, eval = FALSE------------------------------------------ +## ----EMM_example1_interactive, eval = FALSE---- ## ## Usaremos shiny otra ves ## app <- ExploreModelMatrix( ## sampleData = sampleData, @@ -36,11 +36,9 @@ cowplot::plot_grid(plotlist = vd$plotlist) ## if (interactive()) shiny::runApp(app) -## ----download_SRP045638-------------------------------------------------------------- +## ----download_SRP045638---------------- library("recount3") -options(recount3_url = "https://recount-opendata.s3.amazonaws.com/recount3/release") - human_projects <- available_projects() rse_gene_SRP045638 <- create_rse( @@ -52,16 +50,16 @@ rse_gene_SRP045638 <- create_rse( assay(rse_gene_SRP045638, "counts") <- compute_read_counts(rse_gene_SRP045638) -## ----describe_issue------------------------------------------------------------------ +## ----describe_issue-------------------- rse_gene_SRP045638$sra.sample_attributes[1:3] -## ----solve_issue--------------------------------------------------------------------- +## ----solve_issue----------------------- rse_gene_SRP045638$sra.sample_attributes <- gsub("dev_stage;;Fetal\\|", "", rse_gene_SRP045638$sra.sample_attributes) rse_gene_SRP045638$sra.sample_attributes[1:3] -## ----attributes---------------------------------------------------------------------- +## ----attributes------------------------ rse_gene_SRP045638 <- expand_sra_attributes(rse_gene_SRP045638) colData(rse_gene_SRP045638)[ @@ -70,7 +68,7 @@ colData(rse_gene_SRP045638)[ ] -## ----re_cast------------------------------------------------------------------------- +## ----re_cast--------------------------- ## Pasar de character a numeric o factor rse_gene_SRP045638$sra_attribute.age <- as.numeric(rse_gene_SRP045638$sra_attribute.age) rse_gene_SRP045638$sra_attribute.disease <- factor(tolower(rse_gene_SRP045638$sra_attribute.disease)) @@ -84,7 +82,7 @@ summary(as.data.frame(colData(rse_gene_SRP045638)[ ])) -## ----new_variables------------------------------------------------------------------- +## ----new_variables--------------------- ## Encontraremos diferencias entre muestra prenatalas vs postnatales rse_gene_SRP045638$prenatal <- factor(ifelse(rse_gene_SRP045638$sra_attribute.age < 0, "prenatal", "postnatal")) table(rse_gene_SRP045638$prenatal) @@ -98,7 +96,7 @@ with(colData(rse_gene_SRP045638), plot(assigned_gene_prop, sra_attribute.RIN)) with(colData(rse_gene_SRP045638), tapply(assigned_gene_prop, prenatal, summary)) -## ----filter_rse---------------------------------------------------------------------- +## ----filter_rse------------------------ ## Guardemos nuestro objeto entero por si luego cambiamos de opinión rse_gene_SRP045638_unfiltered <- rse_gene_SRP045638 @@ -129,7 +127,7 @@ dim(rse_gene_SRP045638) round(nrow(rse_gene_SRP045638) / nrow(rse_gene_SRP045638_unfiltered) * 100, 2) -## ----normalize----------------------------------------------------------------------- +## ----normalize------------------------- library("edgeR") # BiocManager::install("edgeR", update = FALSE) dge <- DGEList( counts = assay(rse_gene_SRP045638, "counts"), @@ -138,7 +136,7 @@ dge <- DGEList( dge <- calcNormFactors(dge) -## ----explore_gene_prop_by_age-------------------------------------------------------- +## ----explore_gene_prop_by_age---------- library("ggplot2") ggplot(as.data.frame(colData(rse_gene_SRP045638)), aes(y = assigned_gene_prop, x = prenatal)) + geom_boxplot() + @@ -147,14 +145,14 @@ ggplot(as.data.frame(colData(rse_gene_SRP045638)), aes(y = assigned_gene_prop, x xlab("Age Group") -## ----statiscal_model----------------------------------------------------------------- +## ----statiscal_model------------------- mod <- model.matrix(~ prenatal + sra_attribute.RIN + sra_attribute.sex + assigned_gene_prop, data = colData(rse_gene_SRP045638) ) colnames(mod) -## ----run_limma----------------------------------------------------------------------- +## ----run_limma------------------------- library("limma") vGene <- voom(dge, mod, plot = TRUE) @@ -179,7 +177,7 @@ volcanoplot(eb_results, coef = 2, highlight = 3, names = de_results$gene_name) de_results[de_results$gene_name %in% c("ZSCAN2", "VASH2", "KIAA0922"), ] -## ----pheatmap------------------------------------------------------------------------ +## ----pheatmap-------------------------- ## Extraer valores de los genes de interés exprs_heatmap <- vGene$E[rank(de_results$adj.P.Val) <= 50, ] @@ -200,7 +198,7 @@ pheatmap( ) -## ----plot_mds------------------------------------------------------------------------ +## ----plot_mds-------------------------- ## Para colores library("RColorBrewer") @@ -221,7 +219,7 @@ col.sex <- as.character(col.sex) plotMDS(vGene$E, labels = df$Sex, col = col.sex) -## ----respuesta, out.height="1100px"-------------------------------------------------- +## ----respuesta, out.height="1100px"---- ## Tenemos que usar gene_id y gene_name rowRanges(rse_gene_SRP045638) @@ -275,7 +273,7 @@ pheatmap( dev.off() -## ----"centered_and_scaled", out.height="1100px"-------------------------------------- +## ----"centered_and_scaled", out.height="1100px"---- ## Versión con centering y scaling en los renglones (los genes) pheatmap::pheatmap( exprs_heatmap, @@ -288,7 +286,7 @@ pheatmap::pheatmap( ) -## ----"complexheatmap", out.height="1100px"------------------------------------------- +## ----"complexheatmap", out.height="1100px"---- ## Misma versión pero ahora con ComplexHeatmap en vez del paquete pheatmap ComplexHeatmap::pheatmap( exprs_heatmap, diff --git a/05_modelos.Rmd b/05_modelos.Rmd index 9ac3281..a4a0e63 100644 --- a/05_modelos.Rmd +++ b/05_modelos.Rmd @@ -84,8 +84,6 @@ Vamos a usar datos de https://www.ncbi.nlm.nih.gov/sra/?term=SRP045638 procesado ```{r download_SRP045638} library("recount3") -options(recount3_url = "https://recount-opendata.s3.amazonaws.com/recount3/release") - human_projects <- available_projects() rse_gene_SRP045638 <- create_rse(