Skip to content

Instantly share code, notes, and snippets.

Avatar

Stephen Turner stephenturner

View GitHub Profile
@stephenturner
stephenturner / 1-train-deploy.R
Created Jul 26, 2022
Train and deploy a random forest with vetiver + plumber
View 1-train-deploy.R
# 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 Jun 23, 2022
Adds AD=2 to VCF on a stream
View addad.py
#!/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 Apr 20, 2022
stephenturner's ~/.tmux.conf
View .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 Apr 15, 2022
.632 bootstrap proof
View bootstrap632.r
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 Nov 24, 2021
Install htslib, bcftools, samtools to home directory
View build-install-bcftools-home.sh
# 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 Sep 26, 2019
Code to get license information for all loaded packages
View get-licenses-for-loaded-packages.R
# 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 Jul 29, 2019
Perl rename script
View rename.pl
#!/usr/bin/perl
use warnings;
use strict;
use Getopt::Long;
Getopt::Long::Configure('bundling');
my ($verbose, $no_act, $force, $op);
View RStudio__selection_untitled_725A80CF
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 Jul 25, 2018
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.
View mendeley-scihub.json
[
{
"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": {
View RStudio__selection_untitled_9D45B5CF
library(tidyverse)
d <- tibble::tribble(
~disease, ~gene, ~chr, ~inheritance,
"flu", "x", 1L, "infectious",
"flu", "y", 2L, "infectious",
"flu", "z", 3L, "infectious",
"aids", "x", 1L, "st",
"aids", "p", 4L, "st"
) %>% print()