Mercurial > repos > melissacline > ucsc_xena_platform
annotate getXenaData.py @ 55:421b18a0b659 default tip
update v17 step 2, add xena.jar
author | jingchunzhu |
---|---|
date | Tue, 22 Sep 2015 10:07:51 -0700 |
parents | bb840cc2603d |
children |
rev | line source |
---|---|
52 | 1 #!/usr/bin/env python |
2 | |
41
02b0824c7d60
Download data from any hub in the federated xena platform
jingchunzhu <jingchunzhu@gmail.com>
parents:
diff
changeset
|
3 import os, sys, string, json, csv |
02b0824c7d60
Download data from any hub in the federated xena platform
jingchunzhu <jingchunzhu@gmail.com>
parents:
diff
changeset
|
4 import xena_query as xena |
02b0824c7d60
Download data from any hub in the federated xena platform
jingchunzhu <jingchunzhu@gmail.com>
parents:
diff
changeset
|
5 |
52 | 6 if len(sys.argv[:])!=5: |
7 print "python getXenaData.py hub datasetId outputfile galaxy_url\n" | |
8 sys.exit(2) | |
41
02b0824c7d60
Download data from any hub in the federated xena platform
jingchunzhu <jingchunzhu@gmail.com>
parents:
diff
changeset
|
9 |
50 | 10 def main(): |
11 url = sys.argv[1] | |
12 dataset = sys.argv[2] | |
13 output = sys.argv[3] | |
52 | 14 GALAXY_URL = sys.argv[4] |
41
02b0824c7d60
Download data from any hub in the federated xena platform
jingchunzhu <jingchunzhu@gmail.com>
parents:
diff
changeset
|
15 |
50 | 16 fout = open(output,'w') |
42
bc9784300015
more reliable, error handling
jingchunzhu <jingchunzhu@gmail.com>
parents:
41
diff
changeset
|
17 |
50 | 18 contactUrl = url |
19 if string.find(url,"galaxyxena") !=-1 and string.find(url,"ucsc.edu")!=-1: | |
20 contactUrl = "https://galaxyxena.soe.ucsc.edu:443/xena" | |
41
02b0824c7d60
Download data from any hub in the federated xena platform
jingchunzhu <jingchunzhu@gmail.com>
parents:
diff
changeset
|
21 |
50 | 22 #testing if the url is reachable |
23 try: | |
24 r =json.loads(xena.post(contactUrl, "(+ 1 2)")) | |
25 | |
26 if r!=3.0: | |
52 | 27 fout.write("There is an error\n\n") |
50 | 28 fout.write("You entered hub: %s\n" % (url)) |
52 | 29 fout.write("Possible causes for error:\n") |
30 fout.write("1. The hub is not running.\n") | |
31 fout.write("2. The hub is not accessible to this galaxy instance at: %s.\n" %(GALAXY_URL)) | |
32 fout.write("3. The hub url has a typo.\n") | |
50 | 33 fout.close() |
34 sys.exit(1) | |
35 | |
36 except: | |
52 | 37 fout.write("There is an error\n\n") |
43 | 38 fout.write("You entered hub: %s\n" % (url)) |
52 | 39 fout.write("Possible causes for error:\n") |
40 fout.write("1. The hub is not running.\n") | |
41 fout.write("2. The hub is not accessible to this galaxy instance at: %s.\n" %(GALAXY_URL)) | |
42 fout.write("3. The hub url has a typo.\n") | |
43 | 43 fout.close() |
44 sys.exit(1) | |
42
bc9784300015
more reliable, error handling
jingchunzhu <jingchunzhu@gmail.com>
parents:
41
diff
changeset
|
45 |
50 | 46 samples = xena.dataset_samples (contactUrl, dataset) |
47 if not samples: | |
52 | 48 fout.write("There is an error\n\n") |
50 | 49 fout.write("You entered dataset id: %s\n" % (dataset)) |
52 | 50 fout.write("Possible causes for error:\n") |
51 fout.write("1. Dataset does not exist.\n") | |
50 | 52 fout.close() |
53 sys.exit(1) | |
41
02b0824c7d60
Download data from any hub in the federated xena platform
jingchunzhu <jingchunzhu@gmail.com>
parents:
diff
changeset
|
54 |
50 | 55 type = xena.dataset_type(contactUrl, dataset) |
56 if type[0] not in ["genomicMatrix", "clinicalMatrix"]: | |
52 | 57 fout.write("There is an error\n\n") |
58 fout.write("You entered dataset id: %s\n" % (dataset)) | |
59 fout.write("It's datatype=%s\n" % (type[0])) | |
60 fout.write("This type of data is not supported yet.\n") | |
50 | 61 fout.close() |
62 sys.exit(1) | |
63 | |
64 writer = csv.writer(fout, delimiter='\t') | |
65 writer.writerow(["sample"]+samples) | |
41
02b0824c7d60
Download data from any hub in the federated xena platform
jingchunzhu <jingchunzhu@gmail.com>
parents:
diff
changeset
|
66 |
50 | 67 probes = xena.dataset_field(contactUrl, dataset) |
68 start=0 | |
69 size =100 | |
70 N= len(probes) | |
71 for i in range (start, N,size): | |
72 results = xena.dataset_probe_values (contactUrl, dataset, samples, probes[i:i+size]) | |
73 print ".", | |
74 for j in range (0, size): | |
75 if i+j == N: | |
76 break | |
77 writer.writerow([probes[i+j]]+results[j]) | |
41
02b0824c7d60
Download data from any hub in the federated xena platform
jingchunzhu <jingchunzhu@gmail.com>
parents:
diff
changeset
|
78 |
50 | 79 fout.close() |
80 sys.exit(0) | |
41
02b0824c7d60
Download data from any hub in the federated xena platform
jingchunzhu <jingchunzhu@gmail.com>
parents:
diff
changeset
|
81 |
50 | 82 if __name__ == "__main__": |
83 main() | |
84 |