Skip to content

Instantly share code, notes, and snippets.

View shackett's full-sized avatar

Sean Hackett shackett

View GitHub Profile
@shackett
shackett / impulse.R
Last active September 21, 2020 20:42
Simulate a dataset of genomic timecourses
library(dplyr)
library(tidyr)
library(impulse) # from github/shackett
timepts <- c(0, 5, 10, 20, 30, 40, 60, 90) # time points measured
measurement_sd <- 0.5 # standard deviation of Gaussian noise added to each observation
total_measurements <- 10000 # total number of genes
signal_frac <- 0.2 # what fraction of genes contain real signal
set.seed(1234)
@shackett
shackett / parallel_fread.R
Last active March 3, 2024 07:46
Parallelizing fread for fast file reading -- split a file into mc.cores pieces and then aggregate them
parallel_fread <- function(path, mc.cores = parallel::detectCores(), header = TRUE, ...) {
stopifnot(file.exists(path))
dots <- list(...)
fread_args <- dots[intersect(names(formals(fread)), names(dots))]
if (any(c("skip", "nrows") %in% fread_args)) {
stop(paste(intersect(c("skip", "nrows"), fread_args), collapse = " & "), " cannot be provided")
}
extract_color_space <- function(hmin=0, hmax=360, cmin=0, cmax=180, lmin=0, lmax=100) {
# This is a pared down version of the code to generate a
# Presently doesn't allow hmax > hmin (H is circular)
# hmin: lower bound of hue (0-360)
# hmax: upper bound of hue (0-360)
# cmin: lower bound of chroma (0-180)
# cmax: upper bound of chroma (0-180)
# lmin: lower bound of luminance (0-100)
@shackett
shackett / Kinetic_Isotope_Effect_Simulation.R
Last active March 18, 2016 20:12
I use a stochastic simulation of Michaelis-Menten kinetics to show that the kinetic isotope effect (KIE) alters steady-state metabolite concentrations (and flux dynamics) but not steady-sate flux (see figure below). KIE occurs if the isotopologues (compounds differing by isotopes) of a metabolite are use differently by enzymes (i.e. different kc…
library(scales)
library(ggplot2)
library(gridExtra)
library(tidyr)
options(stringsAsFactors = F)
source_dist <- 0.5 # fraction of protonated source
uptake_rate <- 1000 # uptake of A
Vol = 1e7
@shackett
shackett / rNMR_shackett_custom.R
Last active March 18, 2016 20:12
Using rNMR, call this custom quantification metric which will subtract baseline and create informative plots of each specie before and after fit * First run shack_peakHeight or shack_peakArea as a custom ROI summary type* Then run shack_fitSummary(outList) in the R console to visualize fitting summary
shack_peakHeight <- function( inList ){
#### For baseline subtraction and quantification using peak height ####
# Save spectra baseline file in a list so that original and baseline
# subtracted spectra can be compared side-by-side
# Quantification by the maximum value once the baseline has been removed
require(baseline)
if(!exists("outList")){