An Automatic Verification Method and System for Sequencing Adapter Sequences Based on Multi-Strategy Segmentation and Alignment
The sequencing adapter sequence is automatically verified by a multi-strategy segmentation and alignment method, which solves the problems of large errors in manual verification and poor tool adaptability in the existing technology. It achieves efficient and reliable adapter sequence quality control and supports batch sample processing and compatibility with complex sequence features.
Patent Information
- Application Number
- CN202611241184.X
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2026-08-17
- Publication Date
- 2026-11-10
AI Technical Summary
In current sequencing experiments, manual verification of adapter sequences is inefficient and prone to subjective errors. General sequence alignment tools have poor compatibility and lack dedicated automated quality control solutions, resulting in low automation levels in adapter sequence quality control processes, which makes it difficult to meet the quality control requirements of high-throughput sequencing.
An automatic verification method for sequencing adapter sequences based on multi-strategy segmentation and alignment is adopted, including preprocessing, full library scanning, and alignment mechanism for designing the longest common substring cutting mode and common substring anchoring mode. The method generates visualization results and outputs statistical reports, and supports batch sample processing and compatibility with complex sequence features.
It has enabled automated batch processing of samples, improved sequence alignment accuracy and visualization output capabilities, significantly reduced manual review costs and time, and enhanced quality control efficiency and accuracy.
Smart Images

Figure CN123072500A_ABST
Abstract
Description
Technical Field
[0001] This invention relates to the fields of bioinformatics and sequence alignment, specifically to a method and system for automatic verification of sequencing adapter sequences based on multi-strategy segmentation and alignment. Background Technology
[0002] With the widespread application of next-generation high-throughput sequencing technology, quality control of adapter sequences in sequencing libraries has become a core aspect of ensuring the validity of sequencing experiments. Currently, the industry generally relies on Sanger sequencing results, using manual verification or general sequence alignment tools such as BLAST to complete adapter sequence alignment and verification. However, existing technologies have several substantial shortcomings, specifically as follows:
[0003] 1. Manual verification is inefficient and prone to subjective errors: Existing manual verification methods require operators to manually read and compare each .ab1 format sequencing file generated by Sanger sequencing using software such as Chromas. Even if the number of samples verified at one time is controlled to within 200, the manual operation still consumes a lot of manpower and time. At the same time, this method lacks standardized and visualized sequence alignment maps as a basis for judgment, and operators are prone to misjudgment and omission due to visual fatigue and subjective judgment bias. When the difference between the adapter sequence to be tested and the standard sequence is small, the accuracy and consistency of manual verification results cannot be guaranteed.
[0004] 2. Poor adaptability and incomplete result display of general sequence alignment tools: General sequence alignment tools such as BLAST are not designed for adapter sequence quality control scenarios. When dealing with common sequencing sequence variations such as insertions / deletions (Indels), base mutations, and terminal degenerate bases, if the number of sequence variation sites is large, no results may be output. Even if the alignment is successful, the output does not include a complete visual alignment map with coordinate scales, and it cannot specifically annotate and display the alignment details of the core index (tag) sequence. Technicians cannot quickly determine the matching status of the core tag sequence in the adapter sequence, thus limiting quality control efficiency and accuracy.
[0005] 3. Lack of dedicated automated quality control solutions and difficulty in standardizing processes: Currently, there are no dedicated automated technical solutions for adapter sequence verification in the industry. Existing technologies cannot achieve batch processing of samples, nor can they accurately accommodate complex sequence features such as indels and degenerate bases. Furthermore, they lack automated visualization output capabilities, failing to intuitively present details of index sequence matching. These deficiencies result in a low level of automation in adapter sequence quality control processes, making it difficult to meet the efficient and reliable quality control requirements of high-throughput sequencing in its early stages.
[0006] In summary, there is an urgent need in this field for an automated connector sequence verification technology that can process samples in batches, is compatible with complex sequence features, and has high-precision alignment and visualization output capabilities. Summary of the Invention
[0007] The purpose of this invention is to overcome the shortcomings of existing technologies, such as large errors in manual verification, poor adaptability of general tools, and lack of dedicated automated quality control solutions. This invention provides an automatic verification method and system for sequencing adapter sequences based on multi-strategy segmentation and alignment, which realizes automated batch processing of samples, is compatible with complex sequence features such as insertions, deletions, and degenerate bases, improves sequence alignment accuracy, and outputs standardized and visualized results to meet the quality control requirements of high-throughput sequencing.
[0008] To achieve the above objectives, the present invention provides the following technical solution: an automatic verification method for sequencing adapter sequences based on multi-strategy segmentation and alignment, comprising the following steps:
[0009] Step S1: Receive and preprocess batch data containing at least one test connector sequence to obtain a standardized and clean test connector sequence;
[0010] Step S2: Perform a full scan of the connector sequence to be tested against a preset reference sequence library, and select one or more reference sequences with the highest overall matching score;
[0011] Step S3: To address the different variation characteristics of insertions and deletions in the test linker sequence, which are concentrated in specific regions or scattered throughout the entire sequence, two independent alignment mechanisms, the Longest Common Substring Segmentation (LCSC) and the Common Substring Anchoring (CSA), are designed to obtain the final alignment results.
[0012] Step S4: Calculate the number of matching bases in the final alignment result, and calculate the similarity value or coverage value according to the selected alignment mechanism. Compare the calculated similarity value or coverage value with the preset alignment ratio threshold. If the requirement is not met, the matching is judged as a failure.
[0013] Step S5: Generate a visualization image for each successfully aligned sample, including the alignment sequence, gap location, coordinate scale, and index sequence annotation, and output a statistical report containing the sample name, matching template, key alignment indicators, and quality control evaluation.
[0014] Preferably, step S1 preprocessing specifically involves: performing a cleaning process on all the connector sequences to be tested, converting the sequence base characters to uppercase, and removing all non-alphabetic invalid characters in the sequence to obtain a standardized and clean connector sequence to be tested.
[0015] Preferably, the process of screening candidate reference sequences in step S2 is as follows: For each reference sequence, calculate the length of the longest common subsequence (LCS) between the reference sequence and the connector sequence to be tested, and at the same time calculate the sum of the lengths of all common substrings with a length not less than the minimum common substring threshold minCslen. Add the two together as the comprehensive matching score of the reference sequence.
[0016] Preferably, in step S2, if multiple reference sequences have the same score, conflict resolution is performed based on the template ID extracted from the sample number of the connector sequence to be tested to determine a uniquely matching reference sequence, specifically:
[0017] Let N be the sample ID string of the connector sequence to be tested, and let ID be the expected template identifier extracted from N using a preset character matching rule. exp Let ID be the set of candidate identifiers composed of multiple reference sequence templates with the highest overall matching scores. top = {id1, id2, …, id n}, determine ID exp Does it belong to ID? top If ID exp ∈ ID top Then the ID exp The corresponding reference sequence is determined to be the uniquely matching reference sequence; if ID exp ∉ID top If the match fails, it is determined that the match has failed.
[0018] Preferably, the Common Substring Anchoring Pattern (CSA) alignment mechanism in step S3 is used to match the base count / length of the longest common subsequence to calculate the similarity value. The specific design is as follows:
[0019] Sub-step S311: Common substring anchoring and correction: Identify all common substrings between the test connector sequence and the reference sequence whose length is greater than or equal to the minimum common substring threshold minCslen, and correct adjacent common substrings with base overlap to ensure that all common substrings do not overlap in the two sequences;
[0020] Sub-step S312: Sequence Segmentation and Bidirectional Alignment: Using the corrected common substring as anchor points, the reference sequence and the connector sequence to be tested are simultaneously segmented into multiple non-common substring segments and common substring segments; following the order from 5' end to 3' end, the 3' end to 5' end alignment strategy and the 5' end to 3' end alignment strategy are respectively applied to the non-common substring segments at the 5' end and 3' end; the non-common substring segments in the middle section apply the bidirectional comprehensive alignment strategy, that is, both the 5' end to 3' end alignment strategy and the 3' end to 5' end alignment strategy are used simultaneously to generate two candidate alignment results, and then the optimal alignment result is automatically selected according to the following priority rules:
[0021] Sub-step S3121: Return directly if completely identical: If the alignment identifier strings of the two candidate results are exactly the same, then either one can be chosen.
[0022] Sub-step S3122: If both candidate results contain only one matching base, then directly return the result from the 5' end to the 3' end.
[0023] Sub-step S3123: Compare the lengths of the reference sequence strings in the two candidate results and select the one with the shorter length.
[0024] Sub-step S3124: If the two lengths are equal, split the alignment identifier string into several consecutive matching segments by spaces, record the length of each segment, and then enter the loop for comparison:
[0025] Select the alignment result with the longest continuous matching segment;
[0026] If the lengths of the longest consecutive matching segments of the two are equal and the length is greater than 1, then the one with the more occurrences of the longest consecutive matching segment is selected.
[0027] If the longest consecutive matching segments of the two are of equal length and the length is equal to 1, then the result from the 5' end to the 3' end is selected;
[0028] If the longest consecutive matching segments appear the same number of times in both lists, then remove all segments with the current longest length from both lists and continue comparing the length of the longest segment in the next round.
[0029] Sub-step S313: Alignment result splicing and optimization: The alignment results of each segment are spliced with the common substring in sequence to form the initial alignment result; then, the low-density alignment region correction and the end degenerate base alignment correction are performed in sequence to obtain the final alignment result.
[0030] Preferably, the low-density alignment region correction in step S313 includes the following steps:
[0031] First, extract the alignment region from the concatenated alignment identifier string: find the positions of the first and last aligned matching bases, and extract the closed interval [sidx, eidx); count the total number of gaps in the reference sequence revaln and the query sequence seqaln within the closed interval [sidx, eidx), and calculate the alignment region length alnlen = eidx - sidx; if gapnum / alnlen is greater than or equal to 0.2, that is, the proportion of gaps is not less than 20%, then trigger the low-density alignment region location and correction process;
[0032] The low-density alignment region localization algorithm is used to accurately locate the low-confidence intervals that need to be re-aligned within the alignment region of the comparison identifier strings. The specific steps are as follows:
[0033] Step S3131: Extract misaligned positions
[0034] Convert the input alignment identifier string align into a list. Use lists stidxs and edidxs to record the start and end index information of the unaligned positions in the align list, respectively. The end index value of the same unaligned position is the start index value + 1.
[0035] Step S3132: Search for the optimal low-density interval
[0036] Traverse all possible contiguous sub-intervals, which are defined by the starting index stidx in stidxs and the ending index edidx in edidxs. Each interval contains at least one unaligned position. Record the interval with the highest score as a candidate low-density region.
[0037] 1) Interval length seglen = edidx - stidx;
[0038] 2) The number of unaligned spaces within the interval, unalnum, is the number of spaces within the interval;
[0039] 3) Alignment count alnum = seglen - unalnum;
[0040] 4)Score = unalnum / seglen + (unalnum - alnum);
[0041] Step S3133: Adaptive Boundary Expansion
[0042] Find the length of the longest consecutive alignment sequence in the alignment identifier string `align`, `maxalnlen`. Based on `maxalnlen`, determine whether to extend the 5' and 3' boundaries, and return the final value (`stidx`, `edidx`).
[0043] Step S31331: If the starting index stidx of the candidate low-density region is less than or equal to maxalnlen, it indicates that the current region is close to the 5' end of the sequence and there is no independent and effective aligned segment at the 5' end of the sequence. Then, the starting index is extended to 0, that is, the low-density region is extended to the beginning of the sequence to avoid fragmentation.
[0044] Step S31332: If the distance between the termination index position edidx of the candidate low-density region and the right boundary of the alignment identifier string align is less than or equal to maxalnlen, it indicates that the current region is close to the end of the sequence 3'. Then, extend the termination index edidx to the right boundary of the sequence, that is, extend the low-density region to the end of the sequence.
[0045] Step S3134: Logic for all variable values and boundary conditions
[0046] Step S31341: Fix constant boundaries
[0047] Boundary expansion criterion: maxalnlen, which is the length of the longest continuous matching segment in the alignment region, serves as the sole criterion for determining the boundary expansion at both ends of the sequence.
[0048] Step S31342: Traverse the loop boundary
[0049] A. Traversing unaligned positions: Traverse all alignment marker characters, only record the start and end index values of spaces, and store them in stidxs and edidxs respectively. The end index value of the same space = the start index value + 1. The traversal end boundary is the total length of the aligned string;
[0050] B. Candidate low-density interval cycle
[0051] a. Starting position traversal loop: Traverse the index values in stidxs as the starting position index of the candidate area. The lower boundary of the loop is the first starting index value recorded in stidxs, and the upper boundary of the loop is the second to last starting index value recorded in stidxs, so that the last space in the alignment identifier string will not be treated as a candidate area alone.
[0052] b. Termination position traversal loop: Traverse the index values in edidxs as the termination position index of the candidate area. When traversing the nth index value in stidxs as the starting position index of the candidate area, the lower boundary of the loop for the termination position is the (n+1)th termination index value recorded in edidxs, ensuring that the candidate area contains at least 2 spaces. The upper boundary of the loop is the last termination index value recorded in edidxs.
[0053] Step S31343: Variable value retrieval logic
[0054] A.seglen: The total length of characters in the low-density candidate interval, with a value > 1;
[0055] B.unalnum: The total number of spaces in the interval, with a value > 1; spaces include unmatched pairs and gaps.
[0056] C.alnum: Number of matching bases within the interval = seglen - unalnum;
[0057] D. The interval score is calculated as follows: score = unalnum / seglen + (unalnum − alnum). The larger the score, the higher the degree of low density. Only the interval corresponding to the maximum score is retained globally.
[0058] E.stidx / edidx: The final output is the start and end index of a low-density interval, all of which are integers between 0 and the length of the aligned string, and the start < end is always true;
[0059] Step S31344: Extend the boundary
[0060] A. If the starting index of the candidate region is less than or equal to maxalnlen: force the left boundary stidx to be corrected to 0, the starting point of the sequence at 5' end, and there is no negative index out of bounds;
[0061] B. If the total sequence length minus the candidate region termination index is less than or equal to maxalnlen: force the right boundary edidx to be corrected to align with the full length of the string. The maximum right boundary is equal to the total sequence length, and there are no indices that exceed the sequence.
[0062] Based on the start and end indices of the low-density region, by adding the distance of the alignment region from the 5' end, the start and end indices of the low-density alignment region in the alignment identifier string align can be obtained. According to the start and end indices of the low-density region, the reference sequence and query sequence of the low-density region after removing the gap are obtained. The bidirectional alignment method alignBoth is called to re-align the subsequence and compare it with the length of the low-density region. If the length of the region in the re-alignment result is not reduced, the longest common substring cutting method aln5LcsAln3 is used for further re-alignment. Finally, the optimized alignment result is replaced back with the corresponding interval of the original alignment result to complete the correction of the low-density region.
[0063] Preferably, the terminal degenerate base alignment correction in step S313 includes the following steps:
[0064] For the optimized alignment results, check whether there are extra gaps at the end of the reference sequence caused by degenerate bases in the query sequence; if so, call the degenerate base correction method revisRefGaps, re-align the end region based on the predefined degenerate base fuzzy matching rules, and replace the original result to obtain the final alignment result.
[0065] Preferably, the longest common substring (LCSC) alignment mechanism in step S3 is used to match the number of bases / the length of the region between the first and last matching bases to calculate the coverage value. The specific design is as follows:
[0066] Sub-step S321: Recursive segmentation and hierarchical alignment: Extract the longest common substring LCStr of the reference sequence and the connector sequence to be tested. Use the longest common substring LCStr as the cutting point to segment the two sequences into 5' end segments and 3' end segments. Perform alignment from 3' end to 5' end for the 5' end segments and from 5' end to 3' end for the 3' end segments. If the longest continuous aligned sequence of the aligned segment is different from the longest common substring LCStr, and the length of the longest common substring LCStr is greater than or equal to the minimum common substring threshold minCslen, then recursively perform the segmentation and alignment process on the segment until the segmentation conditions are no longer met, and record the source and position of each segment with multi-level numerical identifiers.
[0067] Sub-step S322: Merging hierarchical results: Merge all the segmented alignment fragments in reverse order of identifier values from largest to smallest to generate an initial alignment result; then, obtain the alignment segment of the initial alignment result, which is the region between the first matching base and the last matching base; if the total number of mismatches or insertions / deletions in the alignment segment is less than 3, the initial alignment is considered sufficiently tight, and subsequent optimization steps are skipped directly. The total number of mismatches or insertions / deletions is the number of spaces in the alignment identifier string; otherwise, continue with the following optimization steps.
[0068] Sub-step S323: Local region re-alignment:
[0069] (1) Comparison and enrichment region localization: Call the comparison and enrichment region localization algorithm oaer to find the core region with the highest matching density in the alignment identifier string of the initial comparison result, and record it as the enrichment region;
[0070] (2) Optimization of 5' and 3' regions: The initial alignment result is divided into 5' region and 3' region by the rich region. The number of bases that are completely matched in these two end regions is counted. If the number of matching bases in either region is not less than the preset minimum common substring length threshold minCslen (minCslen, default 4), and the longest continuous alignment sequence maxfrag in the region is different from the longest common substring lcstr, then the longest common substring segmentation alignment strategy aln5LcsAln3 is called for re-alignment, and the optimized alignment result is used to replace the original region.
[0071] Sub-step S324: Correction of terminal degenerate base alignment:
[0072] For the alignment result optimized by sub-step S323, check whether there is an extra gap at the end of the reference sequence caused by degenerate bases in the query sequence; if so, call the degenerate base correction method revisRefGaps, re-align the end region based on the predefined degenerate base fuzzy matching rules, and replace the original result to obtain the final alignment result.
[0073] This invention also discloses an automatic verification system for sequencing adapter sequences based on multi-strategy segmentation and alignment. Based on the aforementioned automatic verification method for sequencing adapter sequences based on multi-strategy segmentation and alignment, the system includes:
[0074] The task scheduling module, based on an asynchronous task queue, enables the splitting, concurrent execution, and status monitoring of batch tasks in the connector sequence to be tested.
[0075] The sequence matching and recognition module is used to calculate the longest common subsequence length of the test sequence and each reference sequence and the sum of the lengths of all valid common substrings as the matching score. Candidate reference sequences are selected based on the highest score, and conflict resolution is performed based on the template ID extracted from the sample name.
[0076] The dual-mode sequence alignment engine includes a CSA alignment submodule that performs the Common Substring Anchoring (CSA) alignment mechanism and an LCSC alignment submodule that performs the Longest Common Substring Cutting (LCSC) alignment mechanism. The sequence processing strategies shared by both alignment submodules include:
[0077] (1) Alignment strategy align5_3 in the 5'→3' direction: Extract the aligned bases between the test sequence and the reference sequence from the 5' end to the 3' end to obtain the alignment results of the two sequences;
[0078] (2) Alignment strategy align3_5 in the 3'→5' direction: Extract the aligned bases between the test sequence and the reference sequence from the 3' end to the 5' end to obtain the alignment results of the two sequences;
[0079] (3) Longest common substring segmentation and alignment strategy aln5LcsAln3: used to optimize the re-alignment of alignment results in local regions;
[0080] (4) Terminal degenerate base correction: used for fuzzy matching-based re-alignment of degenerate base regions at the ends of sequences;
[0081] The quality assessment module is used to calculate the similarity or coverage of the comparisons and perform filtering.
[0082] The data management module stores task batch information, sample comparison details, and audit logs, and is responsible for data isolation and cleanup of the file system.
[0083] The present invention has the following advantages:
[0084] 1. This invention, through its innovative CSA and LCSC segmentation-local alignment-recombination strategy, effectively overcomes the shortcomings of traditional global alignment in handling indel and sequence length differences, significantly improving alignment accuracy. Testing with a large amount of real-world data shows that the LCSC mode achieves a success rate of over 99.5%.
[0085] 2. The low-density alignment region localization, alignment-enriched region localization, and terminal degenerate base correction algorithms designed in this invention can automatically identify and optimize erroneous or low-confidence regions in the initial alignment, greatly improving the reliability of the final results.
[0086] 3. This invention combines asynchronous task scheduling and concurrent processing mechanisms to support automated pipeline operations for batch samples, achieving automation and high efficiency, and significantly reducing the cost and time of manual review.
[0087] 4. This invention generates color alignment diagrams with coordinates, gaps, and index sequence markers, providing intuitive and visual results that facilitate quick and easy confirmation of sequence quality by researchers. Attached Figure Description
[0088] Figure 1 This is an example diagram illustrating the configuration format of the standard connector sequence and its index sequence of the present invention;
[0089] Figure 2 This is an example diagram of the recursive segmentation comparison of the LCSC mode in this invention;
[0090] Figure 3 This is an example diagram showing the comparison between the longest consecutive aligned sequence and the longest common substring in this invention;
[0091] Figure 4 This is an example diagram illustrating the execution of the 5'→3' direction alignment strategy of the present invention;
[0092] Figure 5 This is an example diagram illustrating the execution of the 3'→5' direction alignment strategy of the present invention;
[0093] Figure 6 This is an example diagram of the LCSC model classification result merging process of the present invention;
[0094] Figure 7 This is an example diagram illustrating the determination of the second candidate enrichment region in this invention;
[0095] Figure 8 This is an example diagram illustrating the determination of the first candidate enrichment region in this invention;
[0096] Figure 9 This is an example diagram of the segmentation and local re-alignment of enriched regions based on the present invention;
[0097] Figure 10This is an example diagram illustrating the execution of the longest common substring segmentation and comparison strategy of this invention;
[0098] Figure 11 This is an example diagram of the degenerate base region alignment correction of the present invention;
[0099] Figure 12 This is an example diagram illustrating the identification of valid common substrings (length ≥ minCslen) according to the present invention;
[0100] Figure 13 This is an example diagram of the correction process for overlapping common substrings in this invention;
[0101] Figure 14 This is an example diagram of sequence segmentation based on multiple common substrings in the CSA mode of this invention;
[0102] Figure 15 This is an example diagram illustrating the selection rules for the bidirectional comprehensive comparison strategy in the intermediate segment of this invention.
[0103] Figure 16 This is an example diagram showing the stitching of the CSA mode segmentation comparison results of the present invention;
[0104] Figure 17 This is an example diagram illustrating the correction of the low-density region in this invention;
[0105] Figure 18 This is an example diagram of the adaptive expansion and correction of the low-density region boundary according to the present invention;
[0106] Figure 19 This is an example diagram of the LCSC mode sample verification failure result of the present invention;
[0107] Figure 20 This is an example diagram of the CSA mode sample verification failure result of the present invention;
[0108] Figure 21 This is an example of the final visual comparison output result of the sample in this invention. Detailed Implementation
[0109] The following specific embodiments illustrate the implementation of the present invention. Those skilled in the art can easily understand other advantages and effects of the present invention from the content disclosed in this specification. Obviously, the described embodiments are only some, not all, of the embodiments of the present invention. Based on the embodiments of the present invention, all other embodiments obtained by those skilled in the art without creative effort are within the scope of protection of the present invention.
[0110] Example 1: This invention proposes an automatic verification method for sequencing adapter sequences based on multi-strategy segmentation and alignment. This example uses more than 2,000 Sanger sequencing adapter sequences as the object and describes the method flow of this invention in detail.
[0111] Step S1: Data Preparation and Preprocessing
[0112] The user submits a batch task (batch name "Batch_01") via command line. The system receives a folder containing all .ab1 or .seq files. The system iterates through the folder, extracts the base sequence from each file, converts lowercase letters to uppercase, and removes all non-alphabetic characters to obtain a clean test sequence. Simultaneously, based on a preset regular expression (e.g., r'_([ABCD](0[1-9]|[1-3][0-9]|4[0-8]))_'), the system extracts the expected template ID ("D01") of samples (e.g., "250408-4_D01_RO3Q005_A07") from filenames (e.g., "250408-4_D01_RO3Q005_A07".ab1).
[0113] Step S2: Multi-strategy matching identification
[0114] The system loads the pre-configured reference sequence library (adapter.yml). In this embodiment, the reference sequence library is configured with 193 standard connector sequences, including A01-A48, B01-B48, C01-C48, D01-D48, and RC. The connector sequences are configured as follows: Figure 1 As shown, sequence D01 contains an index sequence, while sequence RC does not. For a sample named "250408-4_D01_RO3Q005_A07", the system calculates the matching score between its test sequence and all 193 reference sequences. The calculation results show that this sample has the highest and identical score to reference sequences C03, C23, D01, and D46. The system extracts the expected template ID "D01" from the sample name. This ID exists in the candidate list, therefore, the final matching reference sequence is determined to be D01.
[0115] Step S3: Adaptive Alignment Mode Selection
[0116] The system defaults to LCSC mode for higher accuracy. The core processing logic of LCSC mode and CSA mode are explained below.
[0117] (a) LCSC mode
[0118] Sub-step S321: See Appendix Figure 2Taking the test sequence “GWCTSGCTAMGTCCGGACGGATCGGAGAGCACACGKCTGARCTCCAGTSACCCAGTTRGATSKCGKATGCCGTCTWCTGCTTGCCGAGAGCGTTGCTAGACTACGGTATA” and the reference sequence “GATCGGAAGAGCACACGTCTGAACTCCAGTCACCCAGTTAGATCTCGTATGCCGTCTTCTGCTTG” as examples, recursive segmentation and hierarchical alignment are performed.
[0119] (1) Initial segmentation: The system calculates the longest common substring (LCStr) between the test sequence and the reference sequence as "AGAGCACACG". Using this LCStr as the cutting point, the two sequences are segmented into a 5' segment, an LCStr segment, and a 3' segment.
[0120] (2) Hierarchical alignment: For 5' end segments, a 3'→5' alignment strategy is used, and for 3' end segments, a 5'→3' alignment strategy is used. If the longest continuous alignment sequence in the alignment result of a segment is inconsistent with the LCStr inside the segment, and the length of the internal LCStr is greater than or equal to 4, then the segment is further segmented and aligned.
[0121] Reference Appendix Figure 3 After the initial alignment, the 5' segment contains a gap region, causing the longest consecutive alignment sequence ("CGGA") to differ from the LCStr ("GATCGG") of that region. The system will recursively perform the above process on this 5' segment. During the recursion, the system uses multi-level numeric identifiers (e.g., the three segments in the first segmentation are identified by IDs 5, 4, and 3; if the segment with ID 5 is segmented a second time, its sub-segments are identified by IDs 55, 54, and 53) to record the hierarchy and positional relationship of each segment.
[0122] (3) Explanation of directional strategy:
[0123] ① 5'→3' direction strategy: First, traverse the sequence from the 3' end to the 5' end, construct a dynamic programming matrix, and then backtrack from the 5' end to the 3' end to extract aligned bases, which is used to optimize the alignment accuracy of the 3' end sequence. (See attached reference.) Figure 4 ,by Figure 2 Taking the segment with ID 33 as an example, the matrix construction, base extraction and alignment process is demonstrated.
[0124] ② 3'→5' direction strategy: First, traverse the sequence from the 5' end to the 3' end, construct a dynamic programming matrix, and then backtrack from the 3' end to the 5' end to extract aligned bases, which is used to optimize the alignment accuracy at the 5' end. (See attached reference.) Figure 5 ,by Figure 2Taking the segment with ID 5 as an example, the matrix construction, base extraction and alignment process is demonstrated.
[0125] Sub-step S322: Merging of hierarchical results
[0126] Reference Appendix Figure 6 The initial alignment result is generated by merging identifiers in descending order of value (e.g., first merging 335, 334, and 333 into 33, then merging 55, 54, and 53 into 5, then merging 35, 34, and 33 into 3, and finally merging 5, 4, and 3 into the complete alignment result). Within the alignment section of this initial alignment result, the number of indels and mismatches is 9, which is greater than 3. Therefore, the following sub-steps are required for further optimization.
[0127] Sub-step S323: Local region re-alignment
[0128] After merging the results in sub-step S322 to obtain the initial alignment result, the system first determines the number of mismatches or indels (spaces) in the alignment region of the initial alignment result (i.e., the region between the first matching base '|' and the last matching base '|'). If the number is less than 3, the initial alignment is considered sufficiently tight, and subsequent optimization steps are skipped; otherwise, the following local region re-alignment process is executed.
[0129] (1) Comparison of enriched region localization algorithm (oaer).
[0130] The system invokes a region-rich region localization algorithm to identify the core sub-region with the highest matching density from the alignment identifier string (composed of '|' and spaces) of the initial alignment results. The specific execution steps of this algorithm are as follows:
[0131] ① Input and Preprocessing
[0132] The input is the alignment identifier string "align". The "align" string is split into a single space to obtain a list of fragments, "alnsegs". Iteration through "alnsegs" records the starting index "stidxs" and the ending index (starting index + 1) "edidxs" for each non-empty fragment (i.e., a continuous string consisting only of '|'). This information is used for subsequent fast location of candidate regions.
[0133] ② Candidate Region Construction and Scoring
[0134] Traverse all possible combinations of consecutive non-empty segments to construct candidate regions. Each candidate region is determined by the index stidx of its starting non-empty segment (taken from stidxs) and the index edidx of its ending non-empty segment (taken from edidxs, and covering at least segn non-empty segments, with a default segn=1).
[0135] For the candidate region, calculate the following two metrics:
[0136] 1) segnum = edidx - stidx: The total number of segments contained in the candidate region (including empty segments).
[0137] 2)alignum: The total number of '|' characters in all non-empty segments within the candidate region, i.e., the total number of matching bases in the region.
[0138] The enrichment score of the candidate region is calculated using the following scoring function:
[0139] ;
[0140] This formula takes into account the absolute number of matches, the segment interval penalty, and the average match density, and can prioritize the selection of regions with dense and continuous matches.
[0141] ③ Optimal region selection
[0142] Preliminary selection: Select the region with the highest score from all candidate regions as the first candidate region, and record its score score1, number of segments segnum1, and segment list cutsegs1.
[0143] Suboptimal validation: Select the region with the second highest score (score2, segnum2, cutsegs2).
[0144] If all of the following conditions are met, the second candidate region is selected as the final enriched region, such as... Figure 7 As shown; otherwise, maintain the first candidate region, as shown. Figure 8 As shown. This mechanism prevents the loss of longer, more complete matching regions due to small differences in scores.
[0145] 1) score1 - score2 < 3 (small score difference);
[0146] 2) 0 < segnum2 - segnum1 < 3 (the second candidate region covers slightly more segments);
[0147] 3) The longest matching segment unique to the second candidate region (i.e. the longest consecutive '|' string that exists in cutsegs2 but not in cutsegs1) has a length not less than the preset minimum common substring length minCslen (default 4).
[0148] ④ Index mapping
[0149] The list of fragments corresponding to the selected optimal region is reconstructed into a substring using spaces. Then, the substring is searched in the original align string to accurately locate its start index stidx and end index edidx (left-closed, right-open) in the original string, and the coordinate tuple (stidx, edidx) is returned.
[0150] ⑤ Logic for all variable values and boundary conditions
[0151] 1) Fixed constant boundary
[0152] A.segn: Algorithm input parameter, the number of non-empty segments contained in the enriched region is at least segn + 1, fixed default value = 1, only positive integers ≥ 1 are allowed as input. Introducing this parameter can reduce the number of invalid candidate regions generated during traversal;
[0153] B.minCslen: The minimum length threshold of the global common substring, with a fixed constant of 4. All segment lengths in the suboptimal verification are determined by this as a hard boundary. Segments with a length less than 4 are not directly included in the suboptimal candidate region selection.
[0154] C. Score difference threshold: Fixed constant = 3. The comparison of the second-best candidate region is triggered only when the score difference between the two candidate regions is strictly less than 3. If the difference is ≥ 3, the second candidate region is directly abandoned.
[0155] D. Segment number difference boundary: interval (0, 3). The screening condition is met only when segnum2-segnum1 is greater than 0 and less than 3. If the difference is ≤0 or ≥3, the second candidate region is directly discarded.
[0156] 2) Variable value retrieval logic
[0157] A.alnsegs: Stores the alignment identifier string split into segments by spaces. It includes two types: non-empty segments (single '|' or consecutive '|') and empty segments (''). Consecutive spaces in the alignment identifier string will form empty segments after splitting. For example, the arnsegs of '| ||||' after splitting by spaces is ['|', '|||', '', '', '|'];
[0158] B.stidxs / edidxs: Stores only the start / end indexes of non-empty segments in arnsegs. The end index value of the same non-empty segment = the start index value + 1. It does not record the start / end index information of empty segments. All list elements are non-negative integers ≥ 0. The two lists have the same length.
[0159] C.segnum: The difference between the ending index and the starting index of the candidate region, that is, the number of segments (including empty segments) contained in the candidate region. The value range is >segn, and there are no negative numbers. Without segn, the minimum value is 1, and with segn, the minimum value is segn + 1.
[0160] D.alignum: The total number of matching bases in the candidate region, i.e. the number of '|'. Since the candidate region contains at least segn+1 non-empty segments, and the minimum number of matching bases in each non-empty segment is 1, the minimum value of alignmentum is segn+1.
[0161] E.score: Outputs the raw floating-point value so that different candidate regions can be distinguished by small numerical differences. During the traversal loop, if the scores of different candidate regions are exactly the same, only the last candidate region that appears is recorded.
[0162] F.cutsegs1 / cutsegs2: The list of aligned segments corresponding to the first / second candidate regions. It is a sublist of arnsegs, containing empty segments, and is used to compare the differences between the aligned segments.
[0163] G. Unique Longest Matching Segment: Take the maximum segment length within the difference set cutsegs2 - cutsegs1. If the difference set is empty, the filtering condition is not met.
[0164] 3) Traversing the candidate region at the loop boundary
[0165] A. Starting position traversal loop: Traverse the index values in stidxs as the starting position index of the candidate region. The lower boundary of the loop is the first starting index value recorded in stidxs, and the upper boundary of the loop is the segn+1th starting index value from the end recorded in stidxs.
[0166] B. Termination position traversal loop: Traverse the index values in edidxs as the termination position index of the candidate region. When traversing the nth index value in stidxs as the starting position index of the candidate region, the lower boundary of the loop for the termination position is the n + segn termination index value recorded in edidxs, ensuring that the candidate region contains at least segn+1 non-empty segments. The upper boundary of the loop is the last termination index value recorded in edidxs.
[0167] 4) Extreme value screening boundary
[0168] All candidate scores are stored in a dictionary called scoresegs, where the key is the score and the value is the corresponding region parameter. The highest global score is directly taken as the first candidate using the max() function, and the second best candidate is the maximum value among the remaining scores.
[0169] (2) Segmentation and re-alignment based on enriched regions
[0170] After obtaining the coordinates (stidx, edidx) of the enriched region, refer to the appendix. Figure 9 The initial alignment result is divided into a 5' end region (index [0, stidx)) and a 3' end region (index [edidx, end)) using this region as the boundary. The number of matching bases ('|') in each end region is counted. If the number of matching bases is greater than or equal to minCslen (default 4), and the longest continuous aligned sequence maxfrag in the alignment region is different from the longest common substring lcstr, then the longest common substring segmentation alignment strategy (aln5LcsAln3) is used for optimization.
[0171] Reference Appendix Figure 10 The arn5LcsAln3 algorithm uses lcstr as the anchor point to divide ref and seq into three parts: the 5' end, the common substring, and the 3' end. It then performs alignment in the 3'→5' direction (5' end) and the 5'→3' direction (3' end), respectively. The results are then concatenated with the common substring to form a new alignment result, which is returned. Finally, the original segment is replaced with the new alignment result.
[0172] Sub-step S324: Correction of terminal degenerate base alignment
[0173] Based on the above optimization results, check the presence of degenerate bases (such as R, Y, M, K, S, W, H, B, V, D, N) in the terminal regions of the target sequence, and check for gaps in the corresponding target sequences. If any gaps are found, perform a re-alignment. (See attached reference.) Figure 11 Alignment correction was performed on the degenerate base region at the 3' end:
[0174] (1) Determine the alignment direction: Starting from the first base at the 5' end of the region, align position by position to the right in the 5'→3' direction. If the degenerate base region is at the 5' end of the alignment result, then start from the first base at the 3' end of the region and align position by position to the left in the 3'→5' direction.
[0175] (2) Fuzzy matching rules: 11 predefined mapping relationships between degenerate bases and standard base sets are defined: R(A / G), Y(C / T), M(A / C), K(G / T), S(G / C), W(A / T), H(A / C / T), B(G / T / C), V(A / C / G), D(A / G / T), and N(A / T / C / G). During alignment, if a base in the reference sequence belongs to the set of degenerate bases at the corresponding position in the test sequence, the fuzzy match is considered successful and is temporarily marked with ' / '.
[0176] (3) Result determination: Count the number of successfully matched bases (including exact matches and fuzzy matches). If the ratio of the number of successfully matched bases to the length of the reference sequence in the region reaches a preset threshold (such as 0.7), then the result of this re-alignment is adopted.
[0177] (II) CSA Model
[0178] Sub-step S311: Anchoring and Correction of Common Substrings
[0179] Reference Appendix Figure 12 The system identifies all common substrings of length ≥ 4 between the reference sequence and the test sequence. After identifying multiple common substrings, the system checks and corrects adjacent substrings that overlap due to shared bases, ensuring that each substring occupies an independent, non-overlapping region within the sequence. Figure 13 As shown.
[0180] Sub-step S312: Sequence segmentation and bidirectional alignment
[0181] Reference Appendix Figure 14 Using the corrected common substring as anchor points, the two sequences are divided into multiple non-common substring segments and common substring segments. Then, the 3'→5' direction alignment strategy is applied to the first non-common substring segment (5' end), and the 5'→3' direction alignment strategy is applied to the last non-common substring segment (3' end).
[0182] For multiple non-common substring segments in the middle, apply the bidirectional comprehensive comparison strategy alignBoth, as shown in the appendix. Figure 15 Simultaneously employing both 5'→3' alignment (align5_3) and 3'→5' alignment (align3_5) strategies, two candidate alignment results are generated for each. Then, the optimal alignment result is automatically selected based on the following priority rules:
[0183] (1) Return directly when completely identical: If the alignment identifier strings of the two candidate results are exactly the same, then either one will be selected (the result in the 5'→3' direction will be returned by default).
[0184] (2) When a single base is matched, the result in the 5'→3' direction is returned by default: If both candidate results contain only one matching base (i.e., the alignment identifier string contains only one '|'), the result in the 5'→3' direction is returned directly to avoid invalid comparisons.
[0185] (3) Prioritize the result with shorter total length: Compare the length of the reference sequence string in the two candidate results. The one with shorter length (i.e., fewer gaps introduced after alignment) is considered more compact and is preferred.
[0186] (4) Compare the length and distribution of consecutive matching segments: If the lengths are equal, divide the alignment identifier string into several consecutive matching segments (composed of consecutive '|' characters) by spaces, and record the length of each segment. Then proceed with the loop comparison:
[0187] ① Select the alignment result of the side with the longest continuous matching segment.
[0188] ② If the lengths of the longest consecutive matching segments of the two are equal and the length is greater than 1, then the one with the more occurrences of the longest consecutive matching segment is selected.
[0189] ③ If the longest consecutive matching segments of the two are of equal length and the length is equal to 1, then the result of the 5'→3' direction is selected by default.
[0190] ④ If the longest consecutive matching segments appear the same number of times in both lists, then remove all segments with the current longest length from both lists and continue comparing the length of the longest segment in the next round.
[0191] This strategy takes into account the compactness of the alignment, the length of the longest continuous matching block and its distribution density, and can automatically select the result with better overall alignment from the alignments in two directions.
[0192] Sub-step S313: Comparison result stitching and optimization
[0193] Reference Appendix Figure 16 The alignment results of each segment are concatenated with the common substring in the order of 5'→3'. Then, low-density alignment region correction and end degenerate base alignment correction are performed sequentially.
[0194] Combined with appendix Figure 17 The following process demonstrates the triggering conditions, localization algorithm, and re-alignment process for low-density alignment region correction.
[0195] (1) Invocation conditions for low-density aligned region correction
[0196] First, extract the alignment region from the concatenated alignment identifier string `align`: find the positions of the first and last alignment `|`, and extract the closed interval [sidx, eidx). Count the total number of Gaps (-) in the reference sequence `refaln` and the query sequence `seqaln` within this region, `gapnum`, and calculate the alignment region length `alnlen = eidx - sidx`. If `gapnum / alnlen` ≥ 0.2 (i.e., the proportion of Gaps is not less than 20%), then trigger the low-density alignment region location and correction process.
[0197] (2) Low-density aligned region localization algorithm (lowDensiAln)
[0198] The algorithm accurately locates the low-confidence intervals that need to be re-aligned within the aligned region of the matching identifier strings. The specific steps are as follows:
[0199] ① Extract misaligned positions
[0200] Convert the input alignment identifier string 'align' into a list. Use lists stidxs and edidxs to record the start and end indices of the unaligned (space character) positions in the 'align' list, respectively. The end index of the same unaligned position is the start index value + 1.
[0201] ② Search for the optimal low-density interval
[0202] Traverse all possible contiguous sub-intervals, which are bounded by the starting index stidx in stidxs and the ending index edidx in edidxs (requiring that each interval contains at least one unaligned position), and record the interval with the highest score as a candidate low-density region.
[0203] 1) Interval length seglen = edidx - stidx
[0204] 2) Number of unaligned spaces within the interval (unalnum)
[0205] 3) Alignment count alnum = seglen - unalnum
[0206] 4)Score = unalnum / seglen + (unalnum - alnum)
[0207] ③ Adaptive boundary expansion
[0208] Find the length maxalnlen of the longest consecutive alignment sequence (consisting of consecutive '|') in the alignment identifier string align. Based on maxalnlen, determine whether to extend the 5' and 3' boundaries, and return the final (stidx, edidx).
[0209] 1) If the starting index stidx of the candidate low-density region is less than or equal to maxalnlen, it means that the current region is close to the 5' end of the sequence and there is no independent and valid aligned segment at the 5' end of the sequence. In this case, the starting index is extended to 0, that is, the low-density region is extended to the beginning of the sequence to avoid fragmentation.
[0210] 2) If the distance between the ending index position edidx of the candidate low-density region and the right boundary of the alignment identifier string align is ≤ maxalnlen, it indicates that the current region is close to the 3' end of the sequence. In this case, the ending index edidx is extended to the right boundary of the sequence, that is, the low-density region is extended to the end of the sequence. Figure 18 As shown.
[0211] ④ Logic for all variable values and boundary conditions
[0212] 1) Fixed constant boundary
[0213] Boundary expansion criterion: maxalnlen, which is the length of the longest continuous matching segment within the alignment region, serves as the sole criterion for determining the boundary expansion at both ends of the sequence.
[0214] 2) Traverse the loop boundary
[0215] A. Traversing unaligned positions: Traverse all alignment marker characters, only record the start and end index values of spaces, and store them in stidxs and edidxs respectively. The end index value of the same space = the start index value + 1. The traversal end boundary is the total length of the aligned string;
[0216] B. Candidate low-density interval cycle
[0217] a. Starting position traversal loop: Traverse the index values in stidxs as the starting position index of the candidate area. The lower boundary of the loop is the first starting index value recorded in stidxs, and the upper boundary of the loop is the second to last starting index value recorded in stidxs, so that the last space in the alignment identifier string will not be treated as a candidate area alone.
[0218] b. Termination position traversal loop: Traverse the index values in edidxs as the termination position index of the candidate area. When traversing the nth index value in stidxs as the starting position index of the candidate area, the lower boundary of the loop for the termination position is the (n+1)th termination index value recorded in edidxs, ensuring that the candidate area contains at least 2 spaces. The upper boundary of the loop is the last termination index value recorded in edidxs.
[0219] 3) Variable value retrieval logic
[0220] A.seglen: The total length of characters in the low-density candidate interval, with a value > 1;
[0221] B.unalnum: The total number of spaces (unmatched / gap) within the interval, >1;
[0222] C.alnum: Number of matching bases within the interval = seglen - unalnum;
[0223] D. The interval score is calculated as follows: score = unalnum / seglen + (unalnum − alnum). The larger the score, the higher the degree of low density. Only the interval corresponding to the maximum score is retained globally.
[0224] E.stidx / edidx: The final output is the start and end index of a low-density interval, all of which are integers between 0 and the length of the aligned string, and the start < end is always true.
[0225] 4) Expanding the boundary
[0226] A. If the starting index of the candidate region is less than or equal to maxalnlen: force the left boundary stidx to be corrected to 0 (starting point of the 5' end of the sequence, no negative index out of bounds);
[0227] B. If the total sequence length - candidate region termination index ≤ maxalnlen: force the right boundary edidx to be corrected to the full length of the aligned string. The maximum right boundary is equal to the total sequence length, and there is no index that exceeds the sequence length.
[0228] (3) Correction of low-density aligned regions (re-alignment)
[0229] Based on the start and end indices of the low-density region (based on the aligned region), by adding the distance of the aligned region from the 5' end, the start and end indices of the low-density aligned region in the alignment identifier string `align` can be obtained. According to the start and end indices of the low-density region, the reference sequence and query sequence of the low-density region are obtained (both with gaps removed). The bidirectional alignment method `alignBoth` is first called to re-align this subsequence, comparing it with the length of the low-density region. If the length of the re-aligned region does not decrease, the longest common substring segmentation method `aln5LcsAln3` is used for further re-alignment. Finally, the optimized alignment result is replaced back with the corresponding interval of the original alignment result, completing the correction of the low-density region.
[0230] Step S4: Quality Assessment and Filtering
[0231] For the final alignment results generated in LCSC mode, calculate its coverage value: number of matching bases / total length of the matching region. If this ratio is ≥ 0.8 (default alignRatio), the verification passes; otherwise, it is marked as a failure. Figure 19 As shown.
[0232] For CSA mode, the similarity value is calculated as: number of matching bases / length of the longest common subsequence. If this ratio is ≥0.8 (default alignRatio), the validation passes; otherwise, it is marked as a failure. Figure 20 As shown.
[0233] Step S5: Result Output and Visualization
[0234] For successfully validated samples, the system generates a comparison image in JPG format. The image clearly shows the reference sequence and the test sequence with gaps ('-'), alignment identifiers, coordinate scales, and the green-marked positions of the index sequence, such as... Figure 21 As shown. Simultaneously, the system compiles and exports all key information about the samples (sample name, matching template, various comparison indicators, quality control evaluation, etc.) into a single .tsv file for users to download and archive.
[0235] Example 2: This example proposes an automatic verification system for sequencing adapter sequences based on multi-strategy segmentation and alignment. This example describes the system that implements the above method. The system uses the Django framework to build the backend service and integrates the Celery distributed task queue.
[0236] 1. Task Scheduling Module: Responsible for breaking down user-submitted batch tasks into multiple independent sample processing subtasks and concurrently assigning them to multiple Workers for execution. The default concurrency is 10, and dynamic configuration is supported. Simultaneously, the module can monitor the status of each subtask and the overall batch in real time (waiting, running, successful, failed).
[0237] 2. Sequence Alignment Engine: The core component, encapsulating the CSA and LCSC alignment algorithms described in Example 1. This engine receives the sequence to be tested and the matching reference sequence, and returns a string of finely aligned results along with various statistical indicators based on the specified alignment mode.
[0238] 3. Quality Assessment Module: Receives the output of the comparison engine, filters it according to the preset alignRatio threshold (default 0.8), generates a final status of "success" or "failure" for each sample, and fills the evaluation field (such as Good, Poor, Doubt, etc.) if successful.
[0239] (1) Good: If the sample number contains template ID information, then this ID is consistent with the reference sequence number ID. Furthermore, the index sequence segment of the alignment result between the reference sequence and the query sequence completely matches, and there is no gap.
[0240] (2) Poor: If the sample number contains template ID information, then this ID is consistent with the reference sequence number ID. Furthermore, there is a gap in the index sequence region of the alignment result between the reference sequence and the query sequence.
[0241] (3) Doubt: The ID information in the sample number is inconsistent with the ID of the reference sequence number, or the ID is consistent, but there is no index sequence information in the reference sequence, and there is no index sequence matching.
[0242] 4. Data Management Module: The system database uses the `batchinfo` table to manage macro-level batch information and the `adapterinfo` table to store detailed comparison data and result image paths for each sample. On the file system, data is isolated and stored in independent folders by batch ID. The system also provides command-line commands, allowing users to delete all data and records for a specified batch with a single click.
[0243] This invention utilizes innovative CSA and LCSC segmentation-local alignment-recombination strategies to identify and match sequencing results from 21 batches of adapter sequences, totaling 2044 Sanger sequencing result files. Test results show that the CSA mode accurately identified and matched 2026 results, while the LCSC mode accurately identified and matched 2034 results, achieving a success rate of over 99.5% for the LCSC mode.
[0244] Although the present invention has been described in detail above with general descriptions and specific embodiments, modifications or improvements can be made to it, which will be obvious to those skilled in the art. Therefore, all such modifications or improvements made without departing from the spirit of the present invention fall within the scope of protection claimed by the present invention.
Claims
1. An automatic verification method for sequencing adapter sequences based on multi-strategy segmentation and alignment, characterized in that: Includes the following steps: Step S1: Receive and preprocess batch data containing at least one test connector sequence to obtain a standardized and clean test connector sequence; Step S2: Perform a full scan of the connector sequence to be tested against a preset reference sequence library, and select one or more reference sequences with the highest overall matching score; Step S3: To address the different variation characteristics of insertions and deletions in the test linker sequence, which are concentrated in specific regions or scattered throughout the entire sequence, two independent alignment mechanisms, the Longest Common Substring Segmentation (LCSC) and the Common Substring Anchoring (CSA), are designed to obtain the final alignment results. Step S4: Calculate the number of matching bases in the final alignment result, and calculate the similarity value or coverage value according to the selected alignment mechanism. Compare the calculated similarity value or coverage value with the preset alignment ratio threshold. If the requirement is not met, the matching is judged as a failure. Step S5: Generate a visualization image for each successfully aligned sample, including the alignment sequence, gap location, coordinate scale, and index sequence annotation, and output a statistical report containing the sample name, matching template, key alignment indicators, and quality control evaluation.
2. The automatic verification method for sequencing adapter sequences based on multi-strategy segmentation and alignment according to claim 1, characterized in that: The preprocessing step S1 is as follows: all the connector sequences to be tested are cleaned, the base characters of the sequence are uniformly converted to uppercase, and all non-alphabetic invalid characters in the sequence are removed to obtain a standardized and clean connector sequence to be tested.
3. The automatic verification method for sequencing adapter sequences based on multi-strategy segmentation and alignment according to claim 1, characterized in that: The process of screening candidate reference sequences in step S2 is as follows: For each reference sequence, calculate the length of the longest common subsequence (LCS) between the reference sequence and the connector sequence to be tested, and at the same time calculate the sum of the lengths of all common substrings with a length not less than the minimum common substring threshold minCslen. Add the two together as the comprehensive matching score of the reference sequence.
4. The automatic verification method for sequencing adapter sequences based on multi-strategy segmentation and alignment according to claim 3, characterized in that: In step S2, if multiple reference sequences have the same score, conflict resolution is performed based on the template ID extracted from the sample number of the connector sequence to be tested to determine a uniquely matching reference sequence, specifically as follows: Let N be the sample ID string of the connector sequence to be tested, and let ID be the expected template identifier extracted from N using a preset character matching rule. exp Let ID be the set of candidate identifiers composed of multiple reference sequence templates with the highest overall matching scores. top = {id1, id2, …, id n }, determine ID exp Does it belong to ID? top If ID exp ∈ ID top Then the ID exp The corresponding reference sequence is determined to be the uniquely matching reference sequence; if ID exp ∉ID top If the match fails, it is determined that the match has failed.
5. The automatic verification method for sequencing adapter sequences based on multi-strategy segmentation and alignment according to claim 1, characterized in that: The Common Substring Anchoring Pattern (CSA) alignment mechanism in step S3 is used to match the base count / longest common subsequence length to calculate the similarity value. The specific design is as follows: Sub-step S311: Common substring anchoring and correction: Identify all common substrings between the test connector sequence and the reference sequence whose length is greater than or equal to the minimum common substring threshold minCslen, and correct adjacent common substrings with base overlap to ensure that all common substrings do not overlap in the two sequences; Sub-step S312: Sequence Segmentation and Bidirectional Alignment: Using the corrected common substring as anchor points, the reference sequence and the connector sequence to be tested are simultaneously segmented into multiple non-common substring segments and common substring segments; following the order from 5' end to 3' end, the 3' end to 5' end alignment strategy and the 5' end to 3' end alignment strategy are respectively applied to the non-common substring segments at the 5' end and 3' end; the non-common substring segments in the middle section apply the bidirectional comprehensive alignment strategy, that is, both the 5' end to 3' end alignment strategy and the 3' end to 5' end alignment strategy are used simultaneously to generate two candidate alignment results, and then the optimal alignment result is automatically selected according to the following priority rules: Sub-step S3121: Return directly if completely identical: If the alignment identifier strings of the two candidate results are exactly the same, then choose one of them; Sub-step S3122: If both candidate results contain only one matching base, then directly return the result from the 5' end to the 3' end. Sub-step S3123: Compare the lengths of the reference sequence strings in the two candidate results and select the one with the shorter length; Sub-step S3124: If the two lengths are equal, split the alignment identifier string into several consecutive matching segments by spaces, record the length of each segment, and then enter the loop for comparison: Select the alignment result with the longest continuous matching segment; If the lengths of the longest consecutive matching segments of the two are equal and the length is greater than 1, then the one with the more occurrences of the longest consecutive matching segment is selected. If the longest consecutive matching segments of the two are of equal length and the length is equal to 1, then the result from the 5' end to the 3' end is selected; If the longest consecutive matching segments in both lists also appear the same number of times, then remove all segments with the current longest length from both lists and continue comparing the length of the longest segment in the next round. Sub-step S313: Comparison result splicing and optimization: The comparison results of each segment are spliced with the common substring in order to form the initial comparison result; Subsequently, low-density alignment region correction and terminal degenerate base alignment correction were performed sequentially to obtain the final alignment result.
6. The automatic verification method for sequencing adapter sequences based on multi-strategy segmentation and alignment according to claim 1, characterized in that: The low-density alignment region correction in step S313 includes the following steps: First, extract the alignment region from the concatenated alignment identifier string: find the positions of the first and last aligned matching bases, and extract the closed interval [sidx, eidx); count the total number of gaps in the reference sequence revaln and the query sequence seqaln within the closed interval [sidx, eidx), and calculate the alignment region length alnlen = eidx - sidx; if gapnum / alnlen is greater than or equal to 0.2, that is, the proportion of gaps is not less than 20%, then trigger the low-density alignment region location and correction process; The low-density alignment region localization algorithm is used to accurately locate the low-confidence intervals that need to be re-aligned within the alignment region of the comparison identifier strings. The specific steps are as follows: Step S3131: Extract misaligned positions: Convert the input alignment identifier string align into a list. Use lists stidxs and edidxs to record the start and end index information of the unaligned positions in the align list, respectively. The end index value of the same unaligned position is the start index value + 1. Step S3132: Search for the optimal low-density interval: Traverse all possible contiguous sub-intervals, which are defined by the starting index stidx in stidxs and the ending index edidx in edidxs. Each interval contains at least one unaligned position. Record the interval with the highest score as a candidate low-density region. 1) Interval length seglen = edidx - stidx; 2) The number of unaligned spaces within the interval, unalnum, is the number of spaces within the interval; 3) Alignment count alnum = seglen - unalnum; 4)Score = unalnum / seglen + (unalnum - alnum); Step S3133: Adaptive boundary expansion: Find the length of the longest consecutive alignment sequence in the alignment identifier string `align`, `maxalnlen`. Based on `maxalnlen`, determine whether to extend the 5' and 3' boundaries, and return the final value (`stidx`, `edidx`). Step S31331: If the starting index stidx of the candidate low-density region is less than or equal to maxalnlen, it indicates that the current region is close to the 5' end of the sequence and there is no independent and effective aligned segment at the 5' end of the sequence. Then, the starting index is extended to 0, that is, the low-density region is extended to the beginning of the sequence to avoid fragmentation. Step S31332: If the distance between the termination index position edidx of the candidate low-density region and the right boundary of the alignment identifier string align is less than or equal to maxalnlen, it indicates that the current region is close to the end of the sequence 3'. Then, extend the termination index edidx to the right boundary of the sequence, that is, extend the low-density region to the end of the sequence. Step S3134: Logical AND boundary conditions for all variable values: Step S31341: Fix constant boundaries: Boundary expansion criterion: maxalnlen, which is the length of the longest continuous matching segment in the alignment region, serves as the sole criterion for determining the boundary expansion at both ends of the sequence. Step S31342: Traverse the loop boundary: A. Traversing unaligned positions: Traverse all alignment marker characters, only record the start and end index values of spaces, and store them in stidxs and edidxs respectively. The end index value of the same space = the start index value + 1. The traversal end boundary is the total length of the aligned string; B. Candidate low-density interval cycle: a. Starting position traversal loop: Traverse the index values in stidxs as the starting position index of the candidate area. The lower boundary of the loop is the first starting index value recorded in stidxs, and the upper boundary of the loop is the second to last starting index value recorded in stidxs, so that the last space in the alignment identifier string will not be treated as a candidate area alone. b. Termination position traversal loop: Traverse the index values in edidxs as the termination position index of the candidate area. When traversing the nth index value in stidxs as the starting position index of the candidate area, the lower boundary of the loop for the termination position is the (n+1)th termination index value recorded in edidxs, ensuring that the candidate area contains at least 2 spaces. The upper boundary of the loop is the last termination index value recorded in edidxs. Step S31343: Variable value retrieval logic: A.seglen: The total length of characters in the low-density candidate interval, with a value greater than 1; B.unalnum: The total number of spaces in the interval, with a value greater than 1; spaces include unmatched spaces and gaps. C.alnum: Number of matching bases within the interval = seglen - unalnum; D. The interval score is calculated as follows: score = unalnum / seglen + (unalnum − alnum). The larger the score, the higher the degree of low density. Only the interval corresponding to the maximum score is retained globally. E.stidx / edidx: The final output is the start and end index of the low-density interval, all of which are integers between 0 and alnlen. The condition that the start stidx is less than the end edidx is always true. Step S31344: Extend the boundary: A. If the starting index of the candidate region is less than or equal to maxalnlen: force the left boundary stidx to be corrected to 0, the starting point of the sequence at 5', and there is no negative index out of bounds; B. If the total sequence length minus the candidate region termination index is less than or equal to maxalnlen: force the right boundary edidx to be corrected to align with the full length of the string. The maximum right boundary is equal to the total sequence length, and there are no indices that exceed the sequence. Based on the start and end indices of the low-density region, by adding the distance of the alignment region from the 5' end, the start and end indices of the low-density alignment region in the alignment identifier string align can be obtained. According to the start and end indices of the low-density region, the reference sequence and query sequence of the low-density region after removing the gap are obtained. The bidirectional alignment method alignBoth is called to re-align the subsequence and compare it with the length of the low-density region. If the length of the region in the re-alignment result is not reduced, the longest common substring cutting method aln5LcsAln3 is used for further re-alignment. Finally, the optimized alignment result is replaced back with the corresponding interval of the original alignment result to complete the correction of the low-density region.
7. The automatic verification method for sequencing adapter sequences based on multi-strategy segmentation and alignment according to claim 1, characterized in that: The terminal degenerate base alignment correction in step S313 includes the following steps: For the optimized alignment results, check whether there are extra gaps at the end of the reference sequence caused by degenerate bases in the query sequence; if so, call the degenerate base correction method revisRefGaps, re-align the end region based on the predefined degenerate base fuzzy matching rules, and replace the original result to obtain the final alignment result.
8. The automatic verification method for sequencing adapter sequences based on multi-strategy segmentation and alignment according to claim 1, characterized in that: The longest common substring (LCSC) alignment mechanism in step S3 is used to match the number of bases / the length of the region between the first and last matching bases to calculate the coverage value. The specific design is as follows: Sub-step S321: Recursive segmentation and hierarchical alignment: Extract the longest common substring LCStr of the reference sequence and the connector sequence to be tested. Use the longest common substring LCStr as the cutting point to segment the two sequences into 5' end segments and 3' end segments. Perform alignment from 3' end to 5' end for the 5' end segments and from 5' end to 3' end for the 3' end segments. If the longest continuous aligned sequence of the aligned segment is different from the longest common substring LCStr, and the length of the longest common substring LCStr is greater than or equal to the minimum common substring threshold minCslen, then recursively perform the segmentation and alignment process on the segment until the segmentation conditions are no longer met, and record the source and position of each segment with multi-level numerical identifiers. Sub-step S322: Merging hierarchical results: Merge all the segmented alignment fragments in reverse order of identifier values from largest to smallest to generate an initial alignment result; then, obtain the alignment segment of the initial alignment result, which is the region between the first matching base and the last matching base; if the total number of mismatches or insertions / deletions in the alignment segment is less than 3, the initial alignment is considered sufficiently tight, and subsequent optimization steps are skipped directly. The total number of mismatches or insertions / deletions is the number of spaces in the alignment identifier string; otherwise, continue with the following optimization steps. Sub-step S323: Local region re-alignment: (1) Comparison and enrichment region localization: Call the comparison and enrichment region localization algorithm oaer to find the core region with the highest matching density in the alignment identifier string of the initial comparison result, and record it as the enrichment region; (2) Optimization of 5' and 3' regions: The initial alignment result is divided into 5' region and 3' region by the rich region. The number of bases that are completely matched in these two end regions is counted. If the number of matching bases in either region is not less than the preset minimum common substring length threshold minCslen, and the longest continuous alignment sequence maxfrag in the region is different from the longest common substring lcstr, then the longest common substring segmentation alignment strategy aln5LcsAln3 is called for re-alignment, and the original region is replaced with the optimized alignment result. Sub-step S324: Correction of terminal degenerate base alignment: For the alignment result optimized by sub-step S323, check whether there is an extra gap at the end of the reference sequence caused by degenerate bases in the query sequence; if so, call the degenerate base correction method revisRefGaps, re-align the end region based on the predefined degenerate base fuzzy matching rules, and replace the original result to obtain the final alignment result.
9. An automatic verification system for sequencing adapter sequences based on multi-strategy segmentation and alignment, characterized in that: The automatic verification method for sequencing adapter sequences based on multi-strategy segmentation and alignment according to any one of claims 1-8, the system comprising: The task scheduling module, based on an asynchronous task queue, enables the splitting, concurrent execution, and status monitoring of batch tasks in the connector sequence to be tested. The sequence matching and recognition module is used to calculate the longest common subsequence length of the test sequence and each reference sequence and the sum of the lengths of all valid common substrings as the matching score. Candidate reference sequences are selected based on the highest score, and conflict resolution is performed based on the template ID extracted from the sample name. The dual-mode sequence alignment engine includes a CSA alignment submodule that performs the Common Substring Anchoring (CSA) alignment mechanism and an LCSC alignment submodule that performs the Longest Common Substring Cutting (LCSC) alignment mechanism. The sequence processing strategies shared by both alignment submodules include: (1) Alignment strategy align5_3 in the 5'→3' direction: Extract the aligned bases between the test sequence and the reference sequence from the 5' end to the 3' end to obtain the alignment results of the two sequences; (2) Alignment strategy align3_5 in the 3'→5' direction: Extract the aligned bases between the test sequence and the reference sequence from the 3' end to the 5' end to obtain the alignment results of the two sequences; (3) Longest common substring segmentation and alignment strategy aln5LcsAln3: used to optimize the re-alignment of alignment results in local regions; (4) Terminal degenerate base correction: used for fuzzy matching-based re-alignment of degenerate base regions at the ends of sequences; The quality assessment module is used to calculate the similarity or coverage of the comparisons and perform filtering. The data management module stores task batch information, sample comparison details, and audit logs, and is responsible for data isolation and cleanup of the file system.
