Mercurial > repos > melissacline > ucsc_xena_platform
view xenaGetDataset.py @ 53:09fdd4d23a3a
version 17
author | jingchunzhu |
---|---|
date | Mon, 21 Sep 2015 13:25:05 -0700 |
parents | bb840cc2603d |
children |
line wrap: on
line source
#!/usr/bin/env python import argparse import re import urllib2 import sys def main(): try: parser = argparse.ArgumentParser() parser.add_argument("dataHub", type=str) parser.add_argument("datasetId", type=str) parser.add_argument("datafile", type=str) parser.add_argument("GALAXY_URL", type=str) args = parser.parse_args() except: print "too few input parameters" sys.exit(2) data = open(args.datafile, "w") datasetUrlHost = re.sub("/proj/", "/download/", args.dataHub) datasetIdTokens = re.split("/", args.datasetId) datasetUrl = datasetUrlHost + "/" + "/".join(datasetIdTokens[1:]) try: dd = urllib2.urlopen(datasetUrl) data.write(dd.read()) dd.close() data.close() except: data.write("There is an error\n\n") data.write("You entered dataset id: %s\n" % (args.datasetId)) data.write("Possible causes for error:\n") data.write("1. Dataset does not exist. check type.\n") data.close() sys.exit(1) if __name__ == "__main__": main()