diff xena_import.py @ 35:d8dc482ef970

add functionality to import probeMap
author jingchunzhu <jingchunzhu@gmail.com>
date Thu, 23 Jul 2015 16:14:33 -0700
parents 6eeb3ca663fb
children d64a002c3b0c
line wrap: on
line diff
--- a/xena_import.py	Thu Jul 23 01:02:24 2015 -0700
+++ b/xena_import.py	Thu Jul 23 16:14:33 2015 -0700
@@ -53,6 +53,7 @@
     parser.add_argument("--dataSubType", type=str, default=None)
     parser.add_argument("--label", type=str, default=None)
     parser.add_argument("--colNormalization", type=bool, default=False)
+    parser.add_argument("--probeMap", type=str, default=None)
     args = parser.parse_args()
 
     fp2 = open(args.outfile, "w")
@@ -62,6 +63,10 @@
     jsonMetadataTargetPathname = "%s/%s.json" % (xenaFileDir, 
                                                  genomicDataFile)
 
+    if args.probeMap is not None:
+        probeMapDataFile = args.probeMap.split("/")[-1]
+        jsonProbeMapMetadataTargetPathname = "%s/%s.json" % (xenaFileDir, 
+                                                             probeMapDataFile)
 
     # The metadata either came as the name of a JSON file or a series of 
     # command line arguments.
@@ -83,13 +88,27 @@
             metadata['colNormalization'] = "true"
         else:
             updateColNormalization(metadata)
+        if args.probeMap is not None:
+            metadata[':probeMap'] = probeMapDataFile
+            
         jsonMetadata = json.dumps(metadata, indent=2) 
         fp = open(jsonMetadataTargetPathname, "w")
         fp.write("%s\n" % (jsonMetadata))
         fp.close()
     
+        if args.probeMap is not None:
+            probeMapMetadata={"type":"probeMap"}
+            jsonProbeMapMetadata = json.dumps(probeMapMetadata, indent=2)
+            jsonProbeMapMetadataTargetPathname = "%s/%s.json" % (xenaFileDir, 
+                                                                 probeMapDataFile)
+            fp = open(jsonProbeMapMetadataTargetPathname, "w")
+            fp.write("%s\n" % ( jsonProbeMapMetadata))
+            fp.close()
+
     # Finally, copy the genomic data into the Xena directory
     shutil.copy(args.genomicDataPath, xenaFileDir)
+    if args.probeMap is not None:
+        shutil.copy(args.probeMap, xenaFileDir)
 
     # Set up the xena load comamnd and try to execute it.  If an exception
     # is generated, output a traceback and exit with nonzero status.  If
@@ -99,6 +118,16 @@
                                                            xenaFileDir,
                                                            genomicDataFile, 
                                                            xena.port())
+    loadInToXena (xenaLoadCmd, fp2)
+    if args.probeMap is not None:
+        xenaLoadCmd = "java -jar %s -l --force %s/%s -p %s" % (xena.jarPath(),
+                                                               xenaFileDir,
+                                                               probeMapDataFile,
+                                                               xena.port())
+        loadInToXena (xenaLoadCmd, fp2)
+
+
+def loadInToXena (xenaLoadCmd, fp2):
     try:
         subprocess.call(xenaLoadCmd, shell=True)
     except:
@@ -113,6 +142,5 @@
         fp2.close()
         sys.exit(0)
 
-
 if __name__ == "__main__":
     main()