How to use the pomoxis.provider.replayfast5.Fast5Data function in pomoxis

To help you get started, we’ve selected a few pomoxis examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github nanoporetech / pomoxis / pomoxis / provider / replayfast5.py View on Github external
        lambda binary: msgpack.unpackb(binary, object_hook=Fast5Data.decode)
    ),
github nanoporetech / pomoxis / pomoxis / provider / replayfast5.py View on Github external
read = self.reads[self.current_read]
        if read['classification'] != self.good_class:
            return None
        else:
            start = int(read['read_start'] + self.sample_rate * delay)
            end = int(min(self.current_sample, start + self.sample_rate * seconds))
            if end <= start:
                return None
            self.logger.debug("Fetching raw [{}, {}] for read {} starting at {}. Current sample is {}.".format(
                start, end,
                self.current_read, int(self.sample_offset + self.reads[self.current_read]['read_start']),
                self.current_sample
            ))
            with BulkFast5(self.fast5) as fh:
                raw = fh.get_raw(self.channel, raw_indices=[start, end])
                return Fast5Data(
                    raw, info=read['read_id'].decode('utf-8'),
                    start=int(self.sample_offset + read['read_start']),
                    end=int(self.sample_offset + read['read_start'] + read['read_length'])
                )
github nanoporetech / pomoxis / pomoxis / provider / replayfast5.py View on Github external
def decode(obj):
        """Deserialize data from RPC request."""
        if obj[b'kind'] == b'V':
            descr = [(x.decode('utf-8'), y.decode('utf-8')) for x, y in obj[b'type']]
        else:
            descr = obj[b'type'][0][1].decode('utf-8')
        data = Fast5Data(
            np.fromstring(
                obj[b'data'],
                dtype=np.dtype(descr)
            ).reshape(obj[b'shape']),
            info=obj[b'info'].decode('utf-8'),
            start=obj[b'start'],
            end=obj[b'end'],
            sample_rate=obj[b'sample_rate'],
        )
        return data
github nanoporetech / pomoxis / pomoxis / provider / replayfast5.py View on Github external
"""
        self.logger.debug("Request for events at {}".format(self.current_sample))
        read = self.reads[self.current_read]
        if read['classification'] != self.good_class:
            return None
        else:
            start = int(read['event_index_start'])
            end = min(self.current_event, start + n_events)
            self.logger.debug("Fetching events [{}, {}] for read {} starting at {}. Current sample is {}.".format(
                start, end,
                self.current_read, int(self.sample_offset + self.reads[self.current_read]['read_start']),
                self.current_sample
            ))
            with BulkFast5(self.fast5) as fh:
                events = fh.get_events(self.channel, event_indices=[start, end])
                return Fast5Data(
                    events, info=read['read_id'].decode('utf-8'),
                    start=int(self.sample_offset + read['read_start']),
                    end=int(self.sample_offset + read['read_start'] + read['read_length'])
                )
github nanoporetech / pomoxis / pomoxis / provider / replayfast5.py View on Github external
descr = obj[b'type'][0][1].decode('utf-8')
        data = Fast5Data(
            np.fromstring(
                obj[b'data'],
                dtype=np.dtype(descr)
            ).reshape(obj[b'shape']),
            info=obj[b'info'].decode('utf-8'),
            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.