## 7 Guide for Integrating WFDB Tools, a Future Prospect  
WFDB tools are crucial for validating predicted R-peaks, as they handle non-beats and compare actual beats based on defined ANSI/AAMI testing protocols and defined guidelines. However, upon reviewing the available literature and PhysioNet databases related to WFDB tools, it becomes evident that there is lack of guidance and the related information is scattered. This makes it challenging to determine which parameters are critical for R-peak validation, as various parameters are required to obtain SUMSTAT evaluation metrics, and additional parameters are necessary to identify annotation discrepancies and their sample values according to AAMI standard mnemonics. Similarly, there is a lack of clarity on how to effectively integrate WFDB tools to conduct the validation process simultaneously across the entire dataset. To bridge this gap, a structured hierarchy is proposed, which can be coded to develop a graphical user interface (GUI). The proposed structured hierarchy is shown in Figure 9. The main directory is named \"Validate\", and it contains various subfolders:  
1. **Peak Samples**: It stores the predicted R-peak samples as individual CSV files for each record. Each predicted file is placed in a separate folder, with the folder name corresponding to the processed individual record. Each CSV file must contain the predicted samples in a single-column matrix. 2. **Comparator**: This folder stores the predicted annotation files (pred) for the R-peak samples produced by the WRANN function. These annotations are generated by processing subfolders for each record within the \"Peak Samples\" folder. The Comparator folder also stores the reference annotations (atr) and their corresponding records downloaded from the PhysioNet online directory. These predicted and reference R-peak annotations will be used for window-based comparison. 3. **Results**: It is the target folder to store all resulting metrics, including TPs, FPs, FNs, positive predictivity, and sensitivity in the form of a CSV report file. 4. **CM:** It is a subfolder of \"Results\" that stores confusion matrices for each record in txt or text format. 5. **Error**: It is also a subfolder of \"Results\" that stores details of the actual annotation discrepancies for each record in txt format. The \"Validate\" algorithm can serve as the main component of this hierarchy, performing validation for all predicted R-peaks and providing statistical results and annotation discrepancies. The \"Sort/Visualize\" algorithm can then categorize these discrepancies into FPs and FNs according to standard label mismatches [74]. To sort the discrepancies, a loop can be set up to check if \"O\" or \"X\" appears on the left side in any annotation difference file, which will be considered an FP, and if it appears on the right side, it will be considered an FN, as illustrated in Figure 9. Any WFDB comparator can be integrated into this pipeline; here, we use the bxb function as an example due to its frequent use in the literature. The bxb function requires several inputs, including the path to the folder containing expert and predicted annotations with extensions atr and pred and a path where the generated CSV will be saved. It further requires a start time, end time, and window size [75; 95] as given below. box (Input path, 'atr', 'pred', path out,'start time', 'end time', 'window size')  
Moreover, to generate annotation differences, a command line can be encoded in the same file as given below. boxb (-r file, -a atr pred, -f 0, -o, -v 2, target folder)  
Here, -r file specifies the record to analyze, -a atr pred indicates the respective annotation files to compare, -f 0 ensures that the analysis starts from the beginning of the record, and -o enables detailed output for each annotation difference in the AAMI-defined mnemonics  
Figure 9: Proposed structured hierarchy that could be utilized for ECG R-peak Validation. format.