@@ -106,22 +106,27 @@ calculateEpletLoad <- function(recipient_geno,
106106 )
107107 names(eplet_sets ) <- all_alleles
108108
109- # Helper: donor-specific eplet count for one pair
109+ # Helper: donor-specific eplet count for one pair (used for pairwise matrix)
110110 pair_count <- function (rec_a , don_a ) {
111111 if (identical(rec_a , don_a )) return (0L )
112112 rec_set <- eplet_sets [[rec_a ]]
113113 don_set <- eplet_sets [[don_a ]]
114114 length(setdiff(don_set , rec_set ))
115115 }
116-
117- # Helper: total per locus
116+
117+ # Helper: total per locus - uses union of all recipient allele eplets vs union of all donor allele eplets
118118 locus_total <- function (L ) {
119119 rL <- r_alleles [grep(paste0(" ^" , L , " _" ), names(r_alleles ))]
120120 dL <- d_alleles [grep(paste0(" ^" , L , " _" ), names(d_alleles ))]
121121 if (length(rL ) == 0L || length(dL ) == 0L ) return (0L )
122- total <- 0L
123- for (ra in rL ) for (da in dL ) total <- total + pair_count(ra , da )
124- total
122+
123+ # Union of all recipient eplets at this locus
124+ rec_union <- unique(unlist(eplet_sets [rL ], use.names = FALSE ))
125+ # Union of all donor eplets at this locus
126+ don_union <- unique(unlist(eplet_sets [dL ], use.names = FALSE ))
127+
128+ # Count donor-specific eplets (in donor but not in recipient)
129+ length(setdiff(don_union , rec_union ))
125130 }
126131
127132 if (return == " total" ) {
0 commit comments