forked from rlsummerscales/acres
-
Notifications
You must be signed in to change notification settings - Fork 0
/
downloadregistry.py
executable file
·52 lines (44 loc) · 1.36 KB
/
downloadregistry.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
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
#!/usr/bin/python
# author: Rodney Summerscales
import sys
import os.path
import urllib2
import re
import xml.dom
from xml.dom import minidom
from xml.dom.minidom import Document
import xmlutil
if len(sys.argv) < 2:
print "Usage: downloadregistry.py <FILES>"
print "Download clinicaltrials.gov registry info"
print "for each file in the list of files <FILES>"
print "downloaded registry information is written to the file '<PMID>.nct.xml'"
sys.exit()
nctCount = 0
isrctnCount = 0
nctPattern = re.compile('.*NCT\s*\d+.*')
for i in range(1, len(sys.argv)):
file = sys.argv[i]
print file
xmldoc = minidom.parse(file)
idNodeList = xmldoc.getElementsByTagName('AccessionNumber')
for node in idNodeList:
id = xmlutil.getText(node)
if len(id) > 3 and id[0:3] == 'NCT':
try:
# fetchCmd = 'http://clinicaltrials.gov/show/'+id+'?resultsxml=true'
fetchCmd = 'http://clinicaltrials.gov/show/'+id+'?displayxml=true'
print 'Downloading:', fetchCmd
doc = urllib2.urlopen(fetchCmd)
out = open(id+'.xml', 'w')
out.write(doc.read())
out.close()
nctCount += 1
except:
print '***Could not download:', fetchCmd
elif len(id) > 6 and id[0:6] == 'ISRCTN':
print id
isrctnID = id
isrctnCount += 1
print 'NCT count:', nctCount
print 'ISRCTN count:', isrctnCount