-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* upgrade to `neutcurve 0.10.1 * all serum titers adjusted to pass QC * mostly complete `aggregate_titers` * complete `aggregate_titers` * document aggregate titers * lint and format * save all results in test Github Actions artifact * update config to pass tests and plot QC failure in `serum_titers` in a clearer-to-look-at order
- Loading branch information
Showing
12 changed files
with
466 additions
and
25 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -21,4 +21,4 @@ dependencies: | |
- ruff | ||
- pip: | ||
- dms_variants==1.4.3 | ||
- neutcurve==0.10.0 | ||
- neutcurve==0.10.1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,232 @@ | ||
{ | ||
"cells": [ | ||
{ | ||
"cell_type": "markdown", | ||
"id": "abe395dc-8a57-4ee8-b22e-8a1acacf1619", | ||
"metadata": {}, | ||
"source": [ | ||
"# Aggregate titers across all sera\n", | ||
"Aggregate the titers across all sera, failing if there are QC failures for any individual sera." | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"id": "f404cc02-6d9a-4a3a-892e-fd73f1e00b52", | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"import pickle\n", | ||
"\n", | ||
"import altair as alt\n", | ||
"\n", | ||
"import neutcurve\n", | ||
"\n", | ||
"import pandas as pd\n", | ||
"\n", | ||
"_ = alt.data_transformers.disable_max_rows()" | ||
] | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"id": "be4112bc-7d79-4b38-8e76-ec81588f40e9", | ||
"metadata": {}, | ||
"source": [ | ||
"Get variables from `snakemake`:" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"id": "83425f55-9905-4cc0-b42c-440926e9a81e", | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"qc_failures_file = snakemake.input.qc_serum_titer_failures\n", | ||
"input_pickles = snakemake.input.pickles\n", | ||
"input_titers = snakemake.input.titers\n", | ||
"output_pickle = snakemake.output.pickle\n", | ||
"output_titers = snakemake.output.titers\n", | ||
"titers_chart_html = snakemake.output.titers_chart\n", | ||
"viral_strain_plot_order = snakemake.params.viral_strain_plot_order" | ||
] | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"id": "d3668ae9-ad6d-436e-8e7b-9a0cd3b30548", | ||
"metadata": {}, | ||
"source": [ | ||
"Check for quality control failures for any individual sera:" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"id": "1fbc6445-bbd0-4d7e-b50e-a861e03c06b6", | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"with open(qc_failures_file) as f:\n", | ||
" qc_failures = f.readlines()\n", | ||
"if not all(line.strip().endswith(\"serum passed all QC\") for line in qc_failures):\n", | ||
" raise ValueError(\n", | ||
" f\"QC failures for some serum titers. See {qc_failures_file}:\\n\\n\"\n", | ||
" + \"\".join(qc_failures)\n", | ||
" )\n", | ||
"else:\n", | ||
" print(\"All serum titers pass the QC filters.\")" | ||
] | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"id": "7a89d9f5-a789-454b-9ec6-3186a5d55c7b", | ||
"metadata": {}, | ||
"source": [ | ||
"Get the merged titers and merged `CurveFits` object:" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"id": "dda8dec6-8981-4f10-9fe2-afc35066929e", | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"assert len(input_titers) == len(input_pickles)\n", | ||
"\n", | ||
"titers = pd.concat([pd.read_csv(f) for f in input_titers], ignore_index=True)\n", | ||
"assert len(titers) == len(titers.groupby([\"serum\", \"virus\"]))\n", | ||
"print(f\"Writing aggregated titers to {output_titers}\")\n", | ||
"titers.to_csv(output_titers, index=False, float_format=\"%.4g\")\n", | ||
"\n", | ||
"fits_list = []\n", | ||
"for fname in input_pickles:\n", | ||
" with open(fname, \"rb\") as f:\n", | ||
" fits_list.append(pickle.load(f))\n", | ||
"curvefits = neutcurve.CurveFits.combineCurveFits(fits_list)\n", | ||
"print(f\"Pickling aggregated `CurveFits` to {output_pickle}\")\n", | ||
"with open(output_pickle, \"wb\") as f:\n", | ||
" pickle.dump(curvefits, f)" | ||
] | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"id": "e194786d-c227-403f-bbf9-d8ab3b19b502", | ||
"metadata": {}, | ||
"source": [ | ||
"Plot all the titers:" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"id": "eb2c2a97-e54a-4875-bc75-d57975017565", | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"viruses = [v for v in viral_strain_plot_order if v in curvefits.allviruses]\n", | ||
"\n", | ||
"sera = curvefits.sera\n", | ||
"\n", | ||
"virus_selection = alt.selection_point(fields=[\"virus\"], on=\"mouseover\", empty=False)\n", | ||
"\n", | ||
"serum_selection = alt.selection_point(\n", | ||
" fields=[\"serum\"],\n", | ||
" bind=\"legend\",\n", | ||
" toggle=\"true\",\n", | ||
")\n", | ||
"\n", | ||
"ncols = 8\n", | ||
"\n", | ||
"titers_chart = (\n", | ||
" alt.Chart(titers)\n", | ||
" .add_params(virus_selection, serum_selection)\n", | ||
" .transform_filter(serum_selection)\n", | ||
" .encode(\n", | ||
" alt.X(\n", | ||
" \"nt50\",\n", | ||
" title=\"neutralization titer\",\n", | ||
" scale=alt.Scale(nice=False, padding=4, type=\"log\"),\n", | ||
" axis=alt.Axis(labelOverlap=True),\n", | ||
" ),\n", | ||
" alt.Y(\"virus\", sort=viruses),\n", | ||
" alt.Facet(\n", | ||
" \"serum\",\n", | ||
" header=alt.Header(\n", | ||
" title=None, labelFontSize=11, labelFontStyle=\"bold\", labelPadding=0\n", | ||
" ),\n", | ||
" spacing=3,\n", | ||
" columns=ncols,\n", | ||
" ),\n", | ||
" alt.StrokeWidth(\n", | ||
" \"serum:N\",\n", | ||
" scale=alt.Scale(domain=sera, range=[1] * len(sera)),\n", | ||
" legend=alt.Legend(\n", | ||
" orient=\"bottom\",\n", | ||
" columns=ncols,\n", | ||
" symbolFillColor=\"black\",\n", | ||
" title=\"serum (click to select)\",\n", | ||
" ),\n", | ||
" ),\n", | ||
" color=alt.condition(virus_selection, alt.value(\"red\"), alt.value(\"black\")),\n", | ||
" tooltip=[\n", | ||
" \"serum\",\n", | ||
" \"virus\",\n", | ||
" alt.Tooltip(\"nt50\", title=\"NT50\", format=\".3g\"),\n", | ||
" \"n_replicates\",\n", | ||
" ],\n", | ||
" )\n", | ||
" .mark_line(point=True)\n", | ||
" .configure_axis(grid=False)\n", | ||
" .configure_point(size=45)\n", | ||
" .properties(\n", | ||
" height=alt.Step(11),\n", | ||
" width=100,\n", | ||
" title=alt.TitleParams(\n", | ||
" \"Interactive chart of serum neutralization titers\",\n", | ||
" subtitle=\"Mouseover points for details, click serum legend at bottom to select sera to show\",\n", | ||
" fontSize=15,\n", | ||
" dx=100,\n", | ||
" dy=-5,\n", | ||
" ),\n", | ||
" autosize=alt.AutoSizeParams(resize=True),\n", | ||
" )\n", | ||
")\n", | ||
"\n", | ||
"print(f\"Saving chart to {titers_chart_html}\")\n", | ||
"titers_chart.save(titers_chart_html)\n", | ||
"\n", | ||
"titers_chart" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"id": "27ff41ab-c967-42a9-adb1-5856810c7f34", | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [] | ||
} | ||
], | ||
"metadata": { | ||
"kernelspec": { | ||
"display_name": "Python 3 (ipykernel)", | ||
"language": "python", | ||
"name": "python3" | ||
}, | ||
"language_info": { | ||
"codemirror_mode": { | ||
"name": "ipython", | ||
"version": 3 | ||
}, | ||
"file_extension": ".py", | ||
"mimetype": "text/x-python", | ||
"name": "python", | ||
"nbconvert_exporter": "python", | ||
"pygments_lexer": "ipython3", | ||
"version": "3.11.6" | ||
} | ||
}, | ||
"nbformat": 4, | ||
"nbformat_minor": 5 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.