diff --git a/bean/cli/profile.py b/bean/cli/profile.py index 514b7c1..6336819 100755 --- a/bean/cli/profile.py +++ b/bean/cli/profile.py @@ -32,9 +32,8 @@ def main(args): control_condition=args.control_condition, max_editing_window_length=args.window_length, pam_col=args.pam_col, + save_fig=args.save_fig, ), kernel_name="bean_python3", ) - os.system( - f"jupyter nbconvert --to html {args.output_prefix}_editing_preference.ipynb" - ) + os.system(f"jupyter nbconvert --to html {args.output_prefix}.ipynb") diff --git a/bean/cli/qc.py b/bean/cli/qc.py index ed1f94b..6182385 100755 --- a/bean/cli/qc.py +++ b/bean/cli/qc.py @@ -53,4 +53,4 @@ def main(args): ), kernel_name="bean_python3", ) - os.system(f"jupyter nbconvert --to html {args.out_report_prefix}.ipynb") + os.system(f"jupyter nbconvert --to=html {args.out_report_prefix}.ipynb") diff --git a/bean/notebooks/profile_editing_preference.ipynb b/bean/notebooks/profile_editing_preference.ipynb index cdcdade..2965673 100755 --- a/bean/notebooks/profile_editing_preference.ipynb +++ b/bean/notebooks/profile_editing_preference.ipynb @@ -56,7 +56,8 @@ "control_condition = \"bulk\"\n", "output_prefix = \"editing pattern\"\n", "max_editing_window_length = 6\n", - "pam_col=\"5-nt PAM\"" + "pam_col=\"5-nt PAM\"\n", + "save_fig=False" ] }, { @@ -617,7 +618,7 @@ " nonref_base_changes = None\n", ")\n", "profile_df.to_csv(f\"{output_prefix}_behive_like_profile.csv\")\n", - "plt.savefig(f\"{output_prefix}_behive_like_profile.pdf\", bbox_inches = 'tight')" + "if save_fig: plt.savefig(f\"{output_prefix}_behive_like_profile.pdf\", bbox_inches = 'tight')" ] }, { @@ -975,7 +976,7 @@ " lw=2\n", " )\n", ")\n", - "plt.savefig(f\"{output_prefix}_behive_like_profile_normed.pdf\", bbox_inches = 'tight')" + "if save_fig: plt.savefig(f\"{output_prefix}_behive_like_profile_normed.pdf\", bbox_inches = 'tight')" ] }, { @@ -1020,7 +1021,8 @@ "source": [ "if pam_col is not None:\n", " pos_by_pam = be.pl.editing_patterns.plot_by_pos_pam(cdata_bulk, cedit_rates_df_ag, pam_col)\n", - " plt.savefig(f\"{output_prefix}_pos_by_pam.pdf\", bbox_inches = 'tight')\n", + " if save_fig: \n", + " plt.savefig(f\"{output_prefix}_pos_by_pam.pdf\", bbox_inches = 'tight')\n", " pos_by_pam.to_csv(f\"{output_prefix}_pos_by_pam.csv\")" ] }, @@ -1068,9 +1070,14 @@ "outputs": [], "source": [ "con_mean_er = {}\n", + "bases = [\"A\", \"C\", \"G\", \"T\"]\n", + "\n", "for i in range(3):\n", + "\n", " cedit_rates_df_ag_window[f\"context_{i}\"] = cedit_rates_df_ag_window.context.map(lambda s: s[i])\n", - " con_mean_er[i] = cedit_rates_df_ag_window.groupby(f\"context_{i}\")[\"rep_mean\"].mean()" + "\n", + " con_mean_er[i] = cedit_rates_df_ag_window.groupby(f\"context_{i}\")[\"rep_mean\"].mean()\n", + " con_mean_er[i] = con_mean_er[i].reindex(bases).fillna(0)" ] }, { @@ -1115,7 +1122,7 @@ "metadata": {}, "outputs": [], "source": [ - "bases = [\"A\", \"C\", \"G\", \"T\"]\n", + "\n", "target_df = pd.DataFrame([int(b == cdata_bulk.uns[\"target_base_change\"][0]) for b in bases], index=bases)\n", "ic_tbl = pd.concat(\n", " [\n", @@ -1138,13 +1145,6 @@ "ic_tbl.to_csv(f\"{output_prefix}_context.csv\")" ] }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [] - }, { "cell_type": "code", "execution_count": 32, @@ -1180,7 +1180,7 @@ "\n", "logomaker.Logo(ic_tbl, ax = ax)\n", "ax.set_ylabel(\"Relative frequency\")\n", - "fig.savefig(f\"{output_prefix}_context_preference_{window_start}_{window_end}.pdf\")" + "if save_fig: fig.savefig(f\"{output_prefix}_context_preference_{window_start}_{window_end}.pdf\")" ] } ], diff --git a/bean/plotting/utils.py b/bean/plotting/utils.py index 69a74a9..4553fa9 100755 --- a/bean/plotting/utils.py +++ b/bean/plotting/utils.py @@ -45,13 +45,22 @@ def parse_args(parser=None): type=int, default=6, ) + parser.add_argument( + "--save-fig", + action="store_true", + help="Save .pdf of the figures included in the report.", + ) return parser def check_args(args): if args.output_prefix is None: - args.output_prefix = os.path.splitext(args.bdata_path)[0] + sample_id = os.path.splitext(os.path.basename(args.bdata_path))[0] + args.output_prefix = ( + f"{os.path.dirname(args.bdata_path)}/bean_profile.{sample_id}/{sample_id}" + ) + os.makedirs(args.output_prefix, exist_ok=True) if args.window_length < 1: raise ValueError(f"window_length {args.window_length} is too small.") if args.window_length > 20: diff --git a/tests/data/var_mini_screen.h5ad b/tests/data/var_mini_screen.h5ad index 5685e2f..3044b5f 100755 Binary files a/tests/data/var_mini_screen.h5ad and b/tests/data/var_mini_screen.h5ad differ