This file contains 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
## If you get the error | |
## > Error in `.rowNamesDF<-`(x, value = value) : invalid 'row.names' length | |
## after singleCellTK::runSeuratPCA(sce) | |
## then run | |
sce@metadata$seurat <- NULL |
This file contains 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
## Going to take non tumour cells as just fibroblast and T/NK | |
## as these are (i) abundant, and (ii) sufficiently distinct transcriptionally | |
## from tumour that we're unlikely to confuse them | |
non_tumour_cells <- c("Fibroblast", "T/NK") | |
get_baf_df <- function(sce) { | |
message(paste0("[Running] Sample ", sce$id[1])) | |
colnames(sce) <- paste0(colData(sce)$id, "-", colData(sce)$barcode) | |
sce$cell_type <- cell_annots[colnames(sce)] | |
This file contains 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
## Can't remember where this comes from unfortunately | |
def gaussian_kernel(a, b): | |
dim1_1, dim1_2 = a.shape[0], b.shape[0] | |
depth = a.shape[1] | |
a = a.view(dim1_1, 1, depth) | |
b = b.view(1, dim1_2, depth) | |
a_core = a.expand(dim1_1, dim1_2, depth) | |
b_core = b.expand(dim1_1, dim1_2, depth) | |
numerator = (a_core - b_core).pow(2).mean(2)/depth | |
return torch.exp(-numerator) |
This file contains 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
def expand_mask_by_one(m): | |
"""Takes a cell mask np array as input | |
and returns with mask expanded by 1 | |
""" | |
from skimage.morphology import dilation | |
m2 = m.copy() | |
unique_cell_ids = np.sort(np.unique(m.reshape(-1))) | |
unique_cell_ids = unique_cell_ids[unique_cell_ids>0] | |
for cell_id in unique_cell_ids: |
This file contains 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
Sys.setenv('R_REMOTES_NO_ERRORS_FROM_WARNINGS' = 'true'); devtools::install_github('...') |
This file contains 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
#' Sort the results of a gsva() call so that the | |
#' pathway activation always correlates positively | |
#' on average with the gene set listed | |
#' @param g Result of call to gsva() (pathway x cell) | |
#' @param genesets List of genes corresponding to genesets of g | |
#' @param sce A SingleCellExperiment with a logcounts assay | |
fix_gsva_direction <- function(g, genesets, sce) { | |
stopifnot(nrow(g) == length(genesets)) | |
genesets <- lapply(genesets, intersect, rownames(sce)) |
This file contains 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
seurat_cluster <- function(sce, | |
resolution = 0.8, | |
dims = 1:10, | |
reduction = "mnn", | |
algorithm = 1, | |
return_SCE = TRUE) { | |
seu <- as.Seurat(sce, counts = "counts", data = "logcounts") | |
seu <- FindNeighbors(seu, dims = dims, reduction = reduction) | |
seu <- FindClusters(seu, resolution = resolution, algorithm = algorithm) |
This file contains 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
javascript:( function(){ f='http://myaccess.library.utoronto.ca/login?url='+window.location.href; if(!window.open(f)) location.href=f; } )() |
This file contains 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
suppressPackageStartupMessages({ | |
library(tidyverse) | |
library(SingleCellExperiment) | |
library(argparser) | |
}) | |
select <- dplyr::select | |
mutate <- dplyr::mutate | |
arrange <- dplyr::arrange | |
rename <- dplyr::rename |
This file contains 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
+ | |
theme(axis.text.x = element_text(angle = 90, hjust = 1, vjust = 0.5)) |
NewerOlder