Skip to content

Instantly share code, notes, and snippets.

library(TwoSampleMR)
library(ieugwasr)
library(tidyverse)
# Get harmonised data for exposure and outcome
# e.g. BMI vs CHD
dat <- make_dat(exposures="ieu-a-2", outcomes="ieu-a-7")
# infer the AF for controls only for CHD
# first get case control sizes
@explodecomputer
explodecomputer / higbee_uploads.r
Last active March 19, 2021 15:29
higbee_uploads
# on bc3
# wget https://fluff.bris.ac.uk/fluff/u2/mk19726/Al7MuuePNzS7tMWliJGG6QznF/fev1_adjusted_only_for_sex_imputed.txt
# wget https://fluff.bris.ac.uk/fluff/u2/mk19726/0ar7Sekl4I3Xj4JyatEf_wznc/fvc_adjusted_only_for_sex_imputed.txt
# wget https://fluff.bris.ac.uk/fluff/u4/mk19726/pUNC547Sala4I5Y1V_G9Bwzna/obstructive_ratio_spirometry_imputed.txt
# FEV1:
# sample size 353315
@explodecomputer
explodecomputer / mdd_upload.r
Last active February 24, 2021 15:58
MDD OpenGWAS upload
library(GwasDataImport)
library(data.table)
library(ieugwasr)
library(dplyr)
# Download the Howard et al 2019 MDD GWAS from https://datashare.ed.ac.uk/handle/10283/3203
a <- data.table::fread("https://datashare.ed.ac.uk/bitstream/handle/10283/3203/PGC_UKB_depression_genome-wide.txt?sequence=3&isAllowed=y")
# It doesn't have chr/pos, so let's look them up on OpenGWAS (a bit slow!)
@explodecomputer
explodecomputer / dementia_mortality.rmd
Created February 18, 2021 12:57
Sex differences in dementia rates over time
---
title: Survival bias in sex association with dementia
author: Gibran Hemani
date: `r Sys.time()`
---
```{r}
library(dplyr)
library(tidyr)
library(ggplot2)
@explodecomputer
explodecomputer / ld.awk
Last active February 11, 2021 14:29
Calculate PCs in ALSPAC data
($1 == 1) && ($4 >= 48227413) && ($4 <= 52227412) {print $2}
($1 == 2) && ($4 >= 86000000) && ($4 <= 100500000) {print $2}
($1 == 2) && ($4 >= 183291755) && ($4 <= 190291755) {print $2}
($1 == 3) && ($4 >= 47524996) && ($4 <= 50024996) {print $2}
($1 == 3) && ($4 >= 83417310) && ($4 <= 86917310) {print $2}
($1 == 5) && ($4 >= 128972101) && ($4 <= 131972101) {print $2}
($1 == 5) && ($4 >= 44500000) && ($4 <= 50500000) {print $2}
($1 == 6) && ($4 >= 57000000) && ($4 <= 64000000) {print $2}
($1 == 6) && ($4 >= 25392021) && ($4 <= 33392022) {print $2}
($1 == 6) && ($4 >= 139958307) && ($4 <= 142458307) {print $2}
@explodecomputer
explodecomputer / tidyverse.md
Last active December 18, 2020 10:09
Tidyverse notes
@explodecomputer
explodecomputer / simple_selection_sim.r
Created October 28, 2020 13:47
simple_selection_sim
# sample size
n <- 10000
# simulate x and y variables - no association
x <- rnorm(n)
y <- rnorm(n)
# selected into the sample is influenced by x and y
sel <- rbinom(n, 1, plogis(x + y))
@explodecomputer
explodecomputer / subl
Created October 9, 2020 12:17
subl in wsl
#!/bin/bash
path=$(readlink -f $*);
cwd=$(pwd);
winpath=$(wslpath -w $path);
echo "Editing ${path}"
echo "Windows path is ${winpath}"
@explodecomputer
explodecomputer / go_kegg_pathways.r
Created September 28, 2020 17:25
go_kegg_pathways
library(dplyr)
library(org.Hs.eg.db)
# get KEGG pathways
xx <- as.list(org.Hs.egPATH2EG)
keggpathways <- lapply(names(xx), function(x) {
tibble(
symbol=select(org.Hs.eg.db, xx[[x]], c("SYMBOL"), "ENTREZID")$SYMBOL,
pathway=x
@explodecomputer
explodecomputer / ld.awk
Last active September 16, 2020 12:11 — forked from samwalrus/ld.awk
Bash script and AWK script for creating genetic principle components including removing long range LD regions
($1 == 1) && ($4 >= 48227413) && ($4 <= 52227412) {print $2}
($1 == 2) && ($4 >= 86000000) && ($4 <= 100500000) {print $2}
($1 == 2) && ($4 >= 183291755) && ($4 <= 190291755) {print $2}
($1 == 3) && ($4 >= 47524996) && ($4 <= 50024996) {print $2}
($1 == 3) && ($4 >= 83417310) && ($4 <= 86917310) {print $2}
($1 == 5) && ($4 >= 128972101) && ($4 <= 131972101) {print $2}
($1 == 5) && ($4 >= 44500000) && ($4 <= 50500000) {print $2}
($1 == 6) && ($4 >= 57000000) && ($4 <= 64000000) {print $2}
($1 == 6) && ($4 >= 25392021) && ($4 <= 33392022) {print $2}
($1 == 6) && ($4 >= 139958307) && ($4 <= 142458307) {print $2}