def plot_phewas_manhattan(): df = pd.read_csv(sys.argv[1], dtype={'phecode':str}) phewas_category = pd.read_table(sys.argv[2], dtype=str) phewas_category = phewas_category.rename(columns={'phewas_code':'phecode'}).loc[:,["phecode","category"]].drop_duplicates() merged = df.merge(phewas_category, how='left', on='phecode') merged = merged.loc[merged.p>0,:] manhattan(merged.p, merged.phecode.astype(float), merged.category, '', xlabel="category") plt.title("Case vs Control: Chi-Squared") plt.savefig(sys.argv[3]) plt.clf()
chrs = [str(i) for i in range(1, 23)] chrs_names = np.array([str(i) for i in range(1, 23)]) chrs_names[1::2] = '' colors = ['#1b9e77', "#d95f02", '#7570b3', '#e7298a'] # Converting from HEX into RGB colors = [hex2color(colors[i]) for i in range(len(colors))] # Load data data = pd.read_fwf(datafile) manhattan(data['P'], data["BP"], data["CHR"].apply(str), '', \ type='single', \ chrs_plot=[str(i) for i in range(1,23)], \ chrs_names=chrs_names, \ cut = 0, \ title='Eye color', \ xlabel='chromosome', \ ylabel='-log10(p-value)', \ lines= [], \ colors = colors, \ scaling = '-log10') plt.savefig('%s_manhattan.png' % prefix, dpi=300) ############# QQ plot ############# from assocplots.qqplot import * mpl.rcParams['figure.dpi'] = 100 mpl.rcParams['savefig.dpi'] = 100 mpl.rcParams['figure.figsize'] = 5.375, 5.375 qqplot([data["P"]], ['eyecolor'],
mpl.rcParams['figure.figsize'] = [12.375, 6.375] chrs = [str(i) for i in range(1, 23)] chrs_names = np.array([str(i) for i in range(1, 23)]) chrs_names[18::2] = '' cmap = plt.get_cmap('Greys') colors = [cmap(i) for i in [1.0, 0.6, 1.0, 0.6]] plt.clf() manhattan(datf['f2'], datf['f21'], datf['f20'], 'OCD-ADHD Female Meta', p2=datm['f2'], pos2=datm['f21'], chr2=datm['f20'], label2='OCD-ADHD Male Meta', type='inverted', chrs_plot=[str(i) for i in range(1, 23)], chrs_names=chrs_names, cut=0, title='', xlabel='chromosome', ylabel='-log10(p-value)', lines=[7.3], top1=10, top2=10, colors=colors) plt.savefig('OCD_ADHD_mal_fem_Manhattan.png', dpi=300)
import matplotlib.pyplot as plt # makes sure can save pictures that a display is present! plt.switch_backend('agg') import pylab import fastlmm.util.util as flutil # better manhattan plot than MS Genomics one (or at least more robust) # can be tweaked at will! from assocplots.manhattan import * from matplotlib.pyplot import figure figure(num=None, figsize=(10, 7), dpi=80,) manhattan(results_df["PValue"], results_df["ChrPos"], results_df["Chr"], OUTPUT_NAME, lines=[5], colors=['r', 'b'], cut=1) plt.savefig('Figures/' + OUTPUT_NAME + '_Manhattan_Plot.png') plt.close() # # QQ Plot # In[11]: from fastlmm.util.stats import plotp plotp.qqplot(results_df["PValue"].values, xlim=[0,5], ylim=[0,5]) pylab.savefig('Figures/' + OUTPUT_NAME + 'QQ_Plot.png') pylab.close()
mpl.rcParams['figure.dpi']=2000 mpl.rcParams['savefig.dpi']=2000 mpl.rcParams['figure.figsize']=17, 7 chrs = [str(i) for i in range(1,23)] chrs_names = np.array([str(i) for i in range(1,23)]) chrs_names[1::2] = '' cmap = plt.get_cmap('viridis') colors = [cmap(i) for i in [0.0,0.33,0.67,0.90]] manhattan( Baseline_PEER10_RegOut['f3'], Baseline_PEER10_RegOut['f1'], Baseline_PEER10_RegOut['f0'].astype(str), 'Baseline_RegOut_PEER10', p2=Baseline_Log2_RegOut['f3'], pos2=Baseline_Log2_RegOut['f1'], chr2=Baseline_Log2_RegOut['f0'].astype(str), label2='Baseline_RegOut_Log2', type='inverted', chrs_plot=[str(i) for i in range(1,23)], chrs_names=chrs_names, cut = 0, title='Baseline eQTLs of TRANSCRiBE 121 patients', xlabel='chromosome', ylabel='-log10(p-value)', lines= [], top1 = 50, top2 = 50, colors = colors) plt.savefig('ChicagoPlot_BaselineRegOut+-PEER10.png', dpi=2000) Li00=[Baseline_Log2_NoReg,Baseline_Log2_RegOut,Baseline_PEER10_NoReg,Baseline_PEER10_RegOut,Ischemia_Log2_NoReg,Ischemia_Log2_RegOut,Ischemia_PEER10_NoReg,Ischemia_PEER10_RegOut]; for x in Li00: mpl.rcParams['figure.dpi']=300