Skip to content

Commit f9ccd6d

Browse files
committed
linting
1 parent 2da61bf commit f9ccd6d

File tree

6 files changed

+24
-24
lines changed

6 files changed

+24
-24
lines changed

ms2query/database/ann_index.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -386,7 +386,10 @@ def get_embeddings(
386386
cur.execute("SELECT merged_id, embedding FROM merged_embeddings ORDER BY merged_id ASC;")
387387
else:
388388
ph = ",".join("?" for _ in ids)
389-
cur.execute(f"SELECT merged_id, embedding FROM merged_embeddings WHERE merged_id IN ({ph}) ORDER BY merged_id ASC;", ids)
389+
cur.execute(
390+
f"SELECT merged_id, embedding FROM merged_embeddings WHERE merged_id IN ({ph}) ORDER BY merged_id ASC;",
391+
ids
392+
)
390393

391394
mids = []
392395
vecs = []

ms2query/database/compound_database.py

Lines changed: 10 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,7 @@
44
from typing import Any, Dict, Iterable, List, Optional, Tuple, Union
55
import numpy as np
66
import pandas as pd
7-
from ms2query.data_processing import inchikey14_from_full, compute_morgan_fingerprints
8-
7+
from ms2query.data_processing import compute_morgan_fingerprints, inchikey14_from_full
98

109

1110
# =========================
@@ -144,9 +143,6 @@ def _ensure_schema(self):
144143
inchi TEXT,
145144
inchikey TEXT UNIQUE,
146145
147-
-- legacy single blob (kept for compat)
148-
fingerprint BLOB,
149-
150146
-- sparse storage (pair)
151147
fingerprint_bits BLOB,
152148
fingerprint_counts BLOB,
@@ -157,11 +153,10 @@ def _ensure_schema(self):
157153
-- FP metadata
158154
fp_nbits INTEGER,
159155
fp_radius INTEGER,
160-
fp_sparse INTEGER, -- 1/0
161-
fp_count INTEGER, -- 1/0
156+
fp_sparse INTEGER,
157+
fp_count INTEGER,
162158
fp_dtype TEXT,
163159
164-
-- classyfire (may be missing in older DBs)
165160
classyfire_class TEXT,
166161
classyfire_superclass TEXT
167162
);
@@ -225,7 +220,6 @@ def _pack_fp_for_write(
225220

226221
# Decide on representation based on requested flags
227222
is_sparse = bool(cols["fp_sparse"])
228-
is_count = bool(cols["fp_count"])
229223

230224
if is_sparse:
231225
# fp may be (bits, counts) or just bits
@@ -361,14 +355,15 @@ def upsert_many(self, rows: Iterable[Dict[str, Any]]) -> List[str]:
361355
WHEN COALESCE(LENGTH(excluded.fingerprint_dense),0) > 0
362356
THEN excluded.fingerprint_dense ELSE {self.table}.fingerprint_dense END,
363357
364-
fp_nbits = COALESCE(excluded.fp_nbits, {self.table}.fp_nbits),
358+
fp_nbits = COALESCE(excluded.fp_nbits, {self.table}.fp_nbits),
365359
fp_radius = COALESCE(excluded.fp_radius, {self.table}.fp_radius),
366360
fp_sparse = COALESCE(excluded.fp_sparse, {self.table}.fp_sparse),
367-
fp_count = COALESCE(excluded.fp_count, {self.table}.fp_count),
368-
fp_dtype = COALESCE(excluded.fp_dtype, {self.table}.fp_dtype),
361+
fp_count = COALESCE(excluded.fp_count, {self.table}.fp_count),
362+
fp_dtype = COALESCE(excluded.fp_dtype, {self.table}.fp_dtype),
369363
370364
classyfire_class=COALESCE(excluded.classyfire_class, {self.table}.classyfire_class),
371-
classyfire_superclass=COALESCE(excluded.classyfire_superclass, {self.table}.classyfire_superclass)
365+
classyfire_superclass=COALESCE(excluded.classyfire_superclass,
366+
{self.table}.classyfire_superclass)
372367
""", (
373368
comp_id,
374369
r.get("smiles"),
@@ -817,9 +812,6 @@ def _ensure_schema(self):
817812
spec_id INTEGER NOT NULL,
818813
comp_id TEXT NOT NULL,
819814
PRIMARY KEY (spec_id),
820-
-- implicit: comp_id should exist in {self.compound_table}.comp_id (not enforced here)
821-
-- to enforce FK, you can enable PRAGMA foreign_keys=ON and create a FK to {self.compound_table}(comp_id)
822-
-- if both tables are in the same SQLite file.
823815
CHECK (length(comp_id) = 14)
824816
);
825817
CREATE INDEX IF NOT EXISTS idx_spec_to_comp_comp ON {self.table}(comp_id);
@@ -935,7 +927,7 @@ def map_from_spectraldb_metadata(
935927
"inchikey": ik_full,
936928
"classyfire_class": r.get("classyfire_class"),
937929
"classyfire_superclass": r.get("classyfire_superclass"),
938-
"fingerprint": None, # still defer; backfill later
930+
"fingerprint": None, # backfill later
939931
})
940932

941933
# Bulk linking
@@ -960,7 +952,7 @@ def map_from_spectraldb_metadata(
960952

961953
n_mapped = len(to_link)
962954

963-
# tidy
955+
# Close connections
964956
mapper.close()
965957
compdb.close()
966958
s_conn.close()

ms2query/metrics.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -242,7 +242,11 @@ def generalized_tanimoto_similarity_weighted(A, B, weights):
242242

243243

244244
@numba.jit(nopython=True, fastmath=True, parallel=True)
245-
def generalized_tanimoto_similarity_matrix_weighted(references: np.ndarray, queries: np.ndarray, weights: np.ndarray) -> np.ndarray:
245+
def generalized_tanimoto_similarity_matrix_weighted(
246+
references: np.ndarray,
247+
queries: np.ndarray,
248+
weights: np.ndarray
249+
) -> np.ndarray:
246250
"""Returns matrix of generalized Tanimoto similarity between all-vs-all vectors of references and queries.
247251
248252
Parameters

tests/test_ann_index.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,12 @@
1-
import io
21
import json
32
import sqlite3
43
from typing import List, Tuple
54
import numpy as np
65
import pytest
76
from matchms import Spectrum
87
from ms2query.database import ANNIndex
9-
from ms2query.database.spectra_merging import ensure_merged_tables
108
from ms2query.database.database_utils import ndarray_to_blob
9+
from ms2query.database.spectra_merging import ensure_merged_tables
1110

1211

1312
@pytest.fixture()

tests/test_compound_database.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,13 @@
44
import numpy as np
55
import pandas as pd
66
import pytest
7+
from ms2query.data_processing import compute_morgan_fingerprints
78
from ms2query.database.compound_database import (
89
CompoundDatabase,
910
SpecToCompoundMap,
1011
get_unique_compounds_from_spectraldb,
1112
map_from_spectraldb_metadata,
1213
)
13-
from ms2query.data_processing import compute_morgan_fingerprints
1414

1515

1616
# -------------------------

tests/test_fingerprint_computation.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,9 @@ def __init__(self,
3737
sparse_dict=None):
3838
# Defaults
3939
self._dense_fp = np.array([0, 1, 1, 0], dtype=np.int32) if dense_fp is None else np.asarray(dense_fp)
40-
self._dense_count_fp = np.array([0, 2, 5, 0], dtype=np.int32) if dense_count_fp is None else np.asarray(dense_count_fp)
40+
self._dense_count_fp = np.array(
41+
[0, 2, 5, 0],
42+
dtype=np.int32) if dense_count_fp is None else np.asarray(dense_count_fp)
4143
self._sparse = {1: 2, 2: 5} if sparse_dict is None else dict(sparse_dict)
4244

4345
def GetFingerprintAsNumPy(self, mol):

0 commit comments

Comments
 (0)