Skip to content
Snippets Groups Projects
Commit faba0626 authored by Alán Muñoz's avatar Alán Muñoz
Browse files

refactor reassign_mothers fn

parent b6ec9982
No related branches found
No related tags found
No related merge requests found
from copy import copy
def reassign_mo_bud(mo_bud, trans):
"""
FIXME:
Update mother_bud dictionary using another dict with tracks joined
input
......@@ -14,18 +16,21 @@ def reassign_mo_bud(mo_bud, trans):
val2lst = lambda x: [j for i in x.values() for j in i]
bud_inter=set(val2lst(mo_bud)).intersection(trans.keys())
bud_inter = set(val2lst(mo_bud)).intersection(trans.keys())
# translate mothers and carry untranslated daughters
new_mb = copy(mo_bud)
for origin, target in trans:
if target in new_mb:
new_mb[target] = new_mb.get(target, set()).union(new_mb[origin])
del new_mb[origin]
# translate daughters
mo_bud = copy(mo_bud)
for k,das in mo_bud.items():
for da in bud_inter.intersection(das):
mo_bud[k][mo_bud[k].index(da)] = trans[da]
# translate mothers
mo_inter = set(mo_bud.keys()).intersection(trans.keys())
for k in mo_inter:
mo_bud[trans[k]] = mo_bud.get(trans[k], []) + mo_bud[k]
del mo_bud[k]
return mo_bud
for origin, target in trans:
if origin in bud_inter: # Limit scope of searcg
for mo, da in new_mb.items():
if origin in da:
da.remove(origin)
new_mb[mo] = da.union(target)
return new_mb
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment