Skip to content

Instantly share code, notes, and snippets.

@diazdc
diazdc / keep_R_alive.R
Created August 7, 2020 21:00
Launches background process from R so you don't get disconnected from an idle session if you
parallel::mcparallel(system('ping -i 600 www.google.com'))
@diazdc
diazdc / conda_install_all.sh
Created February 27, 2020 16:25
Bash script to install to all conda environments
# from https://stackoverflow.com/questions/24117449/install-a-package-into-multiple-all-conda-environments
conda env list | cut -d" " -f1 | tail -n+4 | xargs -L 1 conda install YOUR_PACKAGE -n
@diazdc
diazdc / OneMonokai_update.json
Created February 24, 2020 23:23
Modded colors for the vscode OneMonokai theme
{
"$schema": "vscode://schemas/color-theme",
"type": "dark",
"colors": {
"activityBar.background": "#2f333d",
"activityBar.foreground": "#d7dae0",
"activityBarBadge.background": "#528bff",
"activityBarBadge.foreground": "#f8fafd",
"button.background": "#528bff",
"diffEditor.insertedTextBackground": "#00809b33",
@diazdc
diazdc / git_show.sh
Created February 20, 2020 23:13
Generate file from old git commit or branch
# HEAD~1 is a single commit back, HEAD~2 is two..
# Don't forget to write the full path
git show HEAD:all_regeneration_datasets_Sungmin/app.R
@diazdc
diazdc / env_var_sizes.R
Created January 8, 2020 19:04
Print R environment variable sizes
for (i in seq_along(ls())) {
objects <- ls()
obj_size <- object.size(get(objects[i]))
cat("\n")
print(objects[i])
if (obj_size > 1 * 10^9) {
print(obj_size, units = "GB")
} else if (obj_size > 1 * 10^6) {
print(obj_size, units = "MB")
@diazdc
diazdc / SeuratObjSize.R
Created January 7, 2020 23:48
Print Seurat object slot sizes in MB
SeuratObjSize <- function(seurat_obj) {
all_slots <- slotNames(seurat_obj)
for (i in seq_along(all_slots)) {
obj_size <- object.size(slot(seurat_obj, all_slots[i]))
print(all_slots[i])
print(obj_size, units = "MB")
cat("\n")
}
@diazdc
diazdc / conda_PS1.sh
Last active November 13, 2019 16:31
Colored conda environment prompt with user name
# must overide default conda PS1 with "conda config --set changeps1 False' first
PS1='(\[\e[0;32m\]$(basename "$CONDA_DEFAULT_ENV")\[\e[m\]) \u\[\e[0;90m\]@\[\e[m\]\h ';
@diazdc
diazdc / mcFindMarkers.R
Last active May 24, 2024 16:34
Multicore solution for Seurat FindAllMarkers()
n_clust <- 1:(max(as.numeric(Idents(seurat_obj))))
mcFindMarkers <- function(i){
ident1 <- i
ident2 <- n_clust[n_clust != i]
table <- FindMarkers(seurat_obj,
ident.1 = ident1, ident.2 = ident2, only.pos = TRUE)
table$Gene.name.uniq <- rownames(table)
table$cluster <- rep(i, nrow(table))
return(table)
}
@diazdc
diazdc / gg_color_hue.R
Created September 11, 2019 14:07
ggplot color generator
gg_color_hue <- function(n) {
hues = seq(15, 375, length = n + 1)
hcl(h = hues, l = 65, c = 100)[1:n]
}
# Get size of each slot in Seurat object
objectSize <- function(seurat_obj) {
slots <- slotNames(seurat_obj)
for (i in 1:length(slots)) {
print(paste0(slots[i], " - ", class(slot(seurat_obj, slots[i]))))
print(object.size(slot(seurat_obj, slots[i])), units = "auto")
}
}