Skip to content

Instantly share code, notes, and snippets.

View daskelly's full-sized avatar

Dan Skelly daskelly

View GitHub Profile
library(Seurat)
library(harmony)
# x is a Seurat object not yet processed but we have chosen num_pc
x <- FindNeighbors(x, reduction = 'pca', dims = 1:num_pc, verbose = FALSE) %>%
FindClusters(verbose = FALSE, resolution = 0.2) %>%
RunUMAP(reduction = 'pca', dims = 1:num_pc, verbose = FALSE)
x$noharmony_clusters <- x$seurat_clusters
x@misc$noharmony_umap <- x@reductions$umap
@daskelly
daskelly / datatable.r
Created August 19, 2022 12:46
put an interactive sortable table into Rmarkdown HTML output
library(DT)
#
# make a table of results
# ...
#
datatable(signif_results, filter = 'top', rownames = FALSE,
options=list(pageLength = 10, autoWidth = TRUE))
library(ensembldb)
library(EnsDb.Mmusculus.v79)
ensembl_gene_ids <- c('ENSMUSG00000000120', 'ENSMUSG00000000159', 'ENSMUSG00000000563', 'ENSMUSG00000000600') # some random IDs
ensembldb::select(EnsDb.Mmusculus.v79, keys=ensembl_gene_ids, keytype = "GENEID", columns = c("SYMBOL","GENEID"))
# List all open tabs in front Chrome window
# From https://superuser.com/questions/276321/how-to-export-opened-tabs-in-chrome
alias listtabs="osascript -e{'set o to\"\"','tell app\"google chrome\"','repeat with t in tabs of window 1','set o to o&url of t&\" \"&title of\
t&linefeed',end,end}|sed \$d"
@daskelly
daskelly / wilcox_unequal_var.R
Created March 26, 2020 02:29
Simple code for a t-test with unequal variance on ranked values
wilcox_unequal_var <- function(x, y, ...) {
# The Wilcoxon rank sum test (Mann Whitney U test) does not perform
# that well on data where the variances are unequal. Some
# investigators have recommended as an alternative performing the
# unequal variance t-test on ranked values. See
# https://academic.oup.com/beheco/article/17/4/688/215960
# https://psycnet.apa.org/doiLanding?doi=10.1037%2Fh0078850
rr <- rank(c(x, y))
nx <- length(x)
t.test(rr[1:nx], rr[(nx+1):length(rr)], var.equal=FALSE, ...)
@daskelly
daskelly / read10x
Created December 18, 2018 15:23
Version of Seurat's Read10X function for 10X cellranger 3 data
read10x <- function(dir) {
names <- c("barcodes.tsv", "features.tsv", "matrix.mtx")
for (i in 1:length(names)) {
R.utils::gunzip(paste0(dir, "/", names[i], ".gz"))
}
file.copy(paste0(dir, "/features.tsv"), paste0(dir, "/genes.tsv"))
mat <- Seurat::Read10X(dir)
file.remove(paste0(dir, "/genes.tsv"))
for (i in 1:length(names)) {
R.utils::gzip(paste0(dir, "/", names[i]))
@daskelly
daskelly / find_specific_markers_parallel.R
Last active November 30, 2018 17:57
parallel version of find_specific_markers.R
library(tidyverse)
library(Seurat)
library(doParallel)
# Find specific markers for each cell type
n.cores <- 10
registerDoParallel(cores=n.cores)
celltypes <- # list of cell types (unique ident labels of Seurat object)
obj <- # Seurat object
@daskelly
daskelly / filter_cell_surface.r
Created August 20, 2018 18:11
code to filter genes to find those expressed on cell surface
library(tidyverse)
library(biomaRt)
genes <- # FILL ME IN ... Should be a vector of gene names
markers <- # FILL ME IN ... Should be a data.frame with at least one column called mgi_symbol
ensembl <- useMart("ensembl", dataset="mmusculus_gene_ensembl") # Mouse
# GO:0009986 is cell surface
go_cellsurf <- "GO:0009986"
gene.data <- getBM(attributes=c("mgi_symbol", "ensembl_gene_id", "go_id"),
@daskelly
daskelly / conda_leafcutter.sh
Last active March 10, 2018 23:17
Using conda to install leafcutter
# Intalling leafcutter on a CentOS 6.5 machine
# This machine has glibc 2.12 and leafcutter needs glibc 2.14
module purge
module load gcc/4.9.2
# Install glibc 2.14
mkdir $HOME/apps/glibc_install
cd $HOME/apps/glibc_install
wget http://ftp.gnu.org/gnu/glibc/glibc-2.14.tar.gz
tar zxvf glibc-2.14.tar.gz
@daskelly
daskelly / install_mosh_locally.sh
Last active August 6, 2021 19:34 — forked from lazywei/install_mosh_locally.sh
Install mosh server without root permission
#!/bin/sh
# works on a machine running CentOS 7.7
# no error checking and this requires manual intervention. This script just gives
# an overview of the process.
#
# https://github.com/rust-lang/cargo/issues/713 was helpful...
mkdir -p apps/mosh
cd apps/mosh