Skip to content

Instantly share code, notes, and snippets.

View kbroman's full-sized avatar

Karl Broman kbroman

View GitHub Profile
@kbroman
kbroman / smooth_gmap.R
Created March 21, 2023 14:38
smooth genetic map by mixing it with a bit of constant recombination (separate rec rate for each chromosome)
# smooth genetic map by mixing it with a bit of constant recombination (separate rec rate for each chromosome)
# (the input gmap and pmap are lists of vectors of marker positions)
smooth_gmap <-
function(gmap, pmap, alpha=0.02)
{
stopifnot(is.list(gmap), is.list(pmap))
stopifnot(length(gmap)==length(pmap), all(names(gmap) == names(pmap)))
stopifnot(length(alpha)==1, alpha >= 0, alpha <= 1)
for(chr in seq(along=gmap)) {
g <- gmap[[chr]]
@kbroman
kbroman / dashstack.py
Created September 29, 2021 11:18 — forked from dgfitch/dashstack.py
Stack the UW COVID dashboard graphs, dividing positive tests into tests to get a positive percentage chart.
import re
import requests
from requests_html import HTMLSession
import pandas as pd
import matplotlib.pyplot as plt
session = HTMLSession()
r = session.get('https://covidresponse.wisc.edu/dashboard/')
@kbroman
kbroman / guess_geno.R
Created August 10, 2021 15:47
guess genotypes from allele dosages
# guess genotypes from allele dosages
#
# alleleprob = n_ind x n_alleles matrix of allele dosages (rows sum to 1)
# epsilon = tolerance value
guess_geno_from_alleleprob <-
function(alleleprob, epsilon=0.01)
{
stopifnot(is.matrix(alleleprob)) # expect ind x allele matrix
stopifnot(is.numeric(epsilon), length(epsilon)==1, epsilon >= 0, epsilon <= 1)
@kbroman
kbroman / plot_sdp.R
Last active July 13, 2021 04:12
Plot of strain distribution patterns of SNPs
# plot strain distribution patterns for SNPs
#
# pos = vector of SNP positions
# sdp = vector of strain distribution patterns
# labels = names of the strains
#
# example usage:
# plot_sdp(runif(100, 0, 100), sample(0:255, 100, replace=TRUE))
plot_sdp <-
@kbroman
kbroman / test_plotly.Rmd
Last active May 11, 2021 02:16
test of plotly in R Markdown
---
title: "test_plotly"
author: "Karl"
date: "5/10/2021"
output: html_document
---
Compile this at command line with
```
@kbroman
kbroman / expand4ril.R
Created February 2, 2021 16:04
Expand RIL data for individual-level analysis
# functions for expanding probs and kinship matrices
# for individual-level analysis of RILs
# create mapping, individuals -> lines
#
# n = sample size for each line
n2mapping <-
function(n)
{
@kbroman
kbroman / plotrf_colorscale.R
Last active June 18, 2020 16:52
color scale for R/qtl plotRF()
library(qtl)
# example data set; calculate pairwise rec fracs
data(hyper)
hyper <- est.rf(hyper)
# set up color scale
n_colors <- 256
zmax <- 12
lod <- seq(0, zmax, len=n_colors)
@kbroman
kbroman / scan1boot.R
Created May 27, 2020 18:14
Bootstrap for R/qtl2 scan1()
# bootstrap of scan1()
scan1boot <-
function(genoprobs, pheno, kinship=NULL, addcovar=NULL, Xcovar=NULL, intcovar=NULL,
weights=NULL, n_boot=1, ...)
{
# to contain the results
result <- vector("list", n_boot)
# drop individuals that are not in common across all data
# find large intervals in a map
#
#
# input: map = list of chromosomes that are vectors of marker positions
# [can also be a cross object, in which case pull.map() is used]
# min_distance = minimum distance between markers to be flagged
#
# example use:
# library(qtl)
# data(hyper)
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.