Skip to content

Commit

Permalink
debug profile
Browse files Browse the repository at this point in the history
  • Loading branch information
jykr committed Apr 9, 2024
1 parent 7951331 commit 8fc4895
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 19 deletions.
5 changes: 2 additions & 3 deletions bean/cli/profile.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")
2 changes: 1 addition & 1 deletion bean/cli/qc.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")
28 changes: 14 additions & 14 deletions bean/notebooks/profile_editing_preference.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -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"
]
},
{
Expand Down Expand Up @@ -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')"
]
},
{
Expand Down Expand Up @@ -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')"
]
},
{
Expand Down Expand Up @@ -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\")"
]
},
Expand Down Expand Up @@ -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)"
]
},
{
Expand Down Expand Up @@ -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",
Expand All @@ -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,
Expand Down Expand Up @@ -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\")"
]
}
],
Expand Down
11 changes: 10 additions & 1 deletion bean/plotting/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
Binary file modified tests/data/var_mini_screen.h5ad
Binary file not shown.

0 comments on commit 8fc4895

Please sign in to comment.