view xena_import.py @ 7:4010d0fae297

Trying something else in terms of the tool dependencies revision #
author melissacline
date Thu, 04 Sep 2014 15:54:33 -0700
parents 8d87f0ecc08d
children a2a7096897a8
line wrap: on
line source

#!/usr/bin/env python

"""
  xena_import.py: import a dataset into Xena

  Given a cmdline-specified genomic data file and a cmdline-specified Xena 
  directory, import the genomic data fle into Xena.  This requires assembling
  the necessary json file, based on cmdline input.
"""

import argparse
import json
import shutil

def main():
    parser = argparse.ArgumentParser()
    parser.add_argument("genomicDataPathname", type=str)
    parser.add_argument("cohort", type=str)
    parser.add_argument("type", type=str)
    args = parser.parse_args()

    xenaBaseDir = os.getenv("XENA_BASE_DIR", "~")

    # Assemble the metadata in JSON format
    metadata = { 'cohort': args.cohort, 'type': args.type }
    jsonMetadata = json.dumps(metadata, indent=2) 
    
    # Write the metadata to a file in the Xena directory.  Use the filename
    # of the genomic data file, with an added .json extension.
    genomicDataFilename = args.genomicDataPathname.split("/")[-1]
    jsonMetadataPathname = "%s/%s.json" % (args.xenaInputDir, 
                                           genomicDataFilename)
    fp = open("/Users/melissacline/tmp/xena.out", "w")
    fp.write("xena base dir %s\n" % (xenaBaseDir))
    fp.write(cmdline)
    fp.close()

    fp = open(jsonMetadataPathname, "w")
    fp.write("%s\n" % (jsonMetadata))
    fp.close()

    # Finally, copy the genomic data into the Xena directory
    shutil.copy(args.genomicDataPathname, args.xenaInputDir)

if __name__ == "__main__":
    main()