@@ -104,27 +104,50 @@ F1 <- function(a, b) {
104
104
105
105
# # follow GLIMPSE2_concordance
106
106
# # None Reference Concordnace = 1 - (e0 + e1 + e2) / (e0 + e1 + e2 + m1 + m2)
107
+ # # = (m1 + m2) / (sum(m) - m[ref,ref])
107
108
# # truth\imputed
108
109
# # 0 1 2
109
110
# # 0 ignore e0 e0
110
111
# # 1 e1 m1 e1
111
112
# # 2 e2 e2 m2
112
113
# # a <- c(1, 2, 0, 1,1)
113
- # # b <- c(1, 2, 0, 0 ,1)
114
+ # # b <- c(1, 2, 1, 1 ,1)
114
115
# # NRC(a, b)
115
- NRC <- function (a , b ) {
116
- o <- table(as.vector(a ), as.vector(b ))
117
- # # make sure table is valid
118
- if ( ! ((nrow(o ) == ncol(o )) && (nrow(o ) == 3 )) ) {
119
- warning(" NRC should be used only for a sample with genotypes of all types, hom ref(0), het(1) and hom alt(2)" )
120
- return (NA )
116
+ # # a <- c(1, 2, 0, 1,1)
117
+ # # b <- c(0, 2, 1, 1,1)
118
+ # # NRC(a, b)
119
+ # # a <- c(1, 2, 1, 1,1)
120
+ # # b <- c(2, 1, 1, 1,1)
121
+ # # NRC(a, b)
122
+ # # a <- c(1, 2, 1, 1,1)
123
+ # # b <- c(1, 1, 1, 1,1)
124
+ # # NRC(a, b)
125
+ NRC <- function (a , b , ref = 0 ) {
126
+ # Ensure vectors are treated as factors with all common levels
127
+ all_levels <- union(unique(a ), unique(b ))
128
+ a_fct <- factor (a , levels = all_levels )
129
+ b_fct <- factor (b , levels = all_levels )
130
+ tbl <- table(a_fct , b_fct )
131
+ ref_char <- as.character(ref )
132
+ # Get reference-reference count
133
+ if (ref_char %in% rownames(tbl ) && ref_char %in% colnames(tbl )) {
134
+ ref_ref <- tbl [ref_char , ref_char ]
135
+ } else {
136
+ ref_ref <- 0
137
+ }
138
+
139
+ total_concordant <- sum(diag(tbl ))
140
+ non_ref_concordant <- total_concordant - ref_ref
141
+ total_non_ref <- sum(tbl ) - ref_ref
142
+
143
+ if (total_non_ref == 0 ) {
144
+ return (NA ) # Handle case with no non-reference pairs
145
+ } else {
146
+ return (non_ref_concordant / total_non_ref )
121
147
}
122
- mismatches <- sum(c(o [1 ,2 : 3 ], o [2 ,1 ], o [2 ,3 ], o [3 ,1 : 2 ]))
123
- matches <- sum(c(o [2 ,2 ], o [3 ,3 ]))
124
- res <- mismatches / (mismatches + matches )
125
- return (1 - res )
126
148
}
127
149
150
+
128
151
calculate_pse_2ways <- function (test ,
129
152
truth ,
130
153
which_snps ,
0 commit comments