Beispiel #1
0
def check_arguments(args):
    errors = []
    errors += check_inputs(args, stdin_allowed=True)
    errors += check_outputs(args, stdout_allowed=True)
    errors += check_cpu_count(args)
    errors += check_file_arg(args.seqids_path, none_allowed=True,
                             prefix='-S/--seqids_path')
    errors += check_file_arg(args.descriptions_path, none_allowed=True,
                             prefix='-D/--descriptions_path')
    errors += check_file_arg(args.names_path, none_allowed=True,
                             prefix='-N/--names_path')
    errors += check_file_arg(args.mol_types_path, none_allowed=True,
                             prefix='-M/--mol_types_path')
    errors += check_file_arg(args.taxids_path, none_allowed=True,
                             prefix='-T/--taxids_path')
    if args.input_format != 'genbank':
        values = [args.names, args.mol_types, args.taxids]
        paths = [args.names_path, args.mol_types_path, args.taxids_path]
        prefixes = ['-n/-N', '-m/-M', '-t/-T']
        for value, path, prefix in zip(values, paths, prefixes):
            if value or path is not None:
                errors += ('{}: These options require input file(s) '
                           'in GenBank format.'.format(prefix))
    if args.comparison is None:
        args.comparison = COMPARISON
    if errors:
        for error in errors:
            print_stderr(error, prefix='ERROR')
        sys.exit(1)
Beispiel #2
0
def check_arguments(args):
    errors = []
    errors += check_file_arg(args.input_path, stdio_allowed=True)
    errors += check_file_arg(args.output_path,
                             mode='w',
                             stdio_allowed=True,
                             prefix='-o/--output_path')
    if errors:
        for error in errors:
            print_stderr(error, prefix='ERROR')
        sys.exit(1)
Beispiel #3
0
def check_arguments(args):
    errors = []
    errors += check_sequtils_inputs(args, stdin_allowed=True)
    errors += check_file_arg(args.seq_counts_path,
                             mode='w',
                             none_allowed=True,
                             prefix='-S/--seq_counts_path')
    errors += check_file_arg(args.base_counts_path,
                             mode='w',
                             none_allowed=True,
                             prefix='-C/--base_counts_path')
    if errors:
        for error in errors:
            print_stderr(error, prefix='ERROR')
        sys.exit(1)
Beispiel #4
0
def check_inputs(args,
                 ext=SEQFILE_EXTS,
                 zip_ext=ZIP_EXTS,
                 stdin_allowed=False):
    errors = []
    if args.input_paths is None:
        args.input_paths = [STDIO_PATH]
    try:
        input_files_indexed = args.index_paths is not None
    except AttributeError:
        input_files_indexed = False
    input_formats = set()
    for input_path in args.input_paths:
        error = check_file_arg(input_path,
                               ext=ext,
                               zip_ext=zip_ext,
                               stdio_allowed=stdin_allowed)
        if error:
            errors += error
        else:
            try:
                input_format = check_seq_file_format(
                    input_path,
                    args.input_format,
                    default_format=SEQFILE_FORMAT,
                    file_indexed=input_files_indexed)
                input_formats |= {input_format}
            except ValueError as exc:
                error = ['Input file ', input_path, ': ', str(exc)]
                errors.append(''.join(error))
    if (stdin_allowed and len(args.input_paths) > 1
            and STDIO_PATH in args.input_paths):
        errors.append('Standard input ({}) cannot be part of a list of '
                      'multiple input files.'.format(STDIO_PATH))
    if len(input_formats) > 1:
        errors.append('Input files must all have the same format.')
    elif len(input_formats) == 1:
        args.input_format = list(input_formats)[0]

    if not input_files_indexed:
        return errors
    if len(args.index_paths) not in [1, len(args.input_paths)]:
        errors.append('There must be one index file for each input file '
                      'or one for all.')
        return errors
    for index_path in args.index_paths:
        errors += check_file_arg(index_path, prefix='-i/--index_paths')
    return errors
Beispiel #5
0
def check_arguments(args):
    errors = []
    for annot_path in args.annot_paths:
        errors += check_file_arg(annot_path, stdio_allowed=True)
    errors += check_file_arg(args.tree_path, prefix='-t/--tree_path')
    errors += check_file_arg(args.seqids_path,
                             none_allowed=True,
                             prefix='-s/--seqids_path')
    errors += check_file_arg(args.output_path,
                             mode='w',
                             stdio_allowed=True,
                             prefix='-o/--output_path')
    if errors:
        for error in errors:
            print_stderr(error, prefix='ERROR')
        sys.exit(1)
Beispiel #6
0
def check_arguments(args):
    errors = []
    errors += check_inputs(args)
    errors += check_outputs(args, stdout_allowed=True)
    errors += check_cpu_count(args)
    errors += check_file_arg(args.removed_path,
                             mode='w',
                             none_allowed=True,
                             prefix='-r/--removed')
    if args.no_output:
        args.output_paths = None
    if errors:
        for error in errors:
            print_stderr(error, prefix='ERROR')
        sys.exit(1)
Beispiel #7
0
def check_arguments(args):
    errors = []
    errors += check_inputs(args, zip_ext=BGZIP_EXT)
    if args.output_path is None:
        if len(args.input_paths) > 1:
            args.output_path = 'index.idx'
        else:
            input_basename = os.path.basename(args.input_paths[0])
            args.output_path = input_basename + '.idx'
    errors += check_file_arg(args.output_path,
                             mode='w',
                             prefix='-o/--output_path')

    if errors:
        for error in errors:
            print_stderr(error, prefix='ERROR')
        sys.exit(1)
Beispiel #8
0
def check_outputs(args,
                  ext=SEQFILE_EXTS,
                  zip_ext=ZIP_EXTS,
                  stdout_allowed=False):
    errors = []
    if isinstance(args.output_path, list):
        if args.output_path is None:
            if not hasattr(args, 'no_output') or not args.no_output:
                args.output_path = STDIO_PATH
        output_paths = args.output_path
    else:
        if args.output_path is None:
            if not hasattr(args, 'no_output') or not args.no_output:
                args.output_path = [STDIO_PATH]
        output_paths = [args.output_path]

    try:
        default_format = args.input_format
    except AttributeError:
        default_format = SEQFILE_FORMAT

    output_formats = set()
    for output_path in output_paths:
        error = check_file_arg(output_path,
                               mode='w',
                               ext=ext,
                               zip_ext=zip_ext,
                               stdio_allowed=stdout_allowed,
                               prefix='-o/--output_path')
        if error:
            errors += error
        else:
            try:
                output_format = check_seq_file_format(
                    output_path,
                    args.output_format,
                    default_format=default_format)
                output_formats |= {output_format}
            except ValueError as exc:
                error = ['-o/--output_path: ', output_path, ': ', str(exc)]
                errors.append(''.join(error))

    if len(output_formats) > 1:
        errors.append(prefix + ': Output files must all have the same format.')
    elif len(output_formats) == 1:
        args.output_format = list(output_formats)[0]

    if stdout_allowed and len(output_paths) > 1 and STDIO_PATH in output_paths:
        errors.append('Standard output ({}) cannot be part of a list of '
                      'multiple output files.'.format(STDIO_PATH))

    try:
        nb_inputs = len(args.input_paths)
    except AttributeError:
        return errors

    try:
        nb_indices = len(args.index_paths)
    except (AttributeError, TypeError):
        nb_indices = 0

    if nb_inputs > 1 and nb_indices == 1 and len(output_paths) != 1:
        errors.append('If a common index file is specified for all input '
                      'files, only one output file must be specified.')
    elif len(output_paths) not in [1, nb_inputs]:
        errors.append('There must be one output file for each input file '
                      'or one for all.')
    return errors
Beispiel #9
0
def check_arguments(args):
    errors = []
    for annot_path in args.annot_paths:
        errors += check_file_arg(annot_path, stdio_allowed=True)
    for sample_path in args.sample_paths:
        errors += check_file_arg(sample_path, prefix='-s/--sample_path')
    errors += check_file_arg(args.tree_path, prefix='-t/--tree_path')
    errors += check_file_arg(args.ref_path, prefix='-r/--ref_path')
    errors += check_file_arg(args.info_path,
                             none_allowed=True,
                             prefix='-i/--info_path')
    errors += check_dir_arg(args.output_dir_path,
                            mode='w',
                            create=True,
                            prefix='-o/--output_dir_path')
    errors += check_bin_arg(args.lualatex_path, prefix='--lualatex_path')
    errors += check_num_arg(args.min_level,
                            number_type=int,
                            mini=1,
                            prefix='-l/--min_level')
    errors += check_num_arg(args.max_level,
                            number_type=int,
                            mini=1,
                            none_allowed=True,
                            prefix='-L/--max_level')
    errors += check_num_arg(args.min_fold_change,
                            number_type=float,
                            mini=1.0,
                            prefix='-f/--min_fold_change')
    errors += check_num_arg(args.max_pvalue,
                            number_type=float,
                            mini=0.0,
                            maxi=1.0,
                            prefix='-p/--max_pvalue')
    errors += check_num_arg(args.min_seq_count,
                            number_type=int,
                            mini=0,
                            prefix='-n/--min_seq_count')
    errors += check_num_arg(args.min_seq_prop,
                            number_type=float,
                            mini=0.0,
                            maxi=100.0,
                            prefix='-m/--min_seq_prop')
    if args.max_level is not None and args.min_level > args.max_level:
        error = '-l/-L: Max level must be greater than min level.'
        errors.append(error)
    if args.sample_names is not None:
        if len(args.sample_names) != len(args.sample_paths):
            error = ('-s/-S: The number of sample names does not match '
                     'the number of sample paths.')
            errors.append(error)
    if errors:
        for error in errors:
            print_stderr(error, prefix='ERROR')
        sys.exit(1)

    if args.output_types is None:
        args.output_types = OUTPUT_TYPES

    if not (args.process or args.function or args.component):
        args.process, args.function, args.component = True, True, True

    if not (args.up_reg or args.down_reg or args.not_reg):
        args.up_reg, args.down_reg, args.not_reg = True, True, False