This short blog deal with the detection of SNPs from two aligned sequences
I was working on comparative chloroplast genome analysis. My purpose was to find SNPs between two chloroplast genomes in order to appreciate sequence divergence among two species. Thanks to Biostar platform for the inspiration.
Assuming that I have two chloroplast genome assemblies cp1.fasta and cp2.fasta.
First step: Concatenate the two sequences
Second step: Multiple sequence alignment with MAFFT or other program
Third step: Create the python script
Fourth step:Scripting
from Bio import AlignIO
y=0
alignment = AlignIO.read("fasta.fas", "fasta")
for r in range(0,len(alignment[1].seq)):
if alignment[0,r] != alignment[1,r]:
if alignment[0,r] != "-" and alignment[1,r] != "-":
y=y+1
print (r, alignment[0,r], alignment[1,r], y)
else:
y=0
Fifth step: Run the script
A view of the result
To quickly count the number of detected SNP:
In summary, this returns position of SNP, nucleotide in cp1, nucleotide in cp2, running tally of the number of SNPs upstream of each indel.
Text and figures are licensed under Creative Commons Attribution CC BY 4.0. The figures that have been reused from other sources don't fall under this license and can be recognized by a note in their caption: "Figure from ...".
For attribution, please cite this work as
Zoclanclounon (2021, Jan. 21). Diary of an Autodidact: Python: Find single-nucleotide polymorphism from aligned sequences. Retrieved from https://yedomon.netlify.app/posts/2021-01-21-python-find-single-nucleotide-polymorphism-from-aligned-sequences/
BibTeX citation
@misc{zoclanclounon2021python:,
author = {Zoclanclounon, Yedomon Ange Bovys},
title = {Diary of an Autodidact: Python: Find single-nucleotide polymorphism from aligned sequences},
url = {https://yedomon.netlify.app/posts/2021-01-21-python-find-single-nucleotide-polymorphism-from-aligned-sequences/},
year = {2021}
}