Spec2Vec Module¶
Annotation¶
annotation
¶
calc_embeddings
¶
calc_embeddings(s2v_similarity, spectra)
Calculate spectral embeddings for a list of spectra.
Source code in MS2LDA/Add_On/Spec2Vec/annotation.py
21 22 23 24 25 26 27 |
|
calc_similarity_faiss
¶
calc_similarity_faiss(embeddings_A, embeddings_B, k=None)
Calculate cosine similarity using Faiss, ensuring proper normalization.
Source code in MS2LDA/Add_On/Spec2Vec/annotation.py
62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 |
|
get_library_matches
¶
get_library_matches(similarities, indices, db_path, top_n=10, unique_mols=True)
Return similarity scores, SMILES, and spectra for top n matches for all motifs.
Source code in MS2LDA/Add_On/Spec2Vec/annotation.py
129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 |
|
get_library_matches_per_motif
¶
get_library_matches_per_motif(
similarities, indices, db_path, motif_number=0, top_n=10, unique_mols=True
)
Return similarity scores, SMILES, and spectra for top n matches for one motif.
Source code in MS2LDA/Add_On/Spec2Vec/annotation.py
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 |
|
load_s2v_model
¶
load_s2v_model(path_model)
Load Spec2Vec model.
Source code in MS2LDA/Add_On/Spec2Vec/annotation.py
12 13 14 15 16 17 18 |
|
load_spectrum_from_db
¶
load_spectrum_from_db(db_path, spectrum_id)
Load a spectrum from the SQLite database by ID.
Source code in MS2LDA/Add_On/Spec2Vec/annotation.py
41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 |
|
normalize_embeddings
¶
normalize_embeddings(embeddings)
Normalize embeddings safely to avoid overflow and NaN issues.
Source code in MS2LDA/Add_On/Spec2Vec/annotation.py
30 31 32 33 34 35 36 37 38 |
|
Refined Annotation¶
annotation_refined
¶
calc_similarity
¶
calc_similarity(embeddings_A, embeddings_B)
calculates the cosine similarity of spectral embeddings
Parameters:
Name | Type | Description | Default |
---|---|---|---|
embeddings_A
|
array
|
query spectral embeddings |
required |
embeddings_B
|
array
|
reference spectral embeddings |
required |
Returns:
Name | Type | Description |
---|---|---|
similarities_scores |
list
|
list of lists with s2v similarity scores |
Source code in MS2LDA/Add_On/Spec2Vec/annotation_refined.py
354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 |
|
calc_similarity_matrix
¶
calc_similarity_matrix(s2v_similarity, top_n_spectra, masked_spectra)
Calculates a similarity matrix between top hits.
Source code in MS2LDA/Add_On/Spec2Vec/annotation_refined.py
381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 |
|
get_mz
¶
get_mz(spectra, frag_err=2, loss_err=2)
extracts fragments and losses from a list of spectra
Parameters:
Name | Type | Description | Default |
---|---|---|---|
spectra
|
list
|
list of matchms spectra objects |
required |
frag_err
|
int; default = 2
|
number of significant digits to round for fragments |
2
|
loss_err
|
int; default = 2
|
number of significant digits to round for losses |
2
|
Returns:
Name | Type | Description |
---|---|---|
fragments_mz |
list
|
list of rounded float numbers for fragments |
losses_mz |
list
|
list of rounded float numbers for losses |
Source code in MS2LDA/Add_On/Spec2Vec/annotation_refined.py
27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 |
|
hits_intersection
¶
hits_intersection(features)
returns values that a present across all input lists
Parameters:
Name | Type | Description | Default |
---|---|---|---|
features
|
list
|
list of either losses or fragments |
required |
Returns:
Name | Type | Description |
---|---|---|
common_features |
list
|
list of either losses or fragments that are the intersection of the given lists |
Source code in MS2LDA/Add_On/Spec2Vec/annotation_refined.py
48 49 50 51 52 53 54 55 56 57 58 |
|
mask_fragments
¶
mask_fragments(spectrum, mask=1.0)
masks fragments one by one
Parameters:
Name | Type | Description | Default |
---|---|---|---|
spectrum
|
matchms spectrum object |
required | |
mask
|
float
|
mz with which fragments will be replaced with |
1.0
|
Returns:
Name | Type | Description |
---|---|---|
masked_spectra |
list
|
list of matchms spectrum objects |
Source code in MS2LDA/Add_On/Spec2Vec/annotation_refined.py
230 231 232 233 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 |
|
mask_losses
¶
mask_losses(spectrum, mask=0.0)
masks losses one by one
Parameters:
Name | Type | Description | Default |
---|---|---|---|
spectrum
|
matchms spectrum object |
required | |
mask
|
float
|
mz with which losses will be replaced with |
0.0
|
Returns:
Name | Type | Description |
---|---|---|
masked_spectra |
list
|
list of matchms spectrum objects |
Source code in MS2LDA/Add_On/Spec2Vec/annotation_refined.py
276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 |
|
mask_spectra
¶
mask_spectra(motif_spectra, masks=[-1.0, -1.0])
mask the fragments and losses for a list of spectra 1. mask is for fragments 2. mask is for losses
Parameters:
Name | Type | Description | Default |
---|---|---|---|
motif_spectra
|
list
|
list of matchms spectrum objects |
required |
masks
|
list
|
list of float values for fragment and loss mask |
[-1.0, -1.0]
|
Returns:
Name | Type | Description |
---|---|---|
masked_motifs_spectra |
list
|
list of lists of matchms spectrum objects; every list is for one motif |
Source code in MS2LDA/Add_On/Spec2Vec/annotation_refined.py
324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 |
|
motif_intersection_fragments
¶
motif_intersection_fragments(motif_spectrum, common_fragments, frag_err=2)
retrieves mz values and intensities for fragments that are the intersection between the motif spectrum and the common hits fragments
Parameters:
Name | Type | Description | Default |
---|---|---|---|
motif_spectrum
|
matchms.spectrum.object |
required | |
common_fragments
|
list
|
list of float values |
required |
frag_err
|
int, default = 2
|
number of significant digits to round for fragments |
2
|
Returns:
Name | Type | Description |
---|---|---|
opt_motif_fragments_mz |
list
|
list of float values representing mz values for an optimized motif |
opt_motif_fragments_intensities |
list
|
list of float values representing intensity values for an optimized motif |
Source code in MS2LDA/Add_On/Spec2Vec/annotation_refined.py
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 |
|
motif_intersection_losses
¶
motif_intersection_losses(motif_spectrum, common_losses, loss_err=2)
retrieves mz values and intensities for losses that are the intersection between the motif spectrum and the common hits losses
Parameters:
Name | Type | Description | Default |
---|---|---|---|
motif_spectrum
|
matchms.spectrum.object |
required | |
common_losses
|
list
|
list of float values |
required |
loss_err
|
int, default = 2
|
number of significant digits to round for losses |
2
|
Returns:
Name | Type | Description |
---|---|---|
opt_motif_losses_mz |
list
|
list of float values representing mz values for an optimized motif |
opt_motif_losses_intensities |
list
|
list of float values representing intensity values for an optimized motif |
Source code in MS2LDA/Add_On/Spec2Vec/annotation_refined.py
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 |
|
optimize_motif_spectrum
¶
optimize_motif_spectrum(
motif_spectrum, hit_spectra, smiles_cluster, frag_err=2, loss_err=2
)
runs all scripts from extracting features to overlapping them and creating an optimized motif
Parameters:
Name | Type | Description | Default |
---|---|---|---|
motif_spectrum
|
matchms spectrum object |
required | |
hit_spectra
|
list
|
list of matchms spectrum objects |
required |
frag_err
|
int; default = 2
|
number of significant digits to round for fragments |
2
|
loss_err
|
int; default = 2
|
number of significant digits to round for losses |
2
|
Returns:
Name | Type | Description |
---|---|---|
opt_motif_spectrum |
matchms spectrum object |
Source code in MS2LDA/Add_On/Spec2Vec/annotation_refined.py
184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 |
|
reconstruct_motif_spectrum
¶
reconstruct_motif_spectrum(
opt_motif_fragments_mz,
opt_motif_fragments_intensities,
opt_motif_losses_mz,
opt_motif_losses_intensities,
)
creates a matchms spectrum object based on the optimized features
Parameters:
Name | Type | Description | Default |
---|---|---|---|
opt_motif_fragments_mz
|
list
|
list of float values representing mz values for an optimized motif (fragments) |
required |
opt_motif_fragments_intensities
|
list
|
list of float values representing intensity values for an optimized motif (fragments) |
required |
opt_motif_losses_mz
|
list
|
list of float values representing mz values for an optimized motif (losses) |
required |
opt_motif_losses_intensities
|
list
|
list of float values representing intensity values for an optimized motif (losses) |
required |
Returns:
Name | Type | Description |
---|---|---|
opt_motif_spectrum |
matchms spectrum object |
Source code in MS2LDA/Add_On/Spec2Vec/annotation_refined.py
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 |
|