diff --git a/bean/plotting/utils.py b/bean/plotting/utils.py new file mode 100644 index 0000000..1233cfb --- /dev/null +++ b/bean/plotting/utils.py @@ -0,0 +1,69 @@ +import argparse + + +def parse_args(): + print(" \n~~~BEAN Profile~~~") + print("-Profile editing patterns of your editor-") + print( + r""" + _ _ __ _ _ + / \ '\ _ __ _ _ ___ / _(_) |___ + | \ \ | '_ \ '_/ _ \ _| | / -_) + \ \ | | .__/_| \___/_| |_|_\___| + `.__|/ |_| + """ + ) + parser = argparse.ArgumentParser() + parser.add_argument( + "bdata_path", help="Path to the ReporterScreen object to run QC on", type=str + ) + parser.add_argument( + "-o", + "--output-prefix", + help="Output prefix of editing pattern report (prefix.html, prefix.ipynb). If not provided, base name of `bdata_path` is used.", + type=str, + ) + parser.add_argument( + "--replicate-col", + help="Column name in `bdata.samples` that describes replicate ID.", + type=str, + default="rep", + ) + parser.add_argument( + "--condition-col", + help="Column name in `bdata.samples` that describes experimental condition. (sorting bin, time, etc.)", + type=str, + default="bin", + ) + parser.add_argument( + "--pam-col", + help="Column name describing PAM of each gRNA in `bdata.guides`.", + type=str, + default=None, + ) + parser.add_argument( + "--control-condition", + help="Control condition where editing preference would be profiled at. Pre-filters data where `bdata.samples[condition_col] == control_condition`.", + type=str, + default="bulk", + ) + parser.add_argument( + "-w", + "--window-length", + help="Window length of editing window of maximal editing efficiency to be identified. This window is used to quantify context specificity within the window.", + type=int, + default=6, + ) + + args = parser.parse_args() + if args.output_prefix is None: + args.output_prefix = f"{args.bdata_path.rsplit('.h5ad', 1)[0]}" + return args + + +def check_args(args): + if args.window_length < 1: + raise ValueError(f"window_length {args.window_length} is too small.") + if args.window_length > 20: + raise ValueError(f"window_length {args.window_length} is too large.") + return args diff --git a/bin/bean-profile b/bin/bean-profile new file mode 100644 index 0000000..8b48daa --- /dev/null +++ b/bin/bean-profile @@ -0,0 +1,34 @@ +#!/usr/bin/env python +import os +import papermill as pm +import bean as be +from bean.plotting.utils import parse_args, check_args + + +def main(): + args = parse_args() + args = check_args(args) + os.system( + "python -m ipykernel install --user --name bean_python3 --display-name bean_python3" + ) + pm.execute_notebook( + f"{os.path.dirname(be.__file__)}/../notebooks/profile_editing_preference.ipynb", + f"{args.output_prefix}.ipynb", + parameters=dict( + bdata_path=args.bdata_path, + output_prefix=args.output_prefix, + replicate_col=args.replicate_col, + condition_col=args.condition_col, + control_condition=args.control_condition, + max_editing_window_length=args.window_length, + pam_col=args.pam_col, + ), + kernel_name="bean_python3", + ) + os.system( + f"jupyter nbconvert --to html {args.output_prefix}_editing_preference.ipynb" + ) + + +if __name__ == "__main__": + main()