Mercurial > repos > melissacline > xena_import
annotate xena_import.py @ 16:7f03b062f330 default tip
Cleaned up the user interface a bit
author | melissacline |
---|---|
date | Tue, 23 Sep 2014 21:18:54 -0700 |
parents | a2a7096897a8 |
children |
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 | |
9 | 13 import os |
2 | 14 import shutil |
15 | |
16 def main(): | |
17 parser = argparse.ArgumentParser() | |
18 parser.add_argument("genomicDataPathname", type=str) | |
19 parser.add_argument("cohort", type=str) | |
20 parser.add_argument("type", type=str) | |
21 args = parser.parse_args() | |
22 | |
3 | 23 xenaBaseDir = os.getenv("XENA_BASE_DIR", "~") |
9 | 24 xenaFileDir = xenaBaseDir + "/files" |
3 | 25 |
2 | 26 # Assemble the metadata in JSON format |
27 metadata = { 'cohort': args.cohort, 'type': args.type } | |
28 jsonMetadata = json.dumps(metadata, indent=2) | |
29 | |
30 # Write the metadata to a file in the Xena directory. Use the filename | |
31 # of the genomic data file, with an added .json extension. | |
32 genomicDataFilename = args.genomicDataPathname.split("/")[-1] | |
9 | 33 jsonMetadataPathname = "%s/%s.json" % (xenaFileDir, |
2 | 34 genomicDataFilename) |
9 | 35 #fp = open("/inside/home/cline/tmp/xena_import.out", "w") |
36 #fp.write("xena file dir %s\n" % (xenaFileDir)) | |
37 #fp.write("copying metadata to %s and data to %s" % (jsonMetadataPathname, | |
38 # xenaFileDir)) | |
39 #fp.close() | |
6
8d87f0ecc08d
Removed some debugging messages, which I hope we are now done with
melissacline
parents:
3
diff
changeset
|
40 |
2 | 41 fp = open(jsonMetadataPathname, "w") |
42 fp.write("%s\n" % (jsonMetadata)) | |
43 fp.close() | |
44 | |
45 # Finally, copy the genomic data into the Xena directory | |
16 | 46 try: |
47 shutil.copy(args.genomicDataPathname, xenaFileDir) | |
48 except: | |
49 print "Unexpected error", sys.exc_info()[0] | |
50 else: | |
51 print "Data copied successfully to Xena" | |
2 | 52 |
53 if __name__ == "__main__": | |
54 main() |