changeset 24:1d83dbbee373

Fixing a merge conflict
author melissacline
date Mon, 20 Jul 2015 15:41:22 -0700
parents 7346e5bab4ec (current diff) d0674221a6ae (diff)
children 80b6b64e8b5e
files mergeGenomicMatrixFiles.py
diffstat 1 files changed, 25 insertions(+), 7 deletions(-) [+]
line wrap: on
line diff
--- a/synapseGetDataset.py	Mon Jul 20 15:33:07 2015 -0700
+++ b/synapseGetDataset.py	Mon Jul 20 15:41:22 2015 -0700
@@ -1,10 +1,18 @@
 #!/usr/bin/env python
-"""Download a dataset from Synapse into Galaxy"""
+"""Download a dataset from Synapse into Galaxy """
 
 import argparse
 import json
 import synapseclient
 import sys
+import zipfile
+
+class InputError(Exception):
+    def __init__(self, value):
+        self.value = value
+    def __str__(self):
+        return repr(self.value)
+
 
 def saveMetadata(entity, metadataPathname):
     fp = open(metadataPathname, "w")
@@ -15,12 +23,22 @@
     fp.close()
 
 def saveData(entity, dataPathname):
-    fpIn = open(entity.path)
-    fpOut = open(dataPathname, "w")
-    for row in fpIn:
-        fpOut.write(row)
-    fpIn.close()
-    fpOut.close()
+    if entity.properties['contentType'] == "application/zip":
+        zf = zipfile.ZipFile(entity.path)
+        if len(zf.namelist()) > 1:
+            raise InputError(len(zf.namelist())), "Error: more than one input file"
+        else:
+            data = zf.read(zf.namelist()[0])
+            fpOut = open(dataPathname, "w")
+            fpOut.write(data)
+            fpOut.close()
+    else:
+        fpIn = open(entity.path)
+        fpOut = open(dataPathname, "w")
+        for row in fpIn:
+            fpOut.write(row)
+        fpIn.close()
+        fpOut.close()
 
 def main():
     parser = argparse.ArgumentParser()