comparison synapseGetDataset.py @ 24:1d83dbbee373

Fixing a merge conflict
author melissacline
date Mon, 20 Jul 2015 15:41:22 -0700
parents d1104ad3646a
children e81019e3ac99
comparison
equal deleted inserted replaced
23:7346e5bab4ec 24:1d83dbbee373
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 synapseclient 6 import synapseclient
7 import sys 7 import sys
8 import zipfile
9
10 class InputError(Exception):
11 def __init__(self, value):
12 self.value = value
13 def __str__(self):
14 return repr(self.value)
15
8 16
9 def saveMetadata(entity, metadataPathname): 17 def saveMetadata(entity, metadataPathname):
10 fp = open(metadataPathname, "w") 18 fp = open(metadataPathname, "w")
11 entityMetadata = dict(entity.properties.items() 19 entityMetadata = dict(entity.properties.items()
12 + entity.annotations.items()) 20 + entity.annotations.items())
13 jsonMetadata = json.dumps(entityMetadata) 21 jsonMetadata = json.dumps(entityMetadata)
14 fp.write("%s\n" % (jsonMetadata)) 22 fp.write("%s\n" % (jsonMetadata))
15 fp.close() 23 fp.close()
16 24
17 def saveData(entity, dataPathname): 25 def saveData(entity, dataPathname):
18 fpIn = open(entity.path) 26 if entity.properties['contentType'] == "application/zip":
19 fpOut = open(dataPathname, "w") 27 zf = zipfile.ZipFile(entity.path)
20 for row in fpIn: 28 if len(zf.namelist()) > 1:
21 fpOut.write(row) 29 raise InputError(len(zf.namelist())), "Error: more than one input file"
22 fpIn.close() 30 else:
23 fpOut.close() 31 data = zf.read(zf.namelist()[0])
32 fpOut = open(dataPathname, "w")
33 fpOut.write(data)
34 fpOut.close()
35 else:
36 fpIn = open(entity.path)
37 fpOut = open(dataPathname, "w")
38 for row in fpIn:
39 fpOut.write(row)
40 fpIn.close()
41 fpOut.close()
24 42
25 def main(): 43 def main():
26 parser = argparse.ArgumentParser() 44 parser = argparse.ArgumentParser()
27 parser.add_argument("entityId", type=str) 45 parser.add_argument("entityId", type=str)
28 parser.add_argument("email", type=str) 46 parser.add_argument("email", type=str)