Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
import asyncio
from aiozmq import rpc
from bwapy import BwaAligner
import logging
logger = logging.getLogger(__name__)
class BwapyServe(rpc.AttrHandler):
def __init__(self, index, *args, map_opts={'x':'ont2d'}, **kwargs):
"""bwa mem alignment server implementation using python binding.
:param index: bwa index base path, or list thereof.
:param map_opts: command line options for bwa mem as dictionary.
"""
super().__init__(*args, **kwargs)
self.logger = logging.getLogger('BwaServe')
self.index = index
# expand map_opts to a string:
opts = []
for k, v in map_opts.items():
opts.append('-{} {}'.format(k, v))
import asyncio
import aiozmq.rpc
class Handler(aiozmq.rpc.AttrHandler):
def __init__(self, ident):
self.ident = ident
self.subhandler = SubHandler(self.ident, 'subident')
@aiozmq.rpc.method
def a(self):
return (self.ident, 'a')
class SubHandler(aiozmq.rpc.AttrHandler):
def __init__(self, ident, subident):
self.ident = ident
self.subident = subident
gc.collect()
t1 = time.monotonic()
dealer.write(msg)
yield from dealer_closed
t2 = time.monotonic()
gc.collect()
router.close()
yield from router_closed
return t2 - t1
ret = loop.run_until_complete(go())
loop.close()
return ret
class Handler(aiozmq.rpc.AttrHandler):
@aiozmq.rpc.method
def func(self, data):
return data
def test_aiozmq_rpc(count):
"""aiozmq.rpc"""
print('.', end='', flush=True)
loop = asyncio.new_event_loop()
@asyncio.coroutine
def go():
server = yield from aiozmq.rpc.serve_rpc(Handler(),
bind='tcp://127.0.0.1:*',
loop=loop)
import asyncio
import aiozmq.rpc
class DynamicHandler(aiozmq.rpc.AttrHandler):
def __init__(self, namespace=()):
self.namespace = namespace
def __getitem__(self, key):
try:
return getattr(self, key)
except AttributeError:
return DynamicHandler(self.namespace + (key,))
@aiozmq.rpc.method
def func(self):
return (self.namespace, 'val')
@asyncio.coroutine
from aiozmq import rpc
from fuocore.engine import get_backend
class PlayerHandler(rpc.AttrHandler):
@rpc.method
def current_song(self):
player = get_backend()
if player.playlist.current_song is None:
return None
return player.playlist.current_song.serialize()
import asyncio
import aiozmq.rpc
class ServerHandler(aiozmq.rpc.AttrHandler):
@aiozmq.rpc.method
def remote_func(self, a: int, b: int) -> int:
return a + b
@asyncio.coroutine
def go():
server = yield from aiozmq.rpc.serve_rpc(
ServerHandler(), bind='tcp://*:*')
server_addr = next(iter(server.transport.bindings()))
client = yield from aiozmq.rpc.connect_rpc(
connect=server_addr)
ret = yield from client.call.remote_func(1, 2)
import asyncio
import aiozmq.rpc
class Handler(aiozmq.rpc.AttrHandler):
@aiozmq.rpc.method
def handle_some_event(self, a: int, b: int):
pass
@asyncio.coroutine
def go():
listener = yield from aiozmq.rpc.serve_pipeline(
Handler(), bind='tcp://*:*')
listener_addr = next(iter(listener.transport.bindings()))
notifier = yield from aiozmq.rpc.connect_pipeline(
connect=listener_addr)
yield from notifier.notify.handle_some_event(1, 2)
import asyncio
import aiozmq.rpc
class CustomError(Exception):
def __init__(self, val):
self.val = val
super().__init__(val)
exc_name = CustomError.__module__+'.'+CustomError.__name__
error_table = {exc_name: CustomError}
class ServerHandler(aiozmq.rpc.AttrHandler):
@aiozmq.rpc.method
def remote(self, val):
raise CustomError(val)
@asyncio.coroutine
def go():
server = yield from aiozmq.rpc.serve_rpc(
ServerHandler(), bind='tcp://*:*')
server_addr = list(server.transport.bindings())[0]
client = yield from aiozmq.rpc.connect_rpc(
connect=server_addr,
error_table=error_table)
try:
start=obj[b'start'],
end=obj[b'end'],
sample_rate=obj[b'sample_rate'],
)
return data
translation_table = {
0: (Fast5Data,
lambda value: msgpack.packb(value, default=value.encode),
lambda binary: msgpack.unpackb(binary, object_hook=Fast5Data.decode)
),
}
class ReplayChannel(rpc.AttrHandler):
def __init__(self, fast5, channel, *args, good_class='strand', time_warp=1, **kwargs):
"""An RPC service for replaying a channel from a .fast5 file.
:param fast5: input filename.
:param channel: channel to simulate.
:param good_class: read classification name of desirable reads.
:param time_warp: time multiplier for playback speed.
..note:: `args` and `kwargs` are passed to `aiozmq.rpc.AttrHandler`.
"""
super().__init__(*args, **kwargs)
self.fast5 = fast5
self.channel = channel
self.good_class = good_class
if cur_read['read_id'].decode('utf-8') == read_id:
next_read = self.reads[self.current_read + 1]
jump = int(next_read['read_start'] - self.current_sample)
self.sample_offset += jump
self.logger.debug("Unblocking read {}. Skipping ahead {} samples to sample {}.".format(
read_id, jump, self.current_sample
))
return self.current_sample, True
else:
self.logger.info("Unblock received too late for read {}. Received at {}, read ended at {}".format(
read_id, self.current_sample, read_end
))
return self.current_sample, False
class ReplayFast5(rpc.AttrHandler):
def __init__(self, fast5, channels, *args, good_class='strand', time_warp=1, **kwargs):
"""Replay multiple channels from a .fast5 file.
:param fast5: input filename.
:param channel: list of channels to simulate.
:param good_class: read classification name of desirable reads.
:param time_warp: time multiplier for playback speed.
..note:: `args` and `kwargs` are passed to `aiozmq.rpc.AttrHandler`.
"""
super().__init__(*args, **kwargs)
self.fast5 = fast5
self.channels = channels
self.good_class = good_class
self.time_warp = time_warp