annotate xena_import.py @ 2:b3cd322f7749

Uploaded
author melissacline
date Wed, 03 Sep 2014 15:34:45 -0400
parents
children cae2b765ca5d
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 parser.add_argument("xenaInputDir", type=str)
b3cd322f7749 Uploaded
melissacline
parents:
diff changeset
21 args = parser.parse_args()
b3cd322f7749 Uploaded
melissacline
parents:
diff changeset
22
b3cd322f7749 Uploaded
melissacline
parents:
diff changeset
23 # Assemble the metadata in JSON format
b3cd322f7749 Uploaded
melissacline
parents:
diff changeset
24 metadata = { 'cohort': args.cohort, 'type': args.type }
b3cd322f7749 Uploaded
melissacline
parents:
diff changeset
25 jsonMetadata = json.dumps(metadata, indent=2)
b3cd322f7749 Uploaded
melissacline
parents:
diff changeset
26
b3cd322f7749 Uploaded
melissacline
parents:
diff changeset
27 # Write the metadata to a file in the Xena directory. Use the filename
b3cd322f7749 Uploaded
melissacline
parents:
diff changeset
28 # of the genomic data file, with an added .json extension.
b3cd322f7749 Uploaded
melissacline
parents:
diff changeset
29 genomicDataFilename = args.genomicDataPathname.split("/")[-1]
b3cd322f7749 Uploaded
melissacline
parents:
diff changeset
30 jsonMetadataPathname = "%s/%s.json" % (args.xenaInputDir,
b3cd322f7749 Uploaded
melissacline
parents:
diff changeset
31 genomicDataFilename)
b3cd322f7749 Uploaded
melissacline
parents:
diff changeset
32 fp = open(jsonMetadataPathname, "w")
b3cd322f7749 Uploaded
melissacline
parents:
diff changeset
33 fp.write("%s\n" % (jsonMetadata))
b3cd322f7749 Uploaded
melissacline
parents:
diff changeset
34 fp.close()
b3cd322f7749 Uploaded
melissacline
parents:
diff changeset
35
b3cd322f7749 Uploaded
melissacline
parents:
diff changeset
36 # Finally, copy the genomic data into the Xena directory
b3cd322f7749 Uploaded
melissacline
parents:
diff changeset
37 shutil.copy(args.genomicDataPathname, args.xenaInputDir)
b3cd322f7749 Uploaded
melissacline
parents:
diff changeset
38
b3cd322f7749 Uploaded
melissacline
parents:
diff changeset
39 if __name__ == "__main__":
b3cd322f7749 Uploaded
melissacline
parents:
diff changeset
40 main()