- Semi-global sequence alignment is a method used in bioinformatics to compare two DNA, RNA, or protein sequences when one sequence may be shorter than the other or when the sequences overlap only partially. It is also known as overlap alignment or end-gap-free alignment in certain implementations. Unlike global alignment, which attempts to align both sequences across their complete lengths, semi-global alignment allows selected terminal gaps to be introduced without applying the usual gap penalties. Unlike local alignment, it generally seeks to align the full length of at least one sequence rather than selecting only the highest-scoring internal region. This makes semi-global alignment particularly useful for comparing sequence fragments, identifying overlapping DNA reads, mapping short sequences to longer references, and analysing sequences with incomplete terminal regions.
- The main purpose of semi-global alignment is to identify meaningful sequence correspondence while avoiding unnecessary penalties for unaligned sequence ends. In biological data, two sequences may represent overlapping portions of the same genomic region, or one sequence may be a fragment of a longer gene or protein. If ordinary global alignment is used, the unmatched terminal regions may receive substantial gap penalties, reducing the alignment score even when the overlapping region is highly similar. Semi-global alignment addresses this problem by treating selected terminal gaps differently from internal gaps.
- The treatment of terminal gaps is the defining feature of semi-global alignment. A terminal gap occurs at the beginning or end of an aligned sequence, whereas an internal gap occurs between aligned regions. In a conventional global alignment, both terminal and internal gaps are generally penalized. In semi-global alignment, terminal gaps on one or both sequences can be assigned zero or reduced penalties, while internal gaps continue to receive penalties. This allows the algorithm to focus on the overlapping or corresponding region without treating unmatched sequence ends as biologically equivalent to internal insertions or deletions.
- Semi-global alignment is not a single universally fixed alignment configuration. Different software packages and research applications use different terminal-gap rules. Some methods allow free terminal gaps in both sequences, while others allow free terminal gaps in only one sequence. In an asymmetric configuration, one sequence may be required to align across its full length while the other can extend beyond the aligned region. This is especially useful when aligning a short sequencing read against a longer reference sequence. Therefore, researchers should specify which sequence ends are unpenalized rather than relying only on the term semi-global alignment.
- The mathematical basis of semi-global alignment is closely related to the Needleman–Wunsch dynamic programming algorithm. It uses a scoring matrix to calculate the best alignment based on matches, mismatches, and gaps. The main difference is the initialization and termination of the dynamic programming procedure. Depending on the selected configuration, penalties for gaps at particular sequence ends may be omitted or reduced. Internal gaps are still treated according to the selected gap-scoring system.
- For example, when the terminal gaps of both sequences are unpenalized, the first row and first column of the dynamic programming matrix can be initialized with zero values. The algorithm then calculates the remaining cells using match, mismatch, and internal gap scores. The optimal alignment can be identified by considering the appropriate boundary cells rather than requiring the traceback to begin only at the final matrix cell. Exact initialization and traceback rules depend on which terminal gaps are free and which are penalized.
- A simplified semi-global alignment recurrence for internal matrix positions is:
[
F(i,j)=\max
\begin{cases}
F(i-1,j-1)+s(x_i,y_j)\
F(i-1,j)-d\
F(i,j-1)-d
\end{cases}
]
- Here, (F(i,j)) represents the best alignment score at position (i,j), (s(x_i,y_j)) is the match or mismatch score, and (d) is the internal gap penalty. The recurrence for internal positions is similar to global alignment. The difference lies in the treatment of sequence boundaries and the selection of the traceback endpoint. When terminal gaps are free, the corresponding boundary conditions are modified so that unaligned sequence ends do not receive the normal gap penalty. This equation uses a simplified linear gap penalty; more advanced implementations can use affine gap penalties.
- Affine gap penalties are frequently used in semi-global alignment. They distinguish between opening a gap and extending an existing gap. A gap-opening penalty is applied when a new gap begins, while a smaller gap-extension penalty is applied to additional positions in that gap. This approach is useful because biological insertions and deletions often occur as single events affecting multiple consecutive residues. Semi-global alignment can therefore combine free terminal gaps with affine penalties for internal gaps to produce biologically meaningful overlaps.
- One of the most important applications of semi-global alignment is identifying overlaps between DNA sequencing reads. During genome assembly, sequencing technologies generate numerous DNA fragments that may originate from overlapping regions of a genome. Semi-global alignment can identify the shared portions of two reads while allowing their unmatched ends to extend beyond the overlap. The resulting alignment can help determine whether the reads are likely to represent adjacent regions of the same genomic sequence.
- Semi-global alignment is also useful in sequence assembly and contig construction. A contig is a continuous sequence assembled from overlapping sequencing reads or fragments. Identifying reliable overlaps is an important step in many assembly strategies. Semi-global or overlap alignment can help determine the relative positions of fragments and identify shared sequence regions. However, practical genome assemblers use additional methods such as quality filtering, error correction, graph construction, repeat resolution, and coverage analysis. A sequence overlap alone does not guarantee that two reads belong to the same unique genomic location.
- Another important application is mapping short sequences to longer reference sequences. For example, a short DNA fragment may correspond to an internal region of a longer reference gene or genomic sequence. If the entire short fragment is expected to match the reference, but the reference contains additional bases before and after the matching region, a semi-global configuration can align the complete query while leaving the reference’s unmatched ends unpenalized. This is often described as fitting the query sequence into the target sequence. The exact configuration depends on which sequence is designated as the query and which is designated as the target.
- Semi-global alignment can also be used in primer analysis. A primer is a short DNA sequence designed to bind to a complementary target region during PCR or other molecular techniques. Comparing a primer with a longer target sequence may require an alignment that allows the target sequence to extend beyond the primer-binding region. Semi-global alignment can help identify candidate binding positions and mismatches. However, primer specificity and binding efficiency also depend on melting temperature, GC content, secondary structure, mismatch location, and experimental conditions. Alignment alone cannot establish whether a primer will work effectively in a laboratory experiment.
- In transcriptomics, semi-global alignment may be useful when comparing partial transcripts or sequence fragments with longer reference transcripts. It can help identify a fragment’s corresponding region without penalizing unmatched transcript ends. However, eukaryotic RNA sequencing reads that span exon–exon junctions require splice-aware alignment methods. A simple semi-global alignment does not model introns and exon structures, so tools such as STAR and HISAT2 are more appropriate for many RNA sequencing applications.
- Semi-global alignment may also be useful in protein sequence analysis when comparing incomplete protein sequences or fragments with longer reference proteins. For example, a protein fragment obtained from an experimental study may correspond to a specific region of a known protein. Semi-global alignment can align the fragment while allowing the longer reference protein to contain additional terminal regions. This can help identify the fragment’s likely position and assess sequence similarity. However, if the sequences share only a short internal domain and have unrelated terminal regions on both sides, local alignment may be more appropriate.
- The distinction between global, local, and semi-global alignment is important when selecting an alignment method. Global alignment attempts to align both complete sequences and generally penalizes terminal and internal gaps. Local alignment identifies the highest-scoring matching region and can exclude unrelated regions at either end. Semi-global alignment uses selected free or reduced terminal-gap penalties to align an overlap or fit one sequence into another. Its purpose is to preserve the relevant sequence correspondence without forcing unnecessary terminal gaps to reduce the score.
- The following table summarizes the main differences:
| Feature | Global alignment | Local alignment | Semi-global alignment |
| Main objective | Align both sequences across their lengths | Identify the best matching region | Align overlapping regions or fit one sequence into another |
| Terminal gaps | Usually penalized | Unaligned ends are excluded | Selected terminal gaps are free or less penalized |
| Internal gaps | Penalized | Penalized | Penalized |
| Typical application | Comparing corresponding complete sequences | Finding conserved domains or motifs | Read overlaps and fragment-to-reference alignment |
| Classical algorithm | Needleman–Wunsch | Smith–Waterman | Modified global dynamic programming approach |
- Scoring systems are essential for semi-global alignment. Match scores reward identical nucleotides or amino acids, while mismatch penalties reduce the score for different residues. Internal gap penalties represent insertions and deletions within the aligned region. The scoring system should be appropriate for the sequence type and evolutionary distance. For nucleotide sequences, simple match and mismatch scores may be sufficient for some applications. Protein alignment generally requires substitution matrices such as BLOSUM or PAM because amino acid substitutions differ in their evolutionary likelihood and biochemical properties.
- The treatment of terminal gaps should be selected according to the biological question. If a short query is expected to match completely within a longer reference, the query ends should generally remain penalized while the reference ends can be unpenalized. If two sequencing reads are being compared to identify an overlap, a different configuration may be appropriate depending on whether the objective is to align both reads across their shared region or to identify an overlap at particular ends. Applying free terminal gaps indiscriminately can produce misleading alignments, so the direction and biological meaning of the alignment should be considered.
- The following Python example demonstrates semi-global alignment using Biopython’s PairwiseAligner. It configures the query sequence’s terminal gaps to be free while retaining penalties for internal gaps. This allows the complete query to align to a region within the target sequence. The example assumes that the target is longer than the query and that the query is expected to match a region within it.
from Bio.Align import PairwiseAligner
target = “GGGATGCTAGCTAGCCC”
query = “ATGCTAGCTAG”
aligner = PairwiseAligner()
aligner.mode = “global”
aligner.match_score = 2
aligner.mismatch_score = -1
aligner.open_gap_score = -3
aligner.extend_gap_score = -0.5
# Allow the target sequence to have unaligned terminal regions.
# Keep terminal gaps in the query penalized.
aligner.target_left_open_gap_score = 0
aligner.target_left_extend_gap_score = 0
aligner.target_right_open_gap_score = 0
aligner.target_right_extend_gap_score = 0
alignments = aligner.align(target, query)
print(“Semi-global alignment score:”, alignments.score)
print(alignments[0])
- The example uses zero penalties for gaps at both ends of the target sequence. This permits the query to align to an internal region of the target while requiring the query to be represented in the alignment. It is one specific semi-global configuration, not a universal setting for every overlap problem. Biopython’s available gap-scoring attributes and alignment behaviour should be checked against the installed version.
- Semi-global alignment can also be understood through a simple example. Consider a longer target sequence, GGGATGCTAGCTAGCCC, and a shorter query sequence, ATGCTAGCTAG. The query corresponds to an internal region of the target. A conventional global alignment may introduce gaps to account for the additional bases at the beginning and end of the target, potentially reducing the alignment score. A semi-global configuration can leave these target ends unaligned without applying terminal-gap penalties, allowing the algorithm to focus on the complete query-to-target match.
- In practical bioinformatics workflows, semi-global alignment is implemented in different ways by different tools. Biopython’s PairwiseAligner allows users to configure terminal gap scores. Other alignment libraries provide options for end-gap-free alignment, overlap alignment, or fitting one sequence into another. Tools designed for read mapping and genome assembly may use specialized algorithms that are more efficient for large datasets. Examples include minimap2 for mapping long reads and other sequence types, BWA for short-read mapping, and dedicated genome assemblers that identify and resolve overlaps using specialized data structures and algorithms. These tools do not all implement identical semi-global alignment procedures, so their documentation should be consulted before interpreting their output.
- Semi-global alignment has several limitations. Free terminal gaps can create ambiguous alignments when sequences contain repetitive or low-complexity regions. Different scoring parameters may produce different overlap positions, especially when multiple regions have similar sequence composition. Sequencing errors can introduce mismatches and gaps that obscure the true overlap. In addition, a high-scoring overlap does not necessarily prove that two sequences originate from adjacent regions of the same genome. Repeated sequences may produce overlaps between fragments from different genomic locations, and additional evidence such as read quality, coverage, orientation, and genomic context may be required.
- The interpretation of semi-global alignment should therefore include more than the alignment score. Researchers should examine the aligned length, percent identity, sequence coverage, mismatch distribution, gap locations, and the amount of each sequence left unaligned. For read overlap analysis, they should also consider the expected orientation of reads, sequencing error rates, minimum overlap length, and the possibility of repetitive regions. These factors help distinguish biologically meaningful overlaps from coincidental sequence similarities.
- Reproducibility is important when performing semi-global alignment. Researchers should record the target and query sequences, accession numbers or read identifiers, software name and version, alignment configuration, match and mismatch scores, gap-opening and gap-extension penalties, and the terminal-gap settings. The definition of the overlap and the criteria used to accept or reject an alignment should also be documented. This information allows other researchers to reproduce the analysis and understand why a particular alignment was selected.
- Semi-global sequence alignment provides an important middle ground between global and local alignment. It is particularly valuable when sequences overlap partially, when a short fragment must be aligned against a longer reference, or when unmatched terminal regions should not reduce the alignment score. By adjusting terminal-gap penalties while retaining appropriate internal gap penalties, semi-global alignment provides a flexible method for comparing biological sequences. It is widely relevant to sequencing read overlaps, genome assembly, primer analysis, fragment mapping, and comparative sequence analysis.