Skip to content

Instantly share code, notes, and snippets.

View kbroman's full-sized avatar

Karl Broman kbroman

View GitHub Profile
# elsa-fy for minecraft
# using the miner R package, https://github.com/ROpenSciLabs/iner
#
# when she walks on water, it turns to ice
elsafy <- function(player_id=NULL, water=c(8, 9), ice=174, delay=0.02)
{
on.exit( { # clean up a bit
for(i in 1:20) miner:::mc_receive()
} )
// [[Rcpp::depends(RcppEigen)]]
#include <RcppEigen.h>
using namespace Rcpp;
using namespace Eigen;
MatrixXd AtA(const MatrixXd A) {
int n = A.cols();
return MatrixXd(n,n).setZero().selfadjointView<Lower>()
@kbroman
kbroman / arab_magic.R
Last active April 16, 2017 01:45
transition probabilities for 19-way Arabidopsis MAGIC
# calculating transition probabilities for 19-way Arabidopsis MAGIC
#
# full diallel both directions (F1)
# 3 generations random mating (F4) - 384 families
# selfed for 6 generations; could be "cousin" lines from an F4 family
# 1026 MAGIC lines; 527 in paper
#
# Kover et al (2009) PLOS Genet 5: e1000551
# https://doi.org/10.1371/journal.pgen.1000551
#
# 2^n-way RIL by selfing
# binned two-locus probabilities, likelihood for rec frac, MLE
# 8-way RIL by selfing
probs8 <- function(r) c((1-r)^2, r*(1-r), r/2)/8/(1+2*r) * c(8, 8, 48)
llik8 <-
function(r, counts)
### Keybase proof
I hereby claim:
* I am kbroman on github.
* I am kbroman (https://keybase.io/kbroman) on keybase.
* I have a public key ASDXTXYHggi4u82YcSipBqLzFN0_nIi2Fx_1To3szhvg7Ao
To claim this, I am signing this object:
# Halloween 2016 counts figure
# Karl Broman
# http://kbroman.org
# the data: time and kid count
x <- read.csv("halloween2016.csv", comment.char="#")
colnames(x) <- c("time", "n.kids")
# cumulative numbers of kids
csum <- cumsum(x$n.kids)
\documentclass{article}
\begin{document}
Here's a scatterplot:
<<scatterplot>>=
x <- rnorm(100)
y <- x + rnorm(100)
plot(x,y)
# convert "5 min" "3 h" "4 d" etc to seconds
shit2sec <-
function(shit)
{
# remove leading space
shit <- sub("^\\s+", "", shit)
# remove ending space
shit <- sub("\\s+$", "", shit)
# simulating DOF1 data
# cross between DO individuals and some 9th strain
library(simcross)
library(qtl2geno)
# load some DO data, for the founder genotypes and map
file <- paste0("https://raw.githubusercontent.com/rqtl/",
"qtl2data/master/DO_Recla/recla.zip")
do_recla <- read_cross2(file)
# simulate RIL
#
# QTL on chr 6 at 19.9 cM
# a = -6.85, hsq = 0.1768
# load R/qtl
library(qtl)
# QTL effect and residual SD
a <- -6.85