Materials and Methods
Medical data from breast cancer patients who underwent BRCA gene testing at Chongqing University Cancer Hospital (CUCH) between May 2017 and December 2022 were retrospectively reviewed. The inclusion criteria were: (1) Diagnosis with primary breast invasive ductal cancer (IDC) or invasive Lobular carcinoma (ILC); (2) conduct of BRCA gene or genomic testing on blood and/or tumor samples, which included the examination of germline and/or somatic variations; (3) availability of operative pathological H&E images before antineoplastic treatments were available; The exclusion criteria were: (1) Lack of operative pathological H&E images; (2) poor quality of H&E-stained images; (3) presence of bilateral, multifocal, or special invasive breast cancer. Adhere to the WHO guidance on Ethics & Governance of Artificial Intelligence for Health was maintained. The study was approved by the Ethics Committee of Chongqing University Cancer Hospital (Ethics number: CZLS2023213-A) and patient consent was waived for this retrospective analysis. In reporting the results, the Standards for Reporting Diagnostic Accuracy Studies (STARD) 2015 guidelines were strictly followed.

This study included two cohorts. The first cohort consisted of 152 patients (217 WSIs) collected from Chongqing University Cancer Hospital between May 2017 and December 2022. The second cohort consisted of 102 patients (102 WSIs) collected from The Cancer Genome Atlas ( https://gdc.cancer.gov/ ). The CUCH cohort was randomly divided into a training set and an internal test set, while the TCGA cohort served as an independent external test set. The training set was utilized for hyperparameter tuning through cross-validation, and the test sets were used to assess generalization performance.

Genomic DNA samples were extracted from peripheral blood and/or surgical tissue samples. The BRCA genetic testing was conducted using next-generation sequencing (NGS) technology. Variants were annotated following the Human Genome Variation Society (HGVS) nomenclature guidelines ( http://varnomen.hgvs.org/ ). The biological significance of all reported variants was assessed using the ClinVar database ( www.ncbi.nlm.nih.gov/clinvar/ ). According to the guidelines of the American College of Medical Genetics and Genomics (ACMG) ( Richards et al., 2015 ), the detected variants were classified as pathogenic variants, likely pathogenic variants, variants of uncertain significance, likely benign, or benign. Patients identified with pathogenic and likely pathogenic variants were categorized into the BRCA PV group, which includes BRCA1 PV and BRCA2 PV. Patients identified with variants of uncertain significance, likely benign, or benign variants were categorized into the BRCA WT group. Pathogenicity was defined as any copy loss event (heterozygous or homozygous) in the BRCA1 and BRCA2 genes, as well as truncating or exonic single-nucleotide alterations/indels less than 10 bp in length that are labeled as “pathogenic/likely pathogenic” in ClinVar. The study focused on predicting these two binary outcomes, BRCA PV and BRCA WT for breast cancer patients.

All samples were fixed in 4% neutral formalin, embedded in paraffin, cut into 4 μm thick sections, and stained with H&E. The H&E-stained histopathological slides were scanned at 40× magnification using a KFBIO KF-PRO-005 digital scanner and saved in SVS format. Experienced pathologists with over 1 year of specialization in breast cancer pathology, performed quality control on the images. Slides of poor quality, particularly those with tissue folds and blurriness, were excluded. The TCGA cohort exclusively utilized 40× FFPE WSIs labeled as diagnostic, while excluding slides marred by pen marks or inadequate staining. The WSIs were segmented into tiles of 512 × 512 pixels, with 50% overlap. Tiles displaying more than 75% of the background were discarded. Observed color variations, attributable to differences in raw materials, manufacturing processes, staining methods, and different digital scanners, can cause models to focus on color differences rather than essential tissue morphology for analysis. To address this issue, color normalization was applied to all tiles using the structure-preserving color normalization (SPCN) technique ( Vahadane et al., 2016 ). The model standardized the color pattern of all tiles to resemble that of the target ( Fig. S1 ). Various data augmentation techniques were employed, including random flipping, random rotation, cropping, and adjustments to brightness, contrast, saturation, and hue.

A stratified sampling approach was used to randomly assign images to the training and internal test set, maintaining an 8:2 ratio at the patient level. This method ensures that images of the same patient are assigned exclusively to either the training set or the internal test set, preventing images from the same patient from appearing in both sets simultaneously.

A segmentation network was constructed to automatically identify tumor regions in WSIs. Two experienced pathologists, each with over 3 years of experience in breast cancer pathology, annotated tumor areas on 145 WSIs using the open-source software Qupath Image Scope. These annotated areas were subsequently reviewed independently by a pathologist with over 10 years of experience. The labeled slides were randomly divided into a training set (80%) and a test set (20%), ensuring that WSIs from the same patient did not appear in both sets. Utilizing the ResNet 34 architecture, the network processed tiles from both tumor and non-tumor regions. Deep convolutional and pooling layers extracted features from each tile, which were then passed to the fully connected layer. Following the fully connected layer, a softmax function generated a probability (tumor or non-tumor) for each tile. The network’s performance was evaluated by comparing its results with the manual annotations made by three pathologists of varying experience levels-junior, medium, and senior, with 2, 5 to 8, and 10 years of experience, respectively. Ultimately, this segmentation network was utilized to automatically segment tumor regions in the TCGA cohort.

The CUCH cohort comprised 217 WSIs from 152 patients, each contributing one or two slides. The dataset was stratified and randomly divided into a training set (633,484 tiles from 174 WSIs) and an internal test set (112,096 tiles from 43 WSIs). The BiAMIL network was developed using a multi-instance learning (MIL) framework and attention mechanisms. This architecture included three main components: the feature extraction module based on the ResNet 34 model ( He et al., 2016 ), the bi-directional self-attention module, and the classification module. A bag containing N image tiles was inputted into the feature extractor, generating a feature matrix with dimensions of N × 1000. This feature matrix was processed through the attention module for aggregation. In the bi-directional self-attention module, data features were transformed into embedding vectors via a feature embedding layer. Two attention heads were then designed: a high-risk PV head and a low-risk PV head. Each head utilizes independent core weight matrices W k , W q , W v . For each head, the 1,000-dimensional embedding features in each instance are transformed into matrices K = { W k i 1 , W k i 2 , ⋯ , W k i N } , Q = { W q i 1 , W q i 2 , ⋯ , W q i N } and V = { W v i 1 , W v i 2 , ⋯ , W v i N } through linear transformations. The attention score matrix α is defined as α = K T Q . Each element α i , j in α is computed as the inner product of the i-th row of Q and the j-th column of K T , for example α 1 , 2 = k 1 ⋅ q 2 = ∑ i = 1 D ⁡ k 1 , i q 2 , i . Subsequently, the attention matrix A is calculated as A = V × S o f t m a x ( α ) . For each embedding feature vector, the corresponding attention vector is denoted by a i = A v i , where v i represents the i-th column of matrix V , such that a i = ∑ n = 1 N ⁡ v i α i , n . Let A h and A l ∈ R N × 1000 denote the attention matrices generated separately by the two-head self-attention mechanism. The overall attention matrix A c = { A h : A l } h is formed by concatenating A h and A l . A weight vector w is used to transform A c into the final attention weights F A W T ∈ R 1000 × 1 via a linear transformation F A W = σ ( W A T A c ) . The resulting F A W T represents the attentional representation of the instance bag. The weight vector W A plays a critical role in governing the learning process of the high-risk and low-risk PV heads, optimized using the following loss function:

l o s s = − ∑ i = 1 C ⁡ y i l o g ( S o f t m a x M L P ( γ m a s k ( W A T A c ) h + μ m a s k ( W A T A c ) l ) ) .

The hyperparameters γ and μ are initially initialized to 0.5. As the learning process progresses, these parameters gradually converge towards their optimal values. Two sets of attention-weighted discriminative feature vectors were generated, each set having a dimensionality of 1,000. These two 1,000-dimensional integrated feature vectors were merged and inputted into the classification module. The classification module consisted of a three-layer multilayer perceptron (MLP) with 1,000, 64, and two neurons in each layer, respectively, utilizing the Tanh function as the activation function. The prediction probability for each instance bag was ultimately output through the softmax function. To optimize the model, we employed a five-fold cross-validation by randomly dividing the training set into five balanced subsets ( Fig. S2 ). Using the Adam optimizer, the optimal hyperparameters were identified as a bag of N = 35, a learning rate of 0.001, a batch size of 18, and total epochs of 20 (with the learning rate decreasing by 0.1 every ten epochs). At last, the network was evaluated on the internal and external test sets.

To elucidate the critical histological features most influential in the BiAMIL model’s predictions, the top 20% of tiles, based on their attention scores for predicting BRCA status, were selected. Attention-based visualization techniques were employed to visually represent these tiles. First, the weight values for each tile were calculated. Subsequently, the top 20% of tiles in WSIs with high attention weights were identified, and Smooth Grad-CAM was used to pinpoint the regions within each tile that the neural network relied on for generating predictions. We used cell detection and classification functions using QuPath to identify three types of cells, tumor cells, tumor-infiltrating lymphocytes (TILs), and stroma. TILs% calculated as follows:

T I L s % = T I L s T I L s + T u m o r c e l l s × 100 % .

Cell features, including cell morphology, nuclear morphology, and staining features, were extracted from the tumor regions ( Bankhead et al., 2017 ). Cells were then classified into different clusters using the k-means clustering method based on their cell features. These clusters were projected onto a 2-D UMAP projection ( Dorrity et al., 2020 ). The differences in cell features between BRCA PV and WT were assessed using the Wilcoxon rank-sum test.

The performance of the model was evaluated at the slide level. A probability value was generated for each bag, and a final probability for each slide was determined by calculating the average probability across all bags within the slide. The model’s performance was assessed using several measures, including area under the receiver operating characteristic curve (AUROC), accuracy, sensitivity, specificity, positive predictive value (PPV), negative predictive value (NPV), and F1 score. The most relevant cell features for discriminating between BRCA PV and BRCA WT were identified using the Wilcoxon rank-sum test. All statistical analyses were performed using scikit-learn 0.24.2 in Python and R (version 4.1.1; R Core Team, 2021 ), with a p -value of less than 0.05 was considered statistically significant.