Mercurial > repos > cathywise > truststore_import
changeset 30:c659bd6342ae
Fix deps.
author | Catherine Wise <catherine.wise@csiro.au> |
---|---|
date | Thu, 23 Jan 2014 10:36:03 +1100 |
parents | 4c25b2ce827e |
children | 6e2dba73eebd |
files | TrustStoreGalaxyImport.py TrustStoreGalaxyImport.xml |
diffstat | 2 files changed, 58 insertions(+), 42 deletions(-) [+] |
line wrap: on
line diff
--- a/TrustStoreGalaxyImport.py Thu Jan 23 10:21:58 2014 +1100 +++ b/TrustStoreGalaxyImport.py Thu Jan 23 10:36:03 2014 +1100 @@ -14,6 +14,40 @@ for child in elem.children: printNice(child, f, depth+1) +def ungzip(download, outputFile): + is_gzipped, is_valid = check_gzip(download) + + if is_gzipped and not is_valid: + print "File is compressed (gzip) but not valid." + sys.exit(4) + elif is_gzipped and is_valid: + # We need to uncompress the temp_name file, but BAM files must remain compressed in the BGZF format + CHUNK_SIZE = 2**20 # 1Mb + fd, uncompressed = tempfile.mkstemp(prefix='data_id_upload_gunzip_', dir=os.path.dirname(outputFile), text=False ) + gzipped_file = gzip.GzipFile(download, 'rb') + while 1: + try: + chunk = gzipped_file.read(CHUNK_SIZE) + except IOError: + os.close(fd) + os.remove(uncompressed) + print 'Problem decompressing gzipped data', dataset, json_file + sys.exit(4) + if not chunk: + break + os.write(fd, chunk) + os.close(fd) + gzipped_file.close() + + shutil.copy(uncompressed, outputFile) + try: + os.remove(uncompressed) + os.remove(download) + except OSError: + pass + else: + shutil.copy(download, outputFile) + if __name__ == '__main__': kms_url = sys.argv[1] @@ -29,6 +63,9 @@ if len(sys.argv) > 10: filename = sys.argv[9] outputFile = sys.argv[10] + outputFileId = sys.argv[11] + outputFileType = sys.argv[12] + otherFilesDir = sys.argv[13] else: outputFile = sys.argv[9] @@ -55,44 +92,23 @@ else: location = root if filename and filename != "": - downloadMe = ts_utils.ts_utils.recurseToChildNamed(location, filename) - if downloadMe: - download = ts.getFile(store, downloadMe) - is_gzipped, is_valid = check_gzip(download) - - if is_gzipped and not is_valid: - print "File is compressed (gzip) but not valid." + outputFileList = [outputFile] + inputFileList = None + if "," in filename: # we have multiple files guys. + inputFileList = filename.split(",") + for inputFile in inputFileList: + outName = "%s_%s_%s_%s_%s" % ('primary', outputFileId, inputFile.replace(".","-"), 'visible', outputFileType) + outputFileList.append(os.path.join(otherFilesDir, outName)) + else: + inputFileList = [filename] + for inFile, outFile in zip(inputFileList, outputFileList): + downloadMe = ts_utils.ts_utils.recurseToChildNamed(location, inFile) + if downloadMe: + download = ts.getFile(store, downloadMe) + ungzip(download, outFile) + else: + print "File %s not found" % inFile sys.exit(4) - elif is_gzipped and is_valid: - # We need to uncompress the temp_name file, but BAM files must remain compressed in the BGZF format - CHUNK_SIZE = 2**20 # 1Mb - fd, uncompressed = tempfile.mkstemp(prefix='data_id_upload_gunzip_', dir=os.path.dirname(outputFile), text=False ) - gzipped_file = gzip.GzipFile(download, 'rb') - while 1: - try: - chunk = gzipped_file.read(CHUNK_SIZE) - except IOError: - os.close(fd) - os.remove(uncompressed) - print 'Problem decompressing gzipped data', dataset, json_file - sys.exit(4) - if not chunk: - break - os.write(fd, chunk) - os.close(fd) - gzipped_file.close() - - shutil.copy(uncompressed, outputFile) - try: - os.remove(uncompressed) - os.remove(download) - except OSError: - pass - else: - shutil.copy(download, outputFile) - else: - print "File not found" - sys.exit(4) else: with open(outputFile, 'w+') as f: try:
--- a/TrustStoreGalaxyImport.xml Thu Jan 23 10:21:58 2014 +1100 +++ b/TrustStoreGalaxyImport.xml Thu Jan 23 10:36:03 2014 +1100 @@ -1,4 +1,4 @@ -<tool id="ts_import_1" name="Import Data from TrustStore" vertion="0.1"> <!-- tool_type="data_source"> --> +<tool id="ts_import_1" name="Import Data from TrustStore" vertion="0.1" force_history_refresh="True"> <!-- tool_type="data_source"> --> <description> secure cloud storage.</description> <stdio> <exit_code range="2" err_level="fatal" description="Could not find store with supplied name." /> @@ -6,7 +6,7 @@ <exit_code range="4" err_level="fatal" description="Could not find supplied filename in store at path." /> <exit_code range="5" err_level="fatal" description="Bad credentials supplied. See stdout for more information." /> </stdio> - <command interpreter="python">TrustStoreGalaxyImport.py https://tstest-kms.it.csiro.au/kmscolab_3_0 https://tstest-ims.it.csiro.au/ims_3_0/services/IMS $username $password desktop cpU92F1PT7VOCANjSknuCDp4DrubmujoBaF6b0miz8OpKNokEbGMHCaSFK5/lISbBmaaGVCgeADI2A39F3Hkeg== $storename $path $filename $output</command> + <command interpreter="python">TrustStoreGalaxyImport.py https://tstest-kms.it.csiro.au/kmscolab_3_0 https://tstest-ims.it.csiro.au/ims_3_0/services/IMS $username $password desktop cpU92F1PT7VOCANjSknuCDp4DrubmujoBaF6b0miz8OpKNokEbGMHCaSFK5/lISbBmaaGVCgeADI2A39F3Hkeg== $storename $path $filename $output1 $output1.id $file_type $__new_file_path__</command> <inputs> <param name="file_type" type="select" label="File Format" help="Which format is the data you're downloading?"> <option value="just list files"/> @@ -67,10 +67,10 @@ <!-- <param name="client_secret" type="text" label="client secret" help="kms client secret" value="somesecret" size="20" /> --> <param name="storename" type="text" label="Store Name" help="e.g.: My Galaxy Store" value="galaxy" size="20" /> <param name="path" type="text" label="Path in Store" help="e.g.: /rawdata/feb2014/, leave as / for top level files" value="/" size="20" /> - <param name="filename" type="text" label="Filename" help="e.g.: export1.bam. Leave empty if 'just list files' is chosen above." value="" size="20" /> + <param name="filename(s)" type="text" label="Filename" help="e.g.: export1.bam,export2.bam Comma seperated. Leave empty if 'just list files' is chosen above." value="" size="40" /> </inputs> <outputs> - <data name="output" format="txt"> + <data name="output1" format="txt"> <change_format> <when input="file_type" value="ab1" format="ab1" /> <when input="file_type" value="axt" format="axt" /> @@ -113,7 +113,7 @@ </tests> <requirements> - <requirement type="package" version="0.2">py_ts</requirement> + <requirement type="package" version="0.2.2">py_ts</requirement> <requirement type="python_module">py_ts</requirement> <requirement type="binary" version="1.0.0">openssl</requirement> </requirements>