Mercurial > repos > melissacline > ucsc_cancer_utilities
diff synapseGetDataset.py @ 24:1d83dbbee373
Fixing a merge conflict
author | melissacline |
---|---|
date | Mon, 20 Jul 2015 15:41:22 -0700 |
parents | d1104ad3646a |
children | e81019e3ac99 |
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()