comparison TrustStoreGalaxyImport.py @ 21:8cf18ca6f13f

ugh.
author Catherine Wise <catherine.wise@csiro.au>
date Mon, 13 Jan 2014 09:10:44 +1100
parents b94a8f55b1da
children 1179f6e90e78
comparison
equal deleted inserted replaced
20:b94a8f55b1da 21:8cf18ca6f13f
60 60
61 if is_gzipped and not is_valid: 61 if is_gzipped and not is_valid:
62 print "File is compressed (gzip) but not valid." 62 print "File is compressed (gzip) but not valid."
63 sys.exit(4) 63 sys.exit(4)
64 elif is_gzipped and is_valid: 64 elif is_gzipped and is_valid:
65 if link_data_only == 'copy_files': 65 # We need to uncompress the temp_name file, but BAM files must remain compressed in the BGZF format
66 # We need to uncompress the temp_name file, but BAM files must remain compressed in the BGZF format 66 CHUNK_SIZE = 2**20 # 1Mb
67 CHUNK_SIZE = 2**20 # 1Mb 67 fd, uncompressed = tempfile.mkstemp(prefix='data_id_%s_upload_gunzip_' % dataset.dataset_id, dir=os.path.dirname(outputFile), text=False )
68 fd, uncompressed = tempfile.mkstemp(prefix='data_id_%s_upload_gunzip_' % dataset.dataset_id, dir=os.path.dirname(outputFile), text=False ) 68 gzipped_file = gzip.GzipFile(download, 'rb')
69 gzipped_file = gzip.GzipFile(download, 'rb') 69 while 1:
70 while 1: 70 try:
71 try: 71 chunk = gzipped_file.read(CHUNK_SIZE)
72 chunk = gzipped_file.read(CHUNK_SIZE) 72 except IOError:
73 except IOError: 73 os.close(fd)
74 os.close(fd) 74 os.remove(uncompressed)
75 os.remove(uncompressed) 75 print 'Problem decompressing gzipped data', dataset, json_file
76 print 'Problem decompressing gzipped data', dataset, json_file 76 sys.exit(4)
77 sys.exit(4) 77 if not chunk:
78 if not chunk: 78 break
79 break 79 os.write(fd, chunk)
80 os.write(fd, chunk) 80 os.close(fd)
81 os.close(fd) 81 gzipped_file.close()
82 gzipped_file.close()
83 82
84 shutil.copy(uncompressed, outputFile) 83 shutil.copy(uncompressed, outputFile)
85 else: 84 else:
86 shutil.copy(download, outputFile) 85 shutil.copy(download, outputFile)
87 else: 86 else: