Mercurial > repos > melissacline > xena_import
annotate xena_import.py @ 6:8d87f0ecc08d
Removed some debugging messages, which I hope we are now done with
author | melissacline |
---|---|
date | Thu, 04 Sep 2014 15:41:37 -0700 |
parents | cae2b765ca5d |
children | a2a7096897a8 |
rev | line source |
---|---|
2 | 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 args = parser.parse_args() | |
21 | |
3 | 22 xenaBaseDir = os.getenv("XENA_BASE_DIR", "~") |
23 | |
2 | 24 # Assemble the metadata in JSON format |
25 metadata = { 'cohort': args.cohort, 'type': args.type } | |
26 jsonMetadata = json.dumps(metadata, indent=2) | |
27 | |
28 # Write the metadata to a file in the Xena directory. Use the filename | |
29 # of the genomic data file, with an added .json extension. | |
30 genomicDataFilename = args.genomicDataPathname.split("/")[-1] | |
31 jsonMetadataPathname = "%s/%s.json" % (args.xenaInputDir, | |
32 genomicDataFilename) | |
6
8d87f0ecc08d
Removed some debugging messages, which I hope we are now done with
melissacline
parents:
3
diff
changeset
|
33 fp = open("/Users/melissacline/tmp/xena.out", "w") |
8d87f0ecc08d
Removed some debugging messages, which I hope we are now done with
melissacline
parents:
3
diff
changeset
|
34 fp.write("xena base dir %s\n" % (xenaBaseDir)) |
8d87f0ecc08d
Removed some debugging messages, which I hope we are now done with
melissacline
parents:
3
diff
changeset
|
35 fp.write(cmdline) |
8d87f0ecc08d
Removed some debugging messages, which I hope we are now done with
melissacline
parents:
3
diff
changeset
|
36 fp.close() |
8d87f0ecc08d
Removed some debugging messages, which I hope we are now done with
melissacline
parents:
3
diff
changeset
|
37 |
2 | 38 fp = open(jsonMetadataPathname, "w") |
39 fp.write("%s\n" % (jsonMetadata)) | |
40 fp.close() | |
41 | |
42 # Finally, copy the genomic data into the Xena directory | |
43 shutil.copy(args.genomicDataPathname, args.xenaInputDir) | |
44 | |
45 if __name__ == "__main__": | |
46 main() |