# HG changeset patch # User melissacline # Date 1437432082 25200 # Node ID 1d83dbbee373cd0822cd709fc85cebfb222926cb # Parent 7346e5bab4ec15e4fdf2c750ccc073e29033b054# Parent d0674221a6aedac1781ba4d69ccb0fa5db3804d4 Fixing a merge conflict diff -r 7346e5bab4ec -r 1d83dbbee373 mergeGenomicMatrixFiles.py diff -r 7346e5bab4ec -r 1d83dbbee373 synapseGetDataset.py --- 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()