view xenaGetDataset.py @ 51:47926759295a

fix GALAXY_URL parameter
author jingchunzhu
date Thu, 13 Aug 2015 10:24:12 -0700
parents 3167c1a26101
children bb840cc2603d
line wrap: on
line source

#!/usr/bin/env python

import argparse
import re
import urllib2


def main():
    parser = argparse.ArgumentParser()
    parser.add_argument("dataHub", type=str)
    parser.add_argument("datasetId", type=str)
    parser.add_argument("datafile", type=str)
    args = parser.parse_args()

    datasetUrlHost = re.sub("/proj/", "/download/", args.dataHub)
    datasetIdTokens = re.split("/", args.datasetId)
    datasetUrl = datasetUrlHost + "/" + "/".join(datasetIdTokens[1:])

    data = open(args.datafile, "w")

    try:
        dd = urllib2.urlopen(datasetUrl)
        data.write(dd.read())
        dd.close()
        data.close()
    except:
        data.wriet("You entered dataset id: %s\n" % (args.datasetId))
        data.write("Dataset does not exist. check typo.")
        data.close()
        sys.exit(1)

if __name__ == "__main__":
    main()