Mercurial > repos > melissacline > ucsc_xena_platform
annotate xenaGetDataset.py @ 41:02b0824c7d60
Download data from any hub in the federated xena platform
author | jingchunzhu <jingchunzhu@gmail.com> |
---|---|
date | Mon, 27 Jul 2015 10:05:22 -0700 |
parents | 8bb037f88ed2 |
children | 3167c1a26101 |
rev | line source |
---|---|
0 | 1 #!/usr/bin/env python |
2 | |
3 import argparse | |
4 import re | |
5 import urllib2 | |
6 | |
7 | |
8 def main(): | |
9 parser = argparse.ArgumentParser() | |
10 parser.add_argument("dataHub", type=str) | |
11 parser.add_argument("datasetId", type=str) | |
41
02b0824c7d60
Download data from any hub in the federated xena platform
jingchunzhu <jingchunzhu@gmail.com>
parents:
0
diff
changeset
|
12 #parser.add_argument("metadatafile", type=str) |
0 | 13 parser.add_argument("datafile", type=str) |
14 args = parser.parse_args() | |
15 | |
16 datasetUrlHost = re.sub("/proj/", "/download/", args.dataHub) | |
17 datasetIdTokens = re.split("/", args.datasetId) | |
18 datasetUrl = datasetUrlHost + "/" + "/".join(datasetIdTokens[1:]) | |
19 print datasetUrl | |
41
02b0824c7d60
Download data from any hub in the federated xena platform
jingchunzhu <jingchunzhu@gmail.com>
parents:
0
diff
changeset
|
20 """ |
0 | 21 metadataUrl = datasetUrl + ".json" |
22 mm = urllib2.urlopen(metadataUrl) | |
23 with open(args.metadatafile, "w") as metadata: | |
24 metadata.write(mm.read()) | |
25 mm.close() | |
41
02b0824c7d60
Download data from any hub in the federated xena platform
jingchunzhu <jingchunzhu@gmail.com>
parents:
0
diff
changeset
|
26 """ |
0 | 27 dd = urllib2.urlopen(datasetUrl) |
28 with open(args.datafile, "w") as data: | |
29 data.write(dd.read()) | |
30 dd.close() | |
31 | |
32 | |
33 if __name__ == "__main__": | |
34 main() | |
35 |