Diffing Coronaviruses
jameshfisher.com
jameshfisher.com
since the genome is made out of only A,T,G,C for any change beyond the trivial diffing may generate the incorrect picture, it lines up the "wrong" bases.
Here is a much simpler solution that does a much better job and you don't have to muck around so much. First install some tools:
conda install -c bioconda entrez-direct emboss
Now do a: # Get the data.
efetch -db nuccore -id MG772933 -format fasta > MG772933.fa
efetch -db nuccore -id MN988713 -format fasta > MN988713.fa
# Align globally.
stretcher -filter MG772933.fa MN988713.fa > aligned.txt
A much simpler explanation of what is going on (I picked a variable region here): ...
MG7729 CACTCCTCACTATTCATAGAGGA-----GAC-CCT----ATGCCTAATAA
: : :: :: : :::::: : ::: ::: :: : : : :
MN9887 CTTTACTTGCTTTACATAGAAGTTATTTGACTCCTGGTGATTCTTCTTCA
...
it also reports: # Length: 29922
# Identity: 26272/29922 (87.8%)
# Gaps: 160/29922 ( 0.5%)https://twitter.com/RobertElderSoft/status/12226906294923796...
To produce that image I used this tool:
https://github.com/RobertElderSoftware/roberteldersoftwaredi... With these two genomes:
https://www.ncbi.nlm.nih.gov/nuccore/MN908947
https://www.ncbi.nlm.nih.gov/nuccore/NC_004718.3
with the leading numbers, spaces and newlines removed from each genome file.
My tool (as well as unix diff with --minimal) uses the myers diff algorithm which just compute a mathematically minimal diff. More advanced algorithms exist for computing phylogenetic trees that take into account the biological likelihood of certain sequence change (deletions vs. additions vs. translations etc.).
You need to go further than diff to make meaningful phylogenetic comparisons, though!
https://en.wikipedia.org/wiki/Longest_common_subsequence_pro... has much more.
Alignments differ from a "diff" because they are assigning a score to each operation (match, mismatch, gap). The "optimal" alignment only cares about maximizing the score, does not "care" about the objects that are aligned.
If one chooses the scores incorrectly they could end up with optimal (relative to the score) alignments that visually seem completely "wrong".
I can't see how one could tune a diff, to produce obviously "incorrect" output.
Diff algorithms absolutely do assign a "score" to edits, just in a very simple way. For example, by playing with the Myers diff algorithm, you can get an edit distance of one where you simply rewrite the entire file, or a large edit distance but with the smallest edits possible.
It's worth pointing toward the actual algorithms commonly used for local and global alignments (global is the one to use in the coronavirus genome case).
Local alignments: Smith-Waterman [1]. Global alignments: Needleman–Wunsch [2]
[1] https://en.wikipedia.org/wiki/Smith%E2%80%93Waterman_algorit... [2] https://en.wikipedia.org/wiki/Needleman%E2%80%93Wunsch_algor...
The neat thing about kmers is that it is alignment free, so can find similarities between genomes even if genes have been moved around.
Interestingly, it finds HIV is quite close to cov compared to a random sampling of refseq viruses. Maybe there is credence to that Indian paper after all.
Can we find millions of similar regions in the fruitfly as in the human? Yes. Are those regions on the same chromosome and on the same relative orientations - not even close.
If you start reading the genome from left to right, the human and fruitfly are not even remotely similar. If were to chop the DNA into 100bp pieces now you can find a lot of matches across the organisms, still many sequences will be very different. One basepair difference could lead to a completely different protein. Then the fruit fly genome is 300 million bases long, the human is 3 billion bases.
You can see how there is a lot more to similarity than initially meets the eye.