Skip to content

Instantly share code, notes, and snippets.

View chasemc's full-sized avatar
:octocat:

Chase Clark chasemc

:octocat:
View GitHub Profile
@chasemc
chasemc / clippy.R
Created December 13, 2019 23:05
turn vector into vector text
utils::writeClipboard(
paste0(
"c(\n",
paste0(
sQuote(colnames(z),
q = "ASCII"),
sep = ",",
collapse = "\n"),
@chasemc
chasemc / hash_files.R
Last active January 11, 2020 18:27
Generate a list of sha1 hashes given file paths
# requires openssl package
hash_files <- function(paths){
num_paths <- length(paths)
pb <- txtProgressBar(max=num_paths)
lapply(seq_along(paths), function(x){
setTxtProgressBar(pb, x)
flush.console()
openssl::sha1(file(paths[[x]]))
})
@chasemc
chasemc / idbac_programming_outline.rmd
Created January 31, 2020 15:38
Outline of new IDBac functions for programming with IDBac
---
title: "Programming IDBac"
author: "Chase Clark"
date: "1/31/2020"
output: html_document
---
```{r setup, include=FALSE}
knitr::opts_chunk$set(eval = FALSE, include = TRUE)
```
@chasemc
chasemc / db_path_from_pool.R
Last active March 15, 2020 17:02
Two functions: Check if an object is pool; Get path of database from pool
#' Check if a pool object
#'
#' @param pool variable to check
.checkPool <- function(pool){
val <- all(inherits(pool, "Pool"),
inherits(pool, "R6"))
if (isFALSE(val)) {
library(ggplot2)
library(data.table)
library(geofacet)
library(grid)
library(gganimate)
# Accessed 2020-03-24 at 9pm CST
confirmed <- data.table::fread("http://covidtracking.com/api/states/daily.csv")
confirmed$date <- as.Date(as.character(confirmed$date), "%Y%m%d")
confirmed <- confirmed[confirmed$date != "2020-03-24", ]
@chasemc
chasemc / combn_iterative.R
Created April 2, 2020 14:30
combn, one at a time
N=5
for( i in 1:(N-1) ){
for( j in (i+1):N ){
print(paste(i,j))
}
}
@chasemc
chasemc / bruker_bts.csv
Last active April 2, 2020 17:18
Bruker BTS Standard Masses
protein average
RL29 [M+2H]2+ 3637.8
RS32 [M+H]+ 5096.8
RS34 [M+H]+ 5381.4
RS33meth [M+H]+ 6255.4
RL29 [M+H]+ 7274.5
RS19 [M+H]+ 10300.1
RNAse A [M+H]+ 13683.2
Myoglobin [M+H]+ 16952.3
@chasemc
chasemc / lca_height.R
Last active May 7, 2020 22:40
Find the height of the least common ancestor of two nodes in a dendrogram in R (requires dendextend package)
# install.packages("dendexted")
lca_height <- function(dend,
input_a,
input_b) {
subtrees <- dendextend::partition_leaves(dend)
find_ancestors <- function(input_labels) {
which(sapply(subtrees, function(x) input_labels %in% x))
@chasemc
chasemc / script.R
Created May 13, 2020 22:23
Is Illinois flattening, or still not testing enough?
library(data.table)
library(reshape2)
library(ggplot2)
a <- "https://covidtracking.com/api/v1/states/IL/daily.csv"
a <- data.table::fread(a)
a$date <- as.Date(as.character(a$date), "%Y%m%d")
library(ggplot2)
library(data.table)
library(geofacet)
raw_data <- data.table::fread("http://covidtracking.com/api/states/daily.csv")
raw_data$date <- as.Date(as.character(raw_data$date), "%Y%m%d")
raw_data <- raw_data[date > "2020-03-15", ]