PKH6LC7FFwort/__init__.py""" A web service for sourmash operations. """ __version__ = "0.0.1" PK26LHz wort/app.pyfrom flask import Flask, url_for, jsonify from celery import Celery from . import tasks app = Flask(__name__) app.config.from_object('config.settings') #app.config.from_pyfile('settings.py') celery = Celery(app.name, broker=app.config['CELERY_BROKER_URL']) celery.conf.update(app.config) @app.route('/compute/', methods=['POST']) def compute(sra_id): task = tasks.compute.apply_sync(sra_id) return jsonify({}), 202, {'Location': url_for('taskstatus', task_id=task.id)} @app.route('/status/') def taskstatus(task_id): task = tasks.compute.AsyncResult(task_id) if task.state == 'PENDING': response = { 'state': task.state, 'current': 0, 'total': 1, 'status': 'Pending...' } elif task.state != 'FAILURE': response = { 'state': task.state, 'current': task.info.get('current', 0), 'total': task.info.get('total', 1), 'status': task.info.get('status', '') } if 'result' in task.info: response['result'] = task.info['result'] else: # something went wrong in the background job response = { 'state': task.state, 'current': 1, 'total': 1, 'status': str(task.info), # this is the exception raised } return jsonify(response) if __name__ == '__main__': app.run(debug=True) PK6LIh  wort/tasks.pyimport os from subprocess import CalledProcessError from tempfile import NamedTemporaryFile, TemporaryDirectory from celery.exceptions import Ignore from .app import app @app.task def compute(sra_id): from snakemake import shell with TemporaryDirectory() as tmpdir: with NamedTemporaryFile('w+t') as f: try: shell('fastq-dump -A {sra_id} -Z | ' 'head -4000000 | ' 'trim-low-abund.py -T {tmpdir} -M 5e8 -k 21 -V -Z 10 -C 3 - -o - | ' 'sourmash compute -f -k 21 --dna - -o {output} --name {sra_id}' .format(sra_id=sra_id, output=f.name, tmpdir=tmpdir)) except CalledProcessError as e: # We ignore SIGPIPE, since it is informational (and makes sense, # it happens because `head` is closed and `fastq-dump` can't pipe # its output anymore. More details: # http://www.pixelbeat.org/programming/sigpipe_handling.html if e.returncode != 141: raise e f.seek(0) return f.read() @app.task def compute_syrah(sra_id): from snakemake import shell with NamedTemporaryFile('w+t') as f: try: shell('fastq-dump -A {sra_id} -Z | syrah | ' 'sourmash compute -k 21 --dna - -o {output} --name {sra_id}' .format(sra_id=sra_id, output=f.name)) except CalledProcessError as e: # We ignore SIGPIPE, since it is informational (and makes sense, # it happens because `head` is closed and `fastq-dump` can't pipe # its output anymore. More details: # http://www.pixelbeat.org/programming/sigpipe_handling.html if e.returncode != 141: raise e f.seek(0) return f.read() @app.task(bind=True, ignore_result=True) def compute_syrah_to_s3(self, sra_id): from boto.s3.connection import S3Connection from boto.s3.key import Key from snakemake import shell conn = S3Connection() bucket = conn.get_bucket("soursigs-done") # Check if file is already on S3 key = bucket.get_key(os.path.join('sigs', sra_id)) if key is None: # result not available yet, compute it with NamedTemporaryFile('w+t') as f: try: shell('fastq-dump -A {sra_id} -Z | syrah | ' 'sourmash compute -k 21 --dna - -o {output} --name {sra_id}' .format(sra_id=sra_id, output=f.name)) except CalledProcessError as e: # We ignore SIGPIPE, since it is informational (and makes sense, # it happens because `head` is closed and `fastq-dump` can't pipe # its output anymore. More details: # http://www.pixelbeat.org/programming/sigpipe_handling.html if e.returncode != 141: # TODO: save error to bucket, on 'errors/{sra_id}'? raise e # save to S3 k = Key(bucket) k.key = os.path.join('sigs', sra_id) f.seek(0) k.set_contents_from_string(f.read()) raise Ignore() PKd6L pmmwort-0.0.1.dist-info/LICENSE======= License ======= Files: * Copyright: 2018, The Regents of the University of California. License: BSD-3-Clause Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. * Neither the name of The Regents of the University of California, nor the names of contributors may be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. PK!HxyUbwort-0.0.1.dist-info/WHEEL HM K-*ϳR03rOK-J,/RH,Q034 /, (-JLR()*M ILR(4KM̫#DPK!H%'ղwort-0.0.1.dist-info/METADATAU0 E|)0fbkvH T$F{ϑ7#I|703U#=KT|'zvs(OTC y3w04cVKvy%]7yve&,7N=PRE4r}vj/YZQvWB.ý)ZPK!H+Qwort-0.0.1.dist-info/RECORDur0}%\ XhnD@hPԧeꌋ9q\㞸K4|tyf¡ڭ6̡W/&fɺ}f!J.#:ٮ4,Sҏg˘4M#2kF|{uMm%r s6zϾ"ud(P)=-e K7t; cDBbwJ_b"*TqRo0,s-m!I >7.n&KB̺$Ǒj.Yrx7uw;:a)•sP`~£ _<}PKH6LC7FFwort/__init__.pyPK26LHz twort/app.pyPK6LIh  owort/tasks.pyPKd6L pmmwort-0.0.1.dist-info/LICENSEPK!HxyUbUwort-0.0.1.dist-info/WHEELPK!H%'ղwort-0.0.1.dist-info/METADATAPK!H+Qwort-0.0.1.dist-info/RECORDPKY