Skip to content

Instantly share code, notes, and snippets.

@explodecomputer
explodecomputer / grm_sim_duos.R
Created February 9, 2015 18:04
Simulate GRM for small number of SNPs with mother children pairs
nsnp <- 48
n <- 1000
mothers1 <- matrix(rbinom(n*nsnp*2, 1, 0.5), n)
kids1 <- matrix(rbinom(n*nsnp, 1, 0.5), n)
kids2 <- mothers1[, seq(1, 2*nsnp, 2)]
kids <- kids1 + kids2
@explodecomputer
explodecomputer / cis_trans_mediation.R
Created February 13, 2015 12:42
cis-trans mediation simulations
# Null is true
nsim <- 1000
p <- matrix(0, nsim, 3)
n <- 1000
g1 <- rbinom(n, 2, 0.2)
g2 <- rbinom(n, 2, 0.3)
g3 <- rbinom(n, 2, 0.4)
g <- cbind(g1, g2, g3)
@explodecomputer
explodecomputer / stratify.R
Last active August 29, 2015 14:15
Simulation of stratifying instrument
# Simulate the smoking thing
# SNP influences smoking status
# Smoking status influences income
# Test for association of SNP on income in smokers and non smokers
nsim <- 100
res <- matrix(0, nsim, 4)
n <- 100000
for(i in 1:nsim)
@explodecomputer
explodecomputer / simphen.sh
Last active August 29, 2015 14:16
simulate phenotypes
#!/bin/bash
# name of binary plink filename (excluding .bed/.bim/.fam suffix)
plinkfile=""
# output filename
outname=""
# number of causal variants
nvar=1000
@explodecomputer
explodecomputer / unixtutorial.md
Last active August 29, 2015 14:16
unix tutorial

Introduction to Linux

Overview

A lot of servers use Linux and we need to use a server to run a few specific programmes so let's get familiar with Linux.

First of all, to connect to the server we will use a SSH connection. The idea is that we log in to the remote server from our local computer, so when we are running anything on the server we are using its hardware and infrastructure and our local computer is being used to simply view what is happening remotely and to input commands.

@explodecomputer
explodecomputer / rare_variant_prop.R
Created March 25, 2015 14:16
proportion of variance due to rare variants
calc.proprare <- function(nsnp, shape1, eff.func, nid)
{
# Generate allele frequency distribution
mafs <- rbeta(nsnp, shape1, 1) / 2
# Limit min maf to be function of hypothetical sample size
mafs <- pmax(mafs, 1/(nid*2))
# Create distribution of effect sizes
eff <- eff.func(mafs)
@explodecomputer
explodecomputer / cpg_variance.R
Created April 1, 2015 10:24
Estimating variance explained by CpGs from p-values
# Sample size of PAPA replication
n <- 149
# Pvals from first 14 CpGs in PAPA replication
pval <- c(9.6e-6, 7.2e-5, 2.8e-6, 3.7e-5, 4.8e-4, 6.2e-3, 4.6e-6, 1.3e-2, 2.6e-3, 3.8e-4, 3.2e-5, 9.0e-4, 8.8e-5, 8.3e-5)
# Estimate F statistics
qval <- qf(pval, 1, n-1, low=F)
#!/usr/bin/env bash
# rmate
# Copyright (C) 2011-2013 by Harald Lapp <[email protected]>
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
@explodecomputer
explodecomputer / README.md
Last active August 29, 2015 14:18
Scrape PD gene website for GWAS associations for a given list of SNPs

Scrape PD gene website for GWAS associations for a given list of SNPs

Requirements

This requires Python v2.7 plus the following plugin:

Usage

@explodecomputer
explodecomputer / vcf-extract.sh
Last active September 10, 2020 12:40
Extract SNPs from VCF files
#!/bin/bash
#PBS -l walltime=24:00:00,nodes=1:ppn=1
#PBS -o output.file
#PBS -me
#PBS -S /bin/bash
set -e
module add apps/vcftools-0.1.12b
export PERL5LIB=/cm/shared/apps/VCFTOOLS-0.1.12b/vcftools_0.1.12b/perl/