Beispiel #1
0
def gen_manhattan(path_list, threshold=None, titles=None):
    """Generate separated manhattan plots and one combined QQ plot.
    Input: - path_list is a Python list containing paths to the plink .glm.logistic or .glm.linear files.
           - threshold: draw a threshold line, 0.0 < threshold < 1.0
           - titles: the title are only recognized for amino acid with filenames in the 'xxx.glm.logistic.ADD' format"""
    ################# COLORS
    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 DAT
    # TODO: manage better paths and amino acid name
    aa_names = [file.split('.')[-4] for file in path_list]
    if titles != None:
        aa_names = titles
    list_p_series = []
    for i, file in enumerate(path_list):
        df = pd.read_csv(file, sep='\t')
        list_p_series.append(df.P)
        ################# PLOT
        manhattan.manhattan(
            df['P'],
            df['POS'],
            df['#CHROM'].astype(str),
            '',
            plot_type='single',
            chrs_plot=[str(i) for i in range(1, 23)],
            chrs_names=chrs_names,
            cut=0,
            title=aa_names[i],
            xlabel='chromosome',
            ylabel='-log10(p-value)',
            lines=[],
            #lines_colors=['r'],
            colors=colors)
        if threshold != None:
            minlogthreshold = -np.log10(threshold)
            plt.plot([0, 5000000000], [minlogthreshold, minlogthreshold])
        plt.show()

    ## QQ PLOTS
    N = len(aa_names)
    fill_dens = [0.2] * N
    # ['#1b9e77', "#d95f02", '#7570b3']
    colors = [
        '#c0392b', '#884ea0', '#2471a3', '#17a589', '#229954', '#d4ac0d',
        '#ca6f1e', '#839192', '#17202a'
    ]
    qqplot(list_p_series,
           aa_names,
           color=colors[0:N],
           fill_dens=fill_dens,
           error_type='theoretical',
           distribution='beta',
           title='QQ plots')
    plt.gca().legend(bbox_to_anchor=(1.1, 0.1 * N), loc=2, borderaxespad=0.)
    plt.grid(linestyle='--')
Beispiel #2
0
import matplotlib.pyplot as plt
import numpy as np

from assocplots.qqplot import *

# data = np.genfromtxt('C:\\Users\\Ekaterina\\Desktop\\file_transfer\\fem_assoc_dos_ocd_occc_eur_sr-qc.hg19.dosage.assoc.dosage.QCed')
# data = data[:,-1]
# data2 = np.genfromtxt('C:\\Users\\Ekaterina\\Desktop\\file_transfer\\mal_assoc_dos_ocd_occc_eur_sr-qc.hg19.dosage.assoc.dosage.QCed')
# data2 = data2[:,-1]


q_data, q_th, q_err = qqplot([data, data2], labels=['female', 'male'], error_type='experimental', n_quantiles=1000, alpha=0.95, color=['r', 'b'])


data_male = np.genfromtxt('sample_data\GIANT_Randall2013PlosGenet_stage1_publicrelease_HapMapCeuFreq_BMI_MEN_N.txt', dtype=None, names=True)
data_female = np.genfromtxt('sample_data\GIANT_Randall2013PlosGenet_stage1_publicrelease_HapMapCeuFreq_BMI_WOMEN_N.txt', dtype=None, names=True)


q_data, q_th, q_err = qqplot([data_female['P2gc'], data_male['P2gc']], labels=['female', 'male'], error_type='experimental', n_quantiles=1000, alpha=0.95, color=['r', 'b'])





data = mock_data_generation(1, 100000)

data[0]['chr']=1

