annotate xenaGetDataset.py @ 55:421b18a0b659 default tip

update v17 step 2, add xena.jar
author jingchunzhu
date Tue, 22 Sep 2015 10:07:51 -0700
parents bb840cc2603d
children
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
52
bb840cc2603d better error handling
jingchunzhu
parents: 50
diff changeset
6 import sys
0
8bb037f88ed2 Uploaded
melissacline
parents:
diff changeset
7
8bb037f88ed2 Uploaded
melissacline
parents:
diff changeset
8 def main():
52
bb840cc2603d better error handling
jingchunzhu
parents: 50
diff changeset
9 try:
bb840cc2603d better error handling
jingchunzhu
parents: 50
diff changeset
10 parser = argparse.ArgumentParser()
bb840cc2603d better error handling
jingchunzhu
parents: 50
diff changeset
11 parser.add_argument("dataHub", type=str)
bb840cc2603d better error handling
jingchunzhu
parents: 50
diff changeset
12 parser.add_argument("datasetId", type=str)
bb840cc2603d better error handling
jingchunzhu
parents: 50
diff changeset
13 parser.add_argument("datafile", type=str)
bb840cc2603d better error handling
jingchunzhu
parents: 50
diff changeset
14 parser.add_argument("GALAXY_URL", type=str)
bb840cc2603d better error handling
jingchunzhu
parents: 50
diff changeset
15 args = parser.parse_args()
bb840cc2603d better error handling
jingchunzhu
parents: 50
diff changeset
16 except:
bb840cc2603d better error handling
jingchunzhu
parents: 50
diff changeset
17 print "too few input parameters"
bb840cc2603d better error handling
jingchunzhu
parents: 50
diff changeset
18 sys.exit(2)
0
8bb037f88ed2 Uploaded
melissacline
parents:
diff changeset
19
52
bb840cc2603d better error handling
jingchunzhu
parents: 50
diff changeset
20 data = open(args.datafile, "w")
0
8bb037f88ed2 Uploaded
melissacline
parents:
diff changeset
21 datasetUrlHost = re.sub("/proj/", "/download/", args.dataHub)
8bb037f88ed2 Uploaded
melissacline
parents:
diff changeset
22 datasetIdTokens = re.split("/", args.datasetId)
8bb037f88ed2 Uploaded
melissacline
parents:
diff changeset
23 datasetUrl = datasetUrlHost + "/" + "/".join(datasetIdTokens[1:])
50
jingchunzhu
parents: 41
diff changeset
24
jingchunzhu
parents: 41
diff changeset
25
jingchunzhu
parents: 41
diff changeset
26 try:
jingchunzhu
parents: 41
diff changeset
27 dd = urllib2.urlopen(datasetUrl)
0
8bb037f88ed2 Uploaded
melissacline
parents:
diff changeset
28 data.write(dd.read())
50
jingchunzhu
parents: 41
diff changeset
29 dd.close()
jingchunzhu
parents: 41
diff changeset
30 data.close()
jingchunzhu
parents: 41
diff changeset
31 except:
52
bb840cc2603d better error handling
jingchunzhu
parents: 50
diff changeset
32 data.write("There is an error\n\n")
bb840cc2603d better error handling
jingchunzhu
parents: 50
diff changeset
33 data.write("You entered dataset id: %s\n" % (args.datasetId))
bb840cc2603d better error handling
jingchunzhu
parents: 50
diff changeset
34 data.write("Possible causes for error:\n")
bb840cc2603d better error handling
jingchunzhu
parents: 50
diff changeset
35 data.write("1. Dataset does not exist. check type.\n")
50
jingchunzhu
parents: 41
diff changeset
36 data.close()
jingchunzhu
parents: 41
diff changeset
37 sys.exit(1)
0
8bb037f88ed2 Uploaded
melissacline
parents:
diff changeset
38
8bb037f88ed2 Uploaded
melissacline
parents:
diff changeset
39 if __name__ == "__main__":
8bb037f88ed2 Uploaded
melissacline
parents:
diff changeset
40 main()
8bb037f88ed2 Uploaded
melissacline
parents:
diff changeset
41