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
## Been having issues lately when using tidyverse functions such as mutate or arrange | |
## while having single cell packages such as scran and scater loaded, since they seem to have | |
## similar functions, that override the tidyverse functions | |
## Add this snippet to chunks that use tidyverse functions to unload packages that interfere | |
if(c("package:scran","package::scater") %in% search()){ | |
detach("package:scater", unload=TRUE) | |
detach("package:scran",unload=TRUE) | |
} |
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
## Load library | |
library(dropbead) | |
## Set cell names | |
cell_IDs <- colnames(expression_seurat@data) | |
## Create a new single species object | |
test <- new("SingleSpeciesSample", | |
species1="human", ## Change to mouse if working with mouse data! | |
cells=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
library(scater) | |
## Create new SCE object from the seurat expression object | |
fData <- new("AnnotatedDataFrame", data = [email protected]) | |
seurat_scater_sce <- newSCESet(exprsData = as.matrix(expression_seurat@data), phenoData = fData, | |
lowerDetectionLimit=0.0, | |
logExprsOffset=1) | |
seurat_scater_sce <- calculateQCMetrics(seurat_scater_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
## Use scater to investigate and annotate gene and cluster properties | |
```{r} | |
library(scater) | |
## Create new SCE object from the seurat expression object | |
fData <- new("AnnotatedDataFrame", data = [email protected]) | |
seurat_scater_sce <- newSCESet(exprsData = as.matrix(expression_seurat@data), phenoData = fData, | |
lowerDetectionLimit=0.01, | |
logExprsOffset=1) |
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
library(scran) | |
library(org.Hs.eg.db) | |
## Load pretrained model from scran | |
hg.pairs <- readRDS(system.file("exdata", "human_cycle_markers.rds", package="scran")) | |
## Translate all ensembl IDs to gene symbols for pretrained model | |
g1_symbols <- data.frame() | |
s_symbols <- data.frame() | |
g2m_symbols <- data.frame() |
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
## Cellview export of data for user | |
### Rerun TSNE with 3 dimensions | |
```{r} | |
expression_seurat_cellview <- RunTSNE(expression_seurat, | |
dims.use = 1:20, | |
do.fast=T, | |
dim.embed= 3) | |
``` |
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
library(stringr) | |
## Look at the number of duplicated and unique UMIs per Cell | |
umi_by_gene <- read.table("UMI_by_gene_dist.tab",sep="\t",header=T) | |
## Count number of duplicated UMIs per cell | |
num_of_duplicated_umis_per_cell <- umi_by_gene %>% | |
group_by(Cell.Barcode) %>% | |
subset(Num_Obs > 1) %>% |
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
candidate_markers <- c("GAPDH","NANOG","ACTB") | |
for(this_gene in candidate_markers){ | |
## Violin Plot | |
vln_plot_avgdiff <- VlnPlot(expression_seurat.updated, | |
this_gene, | |
point.size.use = -1, | |
x.lab.rot=TRUE, | |
remove.legend = TRUE, |
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
# Basic function to convert human to mouse gene names | |
convertHumanGeneList <- function(x){ | |
require("biomaRt") | |
human = useMart("ensembl", dataset = "hsapiens_gene_ensembl") | |
mouse = useMart("ensembl", dataset = "mmusculus_gene_ensembl") | |
genesV2 = getLDS(attributes = c("hgnc_symbol"), filters = "hgnc_symbol", values = x , mart = human, attributesL = c("mgi_symbol"), martL = mouse, uniqueRows=T) | |
humanx <- unique(genesV2[, 2]) |
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
library(tidyverse) | |
library(Seurat) | |
# Find specific markers for each cell type | |
celltypes <- # list of cell types (unique ident labels of Seurat object) | |
obj <- # Seurat object | |
specific_markers <- NULL | |
# First we do all pairwise comparisons and retain any markers that | |
# are even somewhat higher in the cell type of interest |
OlderNewer