-
Notifications
You must be signed in to change notification settings - Fork 3
Open
Description
This function is always needed again and again, one might want to just add it to util:
from lingpy.sequence.sound_classes import token2class
def patterns_from_msa(msa, languages, missing="Ø", gap="-"):
"""
Retrieve patterns from an msa object.
"""
out = [["" for x in languages] for y in msa["alignment"][0]]
for j in range(len(msa["alignment"][0])):
for i, language in enumerate(languages):
if language in msa["taxa"]:
out[j][i] = msa["alignment"][msa["taxa"].index(language)][j]
else:
out[j][i] = missing
return [(
token2class(
([c for c in row if c not in (gap, missing)] or ["?"])[0],
"cv"
).lower(),
tuple(row)) for row in out
]
The function takes an MSA object and returns the patterns. One can also do it without the structure involved, or one could do it passing the structure, as done in lingrex.
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels