Skip to content

Instantly share code, notes, and snippets.

@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}
@explodecomputer
explodecomputer / power1.pdf
Last active September 4, 2020 11:17
power_interactions
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
# simulation
n <- 10000
a <- rbinom(n, 2, 0.5)
b <- rbinom(n, 2, 0.49)
# perform fisher's exact test to obtain odds ratio for two allele frequencies being different
cont <- matrix(
c(sum(a==0) * 2 + sum(a==1), sum(a==2) * 2 + sum(a==1), sum(b==0) * 2 + sum(b==1), sum(b==2) * 2 + sum(b==1)), 2, 2)
fisher.test(cont)
# Number of individuals in the population
npop <- 100000
# Distribution of variable in the population
x <- rnorm(npop)
# Individuals selected into sample with high x value
s <- rbinom(npop, 1, plogis(x * 0.4))
# Population mean of x
library(dplyr)
library(data.table)
library(TwoSampleMR)
bmi_id <- "ukb-b-19953"
chd_id <- "ukb-b-3983"
datadir <- "/mnt/storage/private/mrcieu/research/mr-eve/UKBB_replication/replication/results"