Exemple #1
0
def resolve_args_dependency(parser: argparse, args):
    file_path: str = str(args.file[0])

    if args.action == 'update':
        if any([
                args.config is None, args.grub is None, args.directory is None,
                args.mount is None
        ]):
            parser.error("arguments are not enough for update.")

    if not os.path.exists(file_path):
        if args.template is None:
            parser.error(
                "{} is not exist, so template must be present.".format(
                    file_path))

        template_path: str = str(args.template[0])
        if not os.path.exists(template_path):
            parser.error(
                "{} is not exist,  template {} also not exist.".format(
                    file_path, template_path))

        try:
            subprocess.run("sudo cp {} {}".format(template_path, file_path),
                           check=True,
                           shell=True)
            logging.info("Create target {} from template {}".format(
                file_path, template_path))
        except subprocess.CalledProcessError as cpe:
            parser.error(
                "Error creating target {} from template {} :\n  {}".format(
                    file_path, template_path, str(cpe)))

    pass
Exemple #2
0
def folder_parser(sup_parser: argparse):

    folder_parser = sup_parser.add_parser(
        'folder', help='Manage folders. Folders allows to group tasks')
    folder_subparser = folder_parser.add_subparsers(
        dest='action', metavar='', description='Commands to work with folders')
    folder_subparser.required = True

    create = folder_subparser.add_parser('create', help='Create new folder')
    create.add_argument('name', help='Folder name')

    show = folder_subparser.add_parser('show', help='Show folders  info')
    folder_show_parser(show)

    populate = folder_subparser.add_parser(
        'populate', help='Populate folder with provided task')
    populate.add_argument('-fid', '--folder_id', required=True, type=valid_int)
    populate.add_argument('-tid', '--task_id', required=True, type=valid_int)

    unpopulate = folder_subparser.add_parser('unpopulate',
                                             help='delete task from folder')
    unpopulate.add_argument('-fid',
                            '--folder_id',
                            required=True,
                            type=valid_int)
    unpopulate.add_argument('-tid', '--task_id', required=True, type=valid_int)

    edit = folder_subparser.add_parser('edit', help='Edit folder by id')
    edit.add_argument('folder_id', type=valid_int)
    edit.add_argument('name', help='Folder name')

    delete = folder_subparser.add_parser('delete', help='Delete folder by id')
    delete.add_argument('folder_id', type=valid_int)
Exemple #3
0
def task_show_parser(show_subparser: argparse):
    task_show = show_subparser.add_subparsers(
        dest='show_type',
        title='Show tasks info',
        metavar='',
        description='Commands to show tasks')
    task_show.required = True

    task_id = task_show.add_parser('id', help='Show task by id')
    task_id.add_argument('task_id', help='Task id', type=valid_int)

    task_show.add_parser('own', help='Show tasks created by user')

    subtasks = task_show.add_parser('subtasks',
                                    help='Show subtasks by task id')
    subtasks.add_argument('task_id', type=valid_int)

    task_show.add_parser('all', help='Show all tasks user can access')

    task_show.add_parser('assigned', help='Show tasks assigned on user')

    task_show.add_parser('todo', help='Show todo tasks')

    task_show.add_parser('inwork', help='Show inwork tasks')

    task_show.add_parser('done', help='Show done tasks')

    task_show.add_parser('archived', help='Show archived tasks')

    task_show.add_parser('planless', help='Show tasks without plan')
Exemple #4
0
def reminder_parser(sup_parser: argparse):
    reminder_parser = sup_parser.add_parser(
        'reminder',
        help='Manage reminders. Reminders remind you about your tasks')
    reminder_subparser = reminder_parser.add_subparsers(
        dest='action',
        metavar='',
        description='Commands to work with reminders')

    reminder_subparser.required = True

    create = reminder_subparser.add_parser(
        'create', help='Create reminder for existing task')
    create.add_argument('task_id', help='Task id', type=valid_int)
    create.add_argument('date', help='Reminder date', type=valid_future_date)

    show = reminder_subparser.add_parser('show', help='Show reminders info')
    reminder_show_parser(show)

    edit = reminder_subparser.add_parser('edit', help='Edit reminder')
    edit.add_argument('reminder_id', help='Reminder id', type=valid_int)
    edit.add_argument('date', help='Reminder date', type=valid_future_date)

    delete = reminder_subparser.add_parser('delete',
                                           help='Delete reminder by id')
    delete.add_argument('reminder_id', type=valid_int)
Exemple #5
0
def plan_parser(sup_parser: argparse):

    plan_parser = sup_parser.add_parser(
        'plan', help='Manage plans. Plans allows to automate tasks creation')
    plan_subparser = plan_parser.add_subparsers(
        dest='action', metavar='', description='Commands to work with plans')

    plan_subparser.required = True

    create = plan_subparser.add_parser('create',
                                       help='Create plan for existing task')
    create.add_argument('task_id', help='task id', type=valid_int)
    create.add_argument('period_amount', help='Period amount', type=valid_int)
    create.add_argument('period',
                        help='Period type',
                        choices=[x.name.lower() for x in Period])

    create.add_argument('-s',
                        '--start_date',
                        type=valid_future_date,
                        help='Plan start date.',
                        required=True)
    create.add_argument('-r',
                        '--plan_amount',
                        type=valid_int,
                        help='How much times plan should be executed')
    create.add_argument('-e',
                        '--end_date',
                        type=valid_future_date,
                        help='Plan end date.')

    show = plan_subparser.add_parser('show', help='Show plans info')
    plan_show_parser(show)

    edit = plan_subparser.add_parser('edit', help='Edit plan')
    edit.add_argument('plan_id', help='plan_id', type=valid_int)
    edit.add_argument('-p',
                      '--period_amount',
                      help='Period amount',
                      type=valid_int)
    edit.add_argument('-t',
                      '--period',
                      help='Period type',
                      choices=[x.name.lower() for x in Period])
    edit.add_argument('-r',
                      '--plan_amount',
                      type=valid_int,
                      help='How much plan should be executed')
    edit.add_argument('-e',
                      '--end_date',
                      type=valid_future_date,
                      help='Plan end date.')

    delete = plan_subparser.add_parser('delete', help='Delete plan by id')
    delete.add_argument('plan_id', type=valid_int)
Exemple #6
0
def aws_create_iam_user_parser_arguments(aws_parser: argparse):
    iam_user_command_group = aws_parser.add_argument_group(
        "iam_user", "Arguments to add IAM user")

    iam_user_command_group.add_argument("--add_iam_user",
                                        action="store_true",
                                        help="Add IAM user to AWS account")
    iam_user_command_group.add_argument("--user_name",
                                        type=str,
                                        required=False,
                                        help="User name of the IAM user")
Exemple #7
0
def append_service_interfaces_to_parser(
    parent_parser: argparse,
    interfaces: Dict[str, BaseInterface],
    interface_group_name: Optional[str] = 'sub_interface'
) -> argparse.ArgumentParser:
    """
    Append multiple service interfaces to a single parser

    :param parent_parser:
    :param interfaces: A dictionary service interface packages where the key is the name of that interface,
                    and the value is the interface object itself.
    :param interface_group_name: A name identifying where in the component, interface, sub-interface hierarchy these
                                 service_interfaces should be placed
    :return: The parser object
    """

    for name, value in interfaces.items():
        if isinstance(value, tuple):
            interfaces, help_str = value
            new_section_parser = parent_parser.add_parser(name=name,
                                                          help=help_str)
            new_section_subparsers = new_section_parser.add_subparsers()
            append_service_interfaces_to_parser(
                parent_parser=new_section_subparsers,
                interfaces=interfaces,
                interface_group_name=interface_group_name)
        elif isinstance(value, dict):
            new_section_parser = parent_parser.add_parser(name=name,
                                                          help='<None Given>')
            new_section_subparsers = new_section_parser.add_subparsers()
            append_service_interfaces_to_parser(
                parent_parser=new_section_subparsers,
                interfaces=value,
                interface_group_name=interface_group_name)
        else:
            append_service_interface_to_parser(
                parent_parser=parent_parser,
                interface_name=name,
                interface=value,
                interface_group_name=interface_group_name)
    return parent_parser
Exemple #8
0
def parse_args(parser: argparse, config: Config):
    """Parse the programme arguments
    :param config:
    :param parser:
    :return: arguments
    """
    location_help = r"""location specifying the start point to scan to recursively hash files.
                        May also be a single file. 
                        """
    report_location_help = r"""location specifying the csv report file in which to write results. """

    parser.add_argument('scan_location',
                        help=location_help)

    parser.add_argument('-report', '--report',
                        default=config.report,
                        required=False,
                        help=report_location_help)

    args = parser.parse_args()
    logging.debug(str(args))
    return args
Exemple #9
0
def aws_destroy_iam_policy_parser_arguments(aws_parser: argparse):
    iam_policy_command_group = aws_parser.add_argument_group(
        "iam_policy", "Arguments to add IAM policy")

    iam_policy_command_group.add_argument(
        "--delete_iam_policy",
        action="store_true",
        help="Delete IAM policy from AWS account",
    )
    iam_policy_command_group.add_argument("--policy_name",
                                          type=str,
                                          required=False,
                                          help="Policy name to be destroyed")
Exemple #10
0
def user_parser(sup_parser: argparse):
    user_parser = sup_parser.add_parser(
        'user', help='Manage users. Sign up, login, logout, list all users')
    user_subparser = user_parser.add_subparsers(
        dest='action', metavar='', description='Commands to work with user')
    user_subparser.required = True

    create = user_subparser.add_parser('create', help='Register new user')
    create.add_argument('username')
    login = user_subparser.add_parser('login', help='Auth by username')
    login.add_argument('username')
    user_subparser.add_parser('logout', help='Logout user')
    user_subparser.add_parser('current', help='Show current user')
    user_subparser.add_parser('all', help='Show all users in app')
Exemple #11
0
def add_parser_option(parser: argparse,
                      short_name: str = '',
                      full_name: str = '',
                      **kwargs):
    """
    Add a new option to the Parser.

    This function allows us to add a new option to the argument parser. This
    allows for every module with an entry point to set up its own set of
    arguments for multi-module startup.

    Args:
        parser (argparse): The parser we are adding the new option to.
        short_name (str): The short name of the command line flag. e.g. '-f'.
        full_name (str): The fully descriptive command line flag e.g. '--foo'.
        **kwargs: The optional parameters that will be added to the parser.
          see cref: https://github.com/python/cpython/blob/3.7/Lib/argparse.py.

    """
    if short_name and full_name:
        parser.add_argument(short_name, full_name, **kwargs)
    else:
        parser.add_argument(full_name, **kwargs)
Exemple #12
0
def aws_attach_iam_policy_parser_arguments(aws_parser: argparse):
    iam_policy_command_group = aws_parser.add_argument_group(
        "iam_policy_attach", "Arguments to attach IAM policy to the user")

    iam_policy_command_group.add_argument("--attach_iam_policy",
                                          action="store_true",
                                          help="Attaches IAM policy to a user")
    iam_policy_command_group.add_argument("--iam_policy_name",
                                          type=str,
                                          required=False,
                                          help="Policy to be attached")
    iam_policy_command_group.add_argument("--iam_user_name",
                                          type=str,
                                          required=False,
                                          help="Attach policy to user")
Exemple #13
0
def aws_create_iam_policy_parser_arguments(aws_parser: argparse):
    iam_policy_command_group = aws_parser.add_argument_group(
        "iam_policy", "Arguments to add IAM policy")

    iam_policy_command_group.add_argument("--add_iam_policy",
                                          action="store_true",
                                          help="Add IAM policy to AWS account")
    iam_policy_command_group.add_argument("--policy_name",
                                          type=str,
                                          required=False,
                                          help="Policy name to be created")

    iam_policy_command_group.add_argument("--firehose_stream_name",
                                          type=str,
                                          required=False,
                                          help="Firehose stream name")

    iam_policy_command_group.add_argument("--data_bucket_name",
                                          type=str,
                                          required=False,
                                          help="Data bucket name")

    iam_policy_command_group.add_argument("--config_bucket_name",
                                          type=str,
                                          required=False,
                                          help="Config bucket name")

    iam_policy_command_group.add_argument("--database_name",
                                          type=str,
                                          required=False,
                                          help="Database name")

    iam_policy_command_group.add_argument("--table_name",
                                          type=str,
                                          required=False,
                                          help="Table name")

    iam_policy_command_group.add_argument("--cluster_name",
                                          type=str,
                                          required=False,
                                          help="ECS cluster name")

    iam_policy_command_group.add_argument(
        "--ecs_task_execution_role_name",
        type=str,
        required=False,
        help="ECS task execution role name",
    )
Exemple #14
0
def aws_parser_arguments(aws_parser: argparse) -> argparse:
    aws_parser.add_argument("--access_key",
                            type=str,
                            required=False,
                            help="Access key of the AWS account")
    aws_parser.add_argument("--secret_key",
                            type=str,
                            required=False,
                            help="Secret key of the AWS account")
    aws_parser.add_argument("--account_id",
                            type=str,
                            required=False,
                            help="Account ID of the AWS account")
    aws_parser.add_argument("--region",
                            type=str,
                            required=False,
                            help="Region of the AWS account")
    return aws_parser
Exemple #15
0
def append_service_interface_to_parser(
    parent_parser: argparse,
    interface_name: str,
    interface: BaseInterface,
    interface_group_name: Optional[str] = 'interface'
) -> argparse.ArgumentParser:
    """
    Add an interface to an existing parser.

    :param parent_parser: The parent parser to add the interface too
    :param interface_name: The name of this interface as it will appear in the commandline utility
    :param interface: The interface object itself
    :param interface_group_name: A name identifying where in the component, interface, sub-interface hierarchy this
                                 service_interface should be placed
    :return: The parser object
    """
    from dynamite_nsm.cmd import service_interfaces
    from dynamite_nsm.cmd import config_object_interfaces
    from dynamite_nsm.cmd.config_object_interfaces import AnalyzersInterface, FilebeatTargetsInterface
    from dynamite_nsm.cmd.service_interfaces import MultipleResponsibilityInterface, SingleResponsibilityInterface, \
        SimpleConfigManagerInterface

    if not interface:
        return argparse.ArgumentParser()
    interface_group_name_kwargs = {interface_group_name: interface_name}
    sub_interface_parser = parent_parser.add_parser(
        interface_name, help=interface.interface_description)
    sub_interface_parser.set_defaults(**interface_group_name_kwargs)

    if isinstance(interface, SimpleConfigManagerInterface):
        service_interfaces.append_service_simple_config_management_interface_to_parser(
            parser=sub_interface_parser, interface=interface)
    elif isinstance(interface, SingleResponsibilityInterface):
        service_interfaces.append_service_single_responsibility_interface_to_parser(
            parser=sub_interface_parser, interface=interface)
    elif isinstance(interface, MultipleResponsibilityInterface):
        service_interfaces.append_service_multiple_responsibility_interface_to_parser(
            parser=sub_interface_parser, interface=interface)
    elif isinstance(interface, AnalyzersInterface):
        config_object_interfaces.append_config_object_analyzer_interface_to_parser(
            parser=sub_interface_parser, interface=interface)
    elif isinstance(interface, FilebeatTargetsInterface):
        config_object_interfaces.append_config_object_filebeat_targets_to_parser(
            parser=sub_interface_parser, interface=interface)

    return parent_parser
Exemple #16
0
def plan_show_parser(sup_parser: argparse):
    plan_show = sup_parser.add_subparsers(dest='show_type',
                                          title='Show plan and its info',
                                          metavar='',
                                          description='Commands to show plans')
    plan_show.required = True

    plan_id = plan_show.add_parser('id', help='Show plan by id')

    plan_id.add_argument('plan_id', help='Plan id', type=valid_int)
    plan_id.add_argument('--tasks',
                         action='store_true',
                         help='Show plan. Task and generated tasks')

    plan_all = plan_show.add_parser('all', help='Show all plans')
    plan_all.add_argument('--tasks',
                          action='store_true',
                          help='Show plan. Task and generated tasks')
Exemple #17
0
def folder_show_parser(show_subparser: argparse):
    task_show = show_subparser.add_subparsers(
        dest='show_type',
        title='Show folders and its info',
        metavar='',
        description='Commands to show folders')
    task_show.required = True

    folder_id = task_show.add_parser('id', help='Show folder by id')
    folder_id.add_argument('folder_id', help='Folder id', type=valid_int)
    folder_id.add_argument('--tasks',
                           action='store_true',
                           help='Show folder tasks')

    folder_all = task_show.add_parser('all', help='Show all folders')
    folder_all.add_argument('--tasks',
                            action='store_true',
                            help='Show folder_tasks')
Exemple #18
0
def reminder_show_parser(sup_parser: argparse):
    reminder_show = sup_parser.add_subparsers(
        dest='show_type',
        title='Show reminders and its info',
        metavar='',
        description='Commands to show reminders')

    reminder_show.required = True

    reminder_id = reminder_show.add_parser('id', help='Show reminder by id')

    reminder_id.add_argument('reminder_id', help='Reminder id', type=valid_int)

    reminder_id.add_argument('--task',
                             action='store_true',
                             help='Show reminder and its task')

    reminder_all = reminder_show.add_parser('all', help='Show all reminders')

    reminder_all.add_argument('--tasks',
                              action='store_true',
                              help='Show reminders and its tasks')
Exemple #19
0
def add_subparser_args(subparsers: argparse) -> argparse:
    """Add tool-specific arguments for remove-background.

    Args:
        subparsers: Parser object before addition of arguments specific to
            remove-background.

    Returns:
        parser: Parser object with additional parameters.

    """

    subparser = subparsers.add_parser("remove-background",
                                      description="Remove background RNA "
                                                  "from count matrix.",
                                      help="Remove background ambient RNA "
                                           "and barcode-swapped reads from "
                                           "a count matrix, producing a "
                                           "new count matrix and "
                                           "determining which barcodes "
                                           "contain real cells.")

    subparser.add_argument("--input", nargs=None, type=str,
                           dest='input_file', default=None,
                           required=True,
                           help="Data file on which to run tool, as either "
                                "_raw_gene_barcode_matrices_h5.h5 file, or "
                                "as the path containing the raw "
                                "matrix.mtx, barcodes.tsv, and genes.tsv "
                                "files. Supported for outputs of "
                                "CellRanger v2 and v3.")
    subparser.add_argument("--output", nargs=None, type=str,
                           dest='output_file', default=None,
                           required=True,
                           help="Output file location (the path must "
                                "exist, and the file name must have .h5 "
                                "extension).")
    subparser.add_argument("--expected-cells", nargs=None, type=int,
                           default=None,
                           dest="expected_cell_count",
                           help="Number of cells expected in the dataset "
                                "(a rough estimate within a factor of 2 "
                                "is sufficient).")
    subparser.add_argument("--total-droplets-included",
                           nargs=None, type=int,
                           default=consts.TOTAL_DROPLET_DEFAULT,
                           dest="total_droplets",
                           help="The number of droplets from the "
                                "rank-ordered UMI plot that will be "
                                "analyzed. The largest 'total_droplets' "
                                "droplets will have their cell "
                                "probabilities inferred as an output.")
    subparser.add_argument("--model", nargs=None, type=str, default="full",
                           choices=["simple", "ambient",
                                    "swapping", "full"],
                           dest="model",
                           help="Which model is being used for count data. "
                                " 'simple' does not model either ambient "
                                "RNA or random barcode swapping (for "
                                "debugging purposes -- not recommended).  "
                                "'ambient' assumes background RNA is "
                                "incorporated into droplets.  'swapping' "
                                "assumes background RNA comes from random "
                                "barcode swapping.  'full' uses a "
                                "combined ambient and swapping model.  "
                                "Defaults to 'full'.")
    subparser.add_argument("--epochs", nargs=None, type=int, default=150,
                           dest="epochs",
                           help="Number of epochs to train.")
    subparser.add_argument("--cuda",
                           dest="use_cuda", action="store_true",
                           help="Including the flag --cuda will run the "
                                "inference on a GPU.")
    subparser.add_argument("--low-count-threshold", type=int,
                           default=consts.LOW_UMI_CUTOFF,
                           dest="low_count_threshold",
                           help="Droplets with UMI counts below this "
                                "number are completely excluded from the "
                                "analysis.  This can help identify the "
                                "correct prior for empty droplet counts "
                                "in the rare case where empty counts "
                                "are extremely high (over 200).")
    subparser.add_argument("--z-dim", type=int, default=20,
                           dest="z_dim",
                           help="Dimension of latent variable z.")
    subparser.add_argument("--z-layers", nargs="+", type=int, default=[500],
                           dest="z_hidden_dims",
                           help="Dimension of hidden layers in the encoder "
                                "for z.")
    subparser.add_argument("--d-layers", nargs="+", type=int,
                           default=[5, 2, 2],
                           dest="d_hidden_dims",
                           help="Dimension of hidden layers in the encoder "
                                "for d.")
    subparser.add_argument("--p-layers", nargs="+", type=int,
                           default=[100, 10],
                           dest="p_hidden_dims",
                           help="Dimension of hidden layers in the encoder "
                                "for p.")
    subparser.add_argument("--empty-drop-training-fraction",
                           type=float, nargs=None,
                           default=consts.FRACTION_EMPTIES,
                           dest="fraction_empties",
                           help="Training detail: the fraction of the "
                                "training data each epoch "
                                "that is drawn (randomly sampled) from "
                                "surely empty droplets.")
    subparser.add_argument("--blacklist-genes", nargs="+", type=int,
                           default=[],
                           dest="blacklisted_genes",
                           help="Integer indices of genes to ignore "
                                "entirely.  In the output count matrix, "
                                "the counts for these genes will be set "
                                "to zero.")
    subparser.add_argument("--learning-rate", nargs=None,
                           type=float, default=1e-3,
                           dest="learning_rate",
                           help="Training detail: learning rate for "
                                "inference (probably "
                                "do not exceed 1e-3).")

    return subparsers
Exemple #20
0
def add_subparser_args(subparsers: argparse) -> argparse:
    """Add tool-specific arguments for remove-background.

    Args:
        subparsers: Parser object before addition of arguments specific to
            remove-background.

    Returns:
        parser: Parser object with additional parameters.

    """

    subparser = subparsers.add_parser("remove-background",
                                      description="Remove background RNA "
                                                  "from count matrix.",
                                      help="Remove background ambient RNA "
                                           "and barcode-swapped reads from "
                                           "a count matrix, producing a "
                                           "new count matrix and "
                                           "determining which barcodes "
                                           "contain real cells.")

    subparser.add_argument("--input", nargs=None, type=str,
                           dest='input_file', default=None,
                           required=True,
                           help="Data file on which to run tool, as either "
                                "_raw_gene_barcode_matrices_h5.h5 file, or "
                                "as the path containing the raw "
                                "matrix.mtx, barcodes.tsv, and genes.tsv "
                                "files. Supported for outputs of "
                                "CellRanger v2 and v3.")
    subparser.add_argument("--output", nargs=None, type=str,
                           dest='output_file', default=None,
                           required=True,
                           help="Output file location (the path must "
                                "exist, and the file name must have .h5 "
                                "extension).")
    subparser.add_argument("--expected-cells", nargs=None, type=int,
                           default=None,
                           dest="expected_cell_count",
                           help="Number of cells expected in the dataset "
                                "(a rough estimate within a factor of 2 "
                                "is sufficient).")
    subparser.add_argument("--total-droplets-included",
                           nargs=None, type=int,
                           default=consts.TOTAL_DROPLET_DEFAULT,
                           dest="total_droplets",
                           help="The number of droplets from the "
                                "rank-ordered UMI plot that will be "
                                "analyzed. The largest 'total_droplets' "
                                "droplets will have their cell "
                                "probabilities inferred as an output. (default: %(default)s)")
    subparser.add_argument("--model", nargs=None, type=str,
                           default="full",
                           choices=["simple", "ambient", "swapping", "full"],
                           dest="model",
                           help="Which model is being used for count data. "
                                " 'simple' does not model either ambient "
                                "RNA or random barcode swapping (for "
                                "debugging purposes -- not recommended).  "
                                "'ambient' assumes background RNA is "
                                "incorporated into droplets.  'swapping' "
                                "assumes background RNA comes from random "
                                "barcode swapping.  'full' uses a "
                                "combined ambient and swapping model.  "
                                "(default: %(default)s)")
    subparser.add_argument("--epochs", nargs=None, type=int, default=150,
                           dest="epochs",
                           help="Number of epochs to train. (default: %(default)s)")
    subparser.add_argument("--cuda",
                           dest="use_cuda", action="store_true",
                           help="Including the flag --cuda will run the "
                                "inference on a GPU.")
    subparser.add_argument("--low-count-threshold", type=int,
                           default=consts.LOW_UMI_CUTOFF,
                           dest="low_count_threshold",
                           help="Droplets with UMI counts below this "
                                "number are completely excluded from the "
                                "analysis.  This can help identify the "
                                "correct prior for empty droplet counts "
                                "in the rare case where empty counts "
                                "are extremely high (over 200). (default: %(default)s)")
    subparser.add_argument("--z-dim", type=int, default=100,
                           dest="z_dim",
                           help="Dimension of latent variable z. (default: %(default)s)")
    subparser.add_argument("--z-layers", nargs="+", type=int, default=[500],
                           dest="z_hidden_dims",
                           help="Dimension of hidden layers in the encoder "
                                "for z. (default: %(default)s)")
    subparser.add_argument("--training-fraction",
                           type=float, nargs=None,
                           default=consts.TRAINING_FRACTION,
                           dest="training_fraction",
                           help="Training detail: the fraction of the "
                                "data used for training.  The rest is never "
                                "seen by the inference algorithm.  Speeds up "
                                "learning. (default: %(default)s)")
    subparser.add_argument("--empty-drop-training-fraction",
                           type=float, nargs=None,
                           default=consts.FRACTION_EMPTIES,
                           dest="fraction_empties",
                           help="Training detail: the fraction of the "
                                "training data each epoch "
                                "that is drawn (randomly sampled) from "
                                "surely empty droplets. (default: %(default)s)")
    subparser.add_argument("--blacklist-genes", nargs="+", type=int,
                           default=[],
                           dest="blacklisted_genes",
                           help="Integer indices of genes to ignore "
                                "entirely.  In the output count matrix, "
                                "the counts for these genes will be set "
                                "to zero.")
    subparser.add_argument("--fpr", nargs="+",
                           type=float, default=[0.01],
                           dest="fpr",
                           help="Target false positive rate in (0, 1).  A false "
                                "positive is a true signal count that is "
                                "erroneously removed.  More background removal "
                                "is accompanied by more signal removal "
                                "at high values of FPR.  You can specify "
                                "multiple values, which will create multiple "
                                "output files. (default: %(default)s)")
    subparser.add_argument("--exclude-antibody-capture",
                           dest="exclude_antibodies", action="store_true",
                           help="Including the flag --exclude-antibody-capture "
                                "will cause remove-background to operate on "
                                "gene counts only, ignoring other features.")
    subparser.add_argument("--learning-rate", nargs=None,
                           type=float, default=1e-4,
                           dest="learning_rate",
                           help="Training detail: lower learning rate for "
                                "inference. A OneCycle learning rate schedule "
                                "is used, where the upper learning rate is ten "
                                "times this value. (For this value, probably "
                                "do not exceed 1e-3). (default: %(default)s)")
    subparser.add_argument("--final-elbo-fail-fraction", type=float,
                           help="Training is considered to have failed if "
                                "final_training_ELBO >= best_training_ELBO*(1+FINAL_ELBO_FAIL_FRACTION). "
                                "(default: do not fail training based on final_training_ELBO)")
    subparser.add_argument("--epoch-elbo-fail-fraction", type=float,
                           help="Training is considered to have failed if "
                                "current_epoch_training_ELBO >= previous_epoch_training_ELBO*(1+EPOCH_ELBO_FAIL_FRACTION). "
                                "(default: do not fail training based on epoch_training_ELBO)")
    subparser.add_argument("--num-training-tries", type=int, default=1,
                           help="Number of times to attempt to train the model.  Each subsequent "
                                "attempt the learning rate is multiplied by LEARNING_RATE_RETRY_MULT. "
                                "(default: %(default)s)")
    subparser.add_argument("--learning-rate-retry-mult", type=float, default=0.5,
                           help="Learning rate is multiplied by this amount each time "
                                "(default: %(default)s)")

    subparser.add_argument("--posterior-batch-size", type=int, default=consts.PROP_POSTERIOR_BATCH_SIZE,
                           dest="posterior_batch_size",
                           help="Size of batches when creating the posterior.  Reduce this to avoid "
                                "running out of GPU memory creating the posterior (will be slower). "
                                "(default: %(default)s)")
    subparser.add_argument("--cells-posterior-reg-calc", type=int, default=consts.CELLS_POSTERIOR_REG_CALC,
                           dest="cells_posterior_reg_calc",
                           help="Number of cells used to estimate posterior regularization lambda. "
                                "(default: %(default)s)")

    return subparsers
Exemple #21
0
    def add_subparser_args(self, subparsers: argparse) -> argparse:
        """Add tool-specific arguments for remove_background.

        Args:
            subparsers: Parser object before addition of arguments specific to
                remove_background.

        Returns:
            parser: Parser object with additional parameters.

        """

        subparser = subparsers.add_parser(
            self.name,
            description="Remove background RNA from "
            "count matrix.",
            help="Remove background ambient RNA and "
            "barcode-swapped reads from a count "
            "matrix, producing a new count matrix "
            "and determining which barcodes "
            "contain real cells.")

        subparser.add_argument("--input",
                               nargs="+",
                               type=str,
                               dest='input_files',
                               default=[],
                               help="Data files on which to run tool, as "
                               "_raw_gene_barcode_matrices_h5.h5 files.")
        subparser.add_argument(
            "--output",
            nargs="+",
            type=str,
            dest='output_files',
            default=[],
            help="Path to location of output data files, which "
            "will be .h5 files.")
        subparser.add_argument("--epochs",
                               type=int,
                               default=150,
                               dest="epochs",
                               help="Number of epochs to train.")
        subparser.add_argument("--z_dim",
                               type=int,
                               default=20,
                               dest="z_dim",
                               help="Dimension of latent variable z.")
        subparser.add_argument(
            "--z_layers",
            nargs="+",
            type=int,
            default=[500],
            dest="z_hidden_dims",
            help="Dimension of hidden layers in the encoder for z.")
        subparser.add_argument(
            "--d_layers",
            nargs="+",
            type=int,
            default=[5, 2, 2],
            dest="d_hidden_dims",
            help="Dimension of hidden layers in the encoder for d.")
        subparser.add_argument(
            "--p_layers",
            nargs="+",
            type=int,
            default=[100, 10],
            dest="p_hidden_dims",
            help="Dimension of hidden layers in the encoder for p.")
        subparser.add_argument(
            "--expected_cells",
            nargs="+",
            type=int,
            default=[None],
            dest="expected_cell_count",
            help="Number of cells expected in each dataset.")
        subparser.add_argument(
            "--additional_barcodes",
            nargs="+",
            type=int,
            default=[None],
            dest="additional_barcodes",
            help="The number of additional droplets after the "
            "number of expected cells "
            "that have any chance of containing cells.")
        subparser.add_argument(
            "--empty_drop_training_fraction",
            type=float,
            default=0.5,
            dest="fraction_empties",
            help="Fraction of the training data that should be "
            "empty droplets.")
        subparser.add_argument(
            "--training_fraction",
            type=float,
            default=0.95,
            dest="training_fraction",
            help="Fraction of the data to use for training.")
        subparser.add_argument("--blacklist_genes",
                               nargs="+",
                               type=int,
                               default=[],
                               dest="blacklisted_genes",
                               help="Indices of genes to ignore entirely.")
        subparser.add_argument(
            "--model",
            nargs="+",
            type=str,
            default=["full"],
            choices=["simple", "ambient", "swapping", "full"],
            dest="model",
            help="Which model is being used for count data.  "
            "'simple' does not model background or ambient "
            "RNA.  'ambient' assumes background RNA is "
            "incorporated into droplets.  'swapping' assumes "
            "background RNA comes from barcode swapping. "
            "'full' uses a combined ambient and swapping "
            "model.")
        subparser.add_argument(
            "--transform_counts",
            nargs=1,
            type=str,
            default=["identity"],
            choices=["identity", "log", "sqrt"],
            dest="transform",
            help="Transformation to apply to count data prior "
            "to running inference.")
        subparser.add_argument(
            "--learning_rate",
            type=float,
            default=1e-3,
            dest="learning_rate",
            help="Learning rate for inference (probably don't "
            "exceed 1e-3).")
        # subparser.add_argument("--lambda", type=float, default=0.,
        #                        dest="lambda_reg",
        #                        help="Regularization parameter.  Default zero.  "
        #                             "L1 regularizer applied to decoder.")
        subparser.add_argument(
            "--cuda",
            dest="use_cuda",
            action="store_true",
            help="Including the flag --cuda will run the inference "
            "on a GPU.")
        subparser.add_argument("--decaying_average_baseline",
                               dest="use_decaying_average_baseline",
                               action="store_true",
                               help="Including the flag "
                               "--decaying_average_baseline will use a "
                               "decaying average baseline during inference.")
        subparser.add_argument("--use_IAF",
                               dest="use_IAF",
                               action="store_true",
                               help="Including the flag "
                               "--use_IAF will use an inverse autoregressive "
                               "flow during inference to allow more "
                               "flexibility in the learned posterior.")
        subparser.add_argument("--low_count_threshold",
                               type=int,
                               default=30,
                               dest="low_count_threshold",
                               help="Droplets with UMI counts below this are"
                               "completely excluded from the analysis.  This "
                               "can help adjust the prior for empty droplet "
                               "counts in the rare case where empty counts "
                               "are extremely high (over 200).")
        subparser.add_argument(
            "--test",
            dest="test",
            action="store_true",
            help="Including the flag --test will run tests only, "
            "and disregard other input parameters.")

        return subparsers
Exemple #22
0
def task_parser(sup_parser: argparse):
    task_parser = sup_parser.add_parser(
        'task', help='Manage tasks. Task is the main application object.')
    task_subparser = task_parser.add_subparsers(
        dest='action', metavar='', description='Commands to work with tasks')
    task_subparser.required = True

    create = task_subparser.add_parser('create', help='Create new task')
    create.add_argument('name', help='Task name')
    create.add_argument('-d', '--description', help='Task description')
    create.add_argument('-s',
                        '--start_date',
                        type=valid_date,
                        help='Start date (current time by default)')
    create.add_argument('-e', '--end_date', type=valid_date, help='End date')
    create.add_argument('-p',
                        '--parent_task_id',
                        type=valid_int,
                        help='Parent task id')
    create.add_argument('--priority',
                        type=str,
                        choices=[x.name.lower() for x in TaskPriority])
    create.add_argument('--status',
                        type=str,
                        choices=[x.name.lower() for x in TaskStatus])
    create.add_argument('--event',
                        help='Mark as event. No by default settings',
                        choices=['yes', 'no'])

    show = task_subparser.add_parser('show', help='Show tasks')
    task_show_parser(show)

    edit = task_subparser.add_parser('edit', help='Edit task with provided id')
    edit.add_argument('-tid', '--task_id', required=True, type=valid_int)
    edit.add_argument('-n', '--name', help='Task name')
    edit.add_argument('-d', '--description', help='Task description')
    edit.add_argument('-s', '--start_date', type=valid_date, help='Start date')
    edit.add_argument('-e', '--end_date', type=valid_date, help='End date')
    edit.add_argument('--priority',
                      type=str,
                      choices=[x.name.lower() for x in TaskPriority])
    edit.add_argument('--status',
                      type=str,
                      choices=[x.name.lower() for x in TaskStatus])
    edit.add_argument('--event',
                      choices=['yes', 'no'],
                      help='Mark as event. No by default settings')

    share = task_subparser.add_parser('share', help='Share task with user')
    share.add_argument('-tid',
                       '--task_id',
                       type=valid_int,
                       help='Id of task to be shared',
                       required=True)
    share.add_argument('-ur',
                       '--user_receiver',
                       type=str,
                       help='User name to share task with',
                       required=True)

    unshare = task_subparser.add_parser('unshare',
                                        help='Unshare shared task with user')
    unshare.add_argument('-tid',
                         '--task_id',
                         help='Task id',
                         required=True,
                         type=valid_int)
    unshare.add_argument('-urn',
                         '--user_receiver',
                         help='User name to unshare task with',
                         required=True,
                         type=str)

    assign = task_subparser.add_parser('assign', help='Assign task executor')
    assign.add_argument('-tid',
                        '--task_id',
                        help='Task id',
                        required=True,
                        type=valid_int)
    assign.add_argument('-urn',
                        '--user_receiver',
                        help='User name to assign task',
                        required=True,
                        type=str)

    subtask = task_subparser.add_parser(
        'add_subtask',
        help='Set task with task_id as the subtask of task with parent_id')
    subtask.add_argument('-tid',
                         '--task_id',
                         required=True,
                         help='Task id',
                         type=valid_int)
    subtask.add_argument('-pid',
                         '--parent_task_id',
                         help='Parent task id',
                         required=True,
                         type=valid_int)

    subtask = task_subparser.add_parser(
        'detach', help='Remove relation between task and parent task')
    subtask.add_argument('-tid',
                         '--task_id',
                         required=True,
                         help='Task id to detach from parent task',
                         type=valid_int)

    archive = task_subparser.add_parser('archive', help='Archive task')
    archive.add_argument('--subtasks',
                         action='store_true',
                         help='Archive subtasks too')

    archive.add_argument('task_id', help='task id', type=valid_int)
    done = task_subparser.add_parser('done', help='Done task')
    done.add_argument('task_id', help='task id', type=valid_int)

    search = task_subparser.add_parser(
        'search', help='Case insensitive task search by name')
    search.add_argument('name', help='Task name')

    filter = task_subparser.add_parser('filter',
                                       help='Search tasks by specified params')
    filter.add_argument('-n', '--name', help='Task name')
    filter.add_argument('-d', '--description', help='Task description')
    filter.add_argument('-s',
                        '--start_date',
                        type=valid_date,
                        help='Task start date from')
    filter.add_argument('-e',
                        '--end_date',
                        type=valid_date,
                        help='Task end date till to')
    filter.add_argument('-p',
                        '--parent_task_id',
                        type=valid_int,
                        help='Parent task id')
    filter.add_argument('--priority',
                        choices=[x.name.lower() for x in TaskPriority],
                        help='Task priority')
    filter.add_argument('--status',
                        choices=[x.name.lower() for x in TaskStatus],
                        help='Task status')
    filter.add_argument('--event', choices=['yes', 'no'], help='Is Event')

    delete = task_subparser.add_parser('delete',
                                       help='Delete task with provided id')
    delete.add_argument('task_id', type=valid_int)
Exemple #23
0
    def add_parser(self, parser: argparse):
        # pylint: disable=protected-access
        parser.add_argument('archive_file',
                            type=str,
                            help='path to an archived trained model')

        parser.add_argument(
            'input_file',
            type=str,
            help='path to the file containing the evaluation data')

        parser.add_argument('--output-file',
                            type=str,
                            help='path to output file')

        parser.add_argument(
            '--weights-file',
            type=str,
            help='a path that overrides which weights file to use')

        cuda_device = parser.add_mutually_exclusive_group(required=False)
        cuda_device.add_argument('--cuda-device',
                                 type=int,
                                 default=-1,
                                 help='id of GPU to use (if any)')

        parser.add_argument(
            '-t',
            '--thresholds',
            type=str,
            default="0",
            help=
            'A comma (,) or underscore (_) separated list of temperature thresholds to consider'
        )

        parser.add_argument(
            '-o',
            '--overrides',
            type=str,
            default="",
            help=
            'a JSON structure used to override the experiment configuration')

        parser.add_argument(
            '--batch-weight-key',
            type=str,
            default="",
            help=
            'If non-empty, name of metric used to weight the loss on a per-batch basis.'
        )

        parser.add_argument(
            '--extend-vocab',
            action='store_true',
            default=False,
            help=
            'if specified, we will use the instances in your new dataset to '
            'extend your vocabulary. If pretrained-file was used to initialize '
            'embedding layers, you may also need to pass --embedding-sources-mapping.'
        )

        parser.add_argument(
            '--embedding-sources-mapping',
            type=str,
            default="",
            help=
            'a JSON dict defining mapping from embedding module path to embedding'
            'pretrained-file used during training. If not passed, and embedding needs to be '
            'extended, we will try to use the original file paths used during training. If '
            'they are not available we will use random vectors for embedding extension.'
        )
        parser.add_argument('--include-package',
                            type=str,
                            action='append',
                            default=[],
                            help='additional packages to include')
        parser.set_defaults(func=evaluate_from_args)