Skip to content

Instantly share code, notes, and snippets.

View alanocallaghan's full-sized avatar

Alan O'Callaghan alanocallaghan

View GitHub Profile
@alanocallaghan
alanocallaghan / ace-mode-translations.json
Last active May 25, 2023 08:37
Download github linguist language assocations and dump to a yaml file
{
"c": "c_cpp",
"c++": "c_cpp",
"c#": "csharp",
"f#": "fsharp",
"fortran free form": "fortran",
"gradle": "groovy",
"json with comments": "json",
"rmarkdown": "markdown",
"shell": "bash",
library("ggplot2")
library("ggdist")
library("latex2exp")
set.seed(42)
means <- rnorm(4)
df_slabplot <- rbind(
data.frame(
method = "hmc",
bj = rnorm(4000, mean = rep(means, each = 1000)),
@alanocallaghan
alanocallaghan / export-references.sh
Created March 23, 2022 15:17
Exporting references from a central to local bib file
## using natbib
## when finished adding refs, run
bibexport --nosave -o [LOCAL_BIB_FILE] main.aux
## then switch the \bibliography command from the central file to the local one, ie change
# % \bibliography{[CENTRAL_BIB_FILE]}
# % \bibliography{[LOCAL_BIB_FILE]}
# % with biblatex you would run something like
jabref -n --aux main.aux,[LOCAL_BIB_FILE] [CENTRAL_BIB_FILE]
## and again switch which bib file you're working with
@alanocallaghan
alanocallaghan / act-conda-sm-clust.sh
Created December 6, 2021 22:51
Bash script for activating a conda environment with snakemake on a cluster. One argument - the conda environment. Use it like shell.prefix("./act-conda-sm-clust.sh env; ")
#!/usr/bin/env bash
set -eu
if [ -f ~/miniconda3/etc/profile.d/conda.sh ]; then
[ -z "${CONDA_EXE}" ] && echo "Error, missing \$CONDA_EXE !" && exit 1
CONDA_BASE=$(${CONDA_EXE} info --base)
ADDR2LINE=""
source $CONDA_BASE/etc/profile.d/conda.sh
conda activate $1 || exit 1
fi
library(utils)
for (pkg in rownames(installed.packages(priority="base"))) library(pkg, character.only=TRUE)
pkgs <- c(
"NHANES",
"RNHANES",
"ggplot2",
"jtools",
"interactions",
"patchwork",
# R port of Dmitry Kobak's excellent PCA animations.
# See https://gist.github.com/anonymous/7d888663c6ec679ea65428715b99bfdd
# for matlab/octave code
dir.create("gif", showWarnings = FALSE)
set.seed(42)
X <- matrix(rnorm(200), ncol = 2)
X <- X %*% chol(matrix(c(1, 0.6, 0.6, 0.6), ncol = 2, byrow = TRUE))
X <- apply(X, 2, function(col) col - mean(col))

A catalogue of the bugs that have caused me not insignificant amounts of pain

R

  • Dropping attributes

    matrix[, 1, drop=FALSE]
  • Autocompletion for thee but not for me

@alanocallaghan
alanocallaghan / scRNAseq-mixture-experiments.R
Last active July 26, 2022 14:38
Messing around with 2D mixture models for data-driven scRNAseq quality control
library("scRNAseq")
library("scater")
library("scran")
library("flexmix")
library("mixtools")
library("viridis")
library("annotables")
theme_set(theme_bw())
sce <- ZeiselBrainData()
@alanocallaghan
alanocallaghan / cats_and_dogs_log2.R
Last active September 11, 2018 19:51
Quick plot of cat and dog ratios
library("ggplot2")
library("usmap")
library("httr")
library("readxl")
# Read data
GET("https://query.data.world/s/pth2w34nwc6uhg7mmvr7n56257y2gw", write_disk(tf <- tempfile(fileext = ".xlsx")))
pets <- read_excel(tf)
pets <- pets[!colnames(pets) %in% "X"]
@alanocallaghan
alanocallaghan / .nanorc
Last active May 4, 2018 13:48
Place this in your `~/.nanorc` for great R syntax highlighting in the only console editor I can be bothered to learn. Thanks to the author and editor for providing it in the first place.
############################################
# Syntax highlighting for R #
# by Stephen Haptonstahl #
# March 15, 2009 #
# http://srh.ucdavis.edu/drupal/node/20 #
# edited by Mike Miller #
# Placed on GitHub by Alan O'Callaghan #
# (could no longer find the original) #
############################################