44from typing import Any , Dict , Iterable , List , Optional , Tuple , Union
55import numpy as np
66import 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 ()
0 commit comments