This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
library(devtools) | |
library(SingleCellExperiment) | |
library(tidyverse) | |
library(annotables) | |
library(scater) | |
library(annotables) | |
library(scran) | |
library(pheatmap) | |
library(matrixStats) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(load-theme 'tango) | |
(add-to-list 'auto-mode-alist '("\\.smk\\'" . python-mode)) | |
(add-to-list 'auto-mode-alist '("Snakefile\\'" . python-mode)) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
mito_ensembl_ids = ["ENSG00000198888", "ENSG00000198763", "ENSG00000198804", "ENSG00000198712", "ENSG00000228253", | |
"ENSG00000198899", "ENSG00000198938", "ENSG00000198840", "ENSG00000212907", "ENSG00000198886", | |
"ENSG00000198786", "ENSG00000198695", "ENSG00000198727"] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Add a conda env to jupyter | |
# Taken from https://stackoverflow.com/questions/39604271/conda-environments-not-showing-up-in-jupyter-notebook | |
source activate myenv | |
python -m ipykernel install --user --name myenv --display-name "Python (myenv)" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
library(org.Hs.eg.db) | |
example_ensembl_ids <- c("ENSG00000122180", "ENSG00000080824") | |
symbols <- mapIds(org.Hs.eg.db, keys = example_ensembl_ids, column = "SYMBOL", keytype = "ENSEMBL", multiVars = "first") | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
load("../../data/genesets/human_H_v5p2.rdata") | |
go_gs <- Hs.H | |
entrezgene_ensembl_map <- as.list(org.Hs.egENSEMBL) | |
map_ids <- function(entrezgenes) { | |
x <- unlist(entrezgene_ensembl_map[entrezgenes]) | |
names(x) <- NULL | |
x | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
get_ensembl_id <- function(symbol, sce) { | |
if(!(symbol %in% rowData(sce)$Symbol)) { | |
stop("Symbol not in SCE genes") | |
} | |
rownames(sce)[rowData(sce)$Symbol == symbol] | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
clusterMap <- function(sce1, sce2) { | |
clusters1 <- sort(unique(sce1$cluster)) # get unique clusters | |
clusters2 <- sort(unique(sce2$cluster)) | |
# Check this is gene (row) by cluster (cell) - if not needs transposed | |
cluster_means_1 <- sapply(clusters1, function(x) { | |
rowMeans(as.matrix(logcounts(sce1[,sce1$cluster == x])) | |
})) | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Some common functions for manipulating bioconductor SingleCellExperiment objects | |
#' Return the corresponding ensembl gene id for a symbol in a given SCE | |
get_ensembl_id <- function(symbol, sce) { | |
stopifnot(symbol %in% rowData(sce)$Symbol) | |
rownames(sce)[rowData(sce)$Symbol == symbol] | |
} | |
#' Prepare an SCE read using read10XUtils for SC3 | |
prepare_for_sc3 <- function(sce) { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#' Source an HDF5 file (ignoring all groups) where each | |
#' entry in the HDF5 is read and assigned to a variable | |
#' in the current environment | |
#' @importFrom rhdf5 h5ls | |
source_hdf5 <- function(filename, e) { | |
ls <- h5ls(filename) | |
vars <- ls$name | |
for(var in vars) { | |
assign(var, h5read(filename, var), envir = e) | |
} |