Skip to content

Instantly share code, notes, and snippets.

@explodecomputer
explodecomputer / raiss_setup.sh
Last active February 4, 2019 08:28
raiss_setup
for i in {1..22}
do
plink --bfile /mnt/storage/private/mrcieu/research/mr-eve/vcf-reference-datasets/1000g_filtered/data_maf0.01_rs --chr $i --make-bed --out ld/ref/data_$i
done
for i in {1..22}
do
bcftools query -r $i -f '%ID\t%POS\t%REF\t%ALT\t%B\t%SE\n' ../data.bcf | awk 'BEGIN {print "rsID\tpos\tA0\tA1\tZ"; OFS="\t"}; { print $1, $2, $3, $4, $5/$6}' > ld/ref/z_2_$i.txt
done
@explodecomputer
explodecomputer / comparing_packages.r
Last active December 5, 2018 17:54
comparing_packages
library(TwoSampleMR)
library(RadialMR)
library(MendelianRandomization)
# Read in example data
a <- extract_instruments(2)
b <- extract_outcome_data(a$SNP, 7)
ab <- harmonise_data(a,b)
ab$SNP <- as.character(ab$SNP)
# IVW in TwoSampleMR package
#!/bin/bash
# Download 1000 genomes
wget ALL.chr1.phase3_shapeit2_mvncall_integrated_v5a.20130502.genotypes.vcf.gz
wget ALL.chr1.phase3_shapeit2_mvncall_integrated_v5a.20130502.genotypes.vcf.gz.tbi
wget ALL.chr10.phase3_shapeit2_mvncall_integrated_v5a.20130502.genotypes.vcf.gz
wget ALL.chr10.phase3_shapeit2_mvncall_integrated_v5a.20130502.genotypes.vcf.gz.tbi
wget ALL.chr11.phase3_shapeit2_mvncall_integrated_v5a.20130502.genotypes.vcf.gz
wget ALL.chr11.phase3_shapeit2_mvncall_integrated_v5a.20130502.genotypes.vcf.gz.tbi
#===================================#
# GWAS Practical #
# iBSC Genomic Medicine #
# Lavinia Paternoster #
# 08/11/2018 #
#===================================#
# Run the GWAS without PCs but using the cleaned genetic data
@explodecomputer
explodecomputer / rscript.r
Last active December 18, 2020 12:38
Submitting multiple R jobs to bluecrystal 3 and 4
# Get the list of arguments passed to R
args <- commandArgs(T)
# Get the first argument, make it numeric because by default it is read as a string
job_id <- as.numeric(args[1])
# Print the argument
message("job number ", job_id)
@explodecomputer
explodecomputer / combinations.r
Last active October 14, 2018 14:36
combinations
n <- 5
a <- combn(c(1:(2*n)), 2)
b <- combn(1:ncol(a), n)
l <- list()
m <- list()
j <- 1
for(i in 1:ncol(b))
{
x <- a[, b[,i]]
if(!any(duplicated(c(x))))
@explodecomputer
explodecomputer / adjrsq.r
Last active October 9, 2018 09:07
Overfitting and adjusted r square
# How does adjusted r-square do with overfitting?
rm(list=ls())
set.seed(101)
library(ggplot2)
library(tidyr)
y <- rnorm(1000)
x <- matrix(rnorm(1000 * 1000), 1000, 1000)
@explodecomputer
explodecomputer / fix.r
Created September 27, 2018 16:18
fix 3
dat_3a$rsq.exposure <- with(dat_3a, 2 * beta.exposure^2 * eaf.exposure * (1-eaf.exposure))
dat_3a$rsq.outcome <- with(dat_3a, 2 * beta.outcome^2 * eaf.outcome * (1-eaf.outcome))
dat_3a$steiger_dir <- dat_3a$rsq.exposure > dat_3a$rsq.outcome
dat_3b$rsq.exposure <- with(dat_3b, 2 * beta.exposure^2 * eaf.exposure * (1-eaf.exposure))
dat_3b$rsq.outcome <- with(dat_3b, 2 * beta.outcome^2 * eaf.outcome * (1-eaf.outcome))
dat_3b$steiger_dir <- dat_3b$rsq.exposure > dat_3b$rsq.outcome
@explodecomputer
explodecomputer / hwe_sim.r
Created July 18, 2018 15:21
HWE simulations
---
title: Calculating HWE
---
Choose a set of parameters. For each allele frequency and sample size, run 100 simulations
```{r}
library(tidyr)
library(ggplot2)
library(dplyr)
@explodecomputer
explodecomputer / ewas_power.r
Last active July 5, 2018 17:36
EWAS power simulations
library(devtools)
install_github("explodecomputer/simulateGP")
library(simulateGP)
library(ggplot2)
param <- rbind(
expand.grid(
ncase=100,
ncontrol=100,
prev=0.001,