Skip to content

Instantly share code, notes, and snippets.

View kbroman's full-sized avatar

Karl Broman kbroman

View GitHub Profile
# k-by-k version of a mcnemar test
mcnemar <-
function(tab, n_perm=1000)
{
if(diff(dim(tab)) != 0 || any(tab < 0) || any(round(tab) != tab)) {
stop("tab should be a square matrix with non-negative integers")
}
calc_stat <- function(tab) {
@kbroman
kbroman / karl_lego.R
Last active March 21, 2019 00:35
low-res picture of me in legos, rendered via the brickr package
# install_github("ryantimpe/brickr")
# install_github("tylermorganwall/rayshader")
library(brickr) # also need rayshader
url <- paste0("https://gist.githubusercontent.com/kbroman/",
"bfba63a490fb40ea907a79e1ddd2354f/",
"raw/8c3a3d82423956867bc31f0f0980f7c887badff1/",
"karl_lego.csv")
file <- basename(url)
if(!file.exists(file)) download.file(url, file)
We can make this file beautiful and searchable if this error is corrected: It looks like row 3 should actually have 1 column, instead of 9. in line 2.
# nrow 6097
# ncol 9
line,A,B,C,D,E,F,G,H
375,8,6,7,5,2,1,4,3
376,8,6,7,5,2,1,4,3
377,2,1,4,3,7,6,8,5
378,2,1,4,3,7,6,8,5
379,2,1,4,3,7,6,8,5
380,2,1,4,3,7,6,8,5
381,2,1,4,3,7,6,8,5
# simulate DO data, to look at kinship coefficient for siblings vs others
library(simcross) # install with devtools::install_github("kbroman/simcross")
library(qtl2)
# example DO data with megaMUGA genotypes, used for map + founder genotypes
file <- paste0("https://raw.githubusercontent.com/rqtl/",
"qtl2data/master/DO_Svenson291/svenson.zip")
# problem with fit1() with model="binary", in giving negative or NAs for LOD scores
library(qtl2)
dat <- readRDS("fit1_binary_problem.rds")
fit1(dat$p, dat$y, model="binary")$lod # NA value
stopifnot( all(names(dat$y) == rownames(dat$p)) )
out_glm <- glm(dat$y ~ -1 + dat$p, family=binomial(link=logit),
LIB = "packages/"
#LIB = NULL
# These were not on CRAN, so it did not install to "packages/"
# library ("curl")
# library ("devtools")
# devtools::install_github ('ropenscilabs/miner')
# devtools::install_github ('ropenscilabs/craft')
library (miner)
library (craft)
#include <Rcpp.h>
using namespace Rcpp;
// [[Rcpp::export]]
NumericVector sim_crossovers_orig(const double L)
{
int n_xo;
n_xo = R::rpois(L/100.0);
# Study genotype frequencies / haplotype reconstructions in Diversity Outbred mice
# Example with the DOex data (https://github.com/rqtl/qtl2data/tree/master/DOex)
# See R/qtl2 discussion: https://groups.google.com/d/msg/rqtl2-disc/cBJ0zSbvid8/pplbQ_zyAwAJ
library(qtl2)
file <- paste0("https://raw.githubusercontent.com/rqtl/",
"qtl2data/master/DOex/DOex.zip")
DOex <- read_cross2(file)
# genoprobs
@kbroman
kbroman / qtl_papers.md
Last active January 15, 2018 12:56
QTL papers for spring, 2018, plant breeding seminar course

QTL papers

  • Albert and Kruglyak (2015) The role of regulatory variation in complex traits and disease. Nature Reviews Genetics 16:197-212. doi:10.1038/nrg3891

  • Jiang C, Zeng ZB (1995) Multiple trait analysis of genetic mapping for quantitative trait loci. Genetics 140:1111-1127 PMC:1206666

  • Gatti DM et al (2014) Quantitative trait locus mapping methods for diversity outbred mice.

# 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()
} )