Mercurial > repos > melissacline > ucsc_cancer_utilities
comparison synapseGetDataset.py @ 37:e81019e3ac99
Updated synapseGetDataset to look at the filename rather than the (no longer existant) content type field to determine if the data is in zip format
author | melissacline |
---|---|
date | Mon, 27 Jul 2015 16:29:24 -0700 |
parents | d1104ad3646a |
children |
comparison
equal
deleted
inserted
replaced
36:ab161b5ac9cc | 37:e81019e3ac99 |
---|---|
1 #!/usr/bin/env python | 1 #!/usr/bin/env python |
2 """Download a dataset from Synapse into Galaxy """ | 2 """Download a dataset from Synapse into Galaxy """ |
3 | 3 |
4 import argparse | 4 import argparse |
5 import json | 5 import json |
6 import re | |
6 import synapseclient | 7 import synapseclient |
7 import sys | 8 import sys |
8 import zipfile | 9 import zipfile |
9 | 10 |
10 class InputError(Exception): | 11 class InputError(Exception): |
21 jsonMetadata = json.dumps(entityMetadata) | 22 jsonMetadata = json.dumps(entityMetadata) |
22 fp.write("%s\n" % (jsonMetadata)) | 23 fp.write("%s\n" % (jsonMetadata)) |
23 fp.close() | 24 fp.close() |
24 | 25 |
25 def saveData(entity, dataPathname): | 26 def saveData(entity, dataPathname): |
26 if entity.properties['contentType'] == "application/zip": | 27 if re.search("\.zip$", entity.path): |
27 zf = zipfile.ZipFile(entity.path) | 28 zf = zipfile.ZipFile(entity.path) |
28 if len(zf.namelist()) > 1: | 29 if len(zf.namelist()) > 1: |
29 raise InputError(len(zf.namelist())), "Error: more than one input file" | 30 raise InputError(len(zf.namelist())), "Error: more than one input file" |
30 else: | 31 else: |
31 data = zf.read(zf.namelist()[0]) | 32 data = zf.read(zf.namelist()[0]) |