def test_extract_countgraph_info_badfile(): try: khmer.extract_countgraph_info( utils.get_test_data('test-abund-read-2.fa')) assert 0, 'this should fail' except ValueError: pass
def check_conflicting_args(args, hashtype): """ Check argparse args object for conflicts. e.g. --loadgraph and --ksize being set. """ if getattr(args, "quiet", None): configure_logging(args.quiet) loadgraph_table_conflicts = { "ksize": DEFAULT_K, "n_tables": DEFAULT_N_TABLES, "max_tablesize": DEFAULT_MAX_TABLESIZE } loadgraph_autoarg_conflicts = ("unique_kmers", "max_memory_usage") if getattr(args, "loadgraph", None): # check for table config args for key, value in loadgraph_table_conflicts.items(): if getattr(args, key, value) != value: log_warn(''' *** WARNING: You are loading a saved k-mer countgraph from *** {hashfile}, but have set k-mer table parameters. *** Your values for ksize, n_tables, and tablesize *** will be ignored.'''.format(hashfile=args.loadgraph)) break # no repeat warnings for element in loadgraph_autoarg_conflicts: if getattr(args, element, None): log_warn("\n*** WARNING: You have asked that the graph size be" " automatically calculated\n" "*** (by using -U or -M).\n" "*** But you are loading an existing graph!\n" "*** Size will NOT be set automatically.") break # no repeat warnings infoset = None if hashtype in ('countgraph', 'smallcountgraph'): infoset = extract_countgraph_info(args.loadgraph) if infoset is not None: ksize = infoset.ksize max_tablesize = infoset.table_size n_tables = infoset.n_tables args.ksize = ksize args.n_tables = n_tables args.max_tablesize = max_tablesize if infoset.ht_type == khmer.FILETYPES['SMALLCOUNT']: args.small_count = True
def check_conflicting_args(args, hashtype): """ Utility function that takes in an args object and checks if there's things that conflict, e.g. --loadgraph and --ksize being set. """ if getattr(args, "quiet", None): configure_logging(args.quiet) loadgraph_table_conflicts = { "ksize": DEFAULT_K, "n_tables": DEFAULT_N_TABLES, "max_tablesize": DEFAULT_MAX_TABLESIZE } loadgraph_autoarg_conflicts = ("unique_kmers", "max_memory_usage") if getattr(args, "loadgraph", None): # check for table config args for key, value in loadgraph_table_conflicts.items(): if getattr(args, key, value) != value: log_warn(''' *** WARNING: You are loading a saved k-mer countgraph from *** {hashfile}, but have set k-mer table parameters. *** Your values for ksize, n_tables, and tablesize *** will be ignored.'''.format(hashfile=args.loadgraph)) break # no repeat warnings for element in loadgraph_autoarg_conflicts: if getattr(args, element, None): log_warn("\n*** WARNING: You have asked that the graph size be" " automatically calculated\n" "*** (by using -U or -M).\n" "*** But you are loading an existing graph!\n" "*** Size will NOT be set automatically.") break # no repeat warnings infoset = None if hashtype == 'countgraph': infoset = extract_countgraph_info(args.loadgraph) if info: ksize = infoset[0] max_tablesize = infoset[1] n_tables = infoset[2] args.ksize = ksize args.n_tables = n_tables args.max_tablesize = max_tablesize
def check_conflicting_args(args, hashtype): """ Check argparse args object for conflicts. e.g. --loadgraph and --ksize being set. """ if getattr(args, "quiet", None): configure_logging(args.quiet) loadgraph_table_conflicts = {"ksize": DEFAULT_K, "n_tables": DEFAULT_N_TABLES, "max_tablesize": DEFAULT_MAX_TABLESIZE} loadgraph_autoarg_conflicts = ("unique_kmers", "max_memory_usage") if getattr(args, "loadgraph", None): # check for table config args for key, value in loadgraph_table_conflicts.items(): if getattr(args, key, value) != value: log_warn(''' *** WARNING: You are loading a saved k-mer countgraph from *** {hashfile}, but have set k-mer table parameters. *** Your values for ksize, n_tables, and tablesize *** will be ignored.'''.format(hashfile=args.loadgraph)) break # no repeat warnings for element in loadgraph_autoarg_conflicts: if getattr(args, element, None): log_warn("\n*** WARNING: You have asked that the graph size be" " automatically calculated\n" "*** (by using -U or -M).\n" "*** But you are loading an existing graph!\n" "*** Size will NOT be set automatically.") break # no repeat warnings infoset = None if hashtype in ('countgraph', 'smallcountgraph'): infoset = extract_countgraph_info(args.loadgraph) if infoset is not None: ksize = infoset.ksize max_tablesize = infoset.table_size n_tables = infoset.n_tables args.ksize = ksize args.n_tables = n_tables args.max_tablesize = max_tablesize if infoset.ht_type == khmer.FILETYPES['SMALLCOUNT']: args.small_count = True
def check_conflicting_args(args, hashtype): """ Utility function that takes in an args object and checks if there's things that conflict, e.g. --loadgraph and --ksize being set. """ if getattr(args, "quiet", None): configure_logging(args.quiet) loadgraph_table_conflicts = {"ksize": DEFAULT_K, "n_tables": DEFAULT_N_TABLES, "max_tablesize": DEFAULT_MAX_TABLESIZE} loadgraph_autoarg_conflicts = ("unique_kmers", "max_memory_usage") if getattr(args, "loadgraph", None): # check for table config args for key, value in loadgraph_table_conflicts.items(): if getattr(args, key, value) != value: log_warn(''' *** WARNING: You are loading a saved k-mer countgraph from *** {hashfile}, but have set k-mer table parameters. *** Your values for ksize, n_tables, and tablesize *** will be ignored.'''.format(hashfile=args.loadgraph)) break # no repeat warnings for element in loadgraph_autoarg_conflicts: if getattr(args, element, None): log_warn("\n*** WARNING: You have asked that the graph size be" " automatically calculated\n" "*** (by using -U or -M).\n" "*** But you are loading an existing graph!\n" "*** Size will NOT be set automatically.") break # no repeat warnings infoset = None if hashtype == 'countgraph': infoset = extract_countgraph_info(args.loadgraph) if info: ksize = infoset[0] max_tablesize = infoset[1] n_tables = infoset[2] args.ksize = ksize args.n_tables = n_tables args.max_tablesize = max_tablesize
def test_extract_countgraph_info(): fn = utils.get_temp_filename('test_extract_counting.ct') for size in [1e6, 2e6, 5e6, 1e7]: ht = khmer.Countgraph(25, size, 4) ht.save(fn) try: info = khmer.extract_countgraph_info(fn) except ValueError as err: assert 0, 'Should not throw a ValueErorr: ' + str(err) ksize, n_tables, table_size, _, _, _, _ = info print(ksize, table_size, n_tables) assert(ksize) == 25 assert table_size == size assert n_tables == 4 try: os.remove(fn) except OSError as err: assert 0, '...failed to remove ' + fn + str(err)