From b65bbbd01c662300692c496d5e6ba5d8ae760e13 Mon Sep 17 00:00:00 2001 From: Haibao Tang Date: Tue, 30 Apr 2024 18:13:33 -0700 Subject: [PATCH] Remove all OptionGroup --- jcvi/annotation/reformat.py | 11 +++-------- jcvi/apps/base.py | 5 +---- jcvi/assembly/allmaps.py | 10 ++++------ jcvi/compara/synfind.py | 9 +++------ jcvi/formats/agp.py | 5 +---- jcvi/formats/gff.py | 21 +++++++-------------- jcvi/graphics/grabseeds.py | 15 +++++---------- 7 files changed, 24 insertions(+), 52 deletions(-) diff --git a/jcvi/annotation/reformat.py b/jcvi/annotation/reformat.py index 3275b719..40409597 100644 --- a/jcvi/annotation/reformat.py +++ b/jcvi/annotation/reformat.py @@ -19,9 +19,8 @@ from jcvi.formats.bed import Bed, BedLine, sort from jcvi.formats.base import SetFile, must_open, get_number, flexible_cast from jcvi.apps.base import ( - OptionParser, - OptionGroup, ActionDispatcher, + OptionParser, cleanup, need_update, popen, @@ -608,8 +607,7 @@ def annotate(args): help="Specify is locus IDs in `new.bed` file follow ATG nomenclature", ) - g1 = OptionGroup( - p, + g1 = p.add_argument_group( "Optional parameters (alignment):\n" + "Use if resolving ambiguities based on sequence `alignment`", ) @@ -627,10 +625,8 @@ def annotate(args): type=float, help="Alignment score cutoff", ) - p.add_option_group(g1) - g2 = OptionGroup( - p, + g2 = p.add_argument_group( "Optional parameters (overlap):\n" + "Use if resolving ambiguities based on `overlap` length\n" + "Parameters equivalent to `intersectBed`", @@ -656,7 +652,6 @@ def annotate(args): action="store_true", help="Require same strandedness", ) - p.add_option_group(g2) opts, args = p.parse_args(args) diff --git a/jcvi/apps/base.py b/jcvi/apps/base.py index 8896846a..bbaa17ad 100644 --- a/jcvi/apps/base.py +++ b/jcvi/apps/base.py @@ -151,7 +151,7 @@ class OptionParser(ArgumentParser): features. """ - def __init__(self, doc: str): + def __init__(self, doc: Optional[str]): super(OptionParser, self).__init__(doc, epilog=JCVIHELP) def add_option(self, *args, **kwargs): @@ -189,9 +189,6 @@ def add_help_from_choices(self, o): help_pf = help_pf.rsplit("[", 1)[0] help_pf = help_pf.strip() - # for k, v in o.__dict__.items(): - # print(k, v) - if o.type == "choice": if o.default is None: default_tag = "guess" diff --git a/jcvi/assembly/allmaps.py b/jcvi/assembly/allmaps.py index fae00648..501f2a9b 100644 --- a/jcvi/assembly/allmaps.py +++ b/jcvi/assembly/allmaps.py @@ -29,9 +29,8 @@ from ..algorithms.matrix import determine_signs from ..apps.base import ( ActionDispatcher, - OptionGroup, OptionParser, - SUPPRESS_HELP, + SUPPRESS, cleanup, flatten, get_today, @@ -1358,8 +1357,8 @@ def path(args): """ oargs = args p = OptionParser(path.__doc__) - p.add_option("-b", "--bedfile", help=SUPPRESS_HELP) - p.add_option("-s", "--fastafile", help=SUPPRESS_HELP) + p.add_option("-b", "--bedfile", help=SUPPRESS) + p.add_option("-s", "--fastafile", help=SUPPRESS) p.add_option( "-w", "--weightsfile", default="weights.txt", help="Use weights from file" ) @@ -1411,8 +1410,7 @@ def path(args): ) p.set_cpus(cpus=16) - q = OptionGroup(p, "Genetic algorithm options") - p.add_option_group(q) + q = p.add_argument_group("Genetic algorithm options") q.add_option( "--ngen", default=500, type=int, help="Iterations in GA, higher ~ slower" ) diff --git a/jcvi/compara/synfind.py b/jcvi/compara/synfind.py index 9904087c..b413e477 100755 --- a/jcvi/compara/synfind.py +++ b/jcvi/compara/synfind.py @@ -35,7 +35,7 @@ from jcvi.compara.synteny import check_beds, read_blast from jcvi.utils.grouper import Grouper from jcvi.formats.base import must_open -from jcvi.apps.base import OptionParser, OptionGroup +from jcvi.apps.base import OptionParser def transposed(data): @@ -247,12 +247,12 @@ def main(blastfile, p, opts): p.set_stripnames() p.set_outfile() - coge_group = OptionGroup(p, "CoGe-specific options") + coge_group = p.add_argument_group("CoGe-specific options") coge_group.add_option("--sqlite", help="Write sqlite database") coge_group.add_option("--qnote", default="null", help="Query dataset group id") coge_group.add_option("--snote", default="null", help="Subject dataset group id") - params_group = OptionGroup(p, "Synteny parameters") + params_group = p.add_argument_group("Synteny parameters") params_group.add_option( "--window", type=int, default=40, help="Synteny window size" ) @@ -270,9 +270,6 @@ def main(blastfile, p, opts): help="Scoring scheme", ) - p.add_option_group(coge_group) - p.add_option_group(params_group) - opts, args = p.parse_args() if len(args) != 1: diff --git a/jcvi/formats/agp.py b/jcvi/formats/agp.py index 61c837bc..c91d6b14 100644 --- a/jcvi/formats/agp.py +++ b/jcvi/formats/agp.py @@ -27,7 +27,6 @@ from jcvi.utils.range import range_intersect from jcvi.apps.base import ( OptionParser, - OptionGroup, ActionDispatcher, cleanup, flatten, @@ -1765,8 +1764,7 @@ def bed(args): help="Generate bed file for components", ) p.set_outfile() - g1 = OptionGroup( - p, + g1 = p.add_argument_group( "GFF specific parameters", "Note: If not specified, output will be in `bed` format", ) @@ -1782,7 +1780,6 @@ def bed(args): default="golden_path_fragment", help="Specify a gff3 feature type", ) - p.add_option_group(g1) p.set_SO_opts() opts, args = p.parse_args(args) diff --git a/jcvi/formats/gff.py b/jcvi/formats/gff.py index 1fceda34..4259896b 100644 --- a/jcvi/formats/gff.py +++ b/jcvi/formats/gff.py @@ -11,7 +11,6 @@ from ..apps.base import ( OptionParser, - OptionGroup, ActionDispatcher, cleanup, flatten, @@ -1170,7 +1169,7 @@ def filter(args): p.add_option( "--type", default="mRNA", help="The feature to scan for the attributes" ) - g1 = OptionGroup(p, "Filter by identity/coverage attribute values") + g1 = p.add_argument_group("Filter by identity/coverage attribute values") g1.add_option("--id", default=95, type=float, help="Minimum identity") g1.add_option("--coverage", default=90, type=float, help="Minimum coverage") g1.add_option( @@ -1179,8 +1178,7 @@ def filter(args): action="store_true", help="Case insensitive lookup of attribute names", ) - p.add_option_group(g1) - g2 = OptionGroup(p, "Filter by child feature bp length") + g2 = p.add_argument_group("Filter by child feature bp length") g2.add_option( "--child_ftype", default=None, type=str, help="Child featuretype to consider" ) @@ -1190,7 +1188,6 @@ def filter(args): type=int, help="Filter by total bp of children of chosen ftype", ) - p.add_option_group(g2) p.set_outfile() opts, args = p.parse_args(args) @@ -1549,7 +1546,7 @@ def format(args): p = OptionParser(format.__doc__) - g1 = OptionGroup(p, "Parameter(s) used to modify GFF attributes (9th column)") + g1 = p.add_argument_group("Parameter(s) used to modify GFF attributes (9th column)") g1.add_option("--name", help="Add Name attribute from two-column file") g1.add_option("--note", help="Add Note attribute from two-column file") g1.add_option( @@ -1597,9 +1594,8 @@ def format(args): action="store_true", help="Do not maintain attribute order", ) - p.add_option_group(g1) - g2 = OptionGroup(p, "Parameter(s) used to modify content within columns 1-8") + g2 = p.add_argument_group("Parameter(s) used to modify content within columns 1-8") g2.add_option( "--seqid", help="Switch seqid from two-column file. If not" @@ -1621,10 +1617,9 @@ def format(args): action="store_true", help="Change phase 1<->2, 2<->1", ) - p.add_option_group(g2) - g3 = OptionGroup( - p, "Other parameter(s) to perform manipulations to the GFF " + "file content" + g3 = p.add_argument_group( + "Other parameter(s) to perform manipulations to the GFF file content" ) g3.add_option( "--unique", default=False, action="store_true", help="Make IDs unique" @@ -1678,7 +1673,6 @@ def format(args): action="store_true", help="Store entire GFF file in memory during first iteration", ) - p.add_option_group(g3) p.set_outfile() p.set_SO_opts() @@ -3250,7 +3244,7 @@ def load(args): help="Specify if full FASTA header (with seqid, coordinates and datestamp) should be generated", ) - g1 = OptionGroup(p, "Optional parameters (if generating full header)") + g1 = p.add_argument_group("Optional parameters (if generating full header)") g1.add_option( "--sep", dest="sep", @@ -3269,7 +3263,6 @@ def load(args): action="store_true", help="Specify if `conf_class` attribute should be parsed and placed in the header", ) - p.add_option_group(g1) p.set_outfile() diff --git a/jcvi/graphics/grabseeds.py b/jcvi/graphics/grabseeds.py index ae4f179f..310bd8f0 100644 --- a/jcvi/graphics/grabseeds.py +++ b/jcvi/graphics/grabseeds.py @@ -40,9 +40,8 @@ ) from ..algorithms.formula import get_kmeans, reject_outliers from ..apps.base import ( - OptionParser, - OptionGroup, ActionDispatcher, + OptionParser, datadir, logger, iglob, @@ -268,7 +267,7 @@ def add_seeds_options(p, args): """ Add options to the OptionParser for seeds() and batchseeds() functions. """ - g1 = OptionGroup(p, "Image manipulation") + g1 = p.add_argument_group("Image manipulation") g1.add_option("--rotate", default=0, type=int, help="Rotate degrees clockwise") g1.add_option( "--rows", default=":", help="Crop rows e.g. `:800` from first 800 rows" @@ -285,9 +284,8 @@ def add_seeds_options(p, args): choices=valid_colors, help="Changes background color", ) - p.add_option_group(g1) - g2 = OptionGroup(p, "Object recognition") + g2 = p.add_argument_group("Object recognition") g2.add_option( "--minsize", default=0.05, @@ -304,9 +302,8 @@ def add_seeds_options(p, args): action="store_true", help="Run watershed to segment touching objects", ) - p.add_option_group(g2) - g3 = OptionGroup(p, "De-noise") + g3 = p.add_argument_group("De-noise") valid_filters = ("canny", "roberts", "sobel") g3.add_option( "--filter", @@ -329,9 +326,8 @@ def add_seeds_options(p, args): g3.add_option( "--border", default=5, type=int, help="Remove image border of certain pixels" ) - p.add_option_group(g3) - g4 = OptionGroup(p, "Output") + g4 = p.add_argument_group("Output") g4.add_option("--calibrate", help="JSON file to correct distance and color") g4.add_option( "--edges", @@ -346,7 +342,6 @@ def add_seeds_options(p, args): g4.add_option( "--noheader", default=False, action="store_true", help="Do not print header" ) - p.add_option_group(g4) opts, args, iopts = p.set_image_options(args, figsize="12x6", style="white") return opts, args, iopts