Exemplo n.º 1
0
def build_parser():
    """
    Building argument parser

    :return argparse.ArgumentParser
    """
    banner = "%(prog)s - API for sequence collections"
    additional_description = "For subcommand-specific options, type: '%(prog)s <subcommand> -h'"
    additional_description += "\nhttps://github.com/regenie/seqcolapi"

    parser = VersionInHelpParser(prog=PKG_NAME,
                                 description=banner,
                                 epilog=additional_description)

    parser.add_argument("-V",
                        "--version",
                        action="version",
                        version="%(prog)s {v}".format(v=seqcolapi_version))

    msg_by_cmd = {"serve": "run the server"}

    subparsers = parser.add_subparsers(dest="command")

    def add_subparser(cmd, description):
        return subparsers.add_parser(cmd,
                                     description=description,
                                     help=description)

    sps = {}
    # add arguments that are common for all subparsers
    for cmd, desc in msg_by_cmd.items():
        sps[cmd] = add_subparser(cmd, desc)
        sps[cmd].add_argument('-c',
                              '--config',
                              required=True,
                              dest="config",
                              help="Path to the seqcolapi config file (YAML).")
        sps[cmd].add_argument("-d",
                              "--dbg",
                              action="store_true",
                              dest="debug",
                              help="Set logger verbosity to debug")
    # add subparser-specific arguments
    sps["serve"].add_argument("-p",
                              "--port",
                              dest="port",
                              type=int,
                              help="The port the webserver should be run on.",
                              default=None)
    return parser
Exemplo n.º 2
0
def build_argparser():
    # TODO: add cli hooks for ^
    """
    Builds argument parser.

    :return argparse.ArgumentParser
    """
    banner = "%(prog)s - Keeper of druids: " \
             "a python interface to Decomposable Recursive UIDs"
    additional_description = "\n..."
    parser = VersionInHelpParser(version=__version__,
                                 description=banner,
                                 epilog=additional_description)

    parser.add_argument("-V",
                        "--version",
                        action="version",
                        version="%(prog)s {v}".format(v=__version__))

    parser.add_argument("-i",
                        "--input",
                        required=True,
                        help="File path to input file.")

    parser.add_argument("-p",
                        "--parameter",
                        type=int,
                        default=0,
                        help="Some parameter.")

    return parser
Exemplo n.º 3
0
def build_argparser():
    banner = "%(prog)s - Interact with PEPs"
    additional_description = "\nhttp://eido.databio.org/"

    parser = VersionInHelpParser(
            prog=PKG_NAME,
            description=banner,
            epilog=additional_description,
            version=__version__)

    subparsers = parser.add_subparsers(dest="command")
    parser.add_argument(
            "--verbosity", dest="verbosity",
            type=int, choices=range(len(_LEVEL_BY_VERBOSITY)),
            help="Choose level of verbosity (default: %(default)s)")
    parser.add_argument(
            "--logging-level", dest="logging_level",
            help="logging level")
    parser.add_argument(
            "--dbg", dest="dbg", action="store_true",
            help="Turn on debug mode (default: %(default)s)")
    sps = {}

    SUBPARSER_MSGS = {
        "convert": "Convert a PEP using an available filter",
        "list": "List available filters"
    }

    for cmd, desc in SUBPARSER_MSGS.items():
        sps[cmd] = subparsers.add_parser(cmd, description=desc, help=desc)

    sps["convert"].add_argument('pep', metavar="PEP",
                              help="Path to a PEP configuration "
                                   "file in yaml format.")

    sps["convert"].add_argument(
        "-f", "--format", required=True, default="yaml",
        help="Path to a PEP schema file in yaml format.")


    sps["convert"].add_argument(
        "-n", "--sample-name", required=False, nargs="+",
        help="Name of the samples to inspect.")

    return parser
Exemplo n.º 4
0
def build_parser():
    """
    Building argument parser
    :return argparse.ArgumentParser
    """
    banner = "%(prog)s - PEP web server"
    additional_description = (
        "For subcommand-specific options, type: '%(prog)s <subcommand> -h'")
    additional_description += "\nhttps://github.com/pepkit/pepserver"

    parser = VersionInHelpParser(prog=PKG_NAME,
                                 description=banner,
                                 epilog=additional_description)

    parser.add_argument("-V",
                        "--version",
                        action="version",
                        version="%(prog)s {v}".format(v=v))

    msg_by_cmd = {"serve": "run the server"}

    subparsers = parser.add_subparsers(dest="command")

    def add_subparser(cmd, description):
        return subparsers.add_parser(cmd,
                                     description=description,
                                     help=description)

    sps = {}
    # add arguments that are common for both subparsers
    for cmd, desc in msg_by_cmd.items():
        sps[cmd] = add_subparser(cmd, desc)
        sps[cmd].add_argument(
            "-c",
            "--config",
            required=False,
            dest="config",
            help=f"A path to the pepserver config file",
        ),
        sps[cmd].add_argument(
            "-d",
            "--dbg",
            action="store_true",
            dest="debug",
            help="Set logger verbosity to debug",
        )

    sps["serve"].add_argument(
        "-p",
        "--port",
        dest="port",
        type=int,
        help="The port the webserver should be run on.",
        default=DEFAULT_PORT,
    )

    sps["serve"].add_argument("-r",
                              "--reload",
                              action="store_true",
                              default=False,
                              help="Live reloading with uvicorn")

    return parser
