0
|
1 #!/usr/bin/env python
|
|
2
|
|
3 import argparse
|
|
4 import json
|
|
5 from functools import partial
|
|
6 import re
|
|
7 import xena_query as xena
|
|
8
|
|
9 # xena url for public datasets, at ucsc
|
|
10 xena_url = "https://genome-cancer.ucsc.edu/proj/public/xena"
|
|
11
|
|
12
|
|
13 def main():
|
|
14 parser = argparse.ArgumentParser()
|
|
15 parser.add_argument("datasetType", type=str)
|
|
16 parser.add_argument("cohortName", type=str)
|
|
17 parser.add_argument("outfile", type=str)
|
|
18 args = parser.parse_args()
|
|
19
|
|
20 cohort = args.cohortName
|
|
21 if not re.search("^%", cohort):
|
|
22 cohort = "%" + cohort
|
|
23 if not re.search("%$", cohort):
|
|
24 cohort = cohort + "%"
|
|
25
|
|
26 # short-hand wrappers for xena methods
|
|
27 post = xena.compose(json.loads, partial(xena.post, xena_url))
|
|
28 find_datasets_type_pattern = xena.compose(post,
|
|
29 xena.find_datasets_type_pattern)
|
|
30 name_to_url = partial(xena.name_to_url, xena_url)
|
|
31 datasets = find_datasets_type_pattern(args.datasetType, cohort)
|
|
32 fp = open(args.outfile, "w")
|
|
33 fp.write("Cohort\tDataset\n")
|
|
34 for thisDataset in datasets:
|
|
35 tokens = thisDataset.split("/")
|
|
36 cohort = tokens[-2]
|
|
37 datasetName = tokens[-1]
|
|
38 fp.write("%s\t%s\n" % (cohort, datasetName))
|
|
39 fp.close()
|
|
40
|
|
41 if __name__ == "__main__":
|
|
42 main()
|