Skip to content

Instantly share code, notes, and snippets.

@mojaveazure
mojaveazure / doublepin.Dockerfile
Created April 17, 2024 02:29
Dockerfile testing how double-pins work for R package installation and loading/attachment
FROM rocker/r-ver:latest
RUN apt-get update && \
apt-get install -y cmake git wget pandoc
# RUN Rscript -e "repos <- paste0('https://', c('mojaveazure', 'tiledb-inc'), '.r-universe.dev')" \
# -e "repos <- unlist(lapply(repos, \(x) paste0(x, c('/bin/linux/jammy/4.3/', ''))))" \
# -e "repos <- paste(shQuote(repos), collapse = ', ')" \
# -e "cat('options(repos = c(', repos, ', getOption(\"repos\")))\n', sep = '')" | \
# tee -a ~/.Rprofile
@mojaveazure
mojaveazure / ingest-soma.R
Last active April 24, 2024 00:10
Ingest a `Seurat`, `SingleCellExperiment`, or `SummarizedExperiment` object to a SOMA
#!/usr/bin/env Rscript
suppressPackageStartupMessages(library(tiledbsoma))
suppressPackageStartupMessages(library(argparser))
parser <- argparser::arg_parser("", hide.opts = TRUE)
parser <- argparser::add_argument(
parser = parser,
arg = '--input',
help = "Input Seurat, SingleCellExperiment, or SummarizedExperiment object as Rds",
@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)); \
@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 / 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

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 / 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

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 / 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)
}
@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