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
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
2
b3cd322f7749 Uploaded
melissacline
parents:
diff changeset
1 #!/usr/bin/env python
b3cd322f7749 Uploaded
melissacline
parents:
diff changeset
2
b3cd322f7749 Uploaded
melissacline
parents:
diff changeset
3 """
b3cd322f7749 Uploaded
melissacline
parents:
diff changeset
4 xena_import.py: import a dataset into Xena
b3cd322f7749 Uploaded
melissacline
parents:
diff changeset
5
b3cd322f7749 Uploaded
melissacline
parents:
diff changeset
6 Given a cmdline-specified genomic data file and a cmdline-specified Xena
b3cd322f7749 Uploaded
melissacline
parents:
diff changeset
7 directory, import the genomic data fle into Xena. This requires assembling
b3cd322f7749 Uploaded
melissacline
parents:
diff changeset
8 the necessary json file, based on cmdline input.
b3cd322f7749 Uploaded
melissacline
parents:
diff changeset
9 """
b3cd322f7749 Uploaded
melissacline
parents:
diff changeset
10
b3cd322f7749 Uploaded
melissacline
parents:
diff changeset
11 import argparse
b3cd322f7749 Uploaded
melissacline
parents:
diff changeset
12 import json
b3cd322f7749 Uploaded
melissacline
parents:
diff changeset
13 import shutil
b3cd322f7749 Uploaded
melissacline
parents:
diff changeset
14
b3cd322f7749 Uploaded
melissacline
parents:
diff changeset
15 def main():
b3cd322f7749 Uploaded
melissacline
parents:
diff changeset
16 parser = argparse.ArgumentParser()
b3cd322f7749 Uploaded
melissacline
parents:
diff changeset
17 parser.add_argument("genomicDataPathname", type=str)
b3cd322f7749 Uploaded
melissacline
parents:
diff changeset
18 parser.add_argument("cohort", type=str)
b3cd322f7749 Uploaded
melissacline
parents:
diff changeset
19 parser.add_argument("type", type=str)
b3cd322f7749 Uploaded
melissacline
parents:
diff changeset
20 args = parser.parse_args()
b3cd322f7749 Uploaded
melissacline
parents:
diff changeset
21
3
cae2b765ca5d Changing how the Xena base dir is communicated
melissacline
parents: 2
diff changeset
22 xenaBaseDir = os.getenv("XENA_BASE_DIR", "~")
cae2b765ca5d Changing how the Xena base dir is communicated
melissacline
parents: 2
diff changeset
23
2
b3cd322f7749 Uploaded
melissacline
parents:
diff changeset
24 # Assemble the metadata in JSON format
b3cd322f7749 Uploaded
melissacline
parents:
diff changeset
25 metadata = { 'cohort': args.cohort, 'type': args.type }
b3cd322f7749 Uploaded
melissacline
parents:
diff changeset
26 jsonMetadata = json.dumps(metadata, indent=2)
b3cd322f7749 Uploaded
melissacline
parents:
diff changeset
27
b3cd322f7749 Uploaded
melissacline
parents:
diff changeset
28 # Write the metadata to a file in the Xena directory. Use the filename
b3cd322f7749 Uploaded
melissacline
parents:
diff changeset
29 # of the genomic data file, with an added .json extension.
b3cd322f7749 Uploaded
melissacline
parents:
diff changeset
30 genomicDataFilename = args.genomicDataPathname.split("/")[-1]
b3cd322f7749 Uploaded
melissacline
parents:
diff changeset
31 jsonMetadataPathname = "%s/%s.json" % (args.xenaInputDir,
b3cd322f7749 Uploaded
melissacline
parents:
diff changeset
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
b3cd322f7749 Uploaded
melissacline
parents:
diff changeset
38 fp = open(jsonMetadataPathname, "w")
b3cd322f7749 Uploaded
melissacline
parents:
diff changeset
39 fp.write("%s\n" % (jsonMetadata))
b3cd322f7749 Uploaded
melissacline
parents:
diff changeset
40 fp.close()
b3cd322f7749 Uploaded
melissacline
parents:
diff changeset
41
b3cd322f7749 Uploaded
melissacline
parents:
diff changeset
42 # Finally, copy the genomic data into the Xena directory
b3cd322f7749 Uploaded
melissacline
parents:
diff changeset
43 shutil.copy(args.genomicDataPathname, args.xenaInputDir)
b3cd322f7749 Uploaded
melissacline
parents:
diff changeset
44
b3cd322f7749 Uploaded
melissacline
parents:
diff changeset
45 if __name__ == "__main__":
b3cd322f7749 Uploaded
melissacline
parents:
diff changeset
46 main()