manhattan(data[0]['pval'], data[0]['pos'], data[0]['chr'], 'abc',
          p2=None, pos2=None, chr2=None, label2=None,
          type='single',
Beispiel #3
0
import matplotlib.pyplot as plt
import numpy as np

from assocplots.qqplot import *

# data = np.genfromtxt('C:\\Users\\Ekaterina\\Desktop\\file_transfer\\fem_assoc_dos_ocd_occc_eur_sr-qc.hg19.dosage.assoc.dosage.QCed')
# data = data[:,-1]
# data2 = np.genfromtxt('C:\\Users\\Ekaterina\\Desktop\\file_transfer\\mal_assoc_dos_ocd_occc_eur_sr-qc.hg19.dosage.assoc.dosage.QCed')
# data2 = data2[:,-1]

q_data, q_th, q_err = qqplot([data, data2],
                             labels=['female', 'male'],
                             error_type='experimental',
                             n_quantiles=1000,
                             alpha=0.95,
                             color=['r', 'b'])

data_male = np.genfromtxt(
    'sample_data\GIANT_Randall2013PlosGenet_stage1_publicrelease_HapMapCeuFreq_BMI_MEN_N.txt',
    dtype=None,
    names=True)
data_female = np.genfromtxt(
    'sample_data\GIANT_Randall2013PlosGenet_stage1_publicrelease_HapMapCeuFreq_BMI_WOMEN_N.txt',
    dtype=None,
    names=True)

q_data, q_th, q_err = qqplot([data_female['P2gc'], data_male['P2gc']],
                             labels=['female', 'male'],
                             error_type='experimental',
                             n_quantiles=1000,
                             alpha=0.95,
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'],
       color=['b'],
       fill_dens=[0.2],
       error_type='theoretical',
       distribution='beta',
       title='')

plt.savefig('%s_qq.png' % prefix, dpi=300)
Beispiel #5
0
from assocplots.manhattan import *

datf = np.genfromtxt('OCD_ADHD_female.META.CHR.POS', dtype=None, skip_header=1)
datm = np.genfromtxt('OCD_ADHD_male.META.CHR.POS', dtype=None, skip_header=1)

##### QQ plot
import matplotlib as mpl
mpl.rcParams['figure.dpi'] = 150
mpl.rcParams['savefig.dpi'] = 150
mpl.rcParams['figure.figsize'] = 6.375, 6.375

plt.clf()
qqplot([datf['f2'], datm['f2']],
       ['Female $\lambda=1.104$', 'Male $\lambda=1.150$'],
       color=['r', 'b'],
       fill_dens=[0.2, 0.2],
       error_type='theoretical',
       distribution='beta',
       title='')
plt.ylim([0, 8])
#plt.show()
plt.savefig('OCD_ADHD_mal_fem_QQ.png', dpi=300)

get_lambda(datf['f2'], definition='median')
#1.1038305474906456
get_lambda(datm['f2'], definition='median')
#1.1502208100009044

##### Manhattan Plot

import matplotlib as mpl
Beispiel #6
0
[1.2755015584185816,
 1.3253828247438937,
 1.5075929863128841,
 1.4956062686095888,
 1.2630205643665071,
 1.3120597064714479,
 1.4892568965957846,
 1.4884128058714166]

mpl.rcParams['figure.dpi']=300
mpl.rcParams['savefig.dpi']=300
mpl.rcParams['figure.figsize']=5.375, 5.375
qqplot([Baseline_Log2_NoReg['f3'], Baseline_Log2_RegOut['f3']], 
       ['-RegOut(1.27)', '+RegOut(1.32)'], 
       color=['b','r'], 
       fill_dens=[0.2,0.2], 
       error_type='experimental', 
       distribution='beta',
       title='QQ Plot of Baseline_Log2 eQTLs')
plt.savefig('QQ2_Baseline_Log2.png', dpi=300)

mpl.rcParams['figure.dpi']=300
mpl.rcParams['savefig.dpi']=300
mpl.rcParams['figure.figsize']=5.375, 5.375
qqplot([Baseline_PEER10_NoReg['f3'], Baseline_PEER10_RegOut['f3']], 
       ['-RegOut(1.51)', '+RegOut(1.49)'], 
       color=['b','r'], 
       fill_dens=[0.2,0.2], 
       error_type='experimental', 
       distribution='beta',
       title='QQ Plot of Baseline_PEER10 eQTLs')