I am a completely rookie on Bioinformatics, so please bear with me and use simple language (I am a computer scientist) :-)

How can we use k-mers to find out if a gene is similar to our query string?

For example: We have a reference gene r = `ACAAGTC`, and a query string q = `CATGT`. For sequence alignment we could get the two possible solutions: (see photo on link)

![enter image description here][1]

But if we use k-mer with k=2 (reason for 2 is that I tried using k=3 and got 1 match) we could split q into the set = {CA, AT, TG, GT} we can get 2 matches.

I am confused on how to use k-mer for queries. I am guessing that it would also need to know where in the reference string it is found, since order matter. But most importantly, **Why** can we use K-mers? That's maybe my biggest question mark.

 [1]: https://images2.imgbox.com/bc/62/X0aa6MzH_o.png
You wouldn't generally use kmers this short as the odds of finding spurious matches becomes massive, but I accept that this is a toy example.

To my knowledge, we don't really approach a sequence alignment with kmers, though you might use them to seed the alignment (in a **local** alignment, small subregions of alignment are found and then slowly expanded).

You can however compute useful statistics using kmers about how similar 2 sequences are when they are inefficient to align (e.g. a whole genome). It's not uncommon to look at sequence 'distances' in this way. You might find this code interesting: https://github.com/jrjhealey/bioinfo-tools/blob/master/StringComparisons.py#L158-L181

Those are a few of the most common kmer string/sequence comparison methods implemented in python.


You can use kmers to get a rough approximation of 2 large sequences in a very computationally efficient manner, where size or number of sequences becomes prohibitive, with the idea being that the more similar 2 sequences are, the more likely you are to randomly select the same kmer from each of them and the more frequently they will probably occur.

Not sure if that answers your question or not?