Skip to content

Instantly share code, notes, and snippets.

@nievergeltlab
nievergeltlab / loop_cores.sh
Last active July 25, 2017 15:58
Use all cores within a node via a loop E.g. Given N jobs, with K cores, run jobs 1-K, wait for all to finish, then run K+1 - N
ncommands=22
nodesize=6
nodeuse=$(($nodesize ))
totjobs=$(( ($ncommands + $nodeuse - 1 ) / $nodeuse ))
for i in $(seq 1 1 $totjobs)
do
jstart=$((($i-1)*$nodesize +1))
jstop=$(($i*$nodesize))
@nievergeltlab
nievergeltlab / correlate_stats.r
Created July 13, 2017 21:04
Correlate and plot test statistics (pvalues) on a -log10 scale. Useful for comparing two similar analyses.
/home/laramie/CLEANED_DATA/EXTERNAL_DATA/MIRECC6_Duke/duke_gwas_WH/12_15_15/DUKE_WH_model3_w_A2_danerFORMAT
grep -v NA MIRE_eur_analysis1_mf > MIRE_eur_analysis1_mf_nona
adam <- read.table('MIRE_eur_analysis1_mf_nona', nr=10000000,stringsAsFactors=F,header=T)
lara <- read.table('/home/laramie/CLEANED_DATA/EXTERNAL_DATA/MIRECC6_Duke/duke_gwas_WH/12_15_15/DUKE_WH_model3_w_A2_danerFORMAT', nr=8300000,stringsAsFactors=F,header=T)
lara$p <- 2*pnorm(abs(log(lara$OR)/lara$SE),lower.tail=F)
rescor <- merge(adam,lara,by="SNP")
@nievergeltlab
nievergeltlab / familycounter.Rscript
Created July 13, 2017 20:58
Print tables of phenotype information from list of .fam files
args <- commandArgs(trailingOnly = TRUE)
family_files <- args[1]
dat <- read.table(family_files)
for (i in dat$V1)
{
@nievergeltlab
nievergeltlab / roc_cox.r
Last active June 29, 2021 21:14
How competing Cox models of risk of relapse can be compared using ROC analysis. This analysis uses an implementation of the permutation methods suggested for comparing competing models
###################################
### Load R libraries
#Contains survival analysis function
library(survival)
#Functions to build ROC curves from Cox models
library(risksetROC)
###################################
@nievergeltlab
nievergeltlab / heritability.r
Last active November 11, 2025 07:08
Convert heritability from observed scale to liability scale
#K=pop prevalence
#P=proportion of cases in study
#hsq=Heritability estimate (on observed scale)
#bigT = liability threshold
#tau = density of gaussian
K=0.0659
P=0.0659
h2=0.0365
zv <- dnorm(qnorm(K))
@nievergeltlab
nievergeltlab / join.sh
Last active June 29, 2021 21:35
Join two files using the join command. Adjust for localization issues that cause improper sorting.
LC_ALL=C sort -k1b,1 file1.txt > file1.txt.sorted
LC_ALL=C sort -k1b,1 file2.txt > file2.txt.sorted
LC_ALL=C join file1.txt.sorted file2.txt.sorted > joined.txt
@nievergeltlab
nievergeltlab / r_padding.r
Created June 2, 2017 19:19
R Margin Padding With a big font, R will cut off the end of the Y axis label text. This puts padding on the margin to give space for the big text.
pdf('h2_mf_perstudy.pdf',7,7)
par(mar=c(5, 4, 4, 2) + 0.5)
plot(dat$case,dat$SE,cex.axis=1.45,cex.lab=1.5,xlab="N Cases", ylab="Standard Error of SNP Based Heritability",main="",cex=1.5,pch=19)
@nievergeltlab
nievergeltlab / plink_merge.sh
Last active June 30, 2021 16:09
Merge long list of PLINK files
@nievergeltlab
nievergeltlab / plink_cov_pheno_merge.r
Created May 1, 2017 19:08
Merge PLINK phenotype and covariates in R
@nievergeltlab
nievergeltlab / quanto_power.r
Created May 1, 2017 19:03
Filter QUANTO outputs into power plots Plot the detectable OR (at a set power and alpha) for a given sample size and MAF
setwd('C:/Users/adam/Desktop/roycepower')
library(plyr)
dat0 <- read.csv('me_power.csv', header=T)
dat <- dat0
#Fill in the blanks
for (i in 1:dim(dat)[1])
{