Mercurial > repos > melissacline > ucsc_xena_platform
comparison getXenaData.py @ 42:bc9784300015
more reliable, error handling
author | jingchunzhu <jingchunzhu@gmail.com> |
---|---|
date | Mon, 27 Jul 2015 12:01:42 -0700 |
parents | 02b0824c7d60 |
children | 78d6e6772e30 |
comparison
equal
deleted
inserted
replaced
41:02b0824c7d60 | 42:bc9784300015 |
---|---|
8 | 8 |
9 url = sys.argv[1] | 9 url = sys.argv[1] |
10 dataset = sys.argv[2] | 10 dataset = sys.argv[2] |
11 output = sys.argv[3] | 11 output = sys.argv[3] |
12 | 12 |
13 fout = open(output,'w') | |
14 | |
13 if string.find(url,"galaxyxena") !=-1 and string.find(url,"ucsc.edu")!=-1: | 15 if string.find(url,"galaxyxena") !=-1 and string.find(url,"ucsc.edu")!=-1: |
14 url = "https://galaxyxena.soe.ucsc.edu:443/xena" | 16 url = "https://galaxyxena.soe.ucsc.edu:443/xena" |
15 | 17 |
18 #testing if the url is reachable | |
19 #try: | |
20 r =json.loads(xena.post(url, "(+ 1 2)")) | |
21 if r!=3.0: | |
22 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." | |
23 print "You entered hub: %s" % (url) | |
24 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") | |
25 fout.write("You entered hub: %s\n" % (url)) | |
26 fout.close() | |
27 sys.exit(1) | |
28 | |
16 samples = xena.dataset_samples (url, dataset) | 29 samples = xena.dataset_samples (url, dataset) |
17 if not samples: | 30 if not samples: |
18 print "dataset does not exists" | 31 print "Dataset does not exist" |
32 print "You entered dataset id: %s" % (dataset) | |
33 fout.write("Dataset does not exists\n") | |
34 fout.wriet("You entered dataset id: %s\n" % (dataset)) | |
35 fout.close() | |
19 sys.exit(1) | 36 sys.exit(1) |
20 | 37 |
21 type = xena.dataset_type(url, dataset) | 38 type = xena.dataset_type(url, dataset) |
22 if type[0] not in ["genomicMatrix", "clinicalMatrix"]: | 39 if type[0] not in ["genomicMatrix", "clinicalMatrix"]: |
23 print "the current data type is not supported" | 40 print "The type of data is not supported" |
41 print "datatype=%s" % (type[0]) | |
42 fout.write("The type of data is not supported\n") | |
43 fout.write("datatype=%s\n" % (type[0])) | |
44 fout.close() | |
24 sys.exit(1) | 45 sys.exit(1) |
25 | 46 |
26 fout = open(output,'w') | |
27 writer = csv.writer(fout, delimiter='\t') | 47 writer = csv.writer(fout, delimiter='\t') |
28 writer.writerow(["sample"]+samples) | 48 writer.writerow(["sample"]+samples) |
29 | 49 |
30 probes = xena.dataset_field(url, dataset) | 50 probes = xena.dataset_field(url, dataset) |
31 start=0 | 51 start=0 |
32 size =100 | 52 size =100 |
33 N= len(probes) | 53 N= len(probes) |
34 for i in range (start, N,size): | 54 for i in range (start, N,size): |
35 results = xena.dataset_probe_values (url, dataset, samples, probes[i:i+size]) | 55 results = xena.dataset_probe_values (url, dataset, samples, probes[i:i+size]) |
36 print "..." | 56 print ".", |
37 for j in range (0, size): | 57 for j in range (0, size): |
38 if i+j == N: | 58 if i+j == N: |
39 break | 59 break |
40 writer.writerow([probes[i+j]]+results[j]) | 60 writer.writerow([probes[i+j]]+results[j]) |
41 | 61 |