\chapter{Designing Signal Analysis Software For New Generation of Nanopore Sequencers}
\label{ch:design}
The previous chapter described the various parts of a nanopore signal data alignment pipeline, which will be used as a base of this work. Unfortunately, this pipeline has not been maintained for some time, and as such, it is dependent on now obsolete third-party tools, which have to be replaced. The first part of this chapter will focus on changes brought by the new generation of nanopore sequencers and how they affect the pipeline.

In the next part of the chapter, the whole pipeline will be rebuilt using new generation tools. In order to simplify future maintenance, a new framework for building pipelines will be proposed with the aim of abstracting the implementation details of third-party tools from the pipeline.

Lastly, the capabilities of the signal alignment pipeline will be extended for the alignment of RNA sequences obtained using direct RNA sequencing.

\section{Changes in the New Generation of Nanopore Sequencers}
\label{sec:new-generation}
Since the first commercially available nanopore sequencer was released in 2014 by Oxford Nanopore Technologies, the nanopore sequencing platform has been in active development with numerous changes both in the hardware and software~\cite{wang_nanopore_2021}. These changes often enable new functionality or improve the performance and accuracy of sequencing. Unfortunately, many of these changes have been large enough to break compatibility of existing user tools, workflows, and pipelines, such as the one described in~\cref{ch:research}.

This has been the case in the past few years with the introduction of the R10 flow cell, new software tools and formats. Although R10 has been released into early access in 2019~\cite{oxford_nanopore_technologies_new_2019}, the previous generation has been still in use until recently. This section will explain all of the relevant changes that need to be addressed during the development of signal analysis software for this generation of nanopore sequencers.

\subsection{New Flow Cells and Chemistry Kits}
\label{sub:flow-cells}
The nanopore is a protein with limited lifespan that decreases mainly through use. As such, the nanopores are not part of the sequencing device itself but are contained in a separate, replacable cartrige called \emph{flow cell}~\cite{mackenzie_introduction_2023}. When the nanopores in the flow cell are spent, the entire flow cell is removed from the sequencer and replaced by a new one right before the next sequencing.

\begin{figure}
    \centering
    \includegraphics[width=0.7\linewidth]{figures/40-flow-cell.png}
    \caption[MinION flow cell.]{A single MinION flow cell consists of the sensor array, which contains the nanopores and circuits for measurment of the currents during sequencing. Samples are added to the chamber of the sensor array directly through a priming port. After sequencing, samples flow to the waste chamber~\cite{oxford_nanopore_technologies_minion_2017}.}
    \label{fig:minion-flowcell}
\end{figure}
 
The flow cell (see~\cref{fig:minion-flowcell}) houses an array of nanopores embedded in a polymer membrane in a well of the sensor array. The sensor array is connected to an ASIC that measures currents in the nanopores and controls the sensor array itself~\cite{oxford_nanopore_technologies_minion_2017}.

Before DNA or RNA samples can be sequenced, they must first be extracted and chemically prepared by an appropriate procedure (protocol), also known as library preparation. These procedures and chemistry are specific to the type of sequencing performed and the version of the flow cells.

The R10 series of flow cells uses a new design of nanopores with a longer barrel and significantly increases accuracy~\cite{mostafa_evolution_2024}. Furthermore, the new pores support duplex basecalling, in which the complement strand of the DNA is read immediately after sequencing the template strand. When combined with a proper processing (introduced in the new-generation basecaller Dorado, see~\cref{sub:next-gen-basecaller}), this further increases the accuracy of sequencing.

In general, changes in the R10 series have notably improved the accuracy of reads, with some benchmarks reporting an approximately \qty{10}{\percent} improvement over the R9 series~\cite{ni_benchmarking_2023}. The accuracy is now reaching a level where it is starting to be possible to reconstruct the whole genome using only a nanopore sequencer, although hybrid approaches are still considered superior~\cite{sanderson_comparison_2023}.

In some applications, such as detection of methylated bases, R10 flow cells do not seem to provide any observable improvement over the older generation~\cite{ni_benchmarking_2023}. The R10 series is also supposed to have higher yields, though this was not confirmed as an issue with motor protein has probably caused lower yields than R9~\cite{ni_benchmarking_2023, sanderson_comparison_2023}.

\subsection{Data Storage Format}
\label{sub:next-gen-pod5}
A notable change that is mostly related to the new basecaller (see~\cref{sub:next-gen-basecaller}) is the introduction of the POD5 data storage format, which replaces the formerly used FAST5 (described in~\cref{sub:formats-fast5}) with the aim of improving write and read speeds, recovery in case of a crash during writing and increasing the storage efficiency~\cite{oxford_nanopore_technologies_pod5_2022}.

Similarly to FAST5, POD5 is also not a completely custom format, as it is based on the Apache Arrow project, which defines a language-agnostic in-memory data format designed for fast data interchange and analytics~\cite{the_apache_software_foundation_apache_nodate}. However, unlike FAST5, it is used only for the raw signal data itself and not for the outputs of basecalling or other analyses~\cite{oxford_nanopore_technologies_pod5_2022}.

A POD5 file is essentially a container for three Apache Arrow tables~\cite{oxford_nanopore_technologies_pod5_2022}:
%
\begin{itemize}
    \item a \emph{reads} table which contains metadata for each read performed during the sequencing,
    \item a \emph{signal} table containing the raw signal data itself,
    \item a \emph{run info} table identifying the sequencer runs (if the file is a result of multiple runs).
\end{itemize}

Even though the one of the major motivations behind the POD5 format was to enable performance improvements in the future basecaller (as described in~\cref{sub:next-gen-basecaller}, the format itself was released before its introduction. As such, support for POD5 was first added to the previous generation basecaller \emph{Guppy}~\cite{oxford_nanopore_technologies_guppy_2018}.

However, the introduction of the new data format has certainly brought some challenges, as not all legacy software tools have added the support for POD5, making it harder to use newly sequenced data with such tools. While the conversion is a relatively straightforward process, it may cause additional issues mainly in tools that relied on features such as writing basecaller output directly to the FAST5 file.

Fortunately, the impact of the new format on the signal alignment pipeline should be minimal, as no stage of the pipeline expects the FAST5 file to contain anything other than the raw signal. This means that conversion of FAST5 to POD5 files should not cause unexpected problems.

\subsection{Software Tools}
\label{sub:next-gen-basecaller}
The R10 series of flow cell has been released gradually over the span of several years while in continuous development. Therefore, for a significant amount of time, software support for this generation was developed within previous generation tools. As such, the Guppy basecaller supports some of the older versions of the R10 flow cells~\cite{oxford_nanopore_technologies_guppy_2018}.

However, in order to fully utilize the capabilities of the updated hardware, a new basecaller (and other tooling) was eventually introduced. A new basecaller \emph{Dorado} was developed from scratch in order to solve many of the issues that the Guppy basecaller had, and to serve as a platform for future developments~\cite{oxford_nanopore_technologies_dorado_2025}. It is also noteworthy that unlike ONT's previous basecallers, Dorado and its machine learning models are open-source.

Although \emph{Dorado} is first and foremost a basecaller, it also consists of multiple tools designed for processing nanopore sequencing data, which can be integrated into its basecalling pipeline (described in~\cref{fig:dorado-pipeline}).

\begin{figure}
    \centering
    \input{figures/40-dorado-pipeline}
    \caption{The architecture of the Dorado basecalling pipeline.}
    \label{fig:dorado-pipeline}
\end{figure}

In the preprocessing part of the basecalling pipeline, the raw signal data is normalized. The choice of normalization method varies with the used basecalling model, with several strategies such as quantile normalization and median absolute deviation commonly used~\cite{oxford_nanopore_technologies_dorado_2025}. Additionally, sequencing adapters added to the DNA or RNA strand during library preparation are usually detected and trimmed from the raw signal during this phase~\cite{oxford_nanopore_technologies_dorado_2025}.

The next step of the pipeline is the basecalling itself. In this part, a machine learning model trained for the specific combination of the nanopore type, the chemistry used, and the type of sequenced strand (DNA or RNA) is used to predict the most probable sequence of bases captured by the signal. The models themselves were initially of an LSTM based architecture similar to the models in Guppy, but recently new transformer-based models were released~\cite{oxford_nanopore_technologies_dorado_2025}.

The additional processing step of the pipeline provides options for running additional analyzes on the results. For example, the basecalled sequence can be aligned using an embedded \emph{minimap2} aligner to known reference genome (as described in~\cref{sec:mapping}). Finally, the post-processing step can be used for further read trimming and splitting before writing the output~\cite{oxford_nanopore_technologies_dorado_2025}.

Apart from standard DNA and RNA basecalling, \emph{Dorado} also enables basecalling of modified bases and barcoding---a technique, where special sequences called \emph{barcodes} are attached at the beginning of the strands in order to distinguish samples from multiple sources after sequencing them in same run.

The \emph{Dorado} basecaller is a production basecaller meant for general use on sequenced data. However, ONT also maintains an open source research basecaller \emph{Bonito} used primarily to train new basecaller models and develop new methods. Although Bonito's functionality is limited compared to Dorado, Bonito contains the source code for the models used in Dorado, making it useful for creating new custom models~\cite{oxford_nanopore_technologies_nanoporetechbonito_2024}.

Changes in the Dorado base caller will have a significant impact on the pipeline. Previously, the re-alignment step of the pipeline relied on the signal mappings generated by Megalodon and the Guppy basecaller, both of which have been deprecated. Therefore, this functionality will have to be replicated using the new Dorado basecaller.

\section{Designing Signal Analysis Framework}
\label{sec:design-framework}
Historically, these types of changes in the nanopore sequencing platform have occurred many times. Although big platform changes such as this one are more rare, maintaining a larger number of pipelines or software tools may require significant effort.

This is in large part due to the way most of these tools are created. Usually, they consist of a number of scripts and are highly dependent on many third-party tools and libraries. This means that even small changes in the capabilities and interfaces of these dependencies cause significant issues in the whole tool.

While reducing the number of dependencies would certainly help in many instances, it is often not possible due to their complexity. However, these issues can be mitigated by using a common framework that abstracts the details of the third-party tools and provides a stable interface for creating own pipelines and tools. The aim of this chapter is to explore the requirements on such framework and design a basic version, which will be used as a basis of the pipeline described in~\cref{ch:research}.

\section{Adapting Alignment Pipeline}
\label{sec:adapting-alignment-pipeline}

\section{Extending Capability for RNA Alignment}
\label{sec:rna-alignment-capability}