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)
|
|
33 fp = open(jsonMetadataPathname, "w")
|
|
34 fp.write("%s\n" % (jsonMetadata))
|
|
35 fp.close()
|
|
36
|
|
37 # Finally, copy the genomic data into the Xena directory
|
|
38 shutil.copy(args.genomicDataPathname, args.xenaInputDir)
|
|
39
|
|
40 if __name__ == "__main__":
|
|
41 main()
|