Skip to content

Instantly share code, notes, and snippets.

View FloWuenne's full-sized avatar
💻

Florian Wuennemann FloWuenne

💻
  • Seqera
  • Barcelona | Montreal
  • 00:19 (UTC -04:00)
  • X @FloWuenne
View GitHub Profile
@FloWuenne
FloWuenne / gist:619799903afcf7c0dcf5e796731476c3
Last active June 7, 2017 15:54
Unload R packages that override certain tidyverse functions (scran, scater) if they appear in search()
## 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)
}
@FloWuenne
FloWuenne / gist:2ead3f6262c68ef76423c15e3d8fd3b7
Created June 27, 2017 16:20
Cell cycle assignment for single cells (using Dropbead), starting from a Seurat object and adding cell cycle to Metadata of Seurat object
## 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,
@FloWuenne
FloWuenne / gist:5f881d7f4f1f05e205c64a2d05b68ff7
Last active March 9, 2019 16:57
Creating quick SCE object from Seurat expression data
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)
@FloWuenne
FloWuenne / gist:11409997ad826ef429fec511f779cf40
Last active July 26, 2017 14:38
Plot mean expression of a gene vs other parameters and highlight specific genes using ggrepel
## 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)
@FloWuenne
FloWuenne / gist:e2b11727e9c72604e4d14d49797c2d0e
Created July 26, 2017 18:55
Cell cycle assignment for single cell data using scran and cyclone with gene symbols instead of ensembl IDs
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()
@FloWuenne
FloWuenne / gist:f3f0071c4a0ca7a2b14e613ed8bfa102
Last active August 10, 2017 00:26
Create a cellview Rds object from a seurat expression object (updated for Seurat version 2) [MOUSE]
## 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)
```
@FloWuenne
FloWuenne / gist:656aad5b050d0cb5c15ad8dace8d90f1
Created August 2, 2017 14:23
Visualize the output from GatherMolecularBarcodeDistributionByGene to assess UMI duplication rates
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) %>%
@FloWuenne
FloWuenne / gist:c4cacec753440781f0178ec001c1cd6b
Created August 9, 2017 21:53
Plot VlnPlot for markers with minimum axis for joined marker plot as in (Macosko et al for retina)
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,
@FloWuenne
FloWuenne / Translate_human_to_mouse.txt
Last active November 1, 2024 17:56
Translate Human gene symbols into Mouse symbols using bioMart
# 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])
@FloWuenne
FloWuenne / find_specific_markers.R
Created October 30, 2017 13:59 — forked from daskelly/find_specific_markers.R
Use Seurat to find specific markers of each cell type
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