Skip to content
Snippets Groups Projects
Commit d2cf6eb4 authored by Laros's avatar Laros Committed by Vermaat
Browse files

New batch script

parent d419e1b7
No related branches found
No related tags found
No related merge requests found
......@@ -5,6 +5,10 @@
Testing
=======
Unit tests
----------
We use `pytest`_ for the unit tests. To run them, just type ``py.test`` from
the Mutalyzer source directory.
......@@ -16,4 +20,30 @@ Tests are `run automatically on Travis CI
GitHub.
Testing the web services
------------------------
To ease testing the web services during development, some simple web service
client scripts are included in the Mutalyzer source tree::
$ cd extras/soap-tools
$ ./info.py
Version: 2.0.5
Version parts: 2, 0, 5
Release date: 16 Dec 2014
Nomenclature version: 2.0
Nomenclature version parts: 2, 0
Server name: res-muta-app01
Contact e-mail: humgen@lumc.nl
$
They simply call one of the web service functions and print the result. You
may have to change the server location defined at the top of these scripts.
.. note:: One of the scripts, ``run_batch_job.py``, provides an easy way to
run a batch job from the command line. Some additional notes are
available for `running this on a Windows machine
<https://gist.github.com/martijnvermaat/73271252775867f91821>`_.
.. _pytest: http://pytest.org/
#!/usr/bin/env python
"""
Submit a batch job to a Mutalyzer installation.
Usage:
{command} file [type] [argument]
file: Batch job input file to upload.
type: Optional type of the batch job, choose from NameChecker (default),
SyntaxChecker, PositionConverter, SnpConverter.
argument: Additional argument. Currently only used if batch_type is
PositionConverter, denoting the human genome build.
The file is uploaded to the Mutalyzer SOAP API, which is then polled for
completeness of the batch job after which the result is retrieved and printed
to standard output.
"""
from __future__ import unicode_literals
from mutalyzer.util import monkey_patch_suds; monkey_patch_suds()
import sys
from suds import WebFault
from suds.client import Client
import time
from mutalyzer.util import format_usage
WSDL_LOCATION = 'http://localhost/mutalyzer/services/?wsdl'
MAX_TRIES = 10
TRY_WAIT = 5
def main(batch_input, batch_type='NameChecker', batch_argument=''):
"""
Submit a batch job, poll for completeness, and retrieve the result.
"""
service = Client(WSDL_LOCATION, cache=None).service
data = open(batch_input, 'rb').read().encode('base64')
result = service.submitBatchJob(data, batch_type, batch_argument)
job_id = int(result)
for _ in range(MAX_TRIES):
try:
result = service.getBatchJob(job_id)
break
except WebFault:
# Note that calling getBatchJob *and* monitorBatchJob is a bit
# superfluous, but we like to illustrate the use of both of them
# here.
result = service.monitorBatchJob(job_id)
sys.stderr.write('Waiting... (%d entries left)\n' % int(result))
time.sleep(TRY_WAIT)
else:
sys.stderr.write('No result after trying %d times.\n' % MAX_TRIES)
sys.exit(1)
sys.stdout.write(result.decode('base64'))
if __name__ == '__main__':
if len(sys.argv) < 2:
print format_usage()
sys.exit(1)
main(*sys.argv[1:])
#!/usr/bin/env python
"""
Mutalyzer batch job automation.
Copyright (c) 2015 Leiden University Medical Center <humgen@lumc.nl>
Copyright (c) 2015 Jeroen F.J. Laros <j.f.j.laros@lumc.nl>
Licensed under the MIT license, see the LICENSE file.
"""
import argparse
import time
from suds.client import Client
URL = "https://mutalyzer.nl/services/?wsdl"
job_types = ["NameChecker", "SyntaxChecker", "PositionConverter",
"SnpConverter"]
RETRY_WAIT = 1
def run_batchjob(input_handle, output_handle, job_type, build="hg19"):
"""
Run a Mutalyzer batch job.
:arg stream input_handle: Open readable handle to a batch job file.
:arg stream output_handle: Opren writable handle for the results.
:arg str job_type: Type of the job.
:arg str build: Optional build for the Position Converter.
"""
client = Client(URL, cache=None)
batchfile = input_handle.read().encode("base64")
job_id = client.service.submitBatchJob(batchfile, job_type, build)
while client.service.monitorBatchJob(job_id):
time.sleep(RETRY_WAIT)
result = client.service.getBatchJob(job_id).decode("base64")
output_handle.write(result)
def main():
"""
Main entry point.
"""
usage = __doc__.split("\n\n\n")
parser = argparse.ArgumentParser(
formatter_class=argparse.RawDescriptionHelpFormatter,
description=usage[0], epilog=usage[1])
parser.add_argument("-v", action='version', version="0.1")
parser.add_argument("input_handle", metavar="INPUT",
type=argparse.FileType("r"), help="input file")
parser.add_argument("output_handle", metavar="OUTPUT",
type=argparse.FileType("w"), help="output file")
parser.add_argument("job_type", metavar="TYPE", choices=job_types,
help="batch job type ({})".format(", ".join(job_types)))
parser.add_argument("-b", dest="build", type=str,
help="genome build (only valid for the Position Converter)")
args = parser.parse_args()
run_batchjob(args.input_handle, args.output_handle, args.job_type)
if __name__ == "__main__":
main()
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment