scboa 0.1.0__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
scboa/__init__.py ADDED
File without changes
scboa/cli.py ADDED
@@ -0,0 +1,91 @@
1
+ #!/usr/bin/env python
2
+ # -*- coding: utf-8 -*-
3
+ """
4
+ Command-Line Interface for the scBOA Pipeline.
5
+
6
+ This script handles argument parsing and serves as the entry point for the
7
+ scBOA pipeline when it's installed as a package. It imports and calls the
8
+ main orchestrator function from the `pipeline` module.
9
+ """
10
+
11
+ import argparse
12
+
13
+ # This is the crucial relative import. It looks for a file named 'pipeline.py'
14
+ # within the same package directory ('src/scboa/') and imports the 'main' function.
15
+ from .pipeline import main
16
+
17
+ def run():
18
+ """
19
+ Parses all command-line arguments and executes the main scBOA pipeline.
20
+
21
+ This function is the target for the [project.scripts] entry point specified
22
+ in the pyproject.toml file.
23
+ """
24
+ parser = argparse.ArgumentParser(
25
+ description="Integrated Two-Stage Bayesian Optimization and Final Analysis Pipeline for scRNA-seq.",
26
+ formatter_class=argparse.RawTextHelpFormatter
27
+ )
28
+
29
+ stage1_group = parser.add_argument_group('Stage 1 & 2: Main I/O and Mode')
30
+ mode_group = stage1_group.add_mutually_exclusive_group(required=True)
31
+ mode_group.add_argument('--data_dir', type=str, help='Path to 10x Genomics data for single-sample analysis.')
32
+ mode_group.add_argument('--multi_sample', nargs=2, metavar=('WT_DIR', 'TREATED_DIR'), help='Two paths for WT/Control and Treated/Perturbed 10x data for multi-sample integration.')
33
+ stage1_group.add_argument('--output_dir', type=str, required=True, help='Path for all output files.')
34
+ stage1_group.add_argument('--model_path', type=str, required=True, help='Path to CellTypist model (.pkl).')
35
+ stage1_group.add_argument('--output_prefix', type=str, default='bayesian_opt', help='Base prefix for Stage 1 output files.')
36
+
37
+ opt_group = parser.add_argument_group('Stage 1: Optimization Parameters')
38
+ opt_group.add_argument('--seed', type=int, default=42, help='Global random seed for reproducibility.')
39
+ opt_group.add_argument('--n_calls', type=int, default=50, help='Number of trials for EACH of the three optimization strategies.')
40
+ opt_group.add_argument(
41
+ '--model_type',
42
+ type=str,
43
+ default='structural',
44
+ choices=['biological', 'structural', 'silhouette'],
45
+ help= ("'biological': balances CAS & MCS.\n"
46
+ "'structural' (default): adds silhouette score to balance biological concordance with cluster quality.\n"
47
+ "'silhouette': optimizes solely to maximize the silhouette score.")
48
+ )
49
+ opt_group.add_argument('--marker_gene_model', type=str, default='non-mitochondrial', choices=['all', 'non-mitochondrial'], help="'all': use all genes. 'non-mitochondrial' (default): exclude mitochondrial genes from MCS markers.")
50
+ opt_group.add_argument('--target', type=str, default='all', choices=['all', 'weighted_cas', 'simple_cas', 'mcs'], help="'all' (default): runs a single, balanced optimization. Other options optimize for that specific metric.")
51
+
52
+ opt_group.add_argument(
53
+ '--cas_aggregation_method',
54
+ type=str,
55
+ default='leiden',
56
+ choices=['leiden', 'consensus'],
57
+ help=("Method for calculating Simple Mean CAS and for determining refinement candidates.\n"
58
+ "'leiden' (default): Averages the purity of each individual Leiden cluster.\n"
59
+ "'consensus': Merges Leiden clusters with the same consensus label, then averages their purity.")
60
+ )
61
+
62
+ hvg_group = parser.add_argument_group('Stage 1 & 2: HVG Selection Method')
63
+ hvg_group.add_argument('--hvg_min_mean', type=float, default=None, help='(Optional) Activates two-step HVG selection. Min mean for initial filtering.')
64
+ hvg_group.add_argument('--hvg_max_mean', type=float, default=None, help='(Optional) Activates two-step HVG selection. Max mean for initial filtering.')
65
+ hvg_group.add_argument('--hvg_min_disp', type=float, default=None, help='(Optional) Activates two-step HVG selection. Min dispersion for initial filtering.')
66
+
67
+ qc_group = parser.add_argument_group('Stage 1 & 2: QC & Filtering Parameters')
68
+ qc_group.add_argument('--min_genes', type=int, default=200, help='Min genes per cell.')
69
+ qc_group.add_argument('--max_genes', type=int, default=7000, help='Max genes per cell.')
70
+ qc_group.add_argument('--max_pct_mt', type=float, default=10.0, help='Max mitochondrial percentage.')
71
+ qc_group.add_argument('--min_cells', type=int, default=3, help='Min cells per gene.')
72
+
73
+ stage2_group = parser.add_argument_group('Stage 2 & Optional Refinement: Final Run Parameters')
74
+ stage2_group.add_argument('--final_run_prefix', type=str, default='sc_analysis_repro', help='Prefix for all output files in the Stage 2 subdirectory.')
75
+ stage2_group.add_argument('--fig_dpi', default=500, type=int, help='Resolution (DPI) for saved figures in Stage 2.')
76
+ stage2_group.add_argument('--n_pcs_compute', type=int, default=105, help="Number of principal components to COMPUTE in Stage 1 and 2.")
77
+ stage2_group.add_argument('--n_top_genes', type=int, default=5, help="Number of top marker genes to show in plots/tables in Stage 1 and 2.")
78
+ stage2_group.add_argument('--cellmarker_db', type=str, default=None, help="(Optional) Path to a cell marker database (.csv) for manual annotation in Stage 2.")
79
+ stage2_group.add_argument('--n_degs_for_capture', type=int, default=50, help="Number of top DEGs per cluster to use for the Marker Capture Score calculation in Stage 2.")
80
+ stage2_group.add_argument('--cas_refine_threshold', type=float, default=None, help="(Optional) CAS percentage threshold (0-100). If a cluster's CAS is below this, its cells are pooled for a second, refined optimization run.")
81
+ stage2_group.add_argument('--refinement_depth', type=int, default=1, help="(Optional) Maximum number of times to repeat the refinement process on failing cells. Default is 1.")
82
+
83
+ # Parse the arguments provided by the user from the command line
84
+ parsed_args = parser.parse_args()
85
+
86
+ # Apply any pre-processing logic to the arguments before calling the main function
87
+ if parsed_args.multi_sample and "harmony" not in parsed_args.output_prefix:
88
+ parsed_args.output_prefix += "_harmony"
89
+
90
+ # Call the main orchestrator function from pipeline.py and pass the parsed arguments
91
+ main(parsed_args)