changeset 42:bc9784300015

more reliable, error handling
author jingchunzhu <jingchunzhu@gmail.com>
date Mon, 27 Jul 2015 12:01:42 -0700
parents 02b0824c7d60
children 78d6e6772e30
files getXenaData.py
diffstat 1 files changed, 24 insertions(+), 4 deletions(-) [+]
line wrap: on
line diff
--- a/getXenaData.py	Mon Jul 27 10:05:22 2015 -0700
+++ b/getXenaData.py	Mon Jul 27 12:01:42 2015 -0700
@@ -10,20 +10,40 @@
 dataset = sys.argv[2]
 output = sys.argv[3]
 
+fout = open(output,'w')
+
 if string.find(url,"galaxyxena") !=-1 and string.find(url,"ucsc.edu")!=-1:
   url = "https://galaxyxena.soe.ucsc.edu:443/xena"
 
+#testing if the url is reachable
+#try:
+r =json.loads(xena.post(url, "(+ 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 you."
+  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 you.\n")
+  fout.write("You entered hub: %s\n" % (url))
+  fout.close()
+  sys.exit(1)
+
 samples = xena.dataset_samples (url, dataset)
 if not samples:
-  print "dataset does not exists"
+  print "Dataset does not exist"
+  print "You entered dataset id: %s" % (dataset)
+  fout.write("Dataset does not exists\n")
+  fout.wriet("You entered dataset id: %s\n" % (dataset))
+  fout.close()
   sys.exit(1)
 
 type = xena.dataset_type(url, dataset)
 if type[0] not in ["genomicMatrix", "clinicalMatrix"]:
-  print "the current data type is not supported"
+  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.close()
   sys.exit(1)
 
-fout = open(output,'w')
 writer = csv.writer(fout, delimiter='\t')
 writer.writerow(["sample"]+samples)
 
@@ -33,7 +53,7 @@
 N= len(probes)
 for i in range (start, N,size):
   results = xena.dataset_probe_values (url, dataset, samples, probes[i:i+size])
-  print "..."
+  print ".",
   for j in range (0, size):
     if i+j == N:
       break