diff --git a/02-postcards.R b/02-postcards.R index 8dc75b0..40efd82 100644 --- a/02-postcards.R +++ b/02-postcards.R @@ -1,18 +1,18 @@ -## ---- eval=FALSE, warning=FALSE, message=FALSE-------------------------------------------- +## ---- eval=FALSE, warning=FALSE, message=FALSE-------------------------- ## # se descargó previamente, así que solo se carga ## library("here") # busca la raiz del proyecto en el que se encuentre -## ---- eval=FALSE, warning=FALSE, message=FALSE-------------------------------------------- +## ---- eval=FALSE, warning=FALSE, message=FALSE-------------------------- ## here::here() -## ---- eval=FALSE, warning=FALSE, message=FALSE-------------------------------------------- +## ---- eval=FALSE, warning=FALSE, message=FALSE-------------------------- ## getwd() # regresa la path en donde nos encontramos ## setwd("direccion/deseada") # nos lleva a la path indicada -## ---- eval=FALSE, warning=FALSE, message=FALSE-------------------------------------------- +## ---- eval=FALSE, warning=FALSE, message=FALSE-------------------------- ## getwd() # para checar en donde nos encontramos ## here::here() # para checar dónde te encuentras ## @@ -20,7 +20,7 @@ ## setwd(here::here("R")) # podemos cambiar de directorio, aun así `here está en la raíz -## ---- eval=FALSE, warning=FALSE, message=FALSE-------------------------------------------- +## ---- eval=FALSE, warning=FALSE, message=FALSE-------------------------- ## # como ejemplo: vamos a guardar datos en archivo y cargarlos ## a <- 1 ## c <- 23 @@ -39,11 +39,11 @@ ## list.files(here::here(), recursive = TRUE) -## ---- eval=FALSE, warning=FALSE, message=FALSE-------------------------------------------- +## ---- eval=FALSE, warning=FALSE, message=FALSE-------------------------- ## usethis::use_r("notas-prueba.R") # no importando en qué path estemos -## ---- eval=FALSE, warning=FALSE, message=FALSE-------------------------------------------- +## ---- eval=FALSE, warning=FALSE, message=FALSE-------------------------- ## # paquetes que vamos a requerir ## install.packages(c("gitcreds", "gert", "gh")) ## # cargarlos de manera separada @@ -52,14 +52,14 @@ ## library("gh") -## ---- eval=FALSE, warning=FALSE, message=FALSE-------------------------------------------- +## ---- eval=FALSE, warning=FALSE, message=FALSE-------------------------- ## # Para iniciar conexión con GitHub ## usethis::create_github_token() # redirige a github donde eligiras nombre especifico del token ## # copia el token para después ingresarlo con gitcreds_set() ## gitcreds::gitcreds_set() # aquí colocas el token (NO tu contraseña de github!!!) -## ---- eval=FALSE, warning=FALSE, message=FALSE-------------------------------------------- +## ---- eval=FALSE, warning=FALSE, message=FALSE-------------------------- ## # Configurar usuario de gitHub ## usethis::edit_git_config() # que abre el archivo .gitconfig ## # colocaremos nombre y correo de cuenta de github. SOLO borrar los # y respetar los demas espacios @@ -68,7 +68,7 @@ ## # email = correodeGithub -## ---- eval=FALSE, warning=FALSE, message=FALSE-------------------------------------------- +## ---- eval=FALSE, warning=FALSE, message=FALSE-------------------------- ## # inicializar el repositorio de Git ## usethis::use_git() # ## @@ -76,11 +76,11 @@ ## usethis::use_github() -## ---- eval=FALSE, warning=FALSE, message=FALSE-------------------------------------------- +## ---- eval=FALSE, warning=FALSE, message=FALSE-------------------------- ## gh::gh_whoami() # para checar cómo quedó la configuración -## ---- eval=FALSE, warning=FALSE, message=FALSE-------------------------------------------- +## ---- eval=FALSE, warning=FALSE, message=FALSE-------------------------- ## # escribimos un nuevo archivo, volvemos a usar here::here para especificar path ## writeLines("hola", here::here("R", "prueba-here.R")) ## # otra manera es usar use_r @@ -99,31 +99,31 @@ ## gert::git_push() # COMANDO IMPORTANTE -## ----postcards_proj, eval = FALSE--------------------------------------------------------- +## ----postcards_proj, eval = FALSE--------------------------------------- ## ## Creen el RStudio project. Es MUY importante que el usuario debe sea igual que en github ## usethis::create_project("Su_Usuario.github.io") -## ----echo=FALSE, fig.cap="git user", out.width = "40%"------------------------------------ +## ----echo=FALSE, fig.cap="git user", out.width = "40%"------------------ knitr::include_graphics("img_postcard/proyecto_github_user.png") -## ----postcards_git, eval = FALSE---------------------------------------------------------- +## ----postcards_git, eval = FALSE---------------------------------------- ## ## Configura Git y GitHub ## ## # Con use_git() preguntará si desean hacer un commit, y después pedirá reiniciar Rstudio para que obtengan un nuevo botón llamado "git()" ## usethis::use_git() -## ----echo=FALSE, fig.cap="button_git", out.width = "40%"---------------------------------- +## ----echo=FALSE, fig.cap="button_git", out.width = "40%"---------------- knitr::include_graphics("img_postcard/activa_boton_git.png") -## ----postcards_github, eval = FALSE------------------------------------------------------- +## ----postcards_github, eval = FALSE------------------------------------- ## usethis::use_github() -## ----postcards_create, eval = FALSE------------------------------------------------------- +## ----postcards_create, eval = FALSE------------------------------------- ## ## Solo uno de estos, de acuerdo al templado que más les gustó ## postcards::create_postcard(template = "jolla") ## postcards::create_postcard(template = "jolla-blue") @@ -131,30 +131,30 @@ knitr::include_graphics("img_postcard/activa_boton_git.png") ## postcards::create_postcard(template = "onofre") -## ----postcards_git2, eval = FALSE--------------------------------------------------------- +## ----postcards_git2, eval = FALSE--------------------------------------- ## ## Configura Git y GitHub ## ## # Con use_git() preguntará si desean hacer un commit, y después pedirá reiniciar Rstudio para que obtengan un nuevo botón llamado "git()" ## usethis::use_git() -## ----echo=FALSE, fig.cap="button_git", out.width = "40%"---------------------------------- +## ----echo=FALSE, fig.cap="button_git", out.width = "40%"---------------- knitr::include_graphics("img_postcard/activa_boton_git.png") -## ----echo=FALSE, fig.cap="button_branch", out.width = "40%"------------------------------- +## ----echo=FALSE, fig.cap="button_branch", out.width = "40%"------------- knitr::include_graphics("img_postcard/branch.png") -## ----echo=FALSE, fig.cap="add_file", out.width = "40%"------------------------------------ +## ----echo=FALSE, fig.cap="add_file", out.width = "40%"------------------ knitr::include_graphics("img_postcard/add_stag.png") -## ----echo=FALSE, fig.cap="button_git", out.width = "80%"---------------------------------- +## ----echo=FALSE, fig.cap="button_git", out.width = "80%"---------------- knitr::include_graphics("img_postcard/commit_message.png") -## ----postcards_pull, eval = FALSE--------------------------------------------------------- +## ----postcards_pull, eval = FALSE--------------------------------------- ## ## Guardamos los archivos nuevos con el commit ## gert::git_commit_all("mensaje sobre el commit") ## @@ -162,33 +162,33 @@ knitr::include_graphics("img_postcard/commit_message.png") ## gert::git_push() -## ----fawesome_yaml, eval = FALSE---------------------------------------------------------- +## ----fawesome_yaml, eval = FALSE---------------------------------------- ## ## ## # Utlilizando `r fontawesome::fa("font-awesome-logo-full", fill = "forestgreen")` en código YAML ## -## ----echo=FALSE, fig.cap="y_fawesome", out.width = "40%"---------------------------------- +## ----echo=FALSE, fig.cap="y_fawesome", out.width = "40%"---------------- knitr::include_graphics("img_postcard/yaml_awesome.png") -## ----echo=FALSE, fig.cap="fawesome", out.width = "40%"------------------------------------ +## ----echo=FALSE, fig.cap="fawesome", out.width = "40%"------------------ knitr::include_graphics("img_postcard/awesome.png") -## ----fawesome_text, eval = FALSE---------------------------------------------------------- +## ----fawesome_text, eval = FALSE---------------------------------------- ## ## ## # Utlilizando `r fontawesome::fa("font-awesome-logo-full", fill = "forestgreen")` en el texto ## -## ----echo=FALSE, fig.cap="tfawesome", out.width = "40%"----------------------------------- +## ----echo=FALSE, fig.cap="tfawesome", out.width = "40%"----------------- knitr::include_graphics("img_postcard/text_awesome.png") -## ----------------------------------------------------------------------------------------- +## ----------------------------------------------------------------------- ## Información de la sesión de R Sys.time() proc.time() diff --git a/04-estructura_datos.R b/04-estructura_datos.R index cfbb62e..17684ae 100644 --- a/04-estructura_datos.R +++ b/04-estructura_datos.R @@ -1,4 +1,4 @@ -## ---- warning=FALSE, message=FALSE------------------------------------------------------------------ +## ---- warning=FALSE, message=FALSE-------------------------------------- library("scRNAseq") sce.416b <- LunSpikeInData(which = "416b") @@ -233,7 +233,7 @@ sizeFactors(sce) <- scater::librarySizeFactors(sce) head(sizeFactors(sce)) -## --------------------------------------------------------------------------------------------------- +## ----------------------------------------------------------------------- # Creamos un data.frame df <- data.frame(x = c(TRUE, FALSE, NA, NA), y = c(12, 34, 56, 78)) row.names(df) <- letters[1:4] @@ -266,7 +266,7 @@ bool_info <- df$y < 20 | df$y > 60 df[bool_info, ] -## --------------------------------------------------------------------------------------------------- +## ----------------------------------------------------------------------- library("SingleCellExperiment") library("scRNAseq") @@ -282,17 +282,17 @@ col.data <- DataFrame(read.csv(archivo_colData, row.names = 1, header = TRUE, ch row.data <- read.csv(archivo_rowData, row.names = 1, header = TRUE, check.names = F) -## --------------------------------------------------------------------------------------------------- +## ----------------------------------------------------------------------- int_gen <- c("Angpt1", "Chic2", "Mir503", "Magee2", "Nenf", "Eps15l1", "Hsf2bp", "Gnptg", "Vegfb", "Atmin", "Gad1", "Gad2", "Slc32a1", "Dner", "Slc2a13", "Slc6a1", "Nrxn3") -## ---- eval= FALSE----------------------------------------------------------------------------------- +## ---- eval= FALSE------------------------------------------------------- ## library("scater") ## ## plotHeatmap(object = tej_min_sce, features = rownames(tej_min_sce), order_columns_by = "level1class") -## --------------------------------------------------------------------------------------------------- +## ----------------------------------------------------------------------- sce <- SingleCellExperiment( assays = list(counts = counts), colData = col.data, @@ -304,12 +304,12 @@ sce <- scater::logNormCounts(sce) sce -## --------------------------------------------------------------------------------------------------- +## ----------------------------------------------------------------------- bool_data <- rownames(rowData(sce)) min_sce <- sce[bool_data %in% int_gen, ] -## --------------------------------------------------------------------------------------------------- +## ----------------------------------------------------------------------- tej_int <- min_sce$level1class == "interneurons" tej_pyr <- min_sce$level1class == "pyramidal CA1" @@ -317,17 +317,17 @@ tej_pyr <- min_sce$level1class == "pyramidal CA1" tej_min_sce <- min_sce[, tej_int | tej_pyr] -## --------------------------------------------------------------------------------------------------- +## ----------------------------------------------------------------------- library("scater") plotHeatmap(object = tej_min_sce, features = rownames(tej_min_sce), order_columns_by = "level1class") -## --------------------------------------------------------------------------------------------------- +## ----------------------------------------------------------------------- int_gen <- c("ENSMUSG00000071076", "ENSMUSG00000002076", "ENSMUSG00000024962", "ENSMUSG00000031224", "ENSMSG00000036560", "ENSMUSG00000037499", "ENSMUSG00000006276", "ENSMUSG00000035521", "ENSMUSG00000047388", "ENSMUSG0000051079", "ENSMUSG00000076122", "ENSMUSG00000029229", "ENSMUSG00000022309", "ENSMUSG00000036766", "ENSMUSG00000070880", "ENSMUSG00000026787", "ENSMUSG00000066392", "ENSMUSG00000036298", "ENSMUSG00000037771", "ENSMUSG00000030310") -## --------------------------------------------------------------------------------------------------- +## ----------------------------------------------------------------------- # Descarga datos de ejemplo procesados con CellRanger # Paréntesis: al usar BiocFileCache solo tenemos que descargar # los datos una vez. @@ -466,7 +466,7 @@ lun.sce lobstr::obj_size(lun.sce) / 1024^2 ## En MB -## --------------------------------------------------------------------------------------------------- +## ----------------------------------------------------------------------- ## Información de la sesión de R Sys.time() proc.time() diff --git a/11-anotacion_clusters.R b/11-anotacion_clusters.R index cbc29e8..ceedd11 100644 --- a/11-anotacion_clusters.R +++ b/11-anotacion_clusters.R @@ -1,4 +1,4 @@ -## ---- warning=FALSE, message=FALSE---------------------------------------------------- +## ---- warning=FALSE, message=FALSE-------------------------------------- # Usemos datos de pbmc4k library(BiocFileCache) bfc <- BiocFileCache() @@ -14,7 +14,7 @@ fname <- file.path(tempdir(), "pbmc4k/raw_gene_bc_matrices/GRCh38") sce.pbmc <- read10xCounts(fname, col.names = TRUE) -## ---- warning=FALSE, message=FALSE---------------------------------------------------- +## ---- warning=FALSE, message=FALSE-------------------------------------- # Anotación de los genes library(scater) rownames(sce.pbmc) <- uniquifyFeatureNames( @@ -32,7 +32,7 @@ e.out <- emptyDrops(counts(sce.pbmc)) sce.pbmc <- sce.pbmc[, which(e.out$FDR <= 0.001)] -## ---- warning=FALSE, message=FALSE---------------------------------------------------- +## ---- warning=FALSE, message=FALSE-------------------------------------- # Control de calidad stats <- perCellQCMetrics(sce.pbmc, subsets = list(Mito = which(location == "MT")) @@ -50,14 +50,14 @@ sce.pbmc <- computeSumFactors(sce.pbmc, cluster = clusters) sce.pbmc <- logNormCounts(sce.pbmc) -## ---- warning=FALSE, message=FALSE---------------------------------------------------- +## ---- warning=FALSE, message=FALSE-------------------------------------- ## Identificación de genes altamente variables set.seed(1001) dec.pbmc <- modelGeneVarByPoisson(sce.pbmc) top.pbmc <- getTopHVGs(dec.pbmc, prop = 0.1) -## ---- warning=FALSE, message=FALSE---------------------------------------------------- +## ---- warning=FALSE, message=FALSE-------------------------------------- ## Reducción de dimensiones set.seed(10000) sce.pbmc <- denoisePCA(sce.pbmc, @@ -70,34 +70,34 @@ set.seed(1000000) sce.pbmc <- runUMAP(sce.pbmc, dimred = "PCA") -## ---- warning=FALSE, message=FALSE---------------------------------------------------- +## ---- warning=FALSE, message=FALSE-------------------------------------- # clustering g <- buildSNNGraph(sce.pbmc, k = 10, use.dimred = "PCA") clust <- igraph::cluster_walktrap(g)$membership sce.pbmc$cluster <- factor(clust) -## ---- warning=FALSE, message=FALSE, eval = FALSE-------------------------------------- +## ---- warning=FALSE, message=FALSE, eval = FALSE------------------------ ## # Human -## SingleR::BlueprintEncodeData() -## SingleR::DatabaseImmuneCellExpressionData() -## SingleR::HumanPrimaryCellAtlasData() -## SingleR::MonacoImmuneData() -## SingleR::NovershternHematopoieticData() +## celldex::BlueprintEncodeData() +## celldex::DatabaseImmuneCellExpressionData() +## celldex::HumanPrimaryCellAtlasData() +## celldex::MonacoImmuneData() +## celldex::NovershternHematopoieticData() ## ## # Mice -## SingleR::ImmGenData() -## SingleR::MouseRNASeqData() +## celldex::ImmGenData() +## celldex::MouseRNASeqData() -## ---- warning=FALSE, message=FALSE---------------------------------------------------- +## ---- warning=FALSE, message=FALSE-------------------------------------- # if needed install celldex # create directory? y library(celldex) ref <- celldex::BlueprintEncodeData() -## ---- warning=FALSE, message=FALSE---------------------------------------------------- +## ---- warning=FALSE, message=FALSE-------------------------------------- library(SingleR) pred <- SingleR( test = sce.pbmc, ref = ref, @@ -105,20 +105,20 @@ pred <- SingleR( ) -## ---- warning=FALSE, message=FALSE---------------------------------------------------- +## ---- warning=FALSE, message=FALSE-------------------------------------- plotScoreHeatmap(pred) -## ---- warning=FALSE, message=FALSE---------------------------------------------------- +## ---- warning=FALSE, message=FALSE-------------------------------------- total_pruned <- sum(is.na(pred$pruned.labels)) plotScoreHeatmap(pred, show.pruned = TRUE) -## ---- warning=FALSE, message=FALSE---------------------------------------------------- +## ---- warning=FALSE, message=FALSE-------------------------------------- plotScoreDistribution(pred) -## ---- warning=FALSE, message=FALSE---------------------------------------------------- +## ---- warning=FALSE, message=FALSE-------------------------------------- # install gmp, ClusterR, mbkmeans dependencies if needed sce.pbmc$labels <- pred$labels all.markers <- metadata(pred)$de.genes @@ -133,7 +133,7 @@ plotHeatmap(sce.pbmc, ) -## ---- warning=FALSE, message=FALSE---------------------------------------------------- +## ---- warning=FALSE, message=FALSE-------------------------------------- tab <- table(Assigned = pred$pruned.labels, Cluster = sce.pbmc$cluster) library(pheatmap) @@ -149,13 +149,13 @@ pheatmap(log2(tab + 10), ) -## ---- warning=FALSE, message=FALSE---------------------------------------------------- +## ---- warning=FALSE, message=FALSE-------------------------------------- plotTSNE(sce.pbmc, colour_by = "labels", text_by = "labels") plotTSNE(sce.pbmc, colour_by = "cluster", text_by = "labels") -## ------------------------------------------------------------------------------------- +## ----------------------------------------------------------------------- ## Información de la sesión de R Sys.time() proc.time() diff --git a/11-anotacion_clusters.Rmd b/11-anotacion_clusters.Rmd index 199ab4b..1e82ce2 100644 --- a/11-anotacion_clusters.Rmd +++ b/11-anotacion_clusters.Rmd @@ -157,15 +157,15 @@ sce.pbmc$cluster <- factor(clust) ```{r, warning=FALSE, message=FALSE, eval = FALSE} # Human -SingleR::BlueprintEncodeData() -SingleR::DatabaseImmuneCellExpressionData() -SingleR::HumanPrimaryCellAtlasData() -SingleR::MonacoImmuneData() -SingleR::NovershternHematopoieticData() +celldex::BlueprintEncodeData() +celldex::DatabaseImmuneCellExpressionData() +celldex::HumanPrimaryCellAtlasData() +celldex::MonacoImmuneData() +celldex::NovershternHematopoieticData() # Mice -SingleR::ImmGenData() -SingleR::MouseRNASeqData() +celldex::ImmGenData() +celldex::MouseRNASeqData() ```