view build_mods_loc.py @ 2:cf0d72c7b482 draft

Update.
author galaxyp
date Fri, 10 May 2013 17:31:05 -0400
parents
children
line wrap: on
line source

#!/usr/bin/env python

import xml.etree.ElementTree as ET

tree = ET.parse('unimod.xml')
ns = '{http://www.unimod.org/xmlns/schema/unimod_2}'
modifications_el = tree.getroot().find('%smodifications' % ns)


def to_label(title, site):
    return "%s (%s)" % (title, site)


labels = []
for mod in modifications_el.findall('%smod' % ns):
    for specificity in mod.findall('%sspecificity' % ns):
        title = mod.get('title')
        site = specificity.get('site')
        labels.append(to_label(title, site))

with open("openms_mods.loc", "w") as output:
    for mod in sorted(labels, key=str.lower):
        output.write("%s\n" % mod)