-
Notifications
You must be signed in to change notification settings - Fork 3
/
getattributes.py
28 lines (25 loc) · 1.1 KB
/
getattributes.py
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
from lxml import etree
import logging, os, os.path, sys, urllib2
logging.basicConfig(level=logging.INFO)
if __name__ == "__main__":
tree = etree.parse(sys.argv[1])
root = tree.getroot()
logging.info("Got %d segments" % len(root.findall('.//SEGMENT')))
for segment in root.iterdescendants(tag='SEGMENT'):
if os.path.exists('%s/sequences/%s_sequence.xml' % (os.getcwd(), segment.text)):
logging.info("%s already retrieved, skipping" % segment.text)
continue
features = urllib2.urlopen("http://partsregistry.org/das/parts/features?segment=%s" % segment.text)
sequence = urllib2.urlopen("http://partsregistry.org/das/parts/dna?segment=%s" % segment.text)
featuref = open('%s/features/%s_features.xml' % (os.getcwd(), segment.text), 'w')
sequencef = open('%s/sequences/%s_sequence.xml' % (os.getcwd(), segment.text), 'w')
for line in features:
featuref.write(line)
features.close()
featuref.close()
logging.info("Wrote %s_features.xml" % segment.text)
for line in sequence:
sequencef.write(line)
sequence.close()
sequencef.close()
logging.info("Wrote %s_sequence.xml" % segment.text)