annotate build_mods_loc.py @ 5:9816d9abb501 draft

Added repo dependencies
author galaxyp
date Thu, 20 Jun 2013 16:12:09 -0400
parents cf0d72c7b482
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
2
cf0d72c7b482 Update.
galaxyp
parents:
diff changeset
1 #!/usr/bin/env python
cf0d72c7b482 Update.
galaxyp
parents:
diff changeset
2
cf0d72c7b482 Update.
galaxyp
parents:
diff changeset
3 import xml.etree.ElementTree as ET
cf0d72c7b482 Update.
galaxyp
parents:
diff changeset
4
cf0d72c7b482 Update.
galaxyp
parents:
diff changeset
5 tree = ET.parse('unimod.xml')
cf0d72c7b482 Update.
galaxyp
parents:
diff changeset
6 ns = '{http://www.unimod.org/xmlns/schema/unimod_2}'
cf0d72c7b482 Update.
galaxyp
parents:
diff changeset
7 modifications_el = tree.getroot().find('%smodifications' % ns)
cf0d72c7b482 Update.
galaxyp
parents:
diff changeset
8
cf0d72c7b482 Update.
galaxyp
parents:
diff changeset
9
cf0d72c7b482 Update.
galaxyp
parents:
diff changeset
10 def to_label(title, site):
cf0d72c7b482 Update.
galaxyp
parents:
diff changeset
11 return "%s (%s)" % (title, site)
cf0d72c7b482 Update.
galaxyp
parents:
diff changeset
12
cf0d72c7b482 Update.
galaxyp
parents:
diff changeset
13
cf0d72c7b482 Update.
galaxyp
parents:
diff changeset
14 labels = []
cf0d72c7b482 Update.
galaxyp
parents:
diff changeset
15 for mod in modifications_el.findall('%smod' % ns):
cf0d72c7b482 Update.
galaxyp
parents:
diff changeset
16 for specificity in mod.findall('%sspecificity' % ns):
cf0d72c7b482 Update.
galaxyp
parents:
diff changeset
17 title = mod.get('title')
cf0d72c7b482 Update.
galaxyp
parents:
diff changeset
18 site = specificity.get('site')
cf0d72c7b482 Update.
galaxyp
parents:
diff changeset
19 labels.append(to_label(title, site))
cf0d72c7b482 Update.
galaxyp
parents:
diff changeset
20
cf0d72c7b482 Update.
galaxyp
parents:
diff changeset
21 with open("openms_mods.loc", "w") as output:
cf0d72c7b482 Update.
galaxyp
parents:
diff changeset
22 for mod in sorted(labels, key=str.lower):
cf0d72c7b482 Update.
galaxyp
parents:
diff changeset
23 output.write("%s\n" % mod)