1 """Utilities for extracting information from the ENCODE DCC
4 from six.moves import urllib
6 LOGGER = logging.getLogger(__name__)
8 UCSCEncodePipeline = "http://encodesubmit.ucsc.edu/pipeline/"
10 GOLDEN_PATHS = ["http://hgdownload-test.cse.ucsc.edu/goldenPath/"\
11 "{genome}/encodeDCC/{composite}/",
12 "http://hgdownload.cse.ucsc.edu/goldenPath/"\
13 "{genome}/encodeDCC/{composite}/"]
16 def ddf_download_url(submission_id):
17 """Return url to download a DDF for a submission
19 >>> ddf_download_url(1234)
20 'http://encodesubmit.ucsc.edu/pipeline/download_ddf/1234'
22 fragment = 'download_ddf/%s' % (submission_id,)
23 return urllib.parse.urljoin(UCSCEncodePipeline, fragment)
26 def daf_download_url(submission_id):
27 """Return url to download a DAF for a submission
29 >>> daf_download_url(1234)
30 'http://encodesubmit.ucsc.edu/pipeline/download_daf/1234'
32 fragment = 'download_daf/%s' % (submission_id,)
33 return urllib.parse.urljoin(UCSCEncodePipeline, fragment)
36 def submission_view_url(submission_id):
37 """Return url to download a DAF for a submission
39 >>> submission_view_url(1234)
40 'http://encodesubmit.ucsc.edu/pipeline/show/1234'
42 fragment = 'show/%s' % (submission_id,)
43 return urllib.parse.urljoin(UCSCEncodePipeline, fragment)
46 def get_encodedcc_file_index(genome, composite):
47 """Get index of files for a ENCODE collection
52 params = {'genome': genome,
53 'composite': composite}
55 for path in GOLDEN_PATHS:
56 base_url = path.format(**params)
57 request_url = base_url + 'files.txt'
60 request = urllib.request.urlopen(request_url)
61 file_index = parse_ucsc_file_index(request, base_url)
63 except urllib.request.HTTPError as e:
68 errmsg = "get_ucsc_file_index <{0}>: {1}"
69 LOGGER.error(errmsg.format(request_url, str(e)))
74 def parse_ucsc_file_index(stream, base_url):
75 """Turn a UCSC DCC files.txt index into a dictionary of name-value pairs
79 filename, attribute_line = line.split('\t')
80 filename = base_url + filename
82 for assignment in attribute_line.split(';'):
83 name, value = assignment.split('=')
84 attributes[name.strip()] = value.strip()
86 file_index[filename] = attributes