Skip to content

Instantly share code, notes, and snippets.

View stephenturner's full-sized avatar

Stephen Turner stephenturner

View GitHub Profile
@stephenturner
stephenturner / biorxiv-full-text-sentiment.r
Created September 2, 2024 10:11
biorxiv-full-text-sentiment.r
library(tidyverse)
library(rvest)
library(tidytext)
## Function to get full text given a DOI
get_full_text <- function(doi) {
paste0("https://www.biorxiv.org/content/", doi, ".full") |>
rvest::read_html() |>
rvest::html_nodes("div.section") |>
rvest::html_text() |>
@stephenturner
stephenturner / biorxiv-api-httr2.R
Created August 31, 2024 09:11
R code to query bioRxiv API for publication details
library(tidyverse)
library(httr2)
# Set URL path variables
url <- "https://api.biorxiv.org/"
what <- "details"
server <- "biorxiv"
date1 <- "2014-01-01"
date2 <- "2023-12-31"
@stephenturner
stephenturner / test.r
Last active August 30, 2024 20:19
test.r
# Get / clean data ----
library(tidyverse)
library(httr2)
# Set URL path variables
url <- "https://api.biorxiv.org/"
what <- "details"
server <- "biorxiv"
date1 <- "2014-01-01"
date2 <- "2023-12-31"
// 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() %>%