Quality Scores
glc.QualityScorer
Compute quality scores for features based on prediction confidence and local neighborhood consistency in UMAP space.
The following scores are computed:
-
PCOR score: GLC score of the top ranking prediction over the sum of the scores of the top 10 ranking. Noramlized to [0, 1] via quantile transformation. Called the PCOR score (partial correlation score) as GLC scoring is based on partial correlations. Higher GLC scores for a feature tend to results from a combination of i.) more database matches and ii.) stronger partial correlations For the PCOR score, we are seeking to capture how dominant the top prediction is compared to other predictions for that feature.
-
LSI score: Local Simpson's Index measuring the diversity of subclass predictions among k-nearest neighbors in UMAP space of the GGM. Based on the assumption that GGM structure encodes lipid class. We expect that nearest features have the same lipid class.
-
Product score: Product of PCOR and LSI scores, quantile-scaled to [0, 1].
-
The quality scores should be interpreted as the higher the score, the higher the GLC prediction confidence for that feature.
- However, note of caution, these quality scores are dataset specific and cannot be directly compared across datasets.
Source code in src/glc/quality_scores.py
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 | |
__init__(prediction_dict, embedder_obj, k=5)
Initialize the QualityScorer and compute all quality metrics.
Upon initialization, the following steps are performed: - Encode subclass labels - Compute k-nearest neighbors in UMAP space - Calculate LSI, PCOR, and product quality scores - Assemble the results into a single DataFrame
The primary output of this class is the df attribute, which contains the quality scores for each feature.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
prediction_dict
|
Dict[int, List[Tuple[str, float]]]
|
GLC predictions output. A mapping from feature to subclass prediction. |
required |
embedder_obj
|
UMAPEmbedder
|
Fitted UMAPEmbedder object of the GGM structure. |
required |
k
|
int
|
Number of neighbors used for local diversity calculations. |
5
|
Attributes:
| Name | Type | Description |
|---|---|---|
df |
DataFrame
|
DataFrame with one row per feature and the following columns: - feature: Feature identifier - subclass: Top predicted subclass - lsi_score: Local Simpson's Index score - pcor_score: Quantile-scaled PCOR score - product_score: Combined quality score in [0, 1] |
Source code in src/glc/quality_scores.py
38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 | |
glc.build_prediction_dataframe(subclass_predictions, mainclass_predictions, quality_score_df, feat_dicts)
Build a tidy DataFrame summarizing GLC subclass and main class predictions together with feature metadata and quality scores.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
subclass_predictions
|
Dict[int, List[Tuple[str, float]]]
|
Dictionary mapping peak_id to a list of subclass predictions. Each entry is expected to be a ranked list, where the top prediction is accessed as subclass_predictions'[peak_id][0][0]'. |
required |
mainclass_predictions
|
Dict[int, List[Tuple[str, float]]]
|
Dictionary mapping peak_id to a list of main class predictions, structured analogously to subclass_predictions. |
required |
quality_score_df
|
DataFrame
|
DataFrame indexed by peak_id containing quality score columns 'lsi_score', 'pcor_score', and 'product_score'. |
required |
feat_dicts
|
FeatDicts
|
A glc.FeatDicts object providing dictionary-like access to feature m/z and retention time via feat_dicts.mz and feat_dicts.rt. |
required |
Returns:
| Type | Description |
|---|---|
DataFrame
|
pd.DataFrame: A DataFrame with one row per peak_id containing feature metadata, predicted subclass and main class, and associated quality scores. |
Source code in src/glc/glc_model.py
234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 | |