Beispiel #1
0
def add_import_fasta_opts(p):
    px = p.add_argument
    px("fasta_path", type=validate_file, help="Path to Fasta File")
    px("--name", required=True, type=str, help="Name of ReferenceSet")
    px("--organism", required=True, type=str, help="Organism")
    px("--ploidy", required=True, type=str, help="Ploidy")
    px("--block", type=bool, default=False, help="Block during importing process")
    add_sal_options(p)
    add_base_options(p)
    return p
Beispiel #2
0
def get_default_argparser_with_base_opts(version,
                                         description,
                                         default_level="INFO"):
    """Return a parser with the default log related options

    If you don't want the default log behavior to go to stdout, then set
    the default log level to be "ERROR". This will essentially suppress all
    output to stdout.

    Default behavior will only emit to stderr. This is essentially a '--quiet'
    default mode.

    my-tool --my-opt=1234 file_in.txt

    To override the default behavior and add a chatty-er stdout

    my-tool --my-opt=1234 --log-level=INFO file_in.txt

    Or write the console output to write the log file to an explict file and
    leave the stdout untouched.

    my-tool --my-opt=1234 --log-level=DEBUG --log-file=file.log file_in.txt

    """
    return add_base_options(get_default_argparser(version, description),
                            default_level=default_level)
Beispiel #3
0
def pacbio_args_or_contract_runner(argv, parser, args_runner_func,
                                   contract_tool_runner_func, alog,
                                   setup_log_func):
    """
    For tools that understand resolved_tool_contracts, but can't emit
    tool contracts (they may have been written by hand)

    :param parser: argparse Parser
    :type parser: ArgumentParser

    :param args_runner_func: func(args) => int signature

    :param contract_tool_runner_func: func(tool_contract_instance) should be the signature

    :param alog: a python log instance
    :param setup_log_func: func(log_instance) => void signature

    :return: int return code
    :rtype: int
    """
    def _log_not_none(msg):
        if alog is not None:
            alog.info(msg)

    # circumvent the argparse parsing by inspecting the raw argv, then create
    # a temporary parser with limited arguments to process the special case of
    # --resolved-cool-contract (while still respecting verbosity flags).
    if any(a.startswith(RESOLVED_TOOL_CONTRACT_OPTION) for a in argv):
        p_tmp = get_default_argparser(version=parser.version,
                                      description=parser.description)
        add_resolved_tool_contract_option(
            add_base_options(p_tmp, default_level="NOTSET"))
        args_tmp = p_tmp.parse_args(argv)
        resolved_tool_contract = load_resolved_tool_contract_from(
            args_tmp.resolved_tool_contract)
        _log_not_none(
            "Successfully loaded resolved tool contract from {a}".format(
                a=argv))
        # XXX if one of the logging flags was specified, that takes precedence,
        # otherwise use the log level in the resolved tool contract.  note that
        # this takes advantage of the fact that argparse allows us to use
        # NOTSET as the default level even though it's not one of the choices.
        log_level = get_parsed_args_log_level(args_tmp,
                                              default_level=logging.NOTSET)
        if log_level == logging.NOTSET:
            log_level = resolved_tool_contract.task.log_level
        with TemporaryResourcesManager(resolved_tool_contract) as tmp_mgr:
            r = _pacbio_main_runner(alog,
                                    setup_log_func,
                                    contract_tool_runner_func,
                                    resolved_tool_contract,
                                    level=log_level)
            _log_not_none("Completed running resolved contract. {c}".format(
                c=resolved_tool_contract))
            return r
    else:
        # tool was called with the standard commandline invocation
        return pacbio_args_runner(argv, parser, args_runner_func, alog,
                                  setup_log_func)
Beispiel #4
0
def pacbio_args_or_contract_runner(argv,
                                   parser,
                                   args_runner_func,
                                   contract_tool_runner_func,
                                   alog, setup_log_func):
    """
    For tools that understand resolved_tool_contracts, but can't emit
    tool contracts (they may have been written by hand)

    :param parser: argparse Parser
    :type parser: ArgumentParser

    :param args_runner_func: func(args) => int signature

    :param contract_tool_runner_func: func(tool_contract_instance) should be
    the signature

    :param alog: a python log instance
    :param setup_log_func: func(log_instance) => void signature
    :return: int return code
    :rtype: int
    """
    def _log_not_none(msg):
        if alog is not None:
            alog.info(msg)

    # circumvent the argparse parsing by inspecting the raw argv, then create
    # a temporary parser with limited arguments to process the special case of
    # --resolved-cool-contract (while still respecting verbosity flags).
    if any(a.startswith(RESOLVED_TOOL_CONTRACT_OPTION) for a in argv):
        p_tmp = get_default_argparser(version=parser.version,
            description=parser.description)
        add_resolved_tool_contract_option(add_base_options(p_tmp,
            default_level="NOTSET"))
        args_tmp = p_tmp.parse_args(argv)
        resolved_tool_contract = load_resolved_tool_contract_from(
            args_tmp.resolved_tool_contract)
        _log_not_none("Successfully loaded resolved tool contract from {a}".format(a=argv))
        # XXX if one of the logging flags was specified, that takes precedence,
        # otherwise use the log level in the resolved tool contract.  note that
        # this takes advantage of the fact that argparse allows us to use
        # NOTSET as the default level even though it's not one of the choices.
        log_level = get_parsed_args_log_level(args_tmp,
            default_level=logging.NOTSET)
        if log_level == logging.NOTSET:
            log_level = resolved_tool_contract.task.log_level
        with TemporaryResourcesManager(resolved_tool_contract) as tmp_mgr:
            r = _pacbio_main_runner(alog, setup_log_func, contract_tool_runner_func, resolved_tool_contract, level=log_level)
            _log_not_none("Completed running resolved contract. {c}".format(c=resolved_tool_contract))
            return r
    else:
        # tool was called with the standard commandline invocation
        return pacbio_args_runner(argv, parser, args_runner_func, alog,
                                  setup_log_func)
Beispiel #5
0
def get_contract_parser(C=Constants, ccs_mode=False):
    """
    Create and populate the combined tool contract/argument parser.  This
    method can optionally be overridden with a different Constants object for
    defining additional tasks (e.g. CCS alignment).
    """
    resources = ()
    p = get_pbparser(tool_id=C.TOOL_ID,
                     version=C.VERSION,
                     name=C.TOOL_ID,
                     description=C.PARSER_DESC,
                     driver_exe=C.DRIVER_EXE,
                     nproc=SymbolTypes.MAX_NPROC,
                     resource_types=(ResourceTypes.TMP_DIR, ),
                     default_level="WARN")
    p.arg_parser.parser = _ArgParser(
        description=C.PARSER_DESC,
        formatter_class=argparse.ArgumentDefaultsHelpFormatter)
    p.arg_parser.parser.version = C.VERSION
    p.arg_parser.parser.add_argument(
        '--version',
        action="version",
        help="show program's version number and exit")
    add_base_options(p.arg_parser.parser)

    # Required options: inputs and outputs.
    p.add_input_file_type(C.INPUT_FILE_TYPE, "inputFileName",
                          "Subread DataSet", "SubreadSet or unaligned .bam")
    p.add_input_file_type(FileTypes.DS_REF, "referencePath", "ReferenceSet",
                          "Reference DataSet or FASTA file")
    p.add_output_file_type(C.OUTPUT_FILE_TYPE,
                           "outputFileName",
                           name="Alignments",
                           description="Alignment results dataset",
                           default_name=C.OUTPUT_FILE_NAME)
    constructOptionParser(p, ccs_mode=ccs_mode)
    p.arg_parser.parser.add_argument("--profile",
                                     action="store_true",
                                     help="Print runtime profile at exit")
    return p
Beispiel #6
0
def get_contract_parser(C=Constants, ccs_mode=False):
    """
    Create and populate the combined tool contract/argument parser.  This
    method can optionally be overridden with a different Constants object for
    defining additional tasks (e.g. CCS alignment).
    """
    resources = ()
    p = get_pbparser(
        tool_id=C.TOOL_ID,
        version=C.VERSION,
        name=C.TOOL_ID,
        description=C.PARSER_DESC,
        driver_exe=C.DRIVER_EXE,
        nproc=SymbolTypes.MAX_NPROC,
        resource_types=(ResourceTypes.TMP_DIR,),
        default_level="WARN")
    p.arg_parser.parser = _ArgParser(
        description=C.PARSER_DESC,
        formatter_class=argparse.ArgumentDefaultsHelpFormatter)
    p.arg_parser.parser.version = C.VERSION
    p.arg_parser.parser.add_argument('--version',
         action="version",
         help="show program's version number and exit")
    add_base_options(p.arg_parser.parser)

    # Required options: inputs and outputs.
    p.add_input_file_type(C.INPUT_FILE_TYPE, "inputFileName",
        "Subread DataSet", "SubreadSet or unaligned .bam")
    p.add_input_file_type(FileTypes.DS_REF, "referencePath",
        "ReferenceSet", "Reference DataSet or FASTA file")
    p.add_output_file_type(C.OUTPUT_FILE_TYPE, "outputFileName",
        name="XML DataSet",
        description="Output AlignmentSet file",
        default_name=C.OUTPUT_FILE_NAME)
    constructOptionParser(p, ccs_mode=ccs_mode)
    p.arg_parser.parser.add_argument(
        "--profile", action="store_true",
        help="Print runtime profile at exit")
    return p
Beispiel #7
0
def get_default_argparser_with_base_opts(version, description, default_level="INFO"):
    """Return a parser with the default log related options

    If you don't want the default log behavior to go to stdout, then set
    the default log level to be "ERROR". This will essentially suppress all
    output to stdout.

    Default behavior will only emit to stderr. This is essentially a '--quiet'
    default mode.

    my-tool --my-opt=1234 file_in.txt

    To override the default behavior and add a chatty-er stdout

    my-tool --my-opt=1234 --log-level=INFO file_in.txt

    Or write the console output to write the log file to an explict file and
    leave the stdout untouched.

    my-tool --my-opt=1234 --log-level=DEBUG --log-file=file.log file_in.txt

    """
    return add_base_options(get_default_argparser(version, description), default_level=default_level)
Beispiel #8
0
def _add_run_rtc_options(p):
    add_base_options(p)
    p.add_argument('rtc_path', type=str, help="Path to resolved tool contract")
    return p
def _alpha_add_options_with_base_options(p):
    return _alpha_add_options(add_base_options(p))