Skip to content

Instantly share code, notes, and snippets.

View stephenturner's full-sized avatar

Stephen Turner stephenturner

View GitHub Profile
// Place your key bindings in this file to overwrite the defaults
[
// RStudio: Copy lines up/down with alt+cmd+up/down
{
"key": "alt+cmd+down",
"command": "editor.action.copyLinesDownAction",
"when": "editorTextFocus && !editorReadonly"
},
{
"key": "shift+alt+down",
@stephenturner
stephenturner / 1-train-deploy.R
Created July 26, 2022 10:52
Train and deploy a random forest with vetiver + plumber
# R session 1: model training and deployment ------------------------------
library(tidymodels)
library(vetiver)
library(plumber)
# Not the way you'd actually split data - for demo only
cars_train <- mtcars[1:24,]
cars_test <- mtcars[25:32,]
@stephenturner
stephenturner / addad.py
Created June 23, 2022 11:33
Adds AD=2 to VCF on a stream
#!/usr/bin/env python
# Adds allelic depth (AD)=2 to a VCF.
# Usage: bcftools view my.vcf.gz | addad.py | bcftools sort -Oz -o my.ad.vcf.gz && tabix my.ad.vcf.gz
import pysam
vcf_in=pysam.VariantFile("-","r")
vcf_in.header.formats.add("AD",".","Integer","Allelic depth, hard-coded as 2")
@stephenturner
stephenturner / .tmux.conf
Created April 20, 2022 14:59
stephenturner's ~/.tmux.conf
# Start window and pane indices at 1 instead of 0
set -g base-index 1
set -g pane-base-index 1
# Shift arrow keys to move around panes
bind -n S-Up select-pane -U
bind -n S-Down select-pane -D
bind -n S-Left select-pane -L
bind -n S-Right select-pane -R
@stephenturner
stephenturner / bootstrap632.r
Created April 15, 2022 16:34
.632 bootstrap proof
n <- 1e7
x <- sample(n, size=n, replace=TRUE)
length(unique(x))/n
# [1] 0.6321897
1-exp(-1)
# [1] 0.6321206
@stephenturner
stephenturner / build-install-bcftools-home.sh
Last active November 24, 2021 13:14
Install htslib, bcftools, samtools to home directory
# Compile and install htslib, bcftools, samtools 1.9 to home directory
# Set up dirs where stuff will be installed
mkdir -p ${HOME}/bin/htslib
mkdir -p ${HOME}/bin/bcftools
mkdir -p ${HOME}/bin/samtools
# Make a dir to build
mkdir -p ${HOME}/tmp
@stephenturner
stephenturner / get-licenses-for-loaded-packages.R
Created September 26, 2019 15:44
Code to get license information for all loaded packages
# Load some packages
library(knitr)
library(tidyverse)
library(DT)
# Get licenses for all installed packages.
installed_licenses <- installed.packages() %>%
as.data.frame() %>%
rownames_to_column("package") %>%
as_tibble() %>%
@stephenturner
stephenturner / rename.pl
Created July 29, 2019 00:10
Perl rename script
#!/usr/bin/perl
use warnings;
use strict;
use Getopt::Long;
Getopt::Long::Configure('bundling');
my ($verbose, $no_act, $force, $op);
have <- tibble::tribble(
~id1, ~id2, ~value,
"a", "b", 1L,
"c", "a", 2L,
"c", "b", 3L
)
have
want <- tibble::tribble(
~id1, ~id2, ~value,
@stephenturner
stephenturner / mendeley-scihub.json
Created July 25, 2018 09:57
Sci-Hub look up engine for Zotero. Add to zotero engines file (https://www.zotero.org/support/locate#managing_lookup_engines). Afterwards, relaunch Zotero, make sure the newly added lookup engine is checked under Locate (green arrow) -> Manage Lookup Engines.
[
{
"name": "Sci-Hub Lookup",
"alias": "Sci-Hub",
"icon": "null",
"_urlTemplate": "https://sci-hub.tw/{z:DOI}",
"description": "Sci-Hub full text PDF search",
"hidden": false,
"_urlParams": [],
"_urlNamespaces": {