Skip to content

Commit

Permalink
Remove all OptionGroup
Browse files Browse the repository at this point in the history
  • Loading branch information
tanghaibao committed May 1, 2024
1 parent 37e4bd7 commit b65bbbd
Show file tree
Hide file tree
Showing 7 changed files with 24 additions and 52 deletions.
11 changes: 3 additions & 8 deletions jcvi/annotation/reformat.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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`",
)
Expand All @@ -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`",
Expand All @@ -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)

Expand Down
5 changes: 1 addition & 4 deletions jcvi/apps/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down Expand Up @@ -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"
Expand Down
10 changes: 4 additions & 6 deletions jcvi/assembly/allmaps.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,8 @@
from ..algorithms.matrix import determine_signs
from ..apps.base import (
ActionDispatcher,
OptionGroup,
OptionParser,
SUPPRESS_HELP,
SUPPRESS,
cleanup,
flatten,
get_today,
Expand Down Expand Up @@ -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"
)
Expand Down Expand Up @@ -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"
)
Expand Down
9 changes: 3 additions & 6 deletions jcvi/compara/synfind.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down Expand Up @@ -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"
)
Expand All @@ -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:
Expand Down
5 changes: 1 addition & 4 deletions jcvi/formats/agp.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@
from jcvi.utils.range import range_intersect
from jcvi.apps.base import (
OptionParser,
OptionGroup,
ActionDispatcher,
cleanup,
flatten,
Expand Down Expand Up @@ -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",
)
Expand All @@ -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)
Expand Down
21 changes: 7 additions & 14 deletions jcvi/formats/gff.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@

from ..apps.base import (
OptionParser,
OptionGroup,
ActionDispatcher,
cleanup,
flatten,
Expand Down Expand Up @@ -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(
Expand All @@ -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"
)
Expand All @@ -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)
Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -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"
Expand All @@ -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"
Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -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",
Expand All @@ -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()

Expand Down
15 changes: 5 additions & 10 deletions jcvi/graphics/grabseeds.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,8 @@
)
from ..algorithms.formula import get_kmeans, reject_outliers
from ..apps.base import (
OptionParser,
OptionGroup,
ActionDispatcher,
OptionParser,
datadir,
logger,
iglob,
Expand Down Expand Up @@ -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"
Expand All @@ -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,
Expand All @@ -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",
Expand All @@ -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",
Expand All @@ -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
Expand Down

0 comments on commit b65bbbd

Please sign in to comment.