def plot_venn_de_directions( logfc, set_colours_dict, ax=None, set_labels=('Hypo', 'Hyper'), fontsize=16 ): if ax is None: fig = plt.figure(figsize=(5., 3.3)) ax = fig.add_subplot(111) vv, vs, vc = venn.venn_diagram( *[logfc[k].index[logfc[k]['consistent'].astype(bool)] for k in set_labels], set_labels=set_labels, set_colors=[set_colours_dict[t] for t in set_labels], ax=ax ) ax.figure.tight_layout() # modify labels based on direction this_members = collections.OrderedDict() for k in set_labels: this_res = logfc[k] this_ix = this_res['consistent'].astype(bool) this_res = np.sign(this_res.loc[this_ix].astype(float).mean(axis=1)) this_members["%s up" % k] = this_res.index[this_res > 0].difference(vs['11']) this_members["%s down" % k] = this_res.index[this_res < 0].difference(vs['11']) # get the corresponding label lbl = vv.get_label_by_id(setops.specific_sets(set_labels)[k]) ## FIXME: font family seems to change from old text to new - related to LaTeX rendering? lbl.set_text( lbl.get_text() + '\n' + r'$%d\uparrow$' % len(this_members["%s up" % k]) + '\n' + r'$%d\downarrow$' % len(this_members["%s down" % k]), ) plt.setp(common.get_children_recursive(ax, type_filt=plt.Text), fontsize=fontsize) return ax
# DE pids = consts.PIDS outdir = output.unique_output_dir() # load previously generated DE results fn = os.path.join(HGIC_LOCAL_DIR, 'current', 'core_pipeline', 'rnaseq', 'full_de_syngeneic_only.xlsx') de_res = pd.read_excel(fn, header=0, index_col=0) all_ens = de_res.index[(de_res[pids] == 'Y').any(axis=1)] de_per_pat = {pid: de_res.index[de_res[pid] == 'Y'] for pid in pids} n_tot = {pid: de_per_pat[pid].size for pid in pids} vs, vc = setops.venn_from_arrays(*[de_per_pat[pid] for pid in pids]) pp = setops.specific_sets(pids) n_ps = {pid: vc[pp[pid]] for pid in pids} # perms n_all = len(all_ens) n_spec = run_patient_specific_permutations(n_tot, n_all, n_perm=n_perm) fig, axs = plot_perms_kde_vs_obs( n_spec, n_ps, xlabel='Number of patient-specific DE genes', order=pids) fig.savefig(os.path.join(outdir, "patient_specific_de.png"), dpi=200) fig.savefig(os.path.join(outdir, "patient_specific_de.tiff"), dpi=200) fig.savefig(os.path.join(outdir, "patient_specific_de.pdf")) fn = os.path.join(HGIC_LOCAL_DIR, 'current', 'core_pipeline', 'methylation', 'full_dmr_syngeneic_only.xlsx') dm_res = pd.read_excel(fn)
for t in joint_de_dmr_s1.values()])) dgi_all = druggable_genome.dgidb_lookup_drug_gene_interactions(all_genes) # manually resolve a few known ambiguities ambig = {'ELTD1': 'ADGRL4', 'ODZ3': 'TENM3'} for k, v in ambig.items(): x = [t for t in dgi_all['ambiguous'][k] if t['geneName'] == v][0] dgi_all['interactions'][k] = x['interactions'] de_dmr_by_member = [joint_de_dmr_s1[pid].index for pid in pids] venn_set, venn_ct = setops.venn_from_arrays(*de_dmr_by_member) # define short and long list # long list ss = setops.specific_sets(pids) ps_de_dm_long = collections.OrderedDict([(pid, venn_set[ss[pid]]) for pid in pids]) ps_de_dm_long_list = setops.reduce_union(*ps_de_dm_long.values()) # short list vs_dm, vc_dm = setops.venn_from_arrays( *[dmr_res_s1[pid].results_significant.keys() for pid in pids]) vs_de, vc_de = setops.venn_from_arrays( *[de_res_s1[pid]['Gene Symbol'].dropna() for pid in pids]) ps_dm = {pid: vs_dm[v] for pid, v in ss.items()} ps_dm_genes = {} for pid, cids in ps_dm.items(): ps_dm_genes[pid] = sorted(