def plot_full(ax, vals, ylabel, title): ### detected / detected conf / detected high-conf cax = ax.bar([2, 5, 8], vals[1], color=['b', 'g', 'm'], alpha=0.5, width=0.8, linewidth=0) axs.label_bars(ax, cax, vals[1], rotation=90) ### annotated fraction of the counts above cax = ax.bar([3, 6, 9], vals[2], color=['b', 'g', 'm'], alpha=0.9, width=0.8, linewidth=0) axs.label_bars(ax, cax, vals[2], rotation=90) ### high-conf novel events cax = ax.bar([11], vals[3], color=['c'], alpha=0.9, width=0.8, linewidth=0) axs.label_bars(ax, cax, vals[3], rotation=90) ### annotated cax = ax.bar([0], vals[0], color='r', alpha=0.5, width=0.8, linewidth=0) axs.label_bars(ax, cax, vals[0], rotation=90) ax.set_ylabel(ylabel) ax.set_xlabel('') ax.set_xticks(sp.array([0, 2, 3, 5, 6, 8, 9, 11], dtype='float') + 0.4) ax.set_xticklabels([ 'annotated', 'detected', 'detected\n(anno)', 'detected\n(conf)', 'detected\n(conf+anno)', 'detected\n(h_conf)', 'detected\n(h_conf+anno)', 'novel\n(h_conf)' ], rotation=90) ax.set_xlim([-0.2, ax.get_xlim()[1]]) ax.set_title(title) axs.set_ticks_outer(ax) axs.clean_axis(ax)
def main(): figs = dict() gss = dict() gss['stats'] = gridspec.GridSpec(3, 2) #, wspace=0.0, hspace=0.0) gss['stats_log'] = gridspec.GridSpec(3, 2) #, wspace=0.0, hspace=0.0) for e, event_type in enumerate(event_types): print >> sys.stderr, 'Handling %s' % event_type ### load annotation index is_anno_gtex = cPickle.load( open( os.path.join( paths.basedir_as_gtex, 'merge_graphs_%s_C%i.anno_only.pickle' % (event_type, CONF)), 'r')) is_anno_icgc = cPickle.load( open( os.path.join( paths.basedir_as, 'merge_graphs_%s_C%i.anno_only.pickle' % (event_type, CONF)), 'r')) ### load confident events IN = h5py.File( os.path.join( paths.basedir_as, 'merge_graphs_%s_C%i.counts.hdf5' % (event_type, CONF)), 'r') idx_conf_tcga = sp.zeros((is_anno_icgc.shape[0], ), dtype='bool') idx_conf_tcga[IN['conf_idx'][:]] = 1 IN.close() ### for mutex events load cluster idx if event_type == 'mutex_exons': mutex_clusters = cPickle.load( open( os.path.join( paths.basedir_as, 'merge_graphs_%s_C%i.cluster_idx.pickle' % (event_type, CONF)), 'r')) ### load psi filtered events idx_psi_icgc = cPickle.load( open( os.path.join( paths.basedir_as, 'merge_graphs_%s_C%i.counts.psi_filt_per_ct.pickle' % (event_type, CONF)), 'r'))[1] ### get all cancer types ctypes = sp.unique([x[1] for x in idx_psi_icgc.keys()]) colors = sp.array(tc.get_color_scheme('study', labels=ctypes)) for dp in [0.0, 0.1, 0.3, 0.5]: for mr in [5, 20, 50]: ### get counts if event_type == 'mutex_exons': counts_anno = [] counts_new = [] for ct in ctypes: if not (mr, ct, dp) in idx_psi_icgc: counts_anno.append(0) counts_new.append(0) continue tmp_idx = sp.zeros((is_anno_icgc.shape[0], ), dtype='bool') tmp_idx[idx_psi_icgc[(mr, ct, dp)]] = 1 counts_anno.append( sp.unique( mutex_clusters[idx_conf_tcga & is_anno_icgc & tmp_idx]).shape[0]) counts_new.append( sp.unique( mutex_clusters[idx_conf_tcga & ~is_anno_icgc & tmp_idx]).shape[0]) counts_anno = sp.array(counts_anno) counts_new = sp.array(counts_new) else: counts_anno = sp.array([ sp.sum((idx_conf_tcga & is_anno_icgc)[idx_psi_icgc[(mr, ct, dp)]]) if (mr, ct, dp) in idx_psi_icgc else 0 for ct in ctypes ]) counts_new = sp.array([ sp.sum(idx_conf_tcga[idx_psi_icgc[(mr, ct, dp)]]) - sp.sum((idx_conf_tcga & is_anno_icgc)[idx_psi_icgc[(mr, ct, dp)]]) if (mr, ct, dp) in idx_psi_icgc else 0 for ct in ctypes ]) ### plot stats for events by cancer type if e == 0: figs['stats_mr%i_dp%.1f' % (mr, dp)] = plt.figure(figsize=(15, 9)) ax = figs['stats_mr%i_dp%.1f' % (mr, dp)].add_subplot( gss['stats'][e / 2, e % 2]) ax.bar(sp.arange(ctypes.shape[0]) + 0.2, counts_anno, 0.6, color=colors, linewidth=0.5) ax.bar(sp.arange(ctypes.shape[0]) + 0.2, counts_new, 0.6, bottom=counts_anno, color=colors, linewidth=0.5, alpha=0.5) axs.set_ticks_outer(ax) axs.clean_axis(ax) ax.set_xticks(sp.arange(ctypes.shape[0]) + 0.15) ax.set_xlim([-1, ctypes.shape[0]]) ax.set_xticklabels(ctypes, rotation=90, fontsize=10) ax.set_title(event_dict[event_type]) ax.yaxis.grid(True) continue ### skip log for now ### plot stats for events by histotype (log) if e == 0: figs['stats_log_mr%i_dp%.1f' % (mr, dp)] = plt.figure(figsize=(15, 9)) ax = figs['stats_log_mr%i_dp%.1f' % (mr, dp)].add_subplot( gss['stats'][e / 2, e % 2]) ax.bar(sp.arange(ctypes.shape[0]) + 0.1, sp.log10(counts_anno + 1), 0.8, color=colors, linewidth=0.5) ax.bar(sp.arange(ctypes.shape[0]) + 0.1, sp.log10(counts_new + 1), 0.8, bottom=sp.log10(counts_anno + 1), color=colors, linewidth=0.5, alpha=0.3) axs.set_ticks_outer(ax) axs.clean_axis(ax) ax.set_xticks(range(ctypes.shape[0])) ax.set_xlim([-1, ctypes.shape[0]]) ax.set_xticklabels(ctypes, rotation=90, fontsize=10) ax.set_title(event_dict[event_type]) ax.yaxis.grid(True) for p in figs: print 'plotting %s' % p figs[p].tight_layout() figs[p].savefig(os.path.join( PLOTDIR, 'event_overview_per_ct_C%i_%s.pdf' % (CONF, p)), format='pdf', bbox_inches='tight') figs[p].savefig(os.path.join( PLOTDIR, 'event_overview_per_ct_C%i_%s.png' % (CONF, p)), format='png', bbox_inches='tight') plt.close(figs[p])
def main(): figs = dict() figs['stats'] = plt.figure(figsize=(15, 8)) figs['stats_rel'] = plt.figure(figsize=(15, 8)) figs['stats_rel_sampsize'] = plt.figure(figsize=(15, 8)) gss = dict() gss['stats'] = gridspec.GridSpec(2, 3) #, wspace=0.0, hspace=0.0) gss['stats_rel'] = gridspec.GridSpec(2, 3) #, wspace=0.0, hspace=0.0) gss['stats_rel_sampsize'] = gridspec.GridSpec( 2, 3) #, wspace=0.0, hspace=0.0) for e, event_type in enumerate(event_types): print('Handling %s' % event_type, file=sys.stderr) ### is exonization is_exonization = pickle.load( open( os.path.join( BASEDIR_ICGC, 'merge_graphs_%s_C%i.exonize_candidates_step2.pickle' % (event_type, CONF)), 'r')) ### load confident events IN = h5py.File( os.path.join( BASEDIR_ICGC, 'merge_graphs_%s_C%i.counts.hdf5' % (event_type, CONF)), 'r') idx_conf_icgc = IN['conf_idx'][:] [tumor_dict, histo_dict] = tm.translate([('analysis_id', 'is_tumour'), ('analysis_id', 'histotype')]) htypes_all = sp.array([ histo_dict[x.split('.')[0]] if x.split('.')[0] in histo_dict else 'NA' for x in IN['strains'][:] ]) htypes_all_u, htypes_all_cnt = sp.unique(htypes_all, return_counts=True) htypes_all_med = sp.median(htypes_all_cnt).astype('float') htypes_sf = htypes_all_med / htypes_all_cnt IN.close() htypes_sf = dict([(htypes_all_u[_], htypes_sf[_]) for _ in range(htypes_all_u.shape[0])]) ### load psi filtered events idx_psi_icgc = pickle.load( open( os.path.join( BASEDIR_ICGC, 'merge_graphs_%s_C%i.counts.hdf5.psi_filt_per_ht_normalized.pickle' % (event_type, CONF)), 'r'))[1] ### get all histotypes htypes = sp.unique([x[0] for x in list(idx_psi_icgc.keys())]) #colors = dict(zip(htypes, ic.get_color_scheme('tumor_subtype', labels=htypes))) colors = ic.get_color_scheme('tumor_subtype', labels=htypes) ### get counts counts = [] dp = 0.3 counts_anno = sp.array([ sp.sum(is_exonization[idx_psi_icgc[(ht, dp)]]) if (ht, dp) in idx_psi_icgc else 0 for ht in htypes ]) counts_all = sp.array([ idx_psi_icgc[(ht, dp)].shape[0] if (ht, dp) in idx_psi_icgc else 0 for ht in htypes ]) counts_sf = sp.array([htypes_sf[ht] for ht in htypes], dtype='float') ### plot stats for events by histotype ax = figs['stats'].add_subplot(gss['stats'][e / 3, e % 3]) ax.bar(sp.arange(htypes.shape[0]) + 0.2, counts_anno, 0.6, color=colors, linewidth=0.5) #li, = ax.plot(sp.arange(data1_icgc.shape[0]), data1_icgc, '-r', label='ICGC') axs.set_ticks_outer(ax) axs.clean_axis(ax) #if e == len(event_types) - 1: # ax.legend(handles=[lg, lga, li, lia], loc='upper right', frameon=False, fontsize=10) ax.set_xticks(sp.arange(htypes.shape[0]) + 0.5) ax.set_xlim([-0.2, htypes.shape[0]]) if e < len(event_types) - 3: ax.set_xticklabels([]) else: ax.set_xticklabels(htypes, rotation=90, fontsize=10) ax.set_title(event_dict[event_type]) ax.yaxis.grid(True) ### plot stats for events by histotype - relative to events detected ax = figs['stats_rel'].add_subplot(gss['stats_rel'][e / 3, e % 3]) ax.bar(sp.arange(htypes.shape[0]) + 0.2, counts_anno / counts_all.astype('float'), 0.6, color=colors, linewidth=0.5) axs.set_ticks_outer(ax) axs.clean_axis(ax) ax.set_xticks(sp.arange(htypes.shape[0]) + 0.5) ax.set_xlim([-0.2, htypes.shape[0]]) if e < len(event_types) - 3: ax.set_xticklabels([]) else: ax.set_xticklabels(htypes, rotation=90, fontsize=10) ax.set_title(event_dict[event_type]) ax.yaxis.grid(True) ### plot stats for events by histotype - relative to sample size ax = figs['stats_rel_sampsize'].add_subplot( gss['stats_rel_sampsize'][e / 3, e % 3]) ax.bar(sp.arange(htypes.shape[0]) + 0.2, counts_anno * counts_sf, 0.6, color=colors, linewidth=0.5) axs.set_ticks_outer(ax) axs.clean_axis(ax) ax.set_xticks(sp.arange(htypes.shape[0]) + 0.5) ax.set_xlim([-0.2, htypes.shape[0]]) if e < len(event_types) - 3: ax.set_xticklabels([]) else: ax.set_xticklabels(htypes, rotation=90, fontsize=10) ax.set_title(event_dict[event_type]) ax.yaxis.grid(True) for p in figs: figs[p].tight_layout() figs[p].savefig(os.path.join( PLOTDIR, 'event_overview_per_ht_exonize_level2_C%i_%s.pdf' % (CONF, p)), format='pdf', bbox_inches='tight') figs[p].savefig(os.path.join( PLOTDIR, 'event_overview_per_ht_exonize_level2_C%i_%s.png' % (CONF, p)), format='png', bbox_inches='tight') plt.close(figs[p])
def main(): figs = dict() figs['stats'] = plt.figure(figsize=(15, 8)) figs['stats_log'] = plt.figure(figsize=(15, 8)) gss = dict() gss['stats'] = gridspec.GridSpec(2, 3) #, wspace=0.0, hspace=0.0) gss['stats_log'] = gridspec.GridSpec(2, 3) #, wspace=0.0, hspace=0.0) for e, event_type in enumerate(event_types): print('Handling %s' % event_type, file=sys.stderr) ### load events detected in annotation only #anno = cPickle.load(open(os.path.join(BASEDIR_ANNO, 'merge_graphs_%s_C%i.pickle' % (event_type, CONF)), 'r')) #if isinstance(anno, tuple): # anno = anno[0] ### load annotation index is_anno_gtex = pickle.load( open( os.path.join( BASEDIR_GTEX, 'merge_graphs_%s_C%i.anno_only.pickle' % (event_type, CONF)), 'r')) is_anno_icgc = pickle.load( open( os.path.join( BASEDIR_ICGC, 'merge_graphs_%s_C%i.anno_only.pickle' % (event_type, CONF)), 'r')) ### load confident events IN = h5py.File( os.path.join( BASEDIR_GTEX, 'merge_graphs_%s_C%i.counts.hdf5' % (event_type, CONF)), 'r') idx_conf_gtex = IN['conf_idx'][:] IN.close() IN = h5py.File( os.path.join( BASEDIR_ICGC, 'merge_graphs_%s_C%i.counts.hdf5' % (event_type, CONF)), 'r') idx_conf_icgc = IN['conf_idx'][:] IN.close() ### load psi filtered events #idx_psi_gtex = cPickle.load(open(os.path.join(BASEDIR_GTEX, 'merge_graphs_%s_C%i.counts.hdf5.psi_filt_per_ht.pickle' % (event_type, CONF)), 'r'))[1] idx_psi_icgc = pickle.load( open( os.path.join( BASEDIR_ICGC, 'merge_graphs_%s_C%i.counts.hdf5.psi_filt_per_ht.pickle' % (event_type, CONF)), 'r'))[1] ### get all histotypes htypes = sp.unique([x[0] for x in list(idx_psi_icgc.keys())]) #colors = dict(zip(htypes, ic.get_color_scheme('tumor_subtype', labels=htypes))) colors = ic.get_color_scheme('tumor_subtype', labels=htypes) ### get counts counts = [] dp = 0.3 counts_anno = sp.array([ sp.sum(is_anno_icgc[idx_psi_icgc[(ht, dp)]]) if (ht, dp) in idx_psi_icgc else 0 for ht in htypes ]) counts_new = sp.array([ idx_psi_icgc[(ht, dp)].shape[0] - sp.sum(is_anno_icgc[idx_psi_icgc[(ht, dp)]]) if (ht, dp) in idx_psi_icgc else 0 for ht in htypes ]) ### plot stats for events by histotype ax = figs['stats'].add_subplot(gss['stats'][e / 3, e % 3]) ax.bar(sp.arange(htypes.shape[0]) + 0.2, counts_anno, 0.6, color=colors, linewidth=0.5) ax.bar(sp.arange(htypes.shape[0]) + 0.2, counts_new, 0.6, bottom=counts_anno, color=colors, linewidth=0.5, alpha=0.5) #li, = ax.plot(sp.arange(data1_icgc.shape[0]), data1_icgc, '-r', label='ICGC') axs.set_ticks_outer(ax) axs.clean_axis(ax) #if e == len(event_types) - 1: # ax.legend(handles=[lg, lga, li, lia], loc='upper right', frameon=False, fontsize=10) ax.set_xticks(sp.arange(htypes.shape[0]) + 0.5) ax.set_xlim([-0.2, htypes.shape[0]]) if e < len(event_types) - 3: ax.set_xticklabels([]) else: ax.set_xticklabels(htypes, rotation=90, fontsize=10) ax.set_title(event_dict[event_type]) ax.yaxis.grid(True) ### plot stats for events by histotype (log) ax = figs['stats_log'].add_subplot(gss['stats'][e / 3, e % 3]) ax.bar(sp.arange(htypes.shape[0]) + 0.1, sp.log10(counts_anno + 1), 0.8, color=colors, linewidth=0.5) ax.bar(sp.arange(htypes.shape[0]) + 0.1, sp.log10(counts_new + 1), 0.8, bottom=sp.log10(counts_anno + 1), color=colors, linewidth=0.5, alpha=0.3) axs.set_ticks_outer(ax) axs.clean_axis(ax) ax.set_xticks(list(range(htypes.shape[0]))) ax.set_xlim([-0.2, htypes.shape[0]]) if e < len(event_types) - 3: ax.set_xticklabels([]) else: ax.set_xticklabels(htypes, rotation=90, fontsize=10) ax.set_title(event_dict[event_type]) ax.yaxis.grid(True) for p in figs: figs[p].tight_layout() figs[p].savefig(os.path.join( PLOTDIR, 'event_overview_per_ht_C%i_%s.pdf' % (CONF, p)), format='pdf', bbox_inches='tight') figs[p].savefig(os.path.join( PLOTDIR, 'event_overview_per_ht_C%i_%s.png' % (CONF, p)), format='png', bbox_inches='tight') plt.close(figs[p])
return_legend_handle=True, label='Ref: %s' % ref_donors[d])) labels.append('Ref: %s' % ref_donors[d]) plt.legend(cax, labels, fontsize=10) #for vp in var_pos: # ax.plot(vp, 0, 'bo', markersize=1) #ylim = ax.get_ylim() #xlim = ax.get_xlim() #xspan = xlim[1] - xlim[0] #yspan = ylim[1] - ylim[0] #for vp in var_pos: # ax.arrow(vp, yspan * 0.2, 0, yspan * -0.15, head_width=0.01*xspan, head_length=0.01*yspan, fc='b') x_range = ax.get_xlim() ax.set_ylim([0, ax.get_ylim()[1]]) axs.clean_axis(ax) axs.set_ticks_outer(ax) ### plot event layout ax = fig.add_subplot(gs[rows - 1, 0]) gl.multiple([exons1, exons2], x_range=x_range, ax=ax) axs.clean_axis(ax, left=True, bottom=True) plt.tight_layout() outbase = os.path.join( PLOTDIR, 'result_exonization_exon_skip_%s_%s_%s' % (results[i, 1], results[i, 0], un.get_ID(results[i, 9], lookup=lookup))) print('saving to %s' % outbase) plt.savefig('%s%s.pdf' % (outbase, logtag), bbox_inches='tight',
def main(): figs = dict() figs['stats'] = plt.figure(figsize=(12, 8)) figs['stats_log'] = plt.figure(figsize=(12, 8)) figs['stats_full'] = plt.figure(figsize=(12, 8)) figs['stats_full_log'] = plt.figure(figsize=(12, 8)) gss = dict() gss['stats'] = gridspec.GridSpec(2, 3) #, wspace=0.0, hspace=0.0) gss['stats_log'] = gridspec.GridSpec(2, 3) #, wspace=0.0, hspace=0.0) gss['stats_full'] = gridspec.GridSpec(2, 3) #, wspace=0.0, hspace=0.0) gss['stats_full_log'] = gridspec.GridSpec(2, 3) #, wspace=0.0, hspace=0.0) for e, event_type in enumerate(event_types): print('Handling %s' % event_type, file=sys.stderr) ### load events detected in annotation only anno = pickle.load(open(os.path.join(BASEDIR_ANNO, 'merge_graphs_%s_C%i.pickle' % (event_type, CONF)), 'r')) if isinstance(anno, tuple): anno = anno[0] ### load annotation index is_anno_gtex = pickle.load(open(os.path.join(BASEDIR_GTEX, 'merge_graphs_%s_C%i.anno_only.pickle' % (event_type, CONF)), 'r')) is_anno_icgc_t = pickle.load(open(os.path.join(BASEDIR_ICGC_T, 'merge_graphs_%s_C%i.anno_only.pickle' % (event_type, CONF)), 'r')) is_anno_icgc_n = pickle.load(open(os.path.join(BASEDIR_ICGC_N, 'merge_graphs_%s_C%i.anno_only.pickle' % (event_type, CONF)), 'r')) ### load confident events IN = h5py.File(os.path.join(BASEDIR_GTEX, 'merge_graphs_%s_C%i.counts.hdf5' % (event_type, CONF)), 'r') idx_conf_gtex = IN['conf_idx'][:] IN.close() IN = h5py.File(os.path.join(BASEDIR_ICGC_T, 'merge_graphs_%s_C%i.counts.hdf5' % (event_type, CONF)), 'r') idx_conf_icgc_t = IN['conf_idx'][:] IN.close() IN = h5py.File(os.path.join(BASEDIR_ICGC_N, 'merge_graphs_%s_C%i.counts.hdf5' % (event_type, CONF)), 'r') idx_conf_icgc_n = IN['conf_idx'][:] IN.close() ### load filtered events #IN = h5py.File(os.path.join(BASEDIR_GTEX, 'merge_graphs_%s_C%i.counts.r10_s50_V10.hdf5' % (event_type, CONF)), 'r') #idx_filt_gtex = IN['filter_idx'][:] #IN.close() #IN = h5py.File(os.path.join(BASEDIR_ICGC, 'merge_graphs_%s_C%i.counts.r10_s50_V10.hdf5' % (event_type, CONF)), 'r') #idx_filt_icgc = IN['filter_idx'][:] #IN.close() ### load psi filtered events idx_psi_gtex = pickle.load(open(os.path.join(BASEDIR_GTEX, 'merge_graphs_%s_C%i.counts.hdf5.psi_filt.pickle' % (event_type, CONF)), 'r'))[1] idx_psi_icgc_t = pickle.load(open(os.path.join(BASEDIR_ICGC_T, 'merge_graphs_%s_C%i.counts.hdf5.psi_filt.pickle' % (event_type, CONF)), 'r'))[1] idx_psi_icgc_n = pickle.load(open(os.path.join(BASEDIR_ICGC_N, 'merge_graphs_%s_C%i.counts.hdf5.psi_filt.pickle' % (event_type, CONF)), 'r'))[1] ### plot stats for normal counts (FULL) ax = figs['stats_full'].add_subplot(gss['stats_full'][e / 3, e % 3]) xlabels_full = ['detected', 'confident'] xlabels_part = ['confident'] xlabels_full.extend(['dpsi > %.1f' % _ for _ in sorted(idx_psi_gtex.keys())]) xlabels_part.extend(['dpsi > %.1f' % _ for _ in sorted(idx_psi_gtex.keys())]) # all confirmed events, further filtered by PSI - GTEX data1_gtex = [is_anno_gtex.shape[0], idx_conf_gtex.shape[0]] data1_gtex.extend([sp.intersect1d(idx_conf_gtex, idx_psi_gtex[_]).shape[0] for _ in sorted(idx_psi_gtex.keys())]) data1_gtex = sp.array(data1_gtex) lg, = ax.plot(sp.arange(data1_gtex.shape[0]), data1_gtex, '-b', label='GTEx') # all annotated confirmed events, further filtered by PSI - GTEX data2_gtex = [sp.sum(is_anno_gtex), sp.sum(is_anno_gtex[idx_conf_gtex])] data2_gtex.extend([sp.sum(is_anno_gtex[sp.intersect1d(idx_conf_gtex, idx_psi_gtex[_])]) for _ in sorted(idx_psi_gtex.keys())]) data2_gtex = sp.array(data2_gtex) lga, = ax.plot(sp.arange(data2_gtex.shape[0]), data2_gtex, '--b', label='GTEx (anno)') # all confirmed events, further filtered by PSI - ICGC_T data1_icgc_t = [is_anno_icgc_t.shape[0], idx_conf_icgc_t.shape[0]] data1_icgc_t.extend([sp.intersect1d(idx_conf_icgc_t, idx_psi_icgc_t[_]).shape[0] for _ in sorted(idx_psi_icgc_t.keys())]) data1_icgc_t = sp.array(data1_icgc_t) lit, = ax.plot(sp.arange(data1_icgc_t.shape[0]), data1_icgc_t, '-r', label='ICGC Tumor') # all annotated confirmed events, further filtered by PSI - ICGC data2_icgc_t = [sp.sum(is_anno_icgc_t), sp.sum(is_anno_icgc_t[idx_conf_icgc_t])] data2_icgc_t.extend([sp.sum(is_anno_icgc_t[sp.intersect1d(idx_conf_icgc_t, idx_psi_icgc_t[_])]) for _ in sorted(idx_psi_icgc_t.keys())]) data2_icgc_t = sp.array(data2_icgc_t) lita, = ax.plot(sp.arange(data2_icgc_t.shape[0]), data2_icgc_t, '--r', label='ICGC Tumor (anno)') # all confirmed events, further filtered by PSI - ICGC_T data1_icgc_n = [is_anno_icgc_n.shape[0], idx_conf_icgc_n.shape[0]] data1_icgc_n.extend([sp.intersect1d(idx_conf_icgc_n, idx_psi_icgc_n[_]).shape[0] for _ in sorted(idx_psi_icgc_n.keys())]) data1_icgc_n = sp.array(data1_icgc_n) lin, = ax.plot(sp.arange(data1_icgc_n.shape[0]), data1_icgc_n, '-g', label='ICGC Normal') # all annotated confirmed events, further filtered by PSI - ICGC data2_icgc_n = [sp.sum(is_anno_icgc_n), sp.sum(is_anno_icgc_n[idx_conf_icgc_n])] data2_icgc_n.extend([sp.sum(is_anno_icgc_n[sp.intersect1d(idx_conf_icgc_n, idx_psi_icgc_n[_])]) for _ in sorted(idx_psi_icgc_n.keys())]) data2_icgc_n = sp.array(data2_icgc_n) lina, = ax.plot(sp.arange(data2_icgc_n.shape[0]), data2_icgc_n, '--g', label='ICGC Normal (anno)') axs.set_ticks_outer(ax) axs.clean_axis(ax) if e == len(event_types) - 1: ax.legend(handles=[lit, lita, lin, lina, lg, lga], loc='upper right', frameon=False, fontsize=10) ax.set_xticks(list(range(len(xlabels_full)))) if e < len(event_types) - 3: ax.set_xticklabels([]) else: ax.set_xticklabels(xlabels_full, rotation=90, fontsize=10) ax.set_title(event_dict[event_type]) ax.xaxis.grid(True) ### plots stats for log10 counts (FULL) ax = figs['stats_full_log'].add_subplot(gss['stats_full_log'][e / 3, e % 3]) lg, = ax.plot(sp.arange(data1_gtex.shape[0]), sp.log10(data1_gtex + 1), '-b', label='GTEx') lga, = ax.plot(sp.arange(data2_gtex.shape[0]), sp.log10(data2_gtex + 1), '--b', label='GTEx (anno)') lit, = ax.plot(sp.arange(data1_icgc_t.shape[0]), sp.log10(data1_icgc_t + 1), '-r', label='ICGC Tumor') lita, = ax.plot(sp.arange(data2_icgc_t.shape[0]), sp.log10(data2_icgc_t + 1), '--r', label='ICGC Tumor (anno)') lin, = ax.plot(sp.arange(data1_icgc_n.shape[0]), sp.log10(data1_icgc_n + 1), '-g', label='ICGC Normal') lina, = ax.plot(sp.arange(data2_icgc_n.shape[0]), sp.log10(data2_icgc_n + 1), '--g', label='ICGC Normal (anno)') axs.set_ticks_outer(ax) axs.clean_axis(ax) if e == len(event_types) - 1: ax.legend(handles=[lit, lita, lin, lina, lg, lga], loc='lower left', frameon=False, fontsize=10) ax.set_xticks(list(range(len(xlabels_full)))) if e < len(event_types) - 3: ax.set_xticklabels([]) else: ax.set_xticklabels(xlabels_full, rotation=90, fontsize=10) ax.set_title(event_dict[event_type]) ax.xaxis.grid(True) ### plot stats for normal counts (only conf) ax = figs['stats'].add_subplot(gss['stats'][e / 3, e % 3]) lg, = ax.plot(sp.arange(data1_gtex.shape[0] - 1), data1_gtex[1:], '-b', label='GTEx') lga, = ax.plot(sp.arange(data2_gtex.shape[0] - 1), data2_gtex[1:], '--b', label='GTEx (anno)') lit, = ax.plot(sp.arange(data1_icgc_t.shape[0] - 1), data1_icgc_t[1:], '-r', label='ICGC Tumor') lita, = ax.plot(sp.arange(data2_icgc_t.shape[0] - 1), data2_icgc_t[1:], '--r', label='ICGC Tumor (anno)') lin, = ax.plot(sp.arange(data1_icgc_n.shape[0] - 1), data1_icgc_n[1:], '-g', label='ICGC Normal') lina, = ax.plot(sp.arange(data2_icgc_n.shape[0] - 1), data2_icgc_n[1:], '--g', label='ICGC Normal (anno)') axs.set_ticks_outer(ax) axs.clean_axis(ax) if e == len(event_types) - 1: ax.legend(handles=[lit, lita, lin, lina, lg, lga], loc='upper right', frameon=False, fontsize=10) ax.set_xticks(list(range(len(xlabels_part)))) if e < len(event_types) - 3: ax.set_xticklabels([]) else: ax.set_xticklabels(xlabels_part, rotation=90, fontsize=10) ax.set_title(event_dict[event_type]) ax.xaxis.grid(True) ### plots stats for log10 counts (only cony) ax = figs['stats_log'].add_subplot(gss['stats_log'][e / 3, e % 3]) lg, = ax.plot(sp.arange(data1_gtex.shape[0] - 1), sp.log10(data1_gtex[1:] + 1), '-b', label='GTEx') lga, = ax.plot(sp.arange(data2_gtex.shape[0] - 1), sp.log10(data2_gtex[1:] + 1), '--b', label='GTEx (anno)') lit, = ax.plot(sp.arange(data1_icgc_t.shape[0] - 1), sp.log10(data1_icgc_t[1:] + 1), '-r', label='ICGC Tumor') lita, = ax.plot(sp.arange(data2_icgc_t.shape[0] - 1), sp.log10(data2_icgc_t[1:] + 1), '--r', label='ICGC Tumor (anno)') lin, = ax.plot(sp.arange(data1_icgc_n.shape[0] - 1), sp.log10(data1_icgc_n[1:] + 1), '-g', label='ICGC Normal') lina, = ax.plot(sp.arange(data2_icgc_n.shape[0] - 1), sp.log10(data2_icgc_n[1:] + 1), '--g', label='ICGC Normal (anno)') axs.set_ticks_outer(ax) axs.clean_axis(ax) if e == len(event_types) - 1: ax.legend(handles=[lit, lita, lin, lina, lg, lga], loc='lower left', frameon=False, fontsize=10) ax.set_xticks(list(range(len(xlabels_part)))) if e < len(event_types) - 3: ax.set_xticklabels([]) else: ax.set_xticklabels(xlabels_part, rotation=90, fontsize=10) ax.set_title(event_dict[event_type]) ax.xaxis.grid(True) for p in figs: figs[p].tight_layout() figs[p].savefig(os.path.join(PLOTDIR, 'event_overview_cumm_Liver_C%i_%s.pdf' % (CONF, p)), format='pdf', bbox_inches='tight') figs[p].savefig(os.path.join(PLOTDIR, 'event_overview_cumm_Liver_C%i_%s.png' % (CONF, p)), format='png', bbox_inches='tight') plt.close(figs[p])