Skip to content

Instantly share code, notes, and snippets.

<?php
/* Feeds a database with the content of a bibtex file parsed with bibtexbrowser
* See: http://www.monperrus.net/martin/feeding-mysql-database-with-bibtexbrowser
* Author: Martin Monperrus
* Date: Feb 2012
*/
/** MySQL database username */
@define('DB_USER', 'root');
@explodecomputer
explodecomputer / get_rsids.R
Created May 29, 2013 03:22
Get rs IDs for list of SNPs
library(SNPlocs.Hsapiens.dbSNP.20120608)
library(plyr)
# Read in bim file
bimname <- "mnd_b37_flipped.bim"
bim <- read.table(bimname, colClasses=c("numeric", "character", "numeric", "numeric", "character", "character"))
bim$index <- 1:nrow(bim)
# For each chromosome download the SNP locations and match to bim file
@explodecomputer
explodecomputer / extractSnps.R
Last active December 22, 2015 06:49
Extract SNPs from 1kg data when it is split up into separate chromosomes
# Usage:
# R --no-save --args snplist.txt /ibscratch/wrayvisscher/imputation/arichu/data/imputed/chr\*/arichu_1kg_p1v3_\* outputfile < extractSnps.R
# - The first argument is the SNP list (just a list of rs SNP ids and nothing else)
# - The second argument specifies the root name for the genotype data (in binary plink format). Replace the chromosome number with "\*"
# - The third argument is the output file root name that you want to save everything to.
library(snpStats)
@explodecomputer
explodecomputer / circles.R
Created September 12, 2013 22:45
Use R/ggbio to produce circos plots
library(ggbio)
library(grid)
library(gridExtra)
library(plyr)
library(GenomicRanges)
library(qgraph)
multiplot <- function(..., plotlist=NULL, file, cols=1, layout=NULL)
{
require(grid)
@explodecomputer
explodecomputer / polygenic.R
Created October 7, 2013 15:10
Polygenic model with known lambda = sigma2e / sigma2a
n <- 1000
m <- 200
X <- matrix(rbinom(m*n, 2, 0.5), n)
p <- apply(X, 2, mean)/2
pv <- apply(X, 2, sd)
Xp <- t((t(X) - 2*p) / pv)
A <- Xp %*% t(Xp) / m
A[1:10,1:10]
@explodecomputer
explodecomputer / grm_io.R
Created October 25, 2013 06:02
Read and write GRM from GCTA
readGRM <- function(rootname)
{
bin.file.name <- paste(rootname, ".grm.bin", sep="")
n.file.name <- paste(rootname, ".grm.N.bin", sep="")
id.file.name <- paste(rootname, ".grm.id", sep="")
cat("Reading IDs\n")
id <- read.table(id.file.name, colClasses="character")
n <- dim(id)[1]
cat("Reading GRM\n")
library(plyr)
library(ggbio)
library(TxDb.Hsapiens.UCSC.hg19.knownGene)
library(rtracklayer)
#=================================================#
#=================================================#
@explodecomputer
explodecomputer / interaction_vs_varhet.R
Created April 28, 2014 13:09
Comparing interaction test against variance heterogeneity test in gene x smoking interaction example
# Initial parameters
sample_size <- 120000
bmi_mean <- 25
bmi_sd <- 4
allele_freq <- 0.19
effect_size <- -0.23
proportion_smokers <- 0.5
# The transformation of BMI to z^2 allows detection of variance heterogeneity, e.g.:
@explodecomputer
explodecomputer / extractSnps.sh
Last active August 29, 2015 14:01
extractSnps.sh
#!/bin/bash
# set -e
snplistfile=${1}
plinkrt=${2}
outfile=${3}
touch ${outfile}_mergelist.txt
rm ${outfile}_mergelist.txt
@explodecomputer
explodecomputer / manhattanplot.R
Created June 23, 2014 16:34
manhattan plot from GWASTools package
manhattanPlot <- function(p,
chromosome,
ylim = NULL,
trunc.lines = TRUE,
signif = 5e-8,
...)
{
stopifnot(length(p) == length(chromosome))