Skip to content
This repository has been archived by the owner on Aug 15, 2022. It is now read-only.

Commit

Permalink
fix state and trace data: closes #4
Browse files Browse the repository at this point in the history
  • Loading branch information
iiSeymour committed Jan 14, 2021
1 parent c376883 commit b3bea2e
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 19 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,9 @@ from pyguppyclient import GuppyBasecallerClient, yield_reads
config = "dna_r9.4.1_450bps_fast"
read_file = "reads.fast5"

with GuppyBasecallerClient(config_name=config) as client:
with GuppyBasecallerClient(config_name=config, trace=True) as client:
for read in yield_reads(read_file):
called = client.basecall(read, trace=True)
called = client.basecall(read)
print(read.read_id, called.seq[:50], called.move)
```

Expand Down
23 changes: 11 additions & 12 deletions pyguppyclient/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@
Guppy Client
"""

from collections import deque
import time
import asyncio
import logging
from collections import deque

import zmq
import zmq.asyncio
Expand All @@ -26,7 +26,7 @@ class GuppyClientBase:
"""
Blocking Guppy Base Client
"""
def __init__(self, config_name, host="localhost", port=5555, timeout=0.1, retries=50):
def __init__(self, config_name, host="localhost", port=5555, timeout=0.1, retries=50, state=False, trace=False):
self.timeout = timeout
self.retries = retries
self.config_name = parse_config(config_name)
Expand All @@ -37,6 +37,8 @@ def __init__(self, config_name, host="localhost", port=5555, timeout=0.1, retrie
self.socket.connect("tcp://%s:%s" % (host, port))
self.client_id = 0
self.pcl_client = PCLClient("%s:%s" % (host, port), self.config_name)
self.pcl_client.set_params({'state_data_enabled': state})
self.pcl_client.set_params({'move_and_trace_enabled': trace})
_init_pcl_client(self.pcl_client)

def __enter__(self):
Expand Down Expand Up @@ -77,8 +79,9 @@ def connect(self):
pass
elif ret != result.success:
raise ConnectionError(
"Connect with '{}' failed: {}".format(self.config_name,
self.pcl_client.get_error_message())
"Connect with '{}' failed: {}".format(
self.config_name, self.pcl_client.get_error_message()
)
)

def disconnect(self):
Expand Down Expand Up @@ -109,23 +112,19 @@ class GuppyBasecallerClient(GuppyClientBase):
"""
Blocking Guppy Basecall Client
"""

def __init__(self, **kwargs):
super().__init__(**kwargs)
self.read_cache = deque()

def basecall(self, read, state=False, trace=False):
def basecall(self, read):
"""
Basecall a `ReadData` object and get a `CalledReadData` object
:param trace: flag for returning the flipflop trace table from the server.
:param state: flag for returning the state table (requires --post_out).
"""
n = 0
self.pass_read(read)
while n < self.retries:
n += 1
result = self._get_called_read(state=state, trace=trace)
result = self._get_called_read()
if result is not None:
return result
time.sleep(self.timeout)
Expand All @@ -134,7 +133,7 @@ def basecall(self, read, state=False, trace=False):
"Basecall response not received after {}s for read '{}'".format(self.timeout, read.read_id)
)

def _get_called_read(self, state=False, trace=False):
def _get_called_read(self):
"""
Get the `CalledReadData` object back from the server
"""
Expand Down Expand Up @@ -221,7 +220,7 @@ async def pass_read(self, read):
}
return await self.pcl_client.pass_read(read_dict)

async def get_called_read(self, trace=False, state=False):
async def get_called_read(self):
"""
Get the `CalledReadData` object back from the server
"""
Expand Down
12 changes: 7 additions & 5 deletions tests/client_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ class ClientTest(TestCase):

def setUp(self):
self.read_loader = yield_reads(self.read_file)
self.client = GuppyBasecallerClient(config_name=self.config_fast, port=self.port)
self.client = GuppyBasecallerClient(config_name=self.config_fast, port=self.port, trace=True, state=True)
self.client.connect()

def tearDown(self):
Expand All @@ -35,18 +35,20 @@ def test_read_without_state(self):
""" test a read without state """
self.client.pass_read(next(self.read_loader))
time.sleep(1)
self.client._get_called_read(state=False)
self.client._get_called_read()

def test_read_with_state(self):
""" test a read with state """
self.client.pass_read(next(self.read_loader))
time.sleep(1)
self.client._get_called_read(state=True)
res, called = self.client._get_called_read()
self.assertTrue(called.state is not None)
self.assertTrue(called.trace is not None)
self.assertTrue(called.move is not None)

def test_invalid_config(self):
""" try and load in invalid config """
bad_client = GuppyBasecallerClient(config_name="not_a_config",
port=self.port)
bad_client = GuppyBasecallerClient(config_name="not_a_config", port=self.port)
with self.assertRaises(ConnectionError):
bad_client.connect()

Expand Down

0 comments on commit b3bea2e

Please sign in to comment.