1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28
from functools import reduce result = {} for pw_source in ['signalink', 'kegg', 'signor']: attr = '%s_pathways' % pw_source result[pw_source] = {} pwnames = list( reduce( lambda pws1, pws2: pws1 | pws2, map( lambda e: e[attr], pa.graph.es ), set([]) )) for pw in pwnames: result[pw_source][pw] = [] for e in pa.graph.es: if pw in e[attr]: result[pw_source][pw].append(( pa.nodNam[e.source], pa.nodNam[e.target], e.index ))
You can clone a snippet to your computer for local editing. Learn more.