Mercurial > repos > melissacline > ucsc_xena_platform
comparison getXenaData.py @ 50:3167c1a26101
fix
author | jingchunzhu |
---|---|
date | Wed, 12 Aug 2015 16:38:12 -0700 |
parents | 78d6e6772e30 |
children | bb840cc2603d |
comparison
equal
deleted
inserted
replaced
49:8da6920a39ac | 50:3167c1a26101 |
---|---|
4 | 4 |
5 if len(sys.argv[:])!=4: | 5 if len(sys.argv[:])!=4: |
6 print "python getXenaData.py hub datasetId outputfile\n" | 6 print "python getXenaData.py hub datasetId outputfile\n" |
7 sys.exit(1) | 7 sys.exit(1) |
8 | 8 |
9 url = sys.argv[1] | 9 def main(): |
10 dataset = sys.argv[2] | 10 url = sys.argv[1] |
11 output = sys.argv[3] | 11 dataset = sys.argv[2] |
12 output = sys.argv[3] | |
12 | 13 |
13 fout = open(output,'w') | 14 fout = open(output,'w') |
14 | 15 |
15 if string.find(url,"galaxyxena") !=-1 and string.find(url,"ucsc.edu")!=-1: | 16 contactUrl = url |
16 url = "https://galaxyxena.soe.ucsc.edu:443/xena" | 17 if string.find(url,"galaxyxena") !=-1 and string.find(url,"ucsc.edu")!=-1: |
18 contactUrl = "https://galaxyxena.soe.ucsc.edu:443/xena" | |
17 | 19 |
18 #testing if the url is reachable | 20 #testing if the url is reachable |
19 try: | 21 try: |
20 r =json.loads(xena.post(url, "(+ 1 2)")) | 22 r =json.loads(xena.post(contactUrl, "(+ 1 2)")) |
21 if r!=3.0: | 23 |
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." | 24 if r!=3.0: |
25 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." | |
26 print "You entered hub: %s" % (url) | |
27 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") | |
28 fout.write("You entered hub: %s\n" % (url)) | |
29 fout.close() | |
30 sys.exit(1) | |
31 | |
32 except: | |
33 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." | |
23 print "You entered hub: %s" % (url) | 34 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") | 35 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") |
25 fout.write("You entered hub: %s\n" % (url)) | |
26 fout.close() | |
27 sys.exit(1) | |
28 except: | |
29 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." | |
30 print "You entered hub: %s" % (url) | |
31 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") | |
32 fout.write("You entered hub: %s\n" % (url)) | 36 fout.write("You entered hub: %s\n" % (url)) |
33 fout.close() | 37 fout.close() |
34 sys.exit(1) | 38 sys.exit(1) |
35 | 39 |
36 samples = xena.dataset_samples (url, dataset) | 40 samples = xena.dataset_samples (contactUrl, dataset) |
37 if not samples: | 41 if not samples: |
38 print "Dataset does not exist" | 42 print "Dataset does not exist" |
39 print "You entered dataset id: %s" % (dataset) | 43 print "You entered dataset id: %s" % (dataset) |
40 fout.write("Dataset does not exists\n") | 44 fout.write("Dataset does not exists\n") |
41 fout.write("You entered dataset id: %s\n" % (dataset)) | 45 fout.write("You entered dataset id: %s\n" % (dataset)) |
46 fout.close() | |
47 sys.exit(1) | |
48 | |
49 type = xena.dataset_type(contactUrl, dataset) | |
50 if type[0] not in ["genomicMatrix", "clinicalMatrix"]: | |
51 print "The type of data is not supported" | |
52 print "datatype=%s" % (type[0]) | |
53 fout.write("The type of data is not supported\n") | |
54 fout.write("datatype=%s\n" % (type[0])) | |
55 fout.close() | |
56 sys.exit(1) | |
57 | |
58 writer = csv.writer(fout, delimiter='\t') | |
59 writer.writerow(["sample"]+samples) | |
60 | |
61 probes = xena.dataset_field(contactUrl, dataset) | |
62 start=0 | |
63 size =100 | |
64 N= len(probes) | |
65 for i in range (start, N,size): | |
66 results = xena.dataset_probe_values (contactUrl, dataset, samples, probes[i:i+size]) | |
67 print ".", | |
68 for j in range (0, size): | |
69 if i+j == N: | |
70 break | |
71 writer.writerow([probes[i+j]]+results[j]) | |
72 | |
42 fout.close() | 73 fout.close() |
43 sys.exit(1) | 74 print "done" |
75 sys.exit(0) | |
44 | 76 |
45 type = xena.dataset_type(url, dataset) | |
46 if type[0] not in ["genomicMatrix", "clinicalMatrix"]: | |
47 print "The type of data is not supported" | |
48 print "datatype=%s" % (type[0]) | |
49 fout.write("The type of data is not supported\n") | |
50 fout.write("datatype=%s\n" % (type[0])) | |
51 fout.close() | |
52 sys.exit(1) | |
53 | 77 |
54 writer = csv.writer(fout, delimiter='\t') | 78 if __name__ == "__main__": |
55 writer.writerow(["sample"]+samples) | 79 main() |
56 | 80 |
57 probes = xena.dataset_field(url, dataset) | |
58 start=0 | |
59 size =100 | |
60 N= len(probes) | |
61 for i in range (start, N,size): | |
62 results = xena.dataset_probe_values (url, dataset, samples, probes[i:i+size]) | |
63 print ".", | |
64 for j in range (0, size): | |
65 if i+j == N: | |
66 break | |
67 writer.writerow([probes[i+j]]+results[j]) | |
68 | |
69 fout.close() | |
70 print "done" | |
71 sys.exit(0) |