Skip to content

Commit 29cc1e1

Browse files
committed
Add first test run ms2query
1 parent a7bc22a commit 29cc1e1

File tree

1 file changed

+34
-0
lines changed

1 file changed

+34
-0
lines changed

tests/test_run_ms2query.py

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
from ms2query.benchmarking.AnnotatedSpectrumSet import AnnotatedSpectrumSet
2+
from ms2query.benchmarking.Fingerprints import Fingerprints
3+
from ms2query.benchmarking.TopKTanimotoScores import TopKTanimotoScores
4+
from ms2query.run_ms2query import extract_metadata_from_library, run_ms2query
5+
from tests.helper_functions import create_test_spectra, ms2deepscore_model
6+
7+
8+
def test_run_ms2query():
9+
model = ms2deepscore_model()
10+
library_spectra = AnnotatedSpectrumSet.create_spectrum_set(create_test_spectra(nr_of_inchikeys=7))
11+
test_spectra = AnnotatedSpectrumSet.create_spectrum_set(create_test_spectra(1, nr_of_inchikeys=3))
12+
library_spectra.add_embeddings(model)
13+
test_spectra.add_embeddings(model)
14+
fingerprints = Fingerprints.from_spectrum_set(library_spectra, "daylight", 100)
15+
top_k_tanimoto_scores = TopKTanimotoScores.calculate_from_fingerprints(fingerprints, fingerprints, 3)
16+
spectrum_indices_per_inchikey = library_spectra.spectrum_indices_per_inchikey
17+
metadata_library = extract_metadata_from_library(
18+
library_spectra,
19+
[
20+
"precursor_mz",
21+
"collision_energy",
22+
"compound_name",
23+
"smiles",
24+
"inchikey",
25+
],
26+
)
27+
results = run_ms2query(
28+
test_spectra.embeddings,
29+
library_spectra.embeddings,
30+
metadata_library,
31+
spectrum_indices_per_inchikey,
32+
top_k_tanimoto_scores,
33+
)
34+
print(results)

0 commit comments

Comments
 (0)