Exemplo n.º 5
0
def build_argparser():
    """
    Builds argument parser.

    :return argparse.ArgumentParser
    """

    banner = "%(prog)s - reference genome asset manager"
    additional_description = "\nhttps://refgenie.databio.org"

    parser = VersionInHelpParser(prog="refgenie",
                                 version=__version__,
                                 description=banner,
                                 epilog=additional_description)

    subparsers = parser.add_subparsers(dest="command")

    def add_subparser(cmd, description):
        return subparsers.add_parser(cmd,
                                     description=description,
                                     help=description)

    sps = {}
    for cmd, desc in SUBPARSER_MESSAGES.items():
        sps[cmd] = add_subparser(cmd, desc)
        # It's required for init
        sps[cmd].add_argument(
            '-c',
            '--genome-config',
            required=(cmd == INIT_CMD),
            dest="genome_config",
            help=
            "Path to local genome configuration file. Optional if {} environment variable is set."
            .format(", ".join(refgenconf.CFG_ENV_VARS)))

    sps[INIT_CMD].add_argument(
        '-s',
        '--genome-server',
        nargs='+',
        default=DEFAULT_SERVER,
        help="URL(s) to use for the {} attribute in config file. Default: {}.".
        format(DEFAULT_SERVER, CFG_SERVERS_KEY))
    sps[BUILD_CMD] = pypiper.add_pypiper_args(
        sps[BUILD_CMD], groups=None, args=["recover", "config", "new-start"])

    # Add any arguments specific to subcommands.

    sps[BUILD_CMD].add_argument(
        '--tag-description',
        required=False,
        default=None,
        type=str,
        help="Add tag level description (e.g. built with version 0.3.2).")

    sps[BUILD_CMD].add_argument(
        '--genome-description',
        required=False,
        default=None,
        type=str,
        help=
        "Add genome level description (e.g. The mouse mitochondrial genome, released in Dec 2013)."
    )

    sps[BUILD_CMD].add_argument(
        "-d",
        "--docker",
        action="store_true",
        help="Run all commands in the refgenie docker container.")

    sps[BUILD_CMD].add_argument(
        '--assets',
        nargs="+",
        action='append',
        required=False,
        default=None,
        help='Override the default genome, asset and tag of the parents'
        ' (e.g. fasta=hg38/fasta:default gtf=mm10/gencode_gtf:default).')

    sps[BUILD_CMD].add_argument(
        '--files',
        nargs="+",
        action='append',
        required=False,
        default=None,
        help=
        'Provide paths to the required files (e.g. fasta=/path/to/file.fa.gz).'
    )

    sps[BUILD_CMD].add_argument(
        '--params',
        nargs="+",
        action='append',
        required=False,
        default=None,
        help='Provide required parameter values (e.g. param1=value1).')

    sps[BUILD_CMD].add_argument(
        '-v',
        '--volumes',
        nargs="+",
        required=False,
        default=None,
        help='If using docker, also mount these folders as volumes.')

    sps[BUILD_CMD].add_argument(
        '-o',
        '--outfolder',
        dest='outfolder',
        required=False,
        default=None,
        help='Override the default path to genomes folder, which is the '
        'genome_folder attribute in the genome configuration file.')

    sps[BUILD_CMD].add_argument(
        "-q",
        "--requirements",
        action="store_true",
        help="Show the build requirements for the specified asset and exit.")

    sps[BUILD_CMD].add_argument("-r",
                                "--recipe",
                                required=False,
                                default=None,
                                type=str,
                                help="Provide a recipe to use.")

    # add 'genome' argument to many commands
    for cmd in [
            PULL_CMD, GET_ASSET_CMD, BUILD_CMD, INSERT_CMD, REMOVE_CMD,
            GETSEQ_CMD, TAG_CMD, ID_CMD
    ]:
        # genome is not required for listing actions
        sps[cmd].add_argument("-g",
                              "--genome",
                              required=cmd in GETSEQ_CMD,
                              help="Reference assembly ID, e.g. mm10.")

    for cmd in LIST_REMOTE_CMD, LIST_LOCAL_CMD:
        sps[cmd].add_argument("-g",
                              "--genome",
                              required=False,
                              type=str,
                              nargs="*",
                              help="Reference assembly ID, e.g. mm10.")

    for cmd in [
            PULL_CMD, GET_ASSET_CMD, BUILD_CMD, INSERT_CMD, REMOVE_CMD,
            TAG_CMD, ID_CMD
    ]:
        sps[cmd].add_argument(
            "asset_registry_paths",
            metavar="asset-registry-paths",
            type=str,
            nargs='+',
            help=
            "One or more registry path strings that identify assets  (e.g. hg38/fasta or hg38/fasta:tag"
            + (" or hg38/fasta.fai:tag)." if cmd == GET_ASSET_CMD else ")."))

    for cmd in [PULL_CMD, REMOVE_CMD, INSERT_CMD]:
        sps[cmd].add_argument(
            "-f",
            "--force",
            action="store_true",
            help="Do not prompt before action, approve upfront.")

    sps[PULL_CMD].add_argument("-u",
                               "--no-untar",
                               action="store_true",
                               help="Do not extract tarballs.")

    sps[INSERT_CMD].add_argument("-p",
                                 "--path",
                                 required=True,
                                 help="Relative local path to asset.")

    sps[GETSEQ_CMD].add_argument(
        "-l",
        "--locus",
        required=True,
        help="Coordinates of desired sequence; e.g. 'chr1:50000-50200'.")

    sps[GET_ASSET_CMD].add_argument(
        "-e",
        "--check-exists",
        required=False,
        action="store_true",
        help="Whether the returned asset path should be checked for existence "
        "on disk.")

    group = sps[TAG_CMD].add_mutually_exclusive_group(required=True)

    group.add_argument("-t",
                       "--tag",
                       type=str,
                       help="Tag to assign to an asset.")

    group.add_argument("-d",
                       "--default",
                       action="store_true",
                       help="Set the selected asset tag as the default one.")

    sps[SUBSCRIBE_CMD].add_argument(
        "-r",
        "--reset",
        action="store_true",
        help="Overwrite the current list of server URLs.")

    for cmd in [SUBSCRIBE_CMD, UNSUBSCRIBE_CMD]:
        sps[cmd].add_argument(
            "-s",
            "--genome-server",
            nargs='+',
            required=True,
            help=
            "One or more URLs to {action} the {key} attribute in config file.".
            format(action="add to" if cmd == SUBSCRIBE_CMD else "remove from",
                   key=CFG_SERVERS_KEY))

    return parser
Exemplo n.º 6
0
def build_argparser(desc):
    """
    Builds argument parser.
    :param str desc: additional description to print in help
    :return argparse.ArgumentParser
    """
    banner = "%(prog)s - report pipeline results"
    additional_description = desc
    parser = VersionInHelpParser(version=__version__,
                                 description=banner,
                                 epilog=additional_description)

    subparsers = parser.add_subparsers(dest="command")

    def add_subparser(cmd, msg, subparsers):
        return subparsers.add_parser(
            cmd,
            description=msg,
            help=msg,
            formatter_class=lambda prog: argparse.HelpFormatter(
                prog, max_help_position=40, width=90),
        )

    sps = {}
    # common arguments
    for cmd in SUBPARSER_MSGS.keys():
        sps[cmd] = add_subparser(cmd, SUBPARSER_MSGS[cmd], subparsers)
        # status is nested and status subcommands require config path
        if cmd == STATUS_CMD:
            continue
        sps[cmd].add_argument(
            "-n",
            "--namespace",
            type=str,
            metavar="N",
            help=
            f"Name of the pipeline to report result for. {_env_txt('namespace')}",
        )

    status_subparser = sps[STATUS_CMD]
    status_subparsers = status_subparser.add_subparsers(dest="subcommand")

    status_sps = {}
    for cmd, desc in STATUS_SUBPARSER_MESSAGES.items():
        status_sps[cmd] = add_subparser(cmd, desc, status_subparsers)
        status_sps[cmd].add_argument(
            "-n",
            "--namespace",
            type=str,
            metavar="N",
            help=
            f"Name of the pipeline to report result for. {_env_txt('namespace')}",
        )
        if cmd == STATUS_SET_CMD:
            status_sps[cmd].add_argument(
                "status_identifier",
                help="Status identifier to set.",
            )
        status_sps[cmd].add_argument(
            "-f",
            "--results-file",
            type=str,
            metavar="F",
            help=f"Path to the YAML file where the results will be stored. "
            f"This file will be used as {PKG_NAME} backend and to restore"
            f" the reported results across sessions",
        )
        status_sps[cmd].add_argument(
            "-c",
            "--config",
            type=str,
            metavar="C",
            help=f"Path to the YAML configuration file. {_env_txt('config')}",
        )
        status_sps[cmd].add_argument(
            "-a",
            "--database-only",
            action="store_true",
            help="Whether the reported data should not be stored in the memory,"
            " only in the database.",
        )
        status_sps[cmd].add_argument(
            "-s",
            "--schema",
            type=str,
            metavar="S",
            help=
            f"Path to the schema that defines the results that can be reported. {_env_txt('schema')}",
        )
        status_sps[cmd].add_argument(
            "--status-schema",
            type=str,
            metavar="ST",
            help=f"Path to the status schema. "
            f"Default will be used if not provided: {STATUS_SCHEMA}",
        )
        status_sps[cmd].add_argument(
            "--flag-dir",
            type=str,
            metavar="FD",
            help=f"Path to the flag directory in case YAML file is "
            f"the pipestat backend.",
        )
        status_sps[cmd].add_argument(
            "-r",
            "--record-identifier",
            type=str,
            metavar="R",
            help=
            f"ID of the record to report the result for. {_env_txt('record_identifier')}",
        )

    # remove, report and inspect
    for cmd in [REMOVE_CMD, REPORT_CMD, INSPECT_CMD, RETRIEVE_CMD]:
        sps[cmd].add_argument(
            "-f",
            "--results-file",
            type=str,
            metavar="F",
            help=f"Path to the YAML file where the results will be stored. "
            f"This file will be used as {PKG_NAME} backend and to restore"
            f" the reported results across sessions",
        )
        sps[cmd].add_argument(
            "-c",
            "--config",
            type=str,
            metavar="C",
            help=f"Path to the YAML configuration file. {_env_txt('config')}",
        )
        sps[cmd].add_argument(
            "-a",
            "--database-only",
            action="store_true",
            help="Whether the reported data should not be stored in the memory,"
            " only in the database.",
        )
        sps[cmd].add_argument(
            "-s",
            "--schema",
            type=str,
            metavar="S",
            help=
            f"Path to the schema that defines the results that can be reported. {_env_txt('schema')}",
        )
        sps[cmd].add_argument(
            "--status-schema",
            type=str,
            metavar="ST",
            help=f"Path to the status schema. "
            f"Default will be used if not provided: {STATUS_SCHEMA}",
        )
        sps[cmd].add_argument(
            "--flag-dir",
            type=str,
            metavar="FD",
            help=f"Path to the flag directory in case YAML file is "
            f"the pipestat backend.",
        )

    # remove and report
    for cmd in [REMOVE_CMD, REPORT_CMD, RETRIEVE_CMD]:
        sps[cmd].add_argument(
            "-i",
            "--result-identifier",
            required=True,
            type=str,
            metavar="I",
            help=
            "ID of the result to report; needs to be defined in the schema",
        )
        sps[cmd].add_argument(
            "-r",
            "--record-identifier",
            type=str,
            metavar="R",
            help=
            f"ID of the record to report the result for. {_env_txt('record_identifier')}",
        )

    # report
    sps[REPORT_CMD].add_argument(
        "-v",
        "--value",
        required=True,
        metavar="V",
        help="Value of the result to report",
    )

    sps[REPORT_CMD].add_argument(
        "-o",
        "--overwrite",
        action="store_true",
        help="Whether the result should override existing ones in "
        "case of name clashes",
    )

    sps[REPORT_CMD].add_argument(
        "-t",
        "--skip-convert",
        action="store_true",
        help="Whether skip result type conversion into the reqiuired "
        "class in case it does not meet the schema requirements",
    )

    # inspect
    sps[INSPECT_CMD].add_argument("-d",
                                  "--data",
                                  action="store_true",
                                  help="Whether to display the data")

    return parser
Exemplo n.º 7
0
def build_parser():
    """
    Building argument parser.

    :return argparse.ArgumentParser
    """
    # Main looper program help text messages
    banner = "%(prog)s - A project job submission engine and project manager."
    additional_description = "For subcommand-specific options, " \
                             "type: '%(prog)s <subcommand> -h'"
    additional_description += "\nhttps://github.com/pepkit/looper"

    parser = VersionInHelpParser(
        prog="looper", description=banner, epilog=additional_description,
        version=__version__)

    aux_parser = VersionInHelpParser(
        prog="looper", description=banner, epilog=additional_description,
        version=__version__)
    result = []
    for parser in [parser, aux_parser]:
        # Logging control
        parser.add_argument(
                "--logfile", help="Optional output file for looper logs "
                                  "(default: %(default)s)")
        parser.add_argument(
                "--verbosity", type=int, choices=range(len(_LEVEL_BY_VERBOSITY)),
                help="Choose level of verbosity (default: %(default)s)")
        parser.add_argument(
                "--logging-level", help=argparse.SUPPRESS)
        parser.add_argument(
                "--dbg", action="store_true",
                help="Turn on debug mode (default: %(default)s)")
        # Individual subcommands
        msg_by_cmd = {
                "run": "Run or submit sample jobs.",
                "rerun": "Resubmit sample jobs with failed flags.",
                "runp": "Run or submit project jobs.",
                "table": "Write summary stats table for project samples.",
                "report": "Create browsable HTML report of project results.",
                "destroy": "Remove output files of the project.",
                "check": "Check flag status of current runs.",
                "clean": "Run clean scripts of already processed jobs.",
                "inspect": "Print information about a project.",
                "init": "Initialize looper dotfile."
        }

        subparsers = parser.add_subparsers(dest="command")

        def add_subparser(cmd):
            message = msg_by_cmd[cmd]
            return subparsers.add_parser(cmd, description=message, help=message,
                formatter_class=lambda prog: argparse.HelpFormatter(
                    prog, max_help_position=37, width=90))

        # Run and rerun command
        run_subparser = add_subparser("run")
        rerun_subparser = add_subparser("rerun")
        collate_subparser = add_subparser("runp")
        table_subparser = add_subparser("table")
        report_subparser = add_subparser("report")
        destroy_subparser = add_subparser("destroy")
        check_subparser = add_subparser("check")
        clean_subparser = add_subparser("clean")
        inspect_subparser = add_subparser("inspect")
        init_subparser = add_subparser("init")

        # Flag arguments
        ####################################################################
        for subparser in [run_subparser, rerun_subparser, collate_subparser]:
            subparser.add_argument(
                    "-i", "--ignore-flags", default=False,
                    action=_StoreBoolActionType, type=html_checkbox(checked=False),
                    help="Ignore run status flags? Default=False")

        for subparser in [run_subparser, rerun_subparser, destroy_subparser,
                          clean_subparser, collate_subparser]:
            subparser.add_argument(
                    "-d", "--dry-run",
                    action=_StoreBoolActionType, default=False,
                    type=html_checkbox(checked=False),
                    help="Don't actually submit the jobs.  Default=False")

        # Parameter arguments
        ####################################################################
        for subparser in [run_subparser, rerun_subparser, collate_subparser]:
            subparser.add_argument(
                    "-t", "--time-delay", metavar="S",
                    type=html_range(min_val=0, max_val=30, value=0), default=0,
                    help="Time delay in seconds between job submissions")
            subparser.add_argument(
                    "-l", "--limit", default=None, metavar="N",
                    type=html_range(min_val=1, max_val="num_samples",
                                    value="num_samples"),
                    help="Limit to n samples")
            subparser.add_argument(
                    "-x", "--command-extra", default="",
                    metavar="S", help="String to append to every command")
            subparser.add_argument(
                    "-y", "--command-extra-override", metavar="S", default="",
                    help="Same as command-extra, but overrides values in PEP")
            subparser.add_argument(
                    "-f", "--skip-file-checks",
                    action=_StoreBoolActionType, default=False,
                    type=html_checkbox(checked=False),
                    help="Do not perform input file checks")

            divvy_group = \
                subparser.add_argument_group(
                    "divvy arguments",
                    "Configure divvy to change computing settings")
            divvy_group.add_argument(
                "--divvy", default=None, metavar="DIVCFG",
                help="Path to divvy configuration file. Default=$DIVCFG env "
                     "variable. Currently: {}".format(os.getenv('DIVCFG', None)
                                                      or "not set"))
            divvy_group.add_argument(
                    "-p", "--package", metavar="P",
                    help="Name of computing resource package to use")
            divvy_group.add_argument(
                    "-s", "--settings", default="", metavar="S",
                    help="Path to a YAML settings file with compute settings")
            divvy_group.add_argument(
                    "-c", "--compute", metavar="K", nargs="+",
                    help="List of key-value pairs (k1=v1)")

        for subparser in [run_subparser, rerun_subparser]:
            subparser.add_argument(
                    "-u", "--lump", default=None, metavar="X",
                    type=html_range(min_val=0, max_val=100, step=0.1, value=0),
                    help="Total input file size (GB) to batch into one job")
            subparser.add_argument(
                    "-n", "--lumpn", default=None, metavar="N",
                    type=html_range(min_val=1, max_val="num_samples", value=1),
                    help="Number of commands to batch into one job")

        inspect_subparser.add_argument(
            "-n", "--snames", required=False, nargs="+", metavar="S",
            help="Name of the samples to inspect")
        inspect_subparser.add_argument(
            "-l", "--attr-limit", required=False, type=int, default=10,
            metavar="L", help="Number of sample attributes to display")

        check_subparser.add_argument(
                "-A", "--all-folders", action=_StoreBoolActionType,
                default=False, type=html_checkbox(checked=False),
                help="Check status for all  output folders, not just for "
                     "samples specified in the config. Default=False")
        check_subparser.add_argument(
                "-f", "--flags", nargs='*', default=FLAGS,
                type=html_select(choices=FLAGS), metavar="F",
                help="Check on only these flags/status values")

        for subparser in [destroy_subparser, clean_subparser]:
            subparser.add_argument(
                    "--force-yes", action=_StoreBoolActionType, default=False,
                    type=html_checkbox(checked=False),
                    help="Provide upfront confirmation of destruction intent, "
                         "to skip console query.  Default=False")

        init_subparser.add_argument("config_file", help="Project configuration "
                                                        "file (YAML)")

        init_subparser.add_argument("-f", "--force", help="Force overwrite",
            action="store_true", default=False)

        # Common arguments
        for subparser in [run_subparser, rerun_subparser, table_subparser,
                          report_subparser, destroy_subparser, check_subparser,
                          clean_subparser, collate_subparser, inspect_subparser]:
            subparser.add_argument("config_file", nargs="?", default=None,
                                   help="Project configuration file (YAML)")
            # help="Path to the output directory"
            subparser.add_argument("-o", "--output-dir", metavar="DIR",
                                   help=argparse.SUPPRESS)
            # "Submission subdirectory name"
            subparser.add_argument("--submission-subdir", metavar="DIR",
                                   help=argparse.SUPPRESS)
            # "Results subdirectory name"
            subparser.add_argument("--results-subdir", metavar="DIR",
                                   help=argparse.SUPPRESS)
            # "Sample attribute for pipeline interface sources"
            subparser.add_argument("--pipeline-interfaces-key", metavar="K",
                                   help=argparse.SUPPRESS)
            # "Paths to pipeline interface files"
            subparser.add_argument("--pipeline-interfaces", metavar="P",
                                   nargs="+", action="append",
                                   help=argparse.SUPPRESS)

        for subparser in [run_subparser, rerun_subparser, table_subparser,
                          report_subparser, destroy_subparser, check_subparser,
                          clean_subparser, collate_subparser, inspect_subparser]:
            fetch_samples_group = \
                subparser.add_argument_group(
                    "sample selection arguments",
                    "Specify samples to include or exclude based on sample attribute values")
            fetch_samples_group.add_argument(
                "-g", "--toggle-key", metavar="K",
                help="Sample attribute specifying toggle. Default: toggle")
            fetch_samples_group.add_argument(
                "--sel-attr", default="toggle", metavar="ATTR",
                help="Attribute for sample exclusion OR inclusion")
            protocols = fetch_samples_group.add_mutually_exclusive_group()
            protocols.add_argument(
                    "--sel-excl", nargs='*', metavar="E",
                    help="Exclude samples with these values")
            protocols.add_argument(
                    "--sel-incl", nargs='*', metavar="I",
                    help="Include only samples with these values")
            subparser.add_argument(
                    "-a", "--amend", nargs="+", metavar="A",
                    help="List of amendments to activate")
        result.append(parser)
    return result
Exemplo n.º 8
0
def build_argparser(desc):
    """
    Builds argument parser.

    :param str desc: additional description to print in help
    :return argparse.ArgumentParser
    """
    banner = "%(prog)s - report pipeline results"
    additional_description = desc
    parser = VersionInHelpParser(version=__version__,
                                 description=banner,
                                 epilog=additional_description)
    subparsers = parser.add_subparsers(dest="command")
    sps = {}
    # common arguments
    for cmd, desc in SUBPARSER_MSGS.items():
        sps[cmd] = subparsers.add_parser(cmd, description=desc, help=desc)
        sps[cmd].add_argument("-n",
                              "--namespace",
                              required=True,
                              type=str,
                              metavar="N",
                              help="Name of the pipeline to report result for")

    # remove, report and inspect
    for cmd in [REMOVE_CMD, REPORT_CMD, INSPECT_CMD, RETRIEVE_CMD]:
        storage_group = sps[cmd].add_mutually_exclusive_group(required=True)
        storage_group.add_argument(
            "-f",
            "--results-file",
            type=str,
            metavar="F",
            help=f"Path to the YAML file where the results will be stored. "
            f"This file will be used as {PKG_NAME} backend and to restore"
            f" the reported results across sesssions")
        storage_group.add_argument(
            "-c",
            "--database-config",
            type=str,
            metavar="C",
            help=f"Path to the YAML file with PostgreSQL database "
            f"configuration. Please refer to the documentation for the "
            f"file format requirements.")
        sps[cmd].add_argument("-s",
                              "--schema",
                              required=True if cmd == REPORT_CMD else False,
                              type=str,
                              metavar="S",
                              help="Path to the schema that defines the "
                              "results that can be eported")

    # remove and report
    for cmd in [REMOVE_CMD, REPORT_CMD, RETRIEVE_CMD]:
        sps[cmd].add_argument(
            "-i",
            "--result-identifier",
            required=True,
            type=str,
            metavar="I",
            help="ID of the result to report; needs to be defined in the schema"
        )
        sps[cmd].add_argument("-r",
                              "--record-identifier",
                              required=True,
                              type=str,
                              metavar="R",
                              help="ID of the record to report the result for")

    # report
    sps[REPORT_CMD].add_argument("-v",
                                 "--value",
                                 required=True,
                                 metavar="V",
                                 help="Value of the result to report")

    sps[REPORT_CMD].add_argument(
        "-o",
        "--overwrite",
        action="store_true",
        help="Whether the result should override existing ones in "
        "case of name clashes")

    sps[REPORT_CMD].add_argument(
        "-t",
        "--try-convert",
        action="store_true",
        help="Whether to try to convert the reported value into reqiuired "
        "class in case it does not meet the schema requirements")

    # inspect
    sps[INSPECT_CMD].add_argument("-d",
                                  "--data",
                                  action="store_true",
                                  help="Whether to display the data")

    return parser
Exemplo n.º 9
0
def build_parser():
    """
    Example argument parser, needed solely for testing purposes.
    This example parser was copied from looper/__init__.py

    :return argparse.ArgumentParser
    """

    banner = "%(prog)s - Loop through samples and submit pipelines."
    additional_description = "For subcommand-specific options, " \
                             "type: '%(prog)s <subcommand> -h'"
    additional_description += "\nhttps://github.com/pepkit/looper"

    parser = VersionInHelpParser(prog="looper",
                                 description=banner,
                                 epilog=additional_description,
                                 version=0.1)

    # Logging control
    parser.add_argument(
        "--logfile",
        dest="logfile",
        help="Optional output file for looper logs (default: %(default)s)")
    parser.add_argument(
        "--verbosity",
        dest="verbosity",
        type=int,
        choices=range(4),
        help="Choose level of verbosity (default: %(default)s)")
    parser.add_argument("--logging-level",
                        dest="logging_level",
                        help=argparse.SUPPRESS)
    parser.add_argument("--dbg",
                        dest="dbg",
                        action="store_true",
                        help="Turn on debug mode (default: %(default)s)")
    parser.add_argument(
        "--env",
        dest="env",
        default=None,
        help="Environment variable that points to the DIVCFG file. "
        "(default: DIVCFG)")
    parser.add_argument("--dotfile-template",
                        action="store_true",
                        help="Print out a looper dotfile template and exit")

    # Individual subcommands
    msg_by_cmd = {
        "run":
        "Main Looper function: Submit jobs for samples.",
        "rerun":
        "Resubmit jobs with failed flags.",
        "runp":
        "Submit jobs for a project.",
        "summarize":
        "Summarize statistics of project samples.",
        "destroy":
        "Remove all files of the project.",
        "check":
        "Checks flag status of current runs.",
        "clean":
        "Runs clean scripts to remove intermediate "
        "files of already processed jobs."
    }

    subparsers = parser.add_subparsers(dest="command")

    def add_subparser(cmd):
        message = msg_by_cmd[cmd]
        return subparsers.add_parser(cmd, description=message, help=message)

    # Run and rerun command
    run_subparser = add_subparser("run")
    rerun_subparser = add_subparser("rerun")
    collate_subparser = add_subparser("runp")
    for subparser in [run_subparser, rerun_subparser, collate_subparser]:
        subparser.add_argument(
            "--ignore-flags",
            dest="ignore_flags",
            default=False,
            action="store_true",
            help="Ignore run status flags? Default: False. "
            "By default, pipelines will not be submitted if a pypiper "
            "flag file exists marking the run (e.g. as "
            "'running' or 'failed'). Set this option to ignore flags "
            "and submit the runs anyway. Default=False")
        subparser.add_argument(
            "-t",
            "--time-delay",
            dest="time_delay",
            type=int,
            default=0,
            help="Time delay in seconds between job submissions.")
        subparser.add_argument(
            "-p",
            "--package",
            help="Name of computing resource package to use")
        subparser.add_argument(
            "--compute",
            help="Specification of individual computing resource settings; "
            "separate setting name/key from value with equals sign, "
            "and separate key-value pairs from each other by comma")
        subparser.add_argument("--limit",
                               dest="limit",
                               default=None,
                               type=int,
                               help="Limit to n samples.")
        subparser.add_argument("-a",
                               "--pipeline-args",
                               dest="pipeline_args",
                               default="",
                               help="arguments to pass to a pipline")
        subparser.add_argument(
            "-s",
            "--settings",
            dest="settings",
            default="",
            help="path to a YAML-formatted settings file used to populate "
            "the command template")
    for subparser in [run_subparser, rerun_subparser]:
        # Note that defaults for otherwise numeric lump parameters are
        # set to
        # null by default so that the logic that parses their values may
        # distinguish between explicit 0 and lack of specification.
        subparser.add_argument(
            "--lump",
            default=None,
            type=float,
            help="Maximum total input file size for a lump/batch of "
            "commands in a single job (in GB)")
        subparser.add_argument(
            "--lumpn",
            default=None,
            type=int,
            help="Number of individual scripts grouped into "
            "single submission")

    # Other commands
    summarize_subparser = add_subparser("summarize")
    destroy_subparser = add_subparser("destroy")
    check_subparser = add_subparser("check")
    clean_subparser = add_subparser("clean")

    check_subparser.add_argument(
        "-A",
        "--all-folders",
        action="store_true",
        default=False,
        help="Check status for all project's output folders, not just "
        "those for samples specified in the config file used. "
        "Default=False")

    for subparser in [destroy_subparser, clean_subparser]:
        subparser.add_argument(
            "--force-yes",
            action="store_true",
            default=False,
            help="Provide upfront confirmation of destruction intent, "
            "to skip console query.  Default=False")

    # Common arguments
    for subparser in [
            run_subparser, rerun_subparser, summarize_subparser,
            destroy_subparser, check_subparser, clean_subparser,
            collate_subparser
    ]:
        subparser.add_argument("config_file",
                               nargs="?",
                               help="Project configuration file (YAML).")
        # subparser.add_argument(
        #         "-c", "--config", required=False, default=None,
        #         dest="looper_config", help="Looper configuration file (
        #         YAML).")
        subparser.add_argument("--pipeline-interfaces",
                               dest="pifaces",
                               nargs="+",
                               action='append',
                               help="Path to a pipeline interface file")
        subparser.add_argument("--file-checks",
                               dest="file_checks",
                               action="store_true",
                               help="Perform input file checks. Default=True.")
        subparser.add_argument(
            "-d",
            "--dry-run",
            dest="dry_run",
            action="store_true",
            help="Don't actually submit the jobs.  Default=False")

        fetch_samples_group = subparser.add_argument_group(
            "select samples",
            "This group of arguments lets you specify samples to use by "
            "exclusion OR inclusion of the samples attribute values.")
        fetch_samples_group.add_argument(
            "--selector-attribute",
            dest="selector_attribute",
            default="toggle",
            help="Specify the attribute for samples exclusion OR inclusion")
        protocols = fetch_samples_group.add_mutually_exclusive_group()
        protocols.add_argument(
            "--selector-exclude",
            nargs='*',
            dest="selector_exclude",
            help="Operate only on samples that either lack this attribute "
            "value or for which this value is not in this collection.")
        protocols.add_argument(
            "--selector-include",
            nargs='*',
            dest="selector_include",
            help="Operate only on samples associated with these attribute "
            "values; if not provided, all samples are used.")
        subparser.add_argument(
            "--amendments",
            dest="amendments",
            nargs="+",
            help="Name of amendment(s) to use, as designated in the "
            "project's configuration file")

    return parser, msg_by_cmd
Exemplo n.º 10
0
def parse_arguments():
    """
    Creat parser instance and parse command-line arguments passed to the pipeline

    :return argparse.Namespace: parsed arguments namespace
    """
    parser = VersionInHelpParser(prog="PEPATAC_collator",
                                 description='PEPATAC collator',
                                 version=__version__)
    parser = pypiper.add_pypiper_args(parser, groups=['pypiper', 'looper'])
    parser.add_argument("-n",
                        "--name",
                        help="Name of the project to use.",
                        type=str)
    parser.add_argument("-r",
                        "--results",
                        help="Output results sub directory path.",
                        type=str)
    parser.add_argument("--skip-consensus",
                        action='store_true',
                        dest="skip_consensus",
                        default=False,
                        help="Do not calculate consensus peaks.")
    parser.add_argument("--skip-table",
                        action='store_true',
                        dest="skip_table",
                        default=False,
                        help="Do not calculate peak counts table.")
    args = parser.parse_args()
    return args
Exemplo n.º 11
0
def build_parser():
    """
    Building argument parser

    :return argparse.ArgumentParser
    """
    env_var_val = get_first_env_var(CFG_ENV_VARS)[1] if get_first_env_var(
        CFG_ENV_VARS) is not None else "not set"
    banner = "%(prog)s - refgenie web server utilities"
    additional_description = "For subcommand-specific options, type: '%(prog)s <subcommand> -h'"
    additional_description += "\nhttps://github.com/databio/refgenieserver"

    parser = VersionInHelpParser(prog=PKG_NAME,
                                 description=banner,
                                 epilog=additional_description)

    parser.add_argument("-V",
                        "--version",
                        action="version",
                        version="%(prog)s {v}".format(v=v))

    msg_by_cmd = {
        "serve": "run the server",
        "archive": "prepare servable archives"
    }

    subparsers = parser.add_subparsers(dest="command")

    def add_subparser(cmd, description):
        return subparsers.add_parser(cmd,
                                     description=description,
                                     help=description)

    sps = {}
    # add arguments that are common for both subparsers
    for cmd, desc in msg_by_cmd.items():
        sps[cmd] = add_subparser(cmd, desc)
        sps[cmd].add_argument(
            '-c',
            '--config',
            required=False,
            dest="config",
            help=
            "A path to the refgenie config file (YAML). If not provided, the first available environment variable "
            "among: \'{}\' will be used if set. Currently: {}".format(
                ", ".join(CFG_ENV_VARS), env_var_val))
        sps[cmd].add_argument("-d",
                              "--dbg",
                              action="store_true",
                              dest="debug",
                              help="Set logger verbosity to debug")
    # add subparser-specific arguments
    sps["serve"].add_argument("-p",
                              "--port",
                              dest="port",
                              type=int,
                              help="The port the webserver should be run on.",
                              default=DEFAULT_PORT)
    sps["archive"].add_argument(
        "--genomes-desc",
        dest="genomes_desc",
        type=str,
        default=None,
        help=
        "Path to a CSV file with genomes descriptions. Format: genome_name, genome description"
    )
    sps["archive"].add_argument(
        "-f",
        "--force",
        action="store_true",
        dest="force",
        help="whether the server file tree should be rebuilt even if exists")
    sps["archive"].add_argument(
        "-r",
        "--remove",
        action="store_true",
        dest="remove",
        help="Remove selected genome, genome/asset or genome/asset:tag")
    sps["archive"].add_argument(
        "asset_registry_paths",
        metavar="asset-registry-paths",
        type=str,
        nargs='*',
        help=
        "One or more registry path strings that identify assets, e.g. hg38/fasta:tag"
    )
    return parser
Exemplo n.º 12
0
def build_argparser():
    """
    Builds argument parser.

    :return argparse.ArgumentParser
    """

    banner = "%(prog)s - reference genome asset manager"
    additional_description = "\nhttps://refgenie.databio.org"

    parser = VersionInHelpParser(
        prog="refgenie",
        version=f"{__version__} | refgenconf {rgc_version}",
        description=banner,
        epilog=additional_description,
    )

    subparsers = parser.add_subparsers(dest="command")

    def add_subparser(cmd, msg, subparsers):
        return subparsers.add_parser(
            cmd,
            description=msg,
            help=msg,
            formatter_class=lambda prog: HelpFormatter(
                prog, max_help_position=40, width=90),
        )

    sps = {}
    for cmd, desc in SUBPARSER_MESSAGES.items():
        sps[cmd] = add_subparser(cmd, desc, subparsers)
        # alias is nested and alias subcommands require config path
        if cmd == ALIAS_CMD:
            continue
        # It's required for init
        sps[cmd].add_argument(
            "-c",
            "--genome-config",
            required=(cmd == INIT_CMD),
            dest="genome_config",
            metavar="C",
            help=
            "Path to local genome configuration file. Optional if {} environment variable is set."
            .format(", ".join(CFG_ENV_VARS)),
        )
        sps[cmd].add_argument(
            "--skip-read-lock",
            required=False,
            action="store_true",
            help="Whether the config file should not be locked for reading",
        )

    # upgrade: upgrade config and alter file structure to the target version
    sps[UPGRADE_CMD].add_argument(
        "-v",
        "--target-version",
        required=True,
        metavar="V",
        help="Target config version for the upgrade.",
    )
    sps[UPGRADE_CMD].add_argument(
        "-f",
        "--force",
        action="store_true",
        help="Do not prompt before action, approve upfront.",
    )

    sps[INIT_CMD].add_argument(
        "-s",
        "--genome-server",
        nargs="+",
        default=[DEFAULT_SERVER],
        help=
        f"URL(s) to use for the {CFG_SERVERS_KEY} attribute in config file. Default: {DEFAULT_SERVER}.",
    )
    sps[INIT_CMD].add_argument(
        "-f",
        "--genome-folder",
        help="Absolute path to parent folder refgenie-managed assets.",
    )
    sps[INIT_CMD].add_argument(
        "-a",
        "--genome-archive-folder",
        help=
        "Absolute path to parent archive folder refgenie-managed assets; used by refgenieserver.",
    )
    sps[INIT_CMD].add_argument(
        "-b",
        "--genome-archive-config",
        help=
        "Absolute path to desired archive config file; used by refgenieserver.",
    )
    sps[INIT_CMD].add_argument(
        "-u",
        "--remote-url-base",
        help=
        "URL to use as an alternative, remote archive location; used by refgenieserver.",
    )
    sps[INIT_CMD].add_argument(
        "-j",
        "--settings-json",
        help="Absolute path to a JSON file with the key "
        "value pairs to inialize the configuration "
        "file with. Overwritten by itemized specifications.",
    )
    sps[BUILD_CMD] = pypiper.add_pypiper_args(
        sps[BUILD_CMD], groups=None, args=["recover", "config", "new-start"])

    # Add any arguments specific to subcommands.

    sps[BUILD_CMD].add_argument(
        "--tag-description",
        required=False,
        default=None,
        type=str,
        help="Add tag level description (e.g. built with version 0.3.2).",
    )

    sps[BUILD_CMD].add_argument(
        "--genome-description",
        required=False,
        default=None,
        type=str,
        help=
        "Add genome level description (e.g. The mouse mitochondrial genome, released in Dec 2013).",
    )

    sps[BUILD_CMD].add_argument(
        "-d",
        "--docker",
        action="store_true",
        help="Run all commands in the refgenie docker container.",
    )

    sps[BUILD_CMD].add_argument(
        "--map",
        action="store_true",
        help=
        "Run the map procedure: build assets and store the metadata in separate configs.",
    )

    sps[BUILD_CMD].add_argument(
        "--pull-parents",
        action="store_true",
        help=
        "Automatically pull the default parent asset if required but not provided",
    )

    sps[BUILD_CMD].add_argument(
        "--preserve-map-configs",
        action="store_true",
        help=
        "Do not remove the genome configuration files produced in the potential map step of building",
    )

    sps[BUILD_CMD].add_argument(
        "--reduce",
        action="store_true",
        help=
        "Run the reduce procedure: gather the metadata produced with `refgenie build --map`.",
    )

    sps[BUILD_CMD].add_argument(
        "--assets",
        nargs="+",
        action="append",
        required=False,
        default=None,
        help="Override the default genome, asset and tag of the parents"
        " (e.g. fasta=hg38/fasta:default gtf=mm10/gencode_gtf:default).",
    )

    sps[BUILD_CMD].add_argument(
        "--files",
        nargs="+",
        action="append",
        required=False,
        default=None,
        help=
        "Provide paths to the required files (e.g. fasta=/path/to/file.fa.gz).",
    )

    sps[BUILD_CMD].add_argument(
        "--params",
        nargs="+",
        action="append",
        required=False,
        default=None,
        help="Provide required parameter values (e.g. param1=value1).",
    )

    sps[BUILD_CMD].add_argument(
        "-v",
        "--volumes",
        nargs="+",
        required=False,
        default=None,
        help="If using docker, also mount these folders as volumes.",
    )

    sps[BUILD_CMD].add_argument(
        "-q",
        "--requirements",
        action="store_true",
        help="Show the build requirements for the specified asset and exit.",
    )

    sps[BUILD_CMD].add_argument(
        "-r",
        "--recipe",
        required=False,
        default=None,
        type=str,
        help="Provide a recipe to use.",
    )

    alias_subparser = sps[ALIAS_CMD]
    alias_subsubparsers = alias_subparser.add_subparsers(dest="subcommand")

    alias_sps = {}
    for cmd, desc in ALIAS_SUBPARSER_MESSAGES.items():
        alias_sps[cmd] = add_subparser(cmd, desc, alias_subsubparsers)
        alias_sps[cmd].add_argument(
            "-c",
            "--genome-config",
            required=False,
            dest="genome_config",
            metavar="C",
            help=
            "Path to local genome configuration file. Optional if {} environment variable is set."
            .format(", ".join(CFG_ENV_VARS)),
        )
        alias_sps[cmd].add_argument(
            "--skip-read-lock",
            required=False,
            action="store_true",
            help="Whether the config file should not be locked for reading",
        )

    alias_sps[ALIAS_SET_CMD].add_argument(
        "-a",
        "--aliases",
        metavar="A",
        required=False,
        default=None,
        type=str,
        nargs="+",
        help=
        "Aliases to set; single if the digest is to be retrieved from the server.",
    )
    alias_sps[ALIAS_SET_CMD].add_argument(
        "-d",
        "--digest",
        metavar="D",
        required=False,
        type=str,
        help=
        "Digest to set; leave out if the digest is to be retrieved from the server.",
    )
    alias_sps[ALIAS_SET_CMD].add_argument(
        "-r",
        "--reset",
        action="store_true",
        help=
        "Whether all the aliases should be removed prior to setting new ones.",
    )
    alias_sps[ALIAS_SET_CMD].add_argument(
        "-f",
        "--force",
        action="store_true",
        help="Whether the action should be forced, if genome does not exist.",
    )

    alias_sps[ALIAS_REMOVE_CMD].add_argument(
        "-a",
        "--aliases",
        metavar="A",
        required=False,
        default=None,
        type=str,
        nargs="+",
        help="Aliases to remove.",
    )
    alias_sps[ALIAS_REMOVE_CMD].add_argument("-d",
                                             "--digest",
                                             metavar="D",
                                             required=True,
                                             type=str,
                                             help="Digest to remove.")

    alias_sps[ALIAS_GET_CMD].add_argument(
        "-a",
        "--aliases",
        metavar="A",
        required=False,
        type=str,
        nargs="+",
        help="Aliases to get the digests for.",
    )

    sps[COMPARE_CMD].add_argument(
        "genome1",
        metavar="GENOME1",
        type=str,
        nargs=1,
        help="First genome for compatibility check.",
    )
    sps[COMPARE_CMD].add_argument(
        "genome2",
        metavar="GENOME2",
        type=str,
        nargs=1,
        help="Second genome for compatibility check.",
    )
    sps[COMPARE_CMD].add_argument(
        "-e",
        "--no-explanation",
        action="store_true",
        help="Do not print compatibility code explanation.",
    )
    sps[COMPARE_CMD].add_argument(
        "-f",
        "--flag-meanings",
        action="store_true",
        help="Display compatibility flag meanings.",
    )

    # add 'genome' argument to many commands
    for cmd in [
            PULL_CMD,
            GET_ASSET_CMD,
            GET_REMOTE_ASSET_CMD,
            BUILD_CMD,
            INSERT_CMD,
            REMOVE_CMD,
            GETSEQ_CMD,
            TAG_CMD,
            ID_CMD,
    ]:
        # genome is not required for listing actions
        sps[cmd].add_argument(
            "-g",
            "--genome",
            required=cmd in GETSEQ_CMD,
            metavar="G",
            help="Reference assembly ID, e.g. mm10.",
        )

    for cmd in LIST_REMOTE_CMD, LIST_LOCAL_CMD:
        sps[cmd].add_argument(
            "-g",
            "--genome",
            required=False,
            type=str,
            metavar="G",
            nargs="*",
            help="Reference assembly ID, e.g. mm10.",
        )

    for cmd in [
            PULL_CMD,
            GET_ASSET_CMD,
            GET_REMOTE_ASSET_CMD,
            BUILD_CMD,
            INSERT_CMD,
            REMOVE_CMD,
            TAG_CMD,
            ID_CMD,
    ]:
        build_arg_kwargs = dict(
            metavar="asset-registry-paths",
            type=str,
            nargs="+",
            help=
            "One or more registry path strings that identify assets  (e.g. hg38/fasta or hg38/fasta:tag"
            + (" or hg38/fasta.fai:tag)."
               if cmd in [GET_ASSET_CMD, GET_REMOTE_ASSET_CMD] else ")."),
        )
        # make asset-registry-path argument optional for build command
        # and require it manually in CLI when running a non-reduce build
        if cmd == BUILD_CMD:
            build_arg_kwargs.update({"nargs": "*", "default": None})
        sps[cmd].add_argument("asset_registry_paths", **build_arg_kwargs)

    sps[LIST_LOCAL_CMD].add_argument("-r",
                                     "--recipes",
                                     action="store_true",
                                     help="List available recipes.")

    for cmd in [REMOVE_CMD, INSERT_CMD]:
        sps[cmd].add_argument(
            "-f",
            "--force",
            action="store_true",
            help="Do not prompt before action, approve upfront.",
        )

    sps[REMOVE_CMD].add_argument(
        "-a",
        "--aliases",
        action="store_true",
        help=
        "Remove the genome alias if last asset for that genome is removed.",
    )
    force_group = sps[PULL_CMD].add_argument_group(
        title="Prompt handling",
        description="These flags configure the pull prompt responses.",
    )

    overwrite_group = force_group.add_mutually_exclusive_group()

    overwrite_group.add_argument("--no-overwrite",
                                 action="store_true",
                                 help="Do not overwrite if asset exists.")

    overwrite_group.add_argument("--force-overwrite",
                                 action="store_true",
                                 help="Overwrite if asset exists.")

    large_group = force_group.add_mutually_exclusive_group()

    large_group.add_argument("--no-large",
                             action="store_true",
                             help="Do not pull archives over 5GB.")

    large_group.add_argument(
        "--pull-large",
        action="store_true",
        help="Pull any archive, regardless of its size.",
    )

    force_group.add_argument(
        "--size-cutoff",
        type=float,
        default=10,
        metavar="S",
        help=
        "Maximum archive file size to download with no confirmation required (in GB, default: 10)",
    )

    force_group.add_argument(
        "-b",
        "--batch",
        action="store_true",
        help="Use batch mode: pull large archives, do no overwrite",
    )

    sps[INSERT_CMD].add_argument("-p",
                                 "--path",
                                 required=True,
                                 metavar="P",
                                 help="Relative local path to asset.")

    sps[INSERT_CMD].add_argument(
        "-s",
        "--seek-keys",
        required=False,
        type=str,
        metavar="S",
        help="""
        String representation of a JSON object with seek_keys,
        e.g. '{"seek_key1": "file.txt"}'
        """,
    )

    sps[GETSEQ_CMD].add_argument(
        "-l",
        "--locus",
        required=True,
        help="Coordinates of desired sequence; e.g. 'chr1:50000-50200'.",
    )

    sps[GET_ASSET_CMD].add_argument(
        "-e",
        "--check-exists",
        required=False,
        action="store_true",
        help=
        "Whether the returned asset path should be checked for existence on disk.",
    )

    sps[TAG_CMD].add_argument(
        "-f",
        "--force",
        action="store_true",
        help="Do not prompt before action, approve upfront.",
    )

    group = sps[TAG_CMD].add_mutually_exclusive_group(required=True)

    group.add_argument("-t",
                       "--tag",
                       type=str,
                       help="Tag to assign to an asset.")

    group.add_argument(
        "-d",
        "--default",
        action="store_true",
        help="Set the selected asset tag as the default one.",
    )

    sps[SUBSCRIBE_CMD].add_argument(
        "-r",
        "--reset",
        action="store_true",
        help="Overwrite the current list of server URLs.",
    )

    for cmd in [SUBSCRIBE_CMD, UNSUBSCRIBE_CMD]:
        sps[cmd].add_argument(
            "-s",
            "--genome-server",
            nargs="+",
            required=True,
            metavar="S",
            help=
            "One or more URLs to {action} the {key} attribute in config file.".
            format(
                action="add to" if cmd == SUBSCRIBE_CMD else "remove from",
                key=CFG_SERVERS_KEY,
            ),
        )

    for cmd in [LIST_REMOTE_CMD, GET_REMOTE_ASSET_CMD, POPULATE_REMOTE_CMD]:
        sps[cmd].add_argument(
            "-s",
            "--genome-server",
            nargs="+",
            required=False,
            metavar="S",
            help="One or more URLs to use. "
            "This information will not persist in the genome config file.",
        )
        sps[cmd].add_argument(
            "-p",
            "--append-server",
            action="store_true",
            help="Whether the provided servers should be appended to the list.",
        )

    for cmd in [POPULATE_REMOTE_CMD, GET_REMOTE_ASSET_CMD]:
        sps[cmd].add_argument(
            "--remote-class",
            metavar="RC",
            type=str,
            default="http",
            help="Remote data provider class, e.g. 'http' or 's3'",
        )

    for cmd in [POPULATE_REMOTE_CMD, POPULATE_CMD]:
        sps[cmd].add_argument("-f",
                              "--file",
                              metavar="F",
                              help="File with registry paths to populate")

    return parser
Exemplo n.º 13
0
def build_argparser():
    """
    Builds argument parser.

    :return argparse.ArgumentParser
    """

    banner = ("%(prog)s - write compute job scripts that can be submitted to "
              "any computing resource")
    additional_description = "\nhttps://divvy.databio.org"

    parser = VersionInHelpParser(
        prog="divvy",
        description=banner,
        epilog=additional_description,
        version=__version__,
    )

    subparsers = parser.add_subparsers(dest="command")

    def add_subparser(cmd, description):
        return subparsers.add_parser(cmd,
                                     description=description,
                                     help=description)

    subparser_messages = {
        "init": "Initialize a new divvy config file",
        "list": "List available compute packages",
        "write": "Write a job script",
        "submit": "Write and then submit a job script",
    }

    sps = {}
    for cmd, desc in subparser_messages.items():
        sps[cmd] = add_subparser(cmd, desc)
        # sps[cmd].add_argument(
        #     "config", nargs="?", default=None,
        #     help="Divvy configuration file.")

    for sp in [sps["list"], sps["write"], sps["submit"]]:
        sp.add_argument("config",
                        nargs="?",
                        default=None,
                        help="Divvy configuration file.")

    sps["init"].add_argument("config",
                             default=None,
                             help="Divvy configuration file.")

    for sp in [sps["write"], sps["submit"]]:
        sp.add_argument(
            "-s",
            "--settings",
            help="YAML file with job settings to populate the template",
        )

        sp.add_argument(
            "-p",
            "--package",
            default=DEFAULT_COMPUTE_RESOURCES_NAME,
            help="Select from available compute packages",
        )

        sp.add_argument(
            "-c",
            "--compute",
            nargs="+",
            default=None,
            help="Extra key=value variable pairs",
        )

        # sp.add_argument(
        #         "-t", "--template",
        #         help="Provide a template file (not yet implemented).")

        sp.add_argument("-o",
                        "--outfile",
                        required=False,
                        default=None,
                        help="Output filepath")

    return parser