Skip to content

Commit

Permalink
created plotting function to generate upset plot of high ranked likel…
Browse files Browse the repository at this point in the history
…y passengers in cbase results
  • Loading branch information
ashuaibi7 committed Jan 20, 2025
1 parent 5229e3e commit cf795ba
Showing 1 changed file with 30 additions and 0 deletions.
30 changes: 30 additions & 0 deletions src/dialect/utils/plotting.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
from itertools import product
from matplotlib import rcParams
from matplotlib.lines import Line2D
from upsetplot import from_contents, UpSet
from matplotlib.patches import FancyBboxPatch, BoxStyle, Patch

from dialect.utils.postprocessing import generate_top_ranking_tables
Expand Down Expand Up @@ -463,3 +464,32 @@ def plot_cbase_driver_decoy_gene_fractions(subtype_decoy_gene_fractions, fout):
plt.tight_layout()

plt.savefig(fout, transparent=True)


def plot_cbase_top_decoy_genes_upset(
subtype_to_high_ranked_decoys,
high_ranked_decoy_freqs,
top_n,
fout,
):
top_genes = sorted(
high_ranked_decoy_freqs, key=high_ranked_decoy_freqs.get, reverse=True
)[:top_n]
contents = {}
for gene in top_genes:
subtypes_with_gene = [
subtype
for subtype, decoys in subtype_to_high_ranked_decoys.items()
if gene in decoys
]
contents[gene] = set(subtypes_with_gene)

df = from_contents(contents)

upset = UpSet(df, totals_plot_elements=0, element_size=40)
plt.figure(figsize=(16, 8))
subplots = upset.plot()
subplots["intersections"].set_ylabel("Number of Subtypes")
subplots["matrix"].set_ylabel("Likely Passengers")
plt.savefig(fout, transparent=True)
plt.close()

0 comments on commit cf795ba

Please sign in to comment.