Skip to content

Instantly share code, notes, and snippets.

@nievergeltlab
nievergeltlab / beta_logscale_function.r
Last active April 13, 2018 17:10
Implementation of formula converting beta from a linear regression onto the log odds scale EFFICIENT COMPUTATION WITH A LINEAR MIXED MODEL ON LARGE-SCALE DATA SETSWITH APPLICATIONS TO GENETIC STUDIES Author(s): Matti Pirinen, Peter Donnelly and Chri
R
new_beta_se <- function(x ,phi=0.153)
{
#Input should be a vector consisting of beta, p, maf. phi should be a value for the proportion of cases
B=x[1]
P=x[2]
theta=x[3]
B2=B/(phi*(1 - phi) + .5*(1-2*phi)*(1-2*theta)*B - (0.084 + 0.9*phi*(1 - 2*phi)*theta*(1-theta))/(phi*(1-phi))*B^2)
@nievergeltlab
nievergeltlab / tar_wildcards.sh
Created April 8, 2017 23:17
Extract files from tar with wildcards
tar xvzf dnhs_qc_v2_mar7_2017.tgz --wildcards '*-qc.fam' --wildcards '*.header'
@nievergeltlab
nievergeltlab / convert_dosage_to_gmmat_format.sh
Created April 10, 2017 16:00
Logistic Mixed Models with GMMAT
#Script to convert dosage data to GMMAT format. Requires also a list of usuable SNPs as input, but this list does not need to be filtered.
#Create a valid SNPlist
info=0.9
maf=0.01
zcat /home/maihofer/vets/qc/imputation/distribution/vets_eur_analysis_run2/daner_vets_eur_analysis_run2.gz | awk -v info=$info -v maf=$maf '{if (($8 > info) && ($6 > maf) && ($7 > maf) && ($6 < 1-maf) && ($7 < 1-maf) && ($11 != "NA")) print $2}' > european_valid_snps.snplist
echo "SNP" > snp.txt
cat snp.txt european_valid_snps.snplist | LC_ALL=C sort -k 1b,1 > european_valid_snps.sorted.snplist
@nievergeltlab
nievergeltlab / merge_discordance.r
Created April 19, 2017 20:55
Descriptive statistics for genotype merge discordances
#Merge data in PLINK, using merge mode 6 or 7
./plink --bfile YEHUDA --bmerge YEHUDA.bed YEHUDA.bim YEHUDA.fam --merge-mode 7 --out yehude-merge
R
setwd('F:/rutgers_2')
dat <- read.table('yehude-merge.diff', header=T,nr=800000,stringsAsFactors=F)
library(plyr)
#Determine general amount of disagreement for each SNP. Ones that have especially high disagreement may be badly genotyped
quantile(table(dat$SNP))
#Plot it
@nievergeltlab
nievergeltlab / make_locuszoom.qsub
Created May 1, 2017 18:54
Filter METAL outputs for LocusZoom - Splits results by chromosome
#!/bin/bash
#PBS -V
while getopts l:d: option
do
case "${option}"
in
l) snplocations=${OPTARG};;
d) lzresults_list=${OPTARG};;
esac
@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])
{
@nievergeltlab
nievergeltlab / plink_cov_pheno_merge.r
Created May 1, 2017 19:08
Merge PLINK phenotype and covariates in R
@nievergeltlab
nievergeltlab / plink_merge.sh
Last active June 30, 2021 16:09
Merge long list of PLINK files
@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 / 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