# HG changeset patch # User jingchunzhu # Date 1439512219 25200 # Node ID bb840cc2603d476afbb3df6cfdd93c927d8f423d # Parent 47926759295a7c9943e6a9c5abeca504c601d1fe better error handling diff -r 47926759295a -r bb840cc2603d getXenaData.py --- a/getXenaData.py Thu Aug 13 10:24:12 2015 -0700 +++ b/getXenaData.py Thu Aug 13 17:30:19 2015 -0700 @@ -1,15 +1,17 @@ -# getXenaData.py +#!/usr/bin/env python + import os, sys, string, json, csv import xena_query as xena -if len(sys.argv[:])!=4: - print "python getXenaData.py hub datasetId outputfile\n" - sys.exit(1) +if len(sys.argv[:])!=5: + print "python getXenaData.py hub datasetId outputfile galaxy_url\n" + sys.exit(2) def main(): url = sys.argv[1] dataset = sys.argv[2] output = sys.argv[3] + GALAXY_URL = sys.argv[4] fout = open(output,'w') @@ -22,36 +24,40 @@ r =json.loads(xena.post(contactUrl, "(+ 1 2)")) if r!=3.0: - print "The hub seems can not be reached, either it is not running, the url has a typo, or it is not accessible to this galaxy instance." - print "You entered hub: %s" % (url) - fout.write("The hub seems can not be reached, either it is not running, the url has a typo, or it is not accessible to this galaxy instance.\n") + fout.write("There is an error\n\n") fout.write("You entered hub: %s\n" % (url)) + fout.write("Possible causes for error:\n") + fout.write("1. The hub is not running.\n") + fout.write("2. The hub is not accessible to this galaxy instance at: %s.\n" %(GALAXY_URL)) + fout.write("3. The hub url has a typo.\n") fout.close() sys.exit(1) except: - print "The hub seems can not be reached, either it is not running, the url has a typo, or it is not accessible to this galaxy instance." - print "You entered hub: %s" % (url) - fout.write("The hub seems can not be reached, either it is not running, the url has a typo, or it is not accessible to this galaxy instance.\n") + fout.write("There is an error\n\n") fout.write("You entered hub: %s\n" % (url)) + fout.write("Possible causes for error:\n") + fout.write("1. The hub is not running.\n") + fout.write("2. The hub is not accessible to this galaxy instance at: %s.\n" %(GALAXY_URL)) + fout.write("3. The hub url has a typo.\n") fout.close() sys.exit(1) samples = xena.dataset_samples (contactUrl, dataset) if not samples: - print "Dataset does not exist" - print "You entered dataset id: %s" % (dataset) - fout.write("Dataset does not exists\n") + fout.write("There is an error\n\n") fout.write("You entered dataset id: %s\n" % (dataset)) + fout.write("Possible causes for error:\n") + fout.write("1. Dataset does not exist.\n") fout.close() sys.exit(1) type = xena.dataset_type(contactUrl, dataset) if type[0] not in ["genomicMatrix", "clinicalMatrix"]: - print "The type of data is not supported" - print "datatype=%s" % (type[0]) - fout.write("The type of data is not supported\n") - fout.write("datatype=%s\n" % (type[0])) + fout.write("There is an error\n\n") + fout.write("You entered dataset id: %s\n" % (dataset)) + fout.write("It's datatype=%s\n" % (type[0])) + fout.write("This type of data is not supported yet.\n") fout.close() sys.exit(1) @@ -71,10 +77,8 @@ writer.writerow([probes[i+j]]+results[j]) fout.close() - print "done" sys.exit(0) - if __name__ == "__main__": main() diff -r 47926759295a -r bb840cc2603d ucsc_xena_datapages.xml --- a/ucsc_xena_datapages.xml Thu Aug 13 10:24:12 2015 -0700 +++ b/ucsc_xena_datapages.xml Thu Aug 13 17:30:19 2015 -0700 @@ -1,5 +1,5 @@ - + Browse data in the federated UCSC Xena platform diff -r 47926759295a -r bb840cc2603d ucsc_xena_hub.xml --- a/ucsc_xena_hub.xml Thu Aug 13 10:24:12 2015 -0700 +++ b/ucsc_xena_hub.xml Thu Aug 13 17:30:19 2015 -0700 @@ -1,8 +1,7 @@ - Build your Xena Data Hubs - + diff -r 47926759295a -r bb840cc2603d xenaGetDataset.py --- a/xenaGetDataset.py Thu Aug 13 10:24:12 2015 -0700 +++ b/xenaGetDataset.py Thu Aug 13 17:30:19 2015 -0700 @@ -3,20 +3,25 @@ import argparse import re import urllib2 - +import sys 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() + 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:]) - data = open(args.datafile, "w") try: dd = urllib2.urlopen(datasetUrl) @@ -24,8 +29,10 @@ dd.close() data.close() except: - data.wriet("You entered dataset id: %s\n" % (args.datasetId)) - data.write("Dataset does not exist. check typo.") + 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) diff -r 47926759295a -r bb840cc2603d xenaGetDataset.xml --- a/xenaGetDataset.xml Thu Aug 13 10:24:12 2015 -0700 +++ b/xenaGetDataset.xml Thu Aug 13 17:30:19 2015 -0700 @@ -7,11 +7,11 @@ #if $hub.dataHub == "https://genome-cancer.ucsc.edu/proj/public/xena": - xenaGetDataset.py $hub.dataHub $dataset $dataFile + xenaGetDataset.py $hub.dataHub $dataset $dataFile $GALAXY_URL #elif $hub.customDataHub: - getXenaData.py $hub.customDataHub $dataset $dataFile + getXenaData.py $hub.customDataHub $dataset $dataFile $GALAXY_URL #else - getXenaData.py $hub.dataHub $dataset $dataFile + getXenaData.py $hub.dataHub $dataset $dataFile $GALAXY_URL #end if @@ -25,12 +25,16 @@ - + + - + + + + Given the data hub name and the dataset id, download the dataset into this Galaxy. Xena dataset id can be obtained through the Explore Data in Xena tool.