Exemplo n.º 1
0
    def setUp(self) -> None:
        # Here we initialise the server
        self.server = MockMinKNOWServer(data_service=DataServicer)
        self.port = self.server.port
        self.server.start()

        ssl_creds = self.server.make_channel_credentials()
        self.connection = minknow_api.Connection(self.port,
                                                 credentials=ssl_creds)
    def setUp(self):
        self.test_server = MockMinKNOWServer()
        self.test_server.start()

        ssl_creds = self.test_server.make_channel_credentials()
        self.connection = minknow_api.Connection(
            self.test_server.port, credentials=ssl_creds
        )
        LOGGER.info("Connected on {}".format(self.test_server.port))
Exemplo n.º 3
0
    def connect(self, use_tls=None):
        """Connect to the position.

        Only valid to do if `running` is True.

        Returns:
            minknow_api.Connection: A connection to the RPC interface.
        """
        if not use_tls:
            use_tls = self._default_use_tls
        if use_tls:
            port = self.description.rpc_ports.secure
        else:
            port = self.description.rpc_ports.insecure
        return minknow_api.Connection(host=self.host,
                                      port=port,
                                      use_tls=use_tls)
Exemplo n.º 4
0
    def connect(self, credentials=None, developer_api_token=None):
        """Connect to the position.

        Only valid to do if `running` is True.

        Returns:
            minknow_api.Connection: A connection to the RPC interface.
        """
        port = self.description.rpc_ports.secure
        if credentials is None:
            credentials = self.credentials
        if not developer_api_token:
            developer_api_token = self._developer_api_token
        return minknow_api.Connection(
            host=self.host,
            port=port,
            credentials=credentials,
            developer_api_token=developer_api_token,
        )
Exemplo n.º 5
0
 def setUp(self) -> None:
     # Here we initialise the server
     self.server = MockMinKNOWServer(data_service=DataServicer,)
     self.port = self.server.port
     self.server.start()
     self.connection = minknow_api.Connection(self.port)
Exemplo n.º 6
0
    def setUp(self) -> None:
        self.connection = minknow_api.Connection(host=HOST,
                                                 port=PORT,
                                                 use_tls=False)

        self.device = self.connection.device
 def setUp(self):
     self.test_server = MockMinKNOWServer()
     self.test_server.start()
     self.connection = minknow_api.Connection(self.test_server.port)
     LOGGER.info("Connected on {}".format(self.test_server.port))
Exemplo n.º 8
0
    def __init__(self, mk_host='127.0.0.1', mk_port=8000, cache_size=512, cache_type=ReadCache,
                 filter_strands=True, one_chunk=True, prefilter_classes={'strand', 'adapter'}):
        """A basic Read Until client. The class handles basic interaction
        with the MinKNOW gRPC stream and provides a thread-safe queue
        containing the most recent read data on each channel.

        :param mk_port: MinKNOW gRPC port for the sequencing device.
        :param cache_size: maximum number of read chunks to cache from
            gRPC stream. Setting this to the number of device channels
            will allow caching of the most recent data per channel.
        :param cache_type: a type derived from `ReadCache` for managing
            incoming read chunks. 
        :param filter_strands: pre-filter stream to keep only strand-like reads.
        :param one_chunk: attempt to receive only one_chunk per read. When
            enabled a request to stop receiving more data for a read is
            immediately staged when the first chunk is cached.
        :param prefilter_classes: a set of read classes to accept through
            prefilter. Ignored if filter_strands is `False`.

        To set up and use a client:

        >>> read_until_client = ReadUntilClient()

        This creates an initial connection to a MinKNOW instance in 
        preparation for setting up live reads stream. To initiate the stream:

        >>> read_until_client.run()

        The client is now recieving data and can send s
        Calls to methods of `read_until_client` can then be made in a separate
        thread. For example an continually running analysis function can be
        submitted to the executor as:

        >>> def analysis(client, *args, **kwargs):
        ...     while client.is_running:
        ...         for channel, read in client.get_read_chunks():
        ...             raw_data = numpy.fromstring(read.raw_data, client.signal_dtype)
        ...             # do something with raw data... and maybe call:
        ...             #    client.stop_receiving_read(channel, read.number)
        ...             #    client.unblock_read(channel, read.number)
        >>> with ThreadPoolExecutor() as executor:
        ...     executor.submit(analysis_function, read_until_client)

        To stop processing the gRPC read stream:

        >>> read_until_client.reset()

        If an analysis function is set up as above in response to
        `client.is_running`, calling the above call will cause the
        analysis function to return.

        """
        self.logger = logging.getLogger('ReadUntil')

        self.mk_host = mk_host
        self.mk_grpc_port = mk_port
        self.cache_size = cache_size
        self.CacheType = cache_type
        self.filter_strands = filter_strands
        self.one_chunk = one_chunk
        self.prefilter_classes = prefilter_classes

        client_type = 'single chunk' if self.one_chunk else 'many chunk'
        filters = ' '.join(self.prefilter_classes)
        filter_to = 'without prefilter'
        if self.filter_strands:
            if len(self.prefilter_classes) == 0:
                raise ValueError('Read filtering set but no filter classes given.')
            classes = _format_iter(self.prefilter_classes)
            filter_to = 'filtering to {} read chunks'.format(classes)
        self.logger.info('Creating {} client with {} data queue {}.'.format(
            client_type, self.CacheType.__name__, filter_to))

        self.logger.warn("Using pre-defined read classification map.")
        class_map = CLASS_MAP
        self.read_classes = {
            int(k):v for k, v in
            class_map['read_classification_map'].items()
        }
        self.strand_classes = set()
        for key, value in self.read_classes.items():
            if value in self.prefilter_classes:
                self.strand_classes.add(key)
        self.logger.debug('Strand-like classes are {}.'.format(self.strand_classes))

        self.grpc_port = self.mk_grpc_port
        self.logger.info('Creating rpc connection on port {}.'.format(self.grpc_port))
        self.connection = minknow_api.Connection(host=self.mk_host, port=self.grpc_port)
        self.logger.info('Got rpc connection.')
        self.msgs = self.connection.data._pb

        self.signal_dtype = minknow_api.data.get_numpy_types(self.connection).calibrated_signal

        # setup the queues and running status
        self._process_thread = None
        self.reset()