Skip to content

Instantly share code, notes, and snippets.

View npjc's full-sized avatar

Nicolas Coutin npjc

  • Bioc & Mol Bio, UBC Vancouver
  • Vancouver, Canada
View GitHub Profile
@npjc
npjc / smooth-spline-fit-an-extraction.R
Created July 23, 2019 16:57
Example of how to pull out summary metrics from smooth spline fit
ss <- function(tbl) {
fit <- smooth.spline(x = tbl$x, y = tbl$y, cv = TRUE)
# first derivative
deriv1 <- predict(fit, deriv = 1)
slope_max_pos <- which.max(deriv1$y)
x_at_slope_max <- tbl$x[slope_max_pos]
y_at_slope_max <- tbl$y[slope_max_pos]
dy_at_slope_max <- deriv1$y[slope_max_pos]
# translate into new vars
@npjc
npjc / eg_cg12-to-precog-format.R
Created July 23, 2019 16:55
Quick and Dirty Example of Converting CG12 formatted data into Precog formatted data.
# convert cg-12 raw data into generic growth data that can be imported into
# precog-lite
library(tidyverse)
library(lubridate)
# devtools::install_github("npjc/cg12r")
library(cg12r)
# how do you take raw data from the cg-12 and turn it into growth curves
[{"name":"A01","date":"2018-04-19 14:36:36","value":0.078},{"name":"A02","date":"2018-04-19 14:36:36","value":0.077},{"name":"A03","date":"2018-04-19 14:36:36","value":0.082},{"name":"A04","date":"2018-04-19 14:36:36","value":0.285},{"name":"A05","date":"2018-04-19 14:36:36","value":0.081},{"name":"A06","date":"2018-04-19 14:36:36","value":0.08},{"name":"A07","date":"2018-04-19 14:36:36","value":0.142},{"name":"A08","date":"2018-04-19 14:36:36","value":0.083},{"name":"A09","date":"2018-04-19 14:36:36","value":0.077},{"name":"A10","date":"2018-04-19 14:36:36","value":0.101},{"name":"A11","date":"2018-04-19 14:36:36","value":0.078},{"name":"A12","date":"2018-04-19 14:36:36","value":0.077},{"name":"B01","date":"2018-04-19 14:36:36","value":0.076},{"name":"B02","date":"2018-04-19 14:36:36","value":0.079},{"name":"B03","date":"2018-04-19 14:36:36","value":0.08},{"name":"B04","date":"2018-04-19 14:36:36","value":0.08},{"name":"B05","date":"2018-04-19 14:36:36","value":0.102},{"name":"B06","date":"2018-04-19 14:36:3
@npjc
npjc / relative-ranking-the-not-stupid-way.md
Last active August 29, 2017 17:12
how to use relative dose to compare across drugs
library(tidyverse)
#> Loading tidyverse: ggplot2
#> Loading tidyverse: tibble
#> Loading tidyverse: tidyr
#> Loading tidyverse: readr
#> Loading tidyverse: purrr
#> Loading tidyverse: dplyr
#> Conflicts with tidy packages ----------------------------------------------
#&gt; filter(): dplyr, stats
@npjc
npjc / cal-sheet.csv
Created April 24, 2017 17:23
calendar week rows csv
year cw month Sun Mon Tues Wed Thurs Fri Sat
2017 2 Jan 1 2 3 4 5 6 7
2017 3 Jan 8 9 10 11 12 13 14
2017 4 Jan 15 16 17 18 19 20 21
2017 5 Jan 22 23 24 25 26 27 28
2017 6 Jan 29 30 31
2017 6 Feb 1 2 3 4
2017 7 Feb 5 6 7 8 9 10 11
2017 8 Feb 12 13 14 15 16 17 18
2017 9 Feb 19 20 21 22 23 24 25
@npjc
npjc / rtibble.r
Created July 7, 2016 05:14
make-a-random-tibble
# install.packages(c("purrr", "tibble"))
rtibble <- function(n_obs = 10) {
tibble::tibble(
lgl = purrr::rbernoulli(n_obs),
int = purrr::rdunif(n_obs,sample.int(1e3, 1, replace = T)),
dbl = rnorm(n_obs),
chr = sample(letters, n_obs, replace = T),
fctr = as.factor(sample(letters, n_obs, replace = T))
)
pacman::p_load(readr, dplyr, tidyr, ggplot2)
library(partitions)
n <- 5
vals <- as.vector(parts(n))
len <- length(vals) / n
part <- rep(1:len, each = n)
d <- data_frame(vals, part)
d <- d %>%
group_by(part) %>%
@npjc
npjc / pkg-at-a-glance.r
Last active September 10, 2015 01:36
readr ui at a glance
#' the name of the package we want to check
pkg <- "tidyr"
library(pkg, character.only = TRUE)
#' do the work
pacman::p_load(readr, dplyr, tidyr, ggplot2)
`%||%` <- function(a, b) if (!is.null(a)) a else b
ui <- getNamespaceExports(pkg)
only_funs <- unlist(lapply(ui, function(x) is.function(get(x))))
ui <- ui[only_funs]
l <- lapply(ui, function(f) {
@npjc
npjc / number2words.r
Created September 1, 2015 21:48
numbers2words
# John Fox's numbers2words found here:
# http://tolstoy.newcastle.edu.au/R/help/05/04/2715.html
numbers2words <- function(x){
# helper
helper <- function(x){
digits <- rev(strsplit(as.character(x), "")[[1]])
nDigits <- length(digits)
if (nDigits == 1) as.vector(ones[digits])
else if (nDigits == 2)
  • use a cache environment in aaa_cache.R:

    • bg_ws for biogrid webservice.
    • use a function such as bg_ws_build() which assigns useful variables
      • url
      • uris (service endpoints)
      • access key
      • parameters
  • in zzz.R: