Skip to content

Instantly share code, notes, and snippets.

@oshikrororo
Last active April 11, 2023 12:10
Show Gist options
  • Save oshikrororo/6aae586ebd3ae025a4502abfb8402bf8 to your computer and use it in GitHub Desktop.
Save oshikrororo/6aae586ebd3ae025a4502abfb8402bf8 to your computer and use it in GitHub Desktop.
def count_indels(alignment):
total = 0
sequences = [''.join(sequence.split('\n')[1:]) for sequence in alignment.split('>')][1:]
names = [sequence.split('\n')[0] for sequence in alignment.split('>')][1:]
for seq_id, sequence in enumerate(sequences):
indels = 0
closed = True
for index, symbol in enumerate(sequence[:-1]):
if symbol == '-' and closed:
closed = False
elif symbol != '-' and not closed:
indels += 1
closed = True
if not closed:
indels += 1
print(names[seq_id], indels)
total += indels
print(f'Total {total}')
return
PATH = input()
with open(PATH) as file:
alignment = file.read()
count_indels(alignment)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment