Mercurial > repos > melissacline > xena_import
comparison xena_import.py @ 2:b3cd322f7749
Uploaded
author | melissacline |
---|---|
date | Wed, 03 Sep 2014 15:34:45 -0400 |
parents | |
children | cae2b765ca5d |
comparison
equal
deleted
inserted
replaced
1:a42384446daf | 2:b3cd322f7749 |
---|---|
1 #!/usr/bin/env python | |
2 | |
3 """ | |
4 xena_import.py: import a dataset into Xena | |
5 | |
6 Given a cmdline-specified genomic data file and a cmdline-specified Xena | |
7 directory, import the genomic data fle into Xena. This requires assembling | |
8 the necessary json file, based on cmdline input. | |
9 """ | |
10 | |
11 import argparse | |
12 import json | |
13 import shutil | |
14 | |
15 def main(): | |
16 parser = argparse.ArgumentParser() | |
17 parser.add_argument("genomicDataPathname", type=str) | |
18 parser.add_argument("cohort", type=str) | |
19 parser.add_argument("type", type=str) | |
20 parser.add_argument("xenaInputDir", type=str) | |
21 args = parser.parse_args() | |
22 | |
23 # Assemble the metadata in JSON format | |
24 metadata = { 'cohort': args.cohort, 'type': args.type } | |
25 jsonMetadata = json.dumps(metadata, indent=2) | |
26 | |
27 # Write the metadata to a file in the Xena directory. Use the filename | |
28 # of the genomic data file, with an added .json extension. | |
29 genomicDataFilename = args.genomicDataPathname.split("/")[-1] | |
30 jsonMetadataPathname = "%s/%s.json" % (args.xenaInputDir, | |
31 genomicDataFilename) | |
32 fp = open(jsonMetadataPathname, "w") | |
33 fp.write("%s\n" % (jsonMetadata)) | |
34 fp.close() | |
35 | |
36 # Finally, copy the genomic data into the Xena directory | |
37 shutil.copy(args.genomicDataPathname, args.xenaInputDir) | |
38 | |
39 if __name__ == "__main__": | |
40 main() |