Skip to content

Instantly share code, notes, and snippets.

@philippbayer
Last active April 2, 2019 08:53
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save philippbayer/b0f0420a4a749aa35deefd017a3ebe11 to your computer and use it in GitHub Desktop.
Save philippbayer/b0f0420a4a749aa35deefd017a3ebe11 to your computer and use it in GitHub Desktop.
Two scripts to plot BLINK results using rMVP
# assuming that all results tables of BLINK are in the current folder, and assuming that all results tables were gzipped
# usage: python makeSummaryTable.py > Summary_Table.tsv
# this script will make one large summary table in the format rMVP requires, SNP, chrom, position, and then x columns for x phenotypes - each cell one p-value
# use grep -v to kick out regions of the genome you don't want to plot (unplaced contigs etc.)
import glob
import gzip
from collections import OrderedDict
all_phenos = ['SNP','chr','pos']
snp_dict = OrderedDict()
for x in glob.glob('*txt.gz'):
pheno = x.replace('_GWAS_result.txt.gz','')
all_phenos.append(pheno)
with gzip.open(x, 'rb') as fh:
for line in fh:
ll = line.split()
if ll[0] == 'taxa': continue
#['1_1', '1', '1', '7.228916e-02', '1.882767e-01']
snp = ll[0]
if snp in snp_dict:
snp_dict[snp].append(ll[-1])
else:
snp_dict[snp] = [ll[-1]]
print('\t'.join(all_phenos))
for s in snp_dict:
snp_name = s
ss = s.split('_')
snp_chrom = ss[0]
snp_pos = ss[1]
thisll = [snp_chrom, snp_pos, str(int(snp_pos)+2)]
thisll = '\t'.join(thisll) + "\t" + snp_name+'_'+ '_'.join(snp_dict[s])
print(thisll)
library(readr)
library(rMVP)
# this script can easily run for a few hours
df <- read_tsv('Summary_Table.tsv')
# make x Manhattan plots for x phenotypes - for journal submission it's probably better to use file='tiff'
MVP.Report(df, plot.type="m", LOG10=TRUE, ylim=NULL, threshold=c(1e-6,1e-4),threshold.lty=c(1,2),
col=c("dodgerblue4","deepskyblue"), threshold.lwd=c(1,1), threshold.col=c("black","grey"), amplify=TRUE,
chr.den.col=c("darkgreen", "yellow", "red"),bin.size=1e6,signal.col=c("red","green"),
signal.cex=c(1,1),signal.pch=c(19,19),file="jpg",memo="",dpi=300)
# make x QQ-plots for x phenotypes
MVP.Report(df,plot.type="q",conf.int.col=NULL,box=TRUE,file="jpg",memo="",dpi=300)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment