Skip to content

Commit

Permalink
make logo plots narrower and number lineplot sites better (#34)
Browse files Browse the repository at this point in the history
  • Loading branch information
jbloom authored Nov 14, 2024
1 parent c6807a8 commit 399b313
Show file tree
Hide file tree
Showing 14 changed files with 91,513 additions and 91,919 deletions.
131 changes: 88 additions & 43 deletions docs/notebooks/escape_logos.html

Large diffs are not rendered by default.

47 changes: 33 additions & 14 deletions notebooks/escape_logos.py.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -94,12 +94,20 @@
"# amino acids to plot\n",
"aas = list(dmslogo.colorschemes.AA_CHARGE)\n",
"\n",
"# line plot xtick locations\n",
"lineplot_xticks = [0, 100, 200, 300, 400]\n",
"\n",
"# make logo plots with each of these antibody groups in addition to per-antibody logos\n",
"antibody_groups = {\n",
" \"region_3_antibodies\": [\"17C7\", \"CR4098\", \"RVA122\", \"RVC58\"],\n",
" \"region_1_antibodies\": [\"RVC20\", \"CR57\"], \n",
"}\n",
"\n",
"# sites to exclude from highlighting, do not show these sites even if they\n",
"# meet highlight criteria. Key by antibody with value lists of sites\n",
"sites_no_highlight = {\n",
"}\n",
"\n",
"# file extensions on saved plots\n",
"file_extensions = [\".svg\", \".pdf\"]"
]
Expand Down Expand Up @@ -209,6 +217,17 @@
" ).astype(int)\n",
" )\n",
" )\n",
" .merge(\n",
" (\n",
" pd.DataFrame(sites_no_highlight.items(), columns=[\"antibody\", \"site\"])\n",
" .explode(\"site\")\n",
" .assign(manual_no_highlight=True)\n",
" ),\n",
" on=[\"antibody\", \"site\"],\n",
" validate=\"many_to_one\",\n",
" how=\"left\",\n",
" )\n",
" .assign(manual_no_highlight=lambda x: x[\"manual_no_highlight\"].fillna(False))\n",
")"
]
},
Expand All @@ -220,7 +239,7 @@
"outputs": [],
"source": [
"# indicate the sites to highlight\n",
"per_site_escape[\"highlight\"] = functools.reduce(\n",
"per_site_escape[\"highlight\"] = ~per_site_escape[\"manual_no_highlight\"] & functools.reduce(\n",
" operator.or_,\n",
" [\n",
" (\n",
Expand Down Expand Up @@ -264,7 +283,7 @@
" header=alt.Header(orient=\"bottom\", labelFontSize=11, labelFontStyle=\"bold\"),\n",
" ),\n",
" alt.Color(\"highlight\", title=\"site to highlight\"),\n",
" tooltip=[\"site\", \"rank\", \"antibody\"],\n",
" tooltip=[\"site\", \"rank\", \"antibody\", \"manual_no_highlight\"],\n",
" strokeWidth=alt.condition(site_selection, alt.value(3), alt.value(0.25)),\n",
" )\n",
" .mark_circle(size=40, strokeOpacity=1, fillOpacity=0.4, stroke=\"black\")\n",
Expand Down Expand Up @@ -402,7 +421,7 @@
" .query(\"antibody in @antibodies_to_plot\")\n",
" .assign(highlight=lambda x: x.groupby(\"site\")[\"highlight\"].transform(\"any\"))\n",
" )\n",
" fig, _ = dmslogo.facet_plot(\n",
" fig, axes = dmslogo.facet_plot(\n",
" df,\n",
" x_col=\"sequential_site\",\n",
" show_col=\"highlight\",\n",
Expand All @@ -412,22 +431,30 @@
" \"height_col2\": None if positive_escape_only else \"negative_site_escape\",\n",
" \"xtick_col\": \"site\",\n",
" \"ylabel\": \"escape\",\n",
" \"widthscale\": 0.4,\n",
" \"widthscale\": 0.3,\n",
" },\n",
" draw_logo_kwargs={\n",
" \"letter_col\": \"mutant\",\n",
" \"letter_height_col\": \"escape\",\n",
" \"xtick_col\": \"site\",\n",
" \"color_col\": \"letter_color\",\n",
" \"widthscale\": 0.75,\n",
" \"widthscale\": 0.7,\n",
" },\n",
" share_xlabel=True,\n",
" share_ylabel=True,\n",
" height_per_ax=1.9,\n",
" wspace=0.7,\n",
" wspace=0.6,\n",
" share_ylim_across_rows=False,\n",
" )\n",
"\n",
" # adjust x-ticks on line plots\n",
" assert axes.shape[1] == 2\n",
" for i in range(axes.shape[0]):\n",
" axes[i, 0].xaxis.set_ticks(lineplot_xticks)\n",
" if i == axes.shape[0] - 1:\n",
" axes[i, 0].xaxis.set_ticklabels(lineplot_xticks)\n",
" \n",
"\n",
" for ext in file_extensions:\n",
" fname = os.path.join(logoplot_subdir, f\"{antibody_group}{ext}\")\n",
" print(f\"Saving to {fname}\")\n",
Expand All @@ -436,14 +463,6 @@
" display(fig)\n",
" plt.close(fig)"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "d3a497c8-23fd-448d-ae9d-5eafd9963ec5",
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
Expand Down
Loading

0 comments on commit 399b313

Please sign in to comment.