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
#' These functions round an input string 'x' to a desired | |
#' number of decimal places | |
round1 <- function(x) format(round(x, 1), nsmall = 1) | |
round2 <- function(x) format(round(x, 2), nsmall = 2) | |
roundn <- function(x, n = 2) format(round(x, n), nsmall = n) |
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(biomaRt) | |
ensembl <- useMart("ensembl") | |
ensembl <- useDataset("hsapiens_gene_ensembl", mart=ensembl) | |
bm <- getBM(attributes = c("ensembl_gene_id", "hgnc_symbol"), | |
filters = c("ensembl_gene_id"), | |
values = ensembl_gene_ids, | |
mart = ensembl) %>% | |
as_data_frame() |
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(limma) | |
library(tidyverse) | |
dge <- DGEList(counts(sce_de)) | |
dge <- calcNormFactors(dge) | |
design <- model.matrix(~ (dbz_cluster_str == "Unknown"), colData(sce_de)) # Your design matrix here | |
v <- voom(dge, design, plot = TRUE) |
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
export PATH=$PATH:/Applications/RStudio.app/Contents/MacOS/pandoc |
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
#' Plot a CNV heatmap | |
#' \code{cnv_data} must have the following columns: | |
#' | |
#' - start (start position of each region) | |
#' - chr (chromosome) | |
#' - single_cell_id (id of each cell) | |
#' - clone (clone to which each cell is assigned) | |
#' - copy_number (copy number of each clone in region) | |
#' | |
#' @export |
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
select <- dplyr::select | |
mutate <- dplyr::mutate | |
arrange <- dplyr::arrange | |
rename <- dplyr::rename |
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) | |
} |
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
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
get_ensembl_id <- function(symbol, sce) { | |
if(!(symbol %in% rowData(sce)$Symbol)) { | |
stop("Symbol not in SCE genes") | |
} | |
rownames(sce)[rowData(sce)$Symbol == symbol] | |
} |