Logo Questions Linux Laravel Mysql Ubuntu Git Menu

counting number of gaps in python

how can I calculate the number of gaps in sequences:

for example:

s1='G _ A A T T C A G T T A'
s2='G G _ A _ T C _ G _ _ A'
s3='G A A T T C A G T _ T _'

her the number of '_' is 8

I try the following:

def count():
    for i in range(0, len(s1), 3):
        for x,y,z in zip(s1,s2,s3):
            if (x=='_') or (y=='_')or (z=='_') :
        return gap

it gives 6 not 8

like image 461
user3216969 Avatar asked Mar 21 '23 11:03


1 Answers

Strings have a count() method:

s1.count('_') + s2.count('_') + s3.count('_')
like image 180
crunch Avatar answered Apr 01 '23 10:04