Пример #1
0
def test_extract_hashbits_info_badfile():
    try:
        khmer.extract_hashbits_info(
            utils.get_test_data('test-abund-read-2.fa'))
        assert 0, 'this should fail'
    except ValueError:
        pass
Пример #2
0
        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)
Пример #3
0
        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)
Пример #4
0
        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)
Пример #5
0
        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)
Пример #6
0
def test_extract_hashbits_info():
    fn = utils.get_temp_filename('test_extract_hashbits.pt')
    for size in [1e6, 2e6, 5e6, 1e7]:
        ht = khmer.Hashbits(25, size, 4)
        ht.save(fn)

        info = khmer.extract_hashbits_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.stderr, '...failed to remove {fn}'.format(fn)
Пример #7
0
def test_extract_hashbits_info():
    fn = utils.get_temp_filename('test_extract_hashbits.pt')
    for size in [1e6, 2e6, 5e6, 1e7]:
        ht = khmer.Hashbits(25, size, 4)
        ht.save(fn)

        info = khmer.extract_hashbits_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.stderr, '...failed to remove {fn}'.format(fn)
Пример #8
0
        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)
Пример #9
0
def test_extract_hashbits_info_badfile():
    try:
        khmer.extract_hashbits_info(utils.get_test_data("test-abund-read-2.fa"))
        assert 0, "this should fail"
    except ValueError:
        pass