Skip to content

Instantly share code, notes, and snippets.

@explodecomputer
explodecomputer / fourthmeeting.R
Created October 20, 2015 12:40
fourth meeting
manifest <- read.table("manifest.file")
# make sure IDs in manifest are matched to IDs in cpg matrix
tbetas_fom_subset <- t(tbetas[cpgs,])
tbetas_fom_subset[, 1] <- residuals(lm(tbetas_fom_subset[, 1] ~ manifest[,1:5]))
tbetas_fom_subset[, 2] <- residuals(lm(tbetas_fom_subset[, 2] ~ manifest[,1:5]))
tbetas_fom_subset[, 3] <- residuals(lm(tbetas_fom_subset[, 3] ~ manifest[,1:5]))
@explodecomputer
explodecomputer / cellcounts.R
Last active October 23, 2015 08:50
cell counts using betas
library(ggplot2)
library(devtools)
library(reshape2)
#install_github("brentp/celltypes450")
library(celltypes450)
library(meffil)
options(mc.cores=16)
# Using GSE55491
# Estimate cell counts using meffil
@explodecomputer
explodecomputer / profiles.R
Created October 23, 2015 15:06
profile scores
# Suppose you have some files that look like this:
# bmi_chr01.profile
# bmi_chr02.profile
# bmi_chr03.profile
# etc
# Read in each profile score
l <- list()
j <- 1
for(i in 1:22)
@explodecomputer
explodecomputer / filter_1kg.sh
Created October 24, 2015 18:32
filtering 1kg data to hm3 and recoding snp names
#!/bin/bash
module add apps/plink-1.90b3v
cd /panfs/panasas01/shared/alspac/deprecated/gib/data_for_suzi
cp /panfs/panasas01/shared/alspac/deprecated/alspac_combined_1kg_20140424/combined/alspac_1kg_p1v3_maf0.01_info0.8.bed als.bed
cp /panfs/panasas01/shared/alspac/deprecated/alspac_combined_1kg_20140424/combined/alspac_1kg_p1v3_maf0.01_info0.8.bim als.bim
cp /panfs/panasas01/shared/alspac/deprecated/alspac_combined_1kg_20140424/combined/alspac_1kg_p1v3_maf0.01_info0.8.fam als.fam
($1 == 1) && ($4 >= 48287981) && ($4 <= 52287979) {print $2}
($1 == 2) && ($4 >= 86088343) && ($4 <= 101041482) {print $2}
($1 == 2) && ($4 >= 134666269) && ($4 <= 138166268) {print $2}
($1 == 2) && ($4 >= 183174495) && ($4 <= 190174494) {print $2}
($1 == 3) && ($4 >= 47524997) && ($4 <= 50024996) {print $2}
($1 == 3) && ($4 >= 83417311) && ($4 <= 86917310) {print $2}
($1 == 3) && ($4 >= 88917311) && ($4 <= 96017310) {print $2}
($1 == 5) && ($4 >= 44464244) && ($4 <= 50464243) {print $2}
($1 == 5) && ($4 >= 97972101) && ($4 <= 100472101) {print $2}
($1 == 5) && ($4 >= 128972102) && ($4 <= 131972101) {print $2}
@explodecomputer
explodecomputer / ewas.R
Last active November 3, 2015 15:07
k fold cv ewas example
arguments <- commandArgs(T)
k <- as.numeric(arguments[1])
threshold <- as.numeric(arguments[2])
nfold <- as.numeric(arguments[3])
aries.release.dir <- "/panfs/panasas01/shared/alspac/deprecated/aries/releasev2_apr2014/"
time.point <- "cord" ## "FOM","antenatal","cord","F7","15up"
@explodecomputer
explodecomputer / smoking_age.Rmd
Last active May 4, 2016 09:54
smoking and age simulation
---
title: A frailty effect is sufficient to explain the apparent association of a smoking heaviness variant on smoking initiation in a cross sectional population
date: "`r Sys.Date()`"
output: pdf_document
bibliography: smoking_age.bib
---
```{r, echo=FALSE}
opts_chunk$set(warning=FALSE, message=FALSE, echo=FALSE)
```
@explodecomputer
explodecomputer / prediction.R
Created November 12, 2015 23:07
Prediction using absolute values vs positive and negative values
m <- 100
n <- 100
eff <- rnorm(m)
x <- matrix(rbinom(m*n,2,0.5), n, m)
yhat <- x %*% eff
@explodecomputer
explodecomputer / bmicor.R
Created November 16, 2015 22:35
bmi in alspac
library(reshape2)
library(ggplot2)
library(alspac)
b <- findVars("bmi")
b <- subset(b, cat2=="Clinic" & cat3 == "Child")
bmi <- extractVars(b)
c <- cor(bmi[,-c(1:3)], use="pair")