<p>255 is the default maximum size of a <code>Counttable</code> in khmer. You want to do the following:</p>

<pre class="lang-py prettyprint-override"><code>import khmer
counts = khmer.Counttable(31, 1e7, 1)  # Feel free to change the parameters
counts.set_use_bigcount(True)
</code></pre>

<p>The last line increases the maximum value from 255 to 65535. I don't think there's any way to currently go above that without changing the khmer code (at some point you have to increase the size of the number used in the hash table).</p>

CC BY-SA 3.0
2018-03-07T19:57:04.743Z
2018-03-07T21:16:08.987Z
2018-03-07T21:16:08.987Z
Devon Ryan
<p>I have a Fastq file and I want to get the exact count of each possible kmer from this file.</p>

<p>On a previous post called <a href="https://bioinformatics.stackexchange.com/a/562/48">How to use khmer to count k-mers?</a> Daniel Standage proposed a custom script based on khmer methods that you can see down below :</p>

<pre><code>&gt;&gt;&gt; outfile = open('outfile.txt', 'w') 
&gt;&gt;&gt; seenkmers = set()  # Consumes a lot of memory for large input!!!
&gt;&gt;&gt; for read in khmer.ReadParser('reads.fq.gz'):
...     for kmer in counts.get_kmers(read.sequence):
...         if kmer not in seenkmers:
...             print(kmer, counttable.get(kmer), file=outfile)
...             seenkmers.add(kmer)
</code></pre>

<p>The code works if I switch <code>counttable.get(kmer)</code> with <code>counts.get(kmer)</code> but the main problem is that when I try on a customized fastq file with 300 occurrences of one kmer, the count will still be stuck at 255 and can't go further, and for some reason I can't pass through this limit.</p>

<p>Is this coming from the minimum table size ?</p>

<p>Does anyone know if there is a parameter that can work on a custom script to disable this limit ? </p>

<python><fastq><k-mer><khmer>
How to get the count of each kmer past 255 using khmer
# How to get the count of each kmer past 255 using khmer

(Asked by: username_0 on 2018-03-07)

I have a Fastq file and I want to get the exact count of each possible kmer from this file.
On a previous post called How to use khmer to count k-mers? Daniel Standage proposed a custom script based on khmer methods that you can see down below :
>>> outfile = open('outfile.txt', 'w') 
>>> seenkmers = set()  # Consumes a lot of memory for large input!!!
>>> for read in khmer.ReadParser('reads.fq.gz'):
...     for kmer in counts.get_kmers(read.sequence):
...         if kmer not in seenkmers:
...             print(kmer, counttable.get(kmer), file=outfile)
...             seenkmers.add(kmer)

The code works if I switch counttable.get(kmer) with counts.get(kmer) but the main problem is that when I try on a customized fastq file with 300 occurrences of one kmer, the count will still be stuck at 255 and can't go further, and for some reason I can't pass through this limit.
Is this coming from the minimum table size ?
Does anyone know if there is a parameter that can work on a custom script to disable this limit ?

**Tags:** python, fastq, k-mer, khmer

---

## 1 answers

### Answer by username_1 on 2018-03-07. Score: 6 | Accepted answer

255 is the default maximum size of a Counttable in khmer. You want to do the following:
import khmer
counts = khmer.Counttable(31, 1e7, 1)  # Feel free to change the parameters
counts.set_use_bigcount(True)

The last line increases the maximum value from 255 to 65535. I don't think there's any way to currently go above that without changing the khmer code (at some point you have to increase the size of the number used in the hash table).


---

