def _process_reads_worker(fast5_q, snp_calls_q, caller_conn, model_info,
                          device, do_false_ref):
    model_info.prep_model_worker(device)
    map_thr_buf = mappy.ThreadBuffer()

    while True:
        try:
            fast5_fn, read_id = fast5_q.get(block=False)
        except queue.Empty:
            sleep(0.001)
            continue

        if fast5_fn is None:
            if caller_conn is not None:
                caller_conn.send(True)
            break

        try:
            raw_sig = fast5_io.get_signal(fast5_fn, read_id)
            read_snp_calls = process_read(raw_sig, read_id, model_info,
                                          caller_conn, map_thr_buf,
                                          do_false_ref)
            snp_calls_q.put((True, read_snp_calls))
        except Exception as e:
            snp_calls_q.put((False, str(e)))
            pass

    return
Esempio n. 2
0
    def extract_signal_info(self, fast5_fn, read_id, extract_dacs=False):
        read = fast5_io.get_read(fast5_fn, read_id)
        seq_summ_info = mh.extract_seq_summary_info(read)
        dacs = scale_params = raw_sig = None
        if extract_dacs:
            # if not processing signal mappings, don't save dacs
            dacs = fast5_io.get_signal(read, scale=False)
            # scale parameters and trimming computed by guppy
            if not self.model_type == PYGUPPY_NAME:
                scale_params = mh.med_mad(dacs)
                raw_sig = (dacs - scale_params[0]) / scale_params[1]

        if self.model_type == TAI_NAME:
            if raw_sig is None:
                raw_sig = fast5_io.get_signal(read, scale=True)
            sig_data = SIGNAL_DATA(
                raw_signal=raw_sig, dacs=dacs, scale_params=scale_params,
                raw_len=raw_sig.shape[0], fast5_fn=fast5_fn, read_id=read_id,
                stride=self.stride)
            return sig_data, seq_summ_info
        elif self.model_type == FAST5_NAME:
            bc_mod_post = fast5_io.get_posteriors(read)
            if extract_dacs:
                trim_start, trim_len = fast5_io.get_signal_trim_coordiates(
                    read)
                dacs = dacs[trim_start:trim_start + trim_len]
            sig_data = SIGNAL_DATA(
                raw_len=bc_mod_post.shape[0] * self.stride, dacs=dacs,
                fast5_fn=fast5_fn, read_id=read_id, stride=self.stride,
                posteriors=bc_mod_post)
            return sig_data, seq_summ_info
        elif self.model_type == PYGUPPY_NAME:
            if dacs is None:
                dacs = fast5_io.get_signal(read, scale=False)
            sig_data = SIGNAL_DATA(
                dacs=dacs, raw_len=dacs.shape[0], fast5_fn=fast5_fn,
                read_id=read_id, stride=self.stride,
                channel_info=read.get_channel_info())
            return sig_data, seq_summ_info

        raise mh.MegaError('Invalid model type')
Esempio n. 3
0
def _process_reads_worker(
        read_file_q, bc_q, snps_q, failed_reads_q, mods_q, caller_conn,
        model_info, snps_data, mods_info, edge_buffer, device):
    model_info.prep_model_worker(device)
    snps_data.reopen_variant_index()

    while True:
        try:
            try:
                fast5_fn, read_id = read_file_q.get(block=False)
            except queue.Empty:
                sleep(0.001)
                continue

            if fast5_fn is None:
                if caller_conn is not None:
                    caller_conn.send(True)
                break

            raw_sig = fast5_io.get_signal(fast5_fn, read_id, scale=True)
            process_read(
                raw_sig, read_id, model_info, bc_q, caller_conn, snps_data,
                snps_q, mods_q, mods_info, fast5_fn, failed_reads_q,
                edge_buffer)
            failed_reads_q.put((
                False, True, None, None, None, raw_sig.shape[0]))
        except KeyboardInterrupt:
            failed_reads_q.put((
                True, True, 'Keyboard interrupt', fast5_fn, None, 0))
            return
        except mh.MegaError as e:
            failed_reads_q.put((
                True, True, str(e), fast5_fn, None, raw_sig.shape[0]))
        except:
            failed_reads_q.put((
                True, True, _UNEXPECTED_ERROR_CODE, fast5_fn,
                traceback.format_exc(), 0))

    return