Esempio n. 1
0
    def get_events(self, channel, times=None, raw_indices=None, event_indices=(None, None),
                   use_scaling=True):
        """Parse channel event data.

        :param channel: channel number int
        :param times: tuple of floats (start_second, end_second)
        :param raw_indices: tuple of ints (start_index, end_index)
        :param event_indices: tuple of ints (start_index, end_index)
        :param use_scaling: if True, scale the current level

        .. note::
            Exactly one of the slice keyword arguments needs to be specified,
            as the method will override them in the order of times
            > raw_indices > event_indices.
        """

        event_data = self.__event_data__.format(channel)
        ev = self[event_data]

        if times is not None:
            raw_indices = self._time_interval_to_index(channel, times)
        if raw_indices is not None:
            event_indices = np.searchsorted(ev['start'], raw_indices)
        data = _sanitize_data_for_reading(ev[event_indices[0]:event_indices[1]])

        # Change variance to stdv column
        data['variance'] = np.sqrt(data['variance'])
        data.dtype.names = ['stdv' if n == 'variance' else n for n in data.dtype.names]

        if use_scaling:
            return self._scale(channel, data)
        else:
            return data
Esempio n. 2
0
    def test_015_fastq(self):
        """ Test fastq assembly and writing """

        fastq = '@unknown\n{}\n+\n{}\n'.format(self.seq, self.qstring)
        self.assertEqual(
            _sanitize_data_for_reading(
                self.fh['/Analyses/Basecall_1D_000/BaseCalled_template/Fastq'][
                    ()]), fastq)
Esempio n. 3
0
    def get_state_changes(self, channel):
        """Parse channel state changes.

        :param channel: channel number int
        """
        if not self.has_states(channel):
            raise KeyError(
                'Channel {} does not contain state data.'.format(channel))

        if hasattr(self, '_cached_state_changes'):
            if channel in self._cached_state_changes:
                return self._cached_state_changes[channel]
        else:
            self._cached_state_changes = {}

        # state data is enumerated
        col = 'summary_state'
        data = self[self.__state_data__.format(channel)]
        enum_map = h5py.check_dtype(enum=data.dtype[col])
        enum_to_state = _clean_attrs({v: k for k, v in enum_map.items()})

        # translate ints into strings
        states = np.array([enum_to_state[key] for key in data[col]])

        try:
            data = np.array(data['approx_raw_index'])
        except ValueError:  #not a KeyError: see h5py/_hl/dataset.pyc in readtime_dtype(basetype, names)
            data = np.array(data['acquisition_raw_index'])
        if len(data) > 0:
            data = data.astype([('approx_raw_index', data.dtype)], copy=False)
            data = append_fields(
                data, ['approx_raw_index_end', 'summary_state'],
                [np.roll(data['approx_raw_index'], -1), states],
                usemask=False)
            # set end of last state to something approximating infinity (the largest u64 int).
            data['approx_raw_index_end'][-1] = -1
        else:  # some channels don't contain channel state data, just create a dummy array
            data = np.array([],
                            dtype=[('approx_raw_index', '<u8'),
                                   ('approx_raw_index_end', '<u8'),
                                   ('summary_state', 'S28')])
        self._cached_state_changes[channel] = data
        return _sanitize_data_for_reading(data)