Skip to content

Instantly share code, notes, and snippets.

@explodecomputer
explodecomputer / extractSnpsGenfiles.sh
Last active August 29, 2015 14:14
Extract SNPs from gen files
#!/bin/bash
set -e
# This script extracts a list of SNPs from gzipped .gen files that are split into 23 chromosomes
# and outputs as a single gzipped .gen file containing all extracted SNPs that it can find
# To run use the command
#
# $ ./extractSnpsGenfiles.sh \
@explodecomputer
explodecomputer / remove_unrelateds.R
Last active August 29, 2015 14:14
Zaitlen method
#' Read binary GRM files into R
#'
#' @param rootname
#' @export
#' @return List of GRM and id data frames
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="")
@explodecomputer
explodecomputer / make_grms.sh
Last active August 15, 2016 11:07
Zaitlen method
#!/bin/bash
# name of binary plink filename (excluding .bed/.bim/.fam suffix)
plinkfile=""
# name of phenotype file in plink format (i.e. col1=fid, col2=iid, col3=phenotype
phenfile=""
# make up a name for the grm for all individuals
allfile=""
@explodecomputer
explodecomputer / waldratio.R
Last active August 29, 2015 14:13
Estimate causal effect using two-sample MR
# SNP-disease association - need effect size and standard error, can use log(OR) instead of effect size
y_or <- 1.244
y_upperconf <- 1.375
y_lowerconf <- 1.126
y_eff <- log(y_or)
y_se <- (log(y_upperconf) - log(y_lowerconf)) / (2*1.96)
# Alternative method from Shinn 2000, but uncertain what scale this transforms to
# y_eff <- log(y_or) / 1.81
@explodecomputer
explodecomputer / run_snptest.sh
Last active February 15, 2017 12:40
SNPTEST GWAS script
#!/bin/bash
#PBS -N sleepgwas
#PBS -o sleepsnptest-output
#PBS -e sleepsnptest-error
#PBS -t 1-22
#PBS -l walltime=24:00:00
#PBS -l nodes=1:ppn=2
#PBS -S /bin/bash
@explodecomputer
explodecomputer / hwe.R
Created October 27, 2014 16:43
Calculate HWE for multiple SNPs
# Create some SNPs:
px <- 0.5
py <- 0.3
pz <- 0.2
snpx <- rbinom(1000, 2, px)
snpy <- rbinom(1000, 2, py)
snpz <- rbinom(1000, 2, pz)
m <- data.frame(matrix(rnorm(1000*20), 1000, 20))
y = rnorm(1000)
performScan <- function(y, dat)
{
n <- ncol(dat)
res <- array(0, n)
for(i in 1:n)
{
@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))
@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 / 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.: