I'm getting started in biology and bioinformatics with sequencing the SARS-Cov-2 or Coronavirus genome. I'm interested in this code which identifies k-mers in the genome:

from skbio import DNA 
kmers = DNA(str(seq1.seq)).kmer_frequencies(5)
{'ATTAA': 60, 'TTAAA': 95, 'TAAAG': 64, 'AAAGG': 45, 'AAGGT': 46, 'AGGTT': 51, 'GGTTT': 55, 
'GTTTA': 69, 'TTTAT': 75,...}

The author of the code wants to use k-mer breakdowns to vectorize the data for machine learning purposes. What I'm curious about is why the k-mer in this case is five nucleotides? What factors should go into my selection of the length of the k-mer for analysis?


1 Answer 1


5bp produces a high resolution analysis, providing its sufficiently robust.

Its a sliding window of 5 bp wide and 1 bp step length which runs along the length of each genome. They are performing SNP analysis/classification. The original sequence they were examining was,


In any sliding window analysis the window size is arbitary towards the resolution and robustness of the analysis. The author believes that 5bp provides sufficiently robust information for a very high resolution classification/training analysis in their example.

The proof is the accuracy of the classification. I assume they have good results from 5bp. In ML the rationale is the general laws of ML (over/under training) and assessed on the test split in the data (probably 20%).

A key reason for the 1bp step is that this is the way ML works, you need a lot of data and by doing 5 bp sliding window at 1 bp step that will generate ~30 000 pieces of data for each sequence. So that's 3 million data points for 100 sequences.

  • $\begingroup$ Would the SNP analysis you mention include a classification algorithm such as principal component analysis? $\endgroup$ Apr 20, 2020 at 1:41
  • $\begingroup$ Oh sorry thats different, PCA (ML) is a different analysis to the one I had in mind (supervised learning) and is usually performed in conjunction with tSNE @greenpenguin. PCA is judged on its ability to cluster the classification targets into different groups. PCA/tSNE is called unsupervised learning $\endgroup$
    – M__
    Apr 20, 2020 at 9:24

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.