view build_mods_loc.py @ 3:8fa16707e162 draft

Update.
author galaxyp
date Fri, 10 May 2013 17:31:59 -0400
parents cf0d72c7b482
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)