This is a test version of Biostars. For the public version, visit https://www.biostars.org.
Python - finding INDELS and SNPS
seq_a = 'GAGAGATTTTCCAATTCGACG-------CGGGGTCAGG--GAAATTT'
seq_b = 'GAGAGATTGGCCTTAACTACCCAACCCACGGCCTGACCGAGGTCTTC'

G,A,C,T = Bases - = INDEL

PYTHON - I am very new to programming and need some help, I would like to write a python program that will first find indels '-' in seq_a and then compare both sequences (seq_a and seq_b) downstream and upstream from the the indels counting the number of differences between the bases.

e.g.

seq_a - GG--GAAA
seq_b - CCGAGGTC

This example has 5 SNPS upstream and downstream from the the indel c-g, c-g, a-g, a-t, a-c

I was wondering if anyone could give me any pointers or ideas how I would start of this program?

Thanks :)

snp indel python

Note that the easiest solution is to use biopython. It has some built-in facilities to perform alignment (e.g. the pairwise2 module) and can also just use command line alignment tools that tend to be faster.

1 answer

Assuming that you have your alignment in a file named "fasta.fas" this should get you started

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

This returns position of SNP, nt in seq_A, nt in seq_B, running tally of the number of SNPs upstream of each indel

cited in : https://peerj.com/articles/9132/

Comparative analysis of four Zantedeschia chloroplast genomes: expansion and contraction of the IR region, phylogenetic analyses and SSR genetic diversity assessment

Log in to answer this question.