Mercurial > repos > melissacline > xena_import
comparison xena_import.py @ 9:a2a7096897a8
FIXED the xena import process
author | melissacline |
---|---|
date | Mon, 08 Sep 2014 13:26:21 -0700 |
parents | 8d87f0ecc08d |
children | 7f03b062f330 |
comparison
equal
deleted
inserted
replaced
8:dc42b6bbc22b | 9:a2a7096897a8 |
---|---|
8 the necessary json file, based on cmdline input. | 8 the necessary json file, based on cmdline input. |
9 """ | 9 """ |
10 | 10 |
11 import argparse | 11 import argparse |
12 import json | 12 import json |
13 import os | |
13 import shutil | 14 import shutil |
14 | 15 |
15 def main(): | 16 def main(): |
16 parser = argparse.ArgumentParser() | 17 parser = argparse.ArgumentParser() |
17 parser.add_argument("genomicDataPathname", type=str) | 18 parser.add_argument("genomicDataPathname", type=str) |
18 parser.add_argument("cohort", type=str) | 19 parser.add_argument("cohort", type=str) |
19 parser.add_argument("type", type=str) | 20 parser.add_argument("type", type=str) |
20 args = parser.parse_args() | 21 args = parser.parse_args() |
21 | 22 |
22 xenaBaseDir = os.getenv("XENA_BASE_DIR", "~") | 23 xenaBaseDir = os.getenv("XENA_BASE_DIR", "~") |
24 xenaFileDir = xenaBaseDir + "/files" | |
23 | 25 |
24 # Assemble the metadata in JSON format | 26 # Assemble the metadata in JSON format |
25 metadata = { 'cohort': args.cohort, 'type': args.type } | 27 metadata = { 'cohort': args.cohort, 'type': args.type } |
26 jsonMetadata = json.dumps(metadata, indent=2) | 28 jsonMetadata = json.dumps(metadata, indent=2) |
27 | 29 |
28 # Write the metadata to a file in the Xena directory. Use the filename | 30 # Write the metadata to a file in the Xena directory. Use the filename |
29 # of the genomic data file, with an added .json extension. | 31 # of the genomic data file, with an added .json extension. |
30 genomicDataFilename = args.genomicDataPathname.split("/")[-1] | 32 genomicDataFilename = args.genomicDataPathname.split("/")[-1] |
31 jsonMetadataPathname = "%s/%s.json" % (args.xenaInputDir, | 33 jsonMetadataPathname = "%s/%s.json" % (xenaFileDir, |
32 genomicDataFilename) | 34 genomicDataFilename) |
33 fp = open("/Users/melissacline/tmp/xena.out", "w") | 35 #fp = open("/inside/home/cline/tmp/xena_import.out", "w") |
34 fp.write("xena base dir %s\n" % (xenaBaseDir)) | 36 #fp.write("xena file dir %s\n" % (xenaFileDir)) |
35 fp.write(cmdline) | 37 #fp.write("copying metadata to %s and data to %s" % (jsonMetadataPathname, |
36 fp.close() | 38 # xenaFileDir)) |
39 #fp.close() | |
37 | 40 |
38 fp = open(jsonMetadataPathname, "w") | 41 fp = open(jsonMetadataPathname, "w") |
39 fp.write("%s\n" % (jsonMetadata)) | 42 fp.write("%s\n" % (jsonMetadata)) |
40 fp.close() | 43 fp.close() |
41 | 44 |
42 # Finally, copy the genomic data into the Xena directory | 45 # Finally, copy the genomic data into the Xena directory |
43 shutil.copy(args.genomicDataPathname, args.xenaInputDir) | 46 shutil.copy(args.genomicDataPathname, xenaFileDir) |
44 | 47 |
45 if __name__ == "__main__": | 48 if __name__ == "__main__": |
46 main() | 49 main() |