annotate xenaGetDataset.py @ 44:da86478b1d64

clean up strange tools that just a url linkout
author jingchunzhu <jingchunzhu@gmail.com>
date Mon, 27 Jul 2015 15:30:10 -0700
parents 02b0824c7d60
children 3167c1a26101
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
8bb037f88ed2 Uploaded
melissacline
parents:
diff changeset
1 #!/usr/bin/env python
8bb037f88ed2 Uploaded
melissacline
parents:
diff changeset
2
8bb037f88ed2 Uploaded
melissacline
parents:
diff changeset
3 import argparse
8bb037f88ed2 Uploaded
melissacline
parents:
diff changeset
4 import re
8bb037f88ed2 Uploaded
melissacline
parents:
diff changeset
5 import urllib2
8bb037f88ed2 Uploaded
melissacline
parents:
diff changeset
6
8bb037f88ed2 Uploaded
melissacline
parents:
diff changeset
7
8bb037f88ed2 Uploaded
melissacline
parents:
diff changeset
8 def main():
8bb037f88ed2 Uploaded
melissacline
parents:
diff changeset
9 parser = argparse.ArgumentParser()
8bb037f88ed2 Uploaded
melissacline
parents:
diff changeset
10 parser.add_argument("dataHub", type=str)
8bb037f88ed2 Uploaded
melissacline
parents:
diff changeset
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
8bb037f88ed2 Uploaded
melissacline
parents:
diff changeset
13 parser.add_argument("datafile", type=str)
8bb037f88ed2 Uploaded
melissacline
parents:
diff changeset
14 args = parser.parse_args()
8bb037f88ed2 Uploaded
melissacline
parents:
diff changeset
15
8bb037f88ed2 Uploaded
melissacline
parents:
diff changeset
16 datasetUrlHost = re.sub("/proj/", "/download/", args.dataHub)
8bb037f88ed2 Uploaded
melissacline
parents:
diff changeset
17 datasetIdTokens = re.split("/", args.datasetId)
8bb037f88ed2 Uploaded
melissacline
parents:
diff changeset
18 datasetUrl = datasetUrlHost + "/" + "/".join(datasetIdTokens[1:])
8bb037f88ed2 Uploaded
melissacline
parents:
diff changeset
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
8bb037f88ed2 Uploaded
melissacline
parents:
diff changeset
21 metadataUrl = datasetUrl + ".json"
8bb037f88ed2 Uploaded
melissacline
parents:
diff changeset
22 mm = urllib2.urlopen(metadataUrl)
8bb037f88ed2 Uploaded
melissacline
parents:
diff changeset
23 with open(args.metadatafile, "w") as metadata:
8bb037f88ed2 Uploaded
melissacline
parents:
diff changeset
24 metadata.write(mm.read())
8bb037f88ed2 Uploaded
melissacline
parents:
diff changeset
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
8bb037f88ed2 Uploaded
melissacline
parents:
diff changeset
27 dd = urllib2.urlopen(datasetUrl)
8bb037f88ed2 Uploaded
melissacline
parents:
diff changeset
28 with open(args.datafile, "w") as data:
8bb037f88ed2 Uploaded
melissacline
parents:
diff changeset
29 data.write(dd.read())
8bb037f88ed2 Uploaded
melissacline
parents:
diff changeset
30 dd.close()
8bb037f88ed2 Uploaded
melissacline
parents:
diff changeset
31
8bb037f88ed2 Uploaded
melissacline
parents:
diff changeset
32
8bb037f88ed2 Uploaded
melissacline
parents:
diff changeset
33 if __name__ == "__main__":
8bb037f88ed2 Uploaded
melissacline
parents:
diff changeset
34 main()
8bb037f88ed2 Uploaded
melissacline
parents:
diff changeset
35