Skip to content

Instantly share code, notes, and snippets.

@mojaveazure
mojaveazure / UsefulCommands.md
Last active June 3, 2016 22:38
Some commands that I come across and find useful

Useful Commands

Bash

Command Meaning
echo -en "\rSomeText" Return carriage to the beginning of the line (-e and \r), write "SomeText" at that point in time. Do not output a new line at the end of the statement (-n). Useful for dynamic terminal messages.
find . -exec touch -am {} \; Update the access and modified times for all files in this current directory and all subdirectories. Useful for keeping files around when set to expire after a given amount of time.
find . -name 'foo-exclude-me' -prune -o -name 'foo*' -print Find all files with foo*, ignoring foo-exlude-me
@mojaveazure
mojaveazure / read_file_to_array.sh
Created February 9, 2017 18:25
Read a file into an array without using `cat`
#!/bin/bash
set -euo pipefail
MY_FILE="$1"
declare -ax ARRAY=($(<"${MYFILE}"))
@mojaveazure
mojaveazure / translate_ensembl_codes.py
Last active May 24, 2017 20:15
Translate Ensembl codes into gene names
#!/usr/bin/env python3
"""Translate Ensembl codes into gene names"""
import sys
if sys.version_info.major is not 3 and sys.version_info.minor < 5:
sys.exit("Please use Python 3.5 or higher for this program")
import argparse
@mojaveazure
mojaveazure / install_seurat.R
Last active July 7, 2017 19:35
Install Seurat easily and effectively
#!/usr/bin/env Rscript
args <- commandArgs(trailingOnly = TRUE)
msg <- "Please pass 'bitbucket' or 'github' to choose where we install Seurat from"
if (length(x = args) != 1) {
stop(msg)
}

Keybase proof

I hereby claim:

  • I am mojaveazure on github.
  • I am mojaveazure (https://keybase.io/mojaveazure) on keybase.
  • I have a public key ASB4Z0EBpYA3cVTGJWx8Ndx3OSvgxPqondPxy1_0TbMOwgo

To claim this, I am signing this object:

@mojaveazure
mojaveazure / pbmc3k_h5ad.py
Created April 30, 2020 07:34
Script to generate an H5AD file following Scanpy's PBMC 3k tutorial
#!/usr/bin/env python3
"""Generate an H5AD file from the PBMC3k dataset"""
import os
import sys
import time
import shutil
import urllib
import logging

Installing RStudio Server on the Windows Subsystem for Linux

Setting up RStudio Server on the Windows Subsystem for Linux (WSL) is an excellent way for R developers to use and interact with R on Linux while running Windows. While not perfect, it provides a nearly seamless way for Windows users to consume Linux-only packages, and for developers to test on both Windows and Linux at the same time. Moreover, the same benefits of running RStudio server, such as leaving jobs running in the background, apply to RStudio Server on WSL. These are my notes for successfully setting up and using RStudio Server on WSL

Setting up WSL

The first thing that needs to happen in enabling the WSL and installing a Linux distro. To install the WSL, open PowerShell as an administrator and run

dism.exe /online /enable-feature /featurename:Microsoft-Windows-Subsystem-Linux /all /norestart
@mojaveazure
mojaveazure / MinimalRVersion.R
Created September 4, 2020 18:30
Minimal R Version
#!/usr/bin/env Rscript
#' Minimal R version
#'
#' Find the lowest accepted R version for a package and all of its dependencies
#'
#' @param package Name of CRAN package
#'
#' @return A \code{\link[base]{numeric_version}} with the lowest possible R
#' version to install \code{package} and all of its dependencies
@mojaveazure
mojaveazure / matrix_method_caching.Dockerfile
Created August 6, 2023 16:24
Example Dockerfile showcasing S4 method caching at build-time
FROM rocker/r-ver:4.2.2
RUN apt-get update && apt-get upgrade -y
RUN Rscript -e "\
install.packages('remotes'); \
remotes::install_version('Matrix', '1.5.1'); \
install.packages('SeuratObject', repos = 'https://cloud.r-project.org')"
RUN Rscript -e "print(packageVersion('Matrix'))"
@mojaveazure
mojaveazure / rocker_base_tiledbsoma.Dockerfile
Created August 6, 2023 16:25
Install tiledbsoma-r on a fresh R/Debian install with no binary packages
FROM rocker/r-base:latest
RUN apt-get update && \
apt-get install -y ca-certificates lsb-release curl cmake git
RUN curl -O https://apache.jfrog.io/artifactory/arrow/$(lsb_release --id --short | tr 'A-Z' 'a-z')/apache-arrow-apt-source-latest-$(lsb_release --codename --short).deb
RUN apt-get install -yV ./apache-arrow-apt-source-latest-$(lsb_release --codename --short).deb
RUN apt-get update && apt-get install -y libarrow-dev
RUN Rscript -e "\
ncores <- as.integer(system2('grep', c('-c', 'processor', '/proc/cpuinfo'), stdout = TRUE)); \