view xenaGetDataset.py @ 54:3e64e6ed5925

update to version 17 step 1, remove xena.jar
author jingchunzhu
date Tue, 22 Sep 2015 10:06:35 -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()