## ----------------------------------------------------------------------------- library(conflicted) library(destiny) suppressPackageStartupMessages(library(scran)) library(purrr) library(ggplot2) library(SingleCellExperiment) ## ----------------------------------------------------------------------------- # The parts of the help we’re interested in help('scRNAseq-package', package = 'scRNAseq') %>% repr::repr_html() %>% stringr::str_extract_all(stringr::regex('
The dataset.*?
', dotall = TRUE)) %>% unlist() %>% paste(collapse = '') %>% knitr::raw_html() ## ----------------------------------------------------------------------------- allen <- scRNAseq::ReprocessedAllenData() ## ----------------------------------------------------------------------------- rowData(allen)$Symbol <- rownames(allen) rowData(allen)$EntrezID <- AnnotationDbi::mapIds(org.Mm.eg.db::org.Mm.eg.db, rownames(allen), 'ENTREZID', 'ALIAS') rowData(allen)$Uniprot <- AnnotationDbi::mapIds(org.Mm.eg.db::org.Mm.eg.db, rownames(allen), 'UNIPROT', 'ALIAS', multiVals = 'list') assayNames(allen)[assayNames(allen) == 'rsem_counts'] <- 'counts' assayNames(altExp(allen, 'ERCC'))[assayNames(altExp(allen, 'ERCC')) == 'rsem_counts'] <- 'counts' allen ## ----------------------------------------------------------------------------- allen <- computeSpikeFactors(allen, 'ERCC') allen <- logNormCounts(allen) allen ## ----------------------------------------------------------------------------- decomp <- modelGeneVarWithSpikes(allen, 'ERCC') rowData(allen)$hvg_order <- order(decomp$bio, decreasing = TRUE) ## ----------------------------------------------------------------------------- allen_hvg <- subset(allen, hvg_order <= 5000L) ## ----------------------------------------------------------------------------- #reducedDim(allen_hvg, 'pca') <- irlba::prcomp_irlba(t(assay(allen, 'logcounts')), 50)$x ## ----------------------------------------------------------------------------- set.seed(1) dms <- c('euclidean', 'cosine', 'rankcor') %>% #, 'l2' set_names() %>% map(~ DiffusionMap(allen_hvg, distance = ., knn_params = list(method = 'covertree'))) ## ----------------------------------------------------------------------------- dms %>% imap(function(dm, dist) plot(dm, 1:2, col_by = 'driver_1_s') + ggtitle(dist)) %>% cowplot::plot_grid(plotlist = ., nrow = 1) ## ----------------------------------------------------------------------------- grs <- map(dms, gene_relevance) ## ----------------------------------------------------------------------------- gms <- imap(grs, function(gr, dist) plot(gr, iter_smooth = 0) + ggtitle(dist)) cowplot::plot_grid(plotlist = gms, nrow = 1) ## ----------------------------------------------------------------------------- gms[-1] %>% map(~ .$ids[1:10]) %>% purrr::reduce(intersect) %>% cat(sep = ' ') ## ----------------------------------------------------------------------------- httr::GET('https://www.uniprot.org/uniprot/', query = list( columns = 'id,genes,comment(TISSUE SPECIFICITY)', format = 'tab', query = rowData(allen)$Uniprot[gms$cosine$ids[1:6]] %>% unlist() %>% paste(collapse = ' or ') )) %>% httr::content(type = 'text/tab-separated-values', encoding = 'utf-8', )