statistic tools of Kmer including invalid character
Is there a tool that could be helpful to statistic kmers including invalid characters? For example, given a sequence "ANTTA", if K=3, then there will be three kmers which is "ANT","NTT" and "TTA".
• 2,588 views
•
link
1 answer
One way using seqkit, download:
$ echo -e ">seq\nANTTA" \
| seqkit sliding -s 1 -W 3 \
| seqkit grep -s -r -i -p '[^ACGT]' \
| grep -c '^>'
2
- data source: FASTA format
- sliding windows (compute K-mers), window size: K, step: 1
- searching FASTA sequences contain non-ACGT charactors
- counting sequences
[Update 1] Faster way:
$ echo -e ">seq\nANTTA" | seqkit sliding -s 1 -W 3 \
| seqkit seq -s -w 0 \
| grep -c '[^ACGTacgt]'
2
[Update 2] But it's still slow when the input sequences are very large (100Mb+), a much faster way is pre-retrieving sequence regions containing non-ACGT charactors and estimate using method above. (SeqKit v0.5.2-dev or later version needed).
$ cat seqs.fasta \
| seqkit locate -P -p '[^ACGTacgt]+' -G \
| sed 1d | cut -f 1,7 | seqkit tab2fx \
| seqkit sliding -s 1 -W 3 \
| seqkit seq -s -w 0 \
| grep -c '[^ACGTacgt]'
• 0 views
•
link
Log in to answer this question.
Is this a homework? Which way do you prefer, script or existed tools?
Why do you want do this?
If you'd like to write script, just sliding the sequences with window of
Kand step of1, and check every window (kmer) whether it contains non-ACGTcharacters.Thanks for your kind reply, It's not a homework, I am gonna statistic Kmers including invalid characters of a large reference library which may contain hundreds of species, and its size could be 200 gigabytes or even larger. The K might be 33 or larger. I have used Jellyfish, however it drops Kmers with invalid characters. Is SeqKit efficient to do it?
5.5 minutes on my laptop for human genome chr1 (~250 Mb, 248,956,422). It will take 67 hours for 200Gb data~. The bottle neck is that there are too many kmers :-P
A much much faster way by pre-retrieving regions containing non-ACGT chars. (SeqKit v0.5.2-dev or later version needed).
The result is a little different:
18,472,858 < 18,479,833.But only 47s for genome chr1 now!!!! It will take only 10 hours for you 200Gb data.
shenwei, Thanks for your help, I will try seqkit.
Would you please upvote/accept my answer if it helps and works. :)