Skip to content

Instantly share code, notes, and snippets.

@genometoolbox
Created March 12, 2014 13:39
Estimate percent familial risk explained by a list of loci from genome-wide association studies. Input file is a file with columns for annotation, risk allele frequency, and odds ratio for risk allele.
# Import command line arguments
args <- commandArgs(trailingOnly=T)
snp_filename <- args[1]
fd_fam_risk <- as.numeric(args[2])
# Import SNP data
snps <- read.table(snp_filename, as.is=T, header=F)
names(snps) <- c("id", "p", "r")
attach(snps)
# Observed familial risk to first degree relatives
print("Familial Risk Estimate (OR):")
fd_fam_risk
# Calculate familial risk due to each locus
snps$lambda <- (p*r**2+(1-p))/((p*r+(1-p))**2)
snps
# Contribution of known SNPs to familial risk
print("Familial Risk Explained (%):")
sum(log(snps$lambda))/log(fd_fam_risk)*100
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment