def test_extract_countinghash_info_badfile(): try: khmer.extract_countinghash_info( utils.get_test_data('test-abund-read-2.fa')) assert 0, 'this should fail' except ValueError: pass
def __call__(self, parser, namespace, values, option_string=None): env_ksize = os.environ.get('KHMER_KSIZE', DEFAULT_K) env_n_tables = os.environ.get('KHMER_N_TABLES', DEFAULT_N_TABLES) env_tablesize = os.environ.get('KHMER_MIN_TABLESIZE', DEFAULT_MIN_TABLESIZE) from khmer.utils import print_error setattr(namespace, self.dest, values) if getattr(namespace, 'ksize') != env_ksize or \ getattr(namespace, 'n_tables') != env_n_tables or \ getattr(namespace, 'min_tablesize') != env_tablesize: if values: print_error(''' ** WARNING: You are loading a saved k-mer table from {hashfile}, but have set k-mer table parameters. Your values for ksize, n_tables, and tablesize will be ignored.'''.format(hashfile=values)) if hasattr(parser, 'hashtype'): info = None if parser.hashtype == 'hashbits': info = extract_hashbits_info( getattr(namespace, self.dest)) elif parser.hashtype == 'counting': info = extract_countinghash_info( getattr(namespace, self.dest)) if info: K = info[0] x = info[1] n = info[2] setattr(namespace, 'ksize', K) setattr(namespace, 'n_tables', n) setattr(namespace, 'min_tablesize', x)
def __call__(self, parser, namespace, values, option_string=None): env_ksize = os.environ.get('KHMER_KSIZE', DEFAULT_K) env_n_tables = os.environ.get('KHMER_N_TABLES', DEFAULT_N_TABLES) env_tablesize = os.environ.get('KHMER_MIN_TABLESIZE', DEFAULT_MIN_TABLESIZE) from khmer.utils import print_error setattr(namespace, self.dest, values) if getattr(namespace, 'ksize') != env_ksize or \ getattr(namespace, 'n_tables') != env_n_tables or \ getattr(namespace, 'min_tablesize') != env_tablesize: if values: print_error(''' ** WARNING: You are loading a saved k-mer table from {hashfile}, but have set k-mer table parameters. Your values for ksize, n_tables, and tablesize will be ignored.'''.format(hashfile=values)) if hasattr(parser, 'hashtype'): info = None if parser.hashtype == 'hashbits': info = extract_hashbits_info(getattr(namespace, self.dest)) elif parser.hashtype == 'counting': info = extract_countinghash_info( getattr(namespace, self.dest)) if info: K = info[0] x = info[1] n = info[2] setattr(namespace, 'ksize', K) setattr(namespace, 'n_tables', n) setattr(namespace, 'min_tablesize', x)
def __call__(self, parser, namespace, values, option_string=None): setattr(namespace, self.dest, values) if getattr(namespace, 'ksize') != DEFAULT_K or \ getattr(namespace, 'n_tables') != DEFAULT_N_TABLES or \ getattr(namespace, 'max_tablesize') != DEFAULT_MAX_TABLESIZE: if values: print_error(''' ** WARNING: You are loading a saved k-mer table from ** {hashfile}, but have set k-mer table parameters. ** Your values for ksize, n_tables, and tablesize ** will be ignored.'''.format(hashfile=values)) if hasattr(parser, 'hashtype'): info = None if parser.hashtype == 'nodegraph': info = extract_hashbits_info( getattr(namespace, self.dest)) elif parser.hashtype == 'countgraph': info = extract_countinghash_info( getattr(namespace, self.dest)) if info: K = info[0] x = info[1] n = info[2] setattr(namespace, 'ksize', K) setattr(namespace, 'n_tables', n) setattr(namespace, 'max_tablesize', x)
def test_extract_countinghash_info(): fn = utils.get_temp_filename('test_extract_counting.ct') for size in [1e6, 2e6, 5e6, 1e7]: ht = khmer.new_counting_hash(25, size, 4) ht.save(fn) info = khmer.extract_countinghash_info(fn) ksize, table_size, n_tables, _, _, _ = 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 e: print >>sys.stder, '...failed to remove {fn}'.format(fn)
def test_extract_countinghash_info(): fn = utils.get_temp_filename('test_extract_counting.ct') for size in [1e6, 2e6, 5e6, 1e7]: ht = khmer.new_counting_hash(25, size, 4) ht.save(fn) try: info = khmer.extract_countinghash_info(fn) except ValueError as err: assert 0, 'Should not throw a ValueErorr: ' + str(err) ksize, table_size, n_tables, _, _, _ = 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)
def test_extract_countinghash_info(): fn = utils.get_temp_filename("test_extract_counting.ct") for size in [1e6, 2e6, 5e6, 1e7]: ht = khmer.new_counting_hash(25, size, 4) ht.save(fn) try: info = khmer.extract_countinghash_info(fn) except ValueError as err: assert 0, "Should not throw a ValueErorr: " + str(err) ksize, table_size, n_tables, _, _, _ = 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)
def __call__(self, parser, namespace, values, option_string=None): env_ksize = os.environ.get("KHMER_KSIZE", DEFAULT_K) env_n_tables = os.environ.get("KHMER_N_TABLES", DEFAULT_N_TABLES) env_tablesize = os.environ.get("KHMER_MIN_TABLESIZE", DEFAULT_MIN_TABLESIZE) from khmer.utils import print_error setattr(namespace, self.dest, values) if ( getattr(namespace, "ksize") != env_ksize or getattr(namespace, "n_tables") != env_n_tables or getattr(namespace, "min_tablesize") != env_tablesize ): if values: print_error( """ ** WARNING: You are loading a saved k-mer table from {hashfile}, but have set k-mer table parameters. Your values for ksize, n_tables, and tablesize will be ignored.""".format( hashfile=values ) ) if hasattr(parser, "hashtype"): info = None if parser.hashtype == "hashbits": info = extract_hashbits_info(getattr(namespace, self.dest)) elif parser.hashtype == "counting": info = extract_countinghash_info(getattr(namespace, self.dest)) if info: K = info[0] x = info[1] n = info[2] setattr(namespace, "ksize", K) setattr(namespace, "n_tables", n) setattr(namespace, "min_tablesize", x)
def test_extract_countinghash_info_badfile(): try: khmer.extract_countinghash_info(utils.get_test_data("test-abund-read-2.fa")) assert 0, "this should fail" except ValueError: pass