Skip to content

Instantly share code, notes, and snippets.

View daskelly's full-sized avatar

Dan Skelly daskelly

View GitHub Profile
@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, ...)
# 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"
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"))
@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(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