Skip to content

Commit 3a8ef59

Browse files
committed
rename methods
1 parent f8648a8 commit 3a8ef59

File tree

2 files changed

+12
-12
lines changed

2 files changed

+12
-12
lines changed

ms2query/spectral_database.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,7 @@ def ids(self) -> List[int]:
145145
rows = cur.execute("SELECT spec_id FROM spectra").fetchall()
146146
return [int(row["spec_id"]) for row in rows]
147147

148-
def retrieve_spectra_by_ids(self, specIDs: List[int]) -> List[Spectrum]:
148+
def get_spectra_by_ids(self, specIDs: List[int]) -> List[Spectrum]:
149149
"""Retrieve full Spectrum objects for given specIDs (order preserved, missing IDs skipped)."""
150150
rows = self._fetch_rows_by_ids(specIDs, cols="spec_id, mz_blob, intensity_blob, n_peaks, " + ", ".join(self.metadata_fields))
151151
by_id = {row["spec_id"]: row for row in rows}
@@ -163,7 +163,7 @@ def retrieve_spectra_by_ids(self, specIDs: List[int]) -> List[Spectrum]:
163163
result.append(Spectrum(mz=mz, intensities=inten, metadata=md))
164164
return result
165165

166-
def retrieve_fragments_by_ids(self, specIDs: List[int]) -> List[Tuple[np.ndarray, np.ndarray]]:
166+
def get_fragments_by_ids(self, specIDs: List[int]) -> List[Tuple[np.ndarray, np.ndarray]]:
167167
"""Retrieve (mz, intensity) arrays for given specIDs (order preserved, missing IDs skipped)."""
168168
rows = self._fetch_rows_by_ids(specIDs, cols="spec_id, mz_blob, intensity_blob, n_peaks")
169169
by_id = {row["spec_id"]: row for row in rows}
@@ -179,7 +179,7 @@ def retrieve_fragments_by_ids(self, specIDs: List[int]) -> List[Tuple[np.ndarray
179179
out.append((mz, inten))
180180
return out
181181

182-
def retrieve_metadata_by_ids(self, specIDs: List[int]) -> pd.DataFrame:
182+
def get_metadata_by_ids(self, specIDs: List[int]) -> pd.DataFrame:
183183
"""Retrieve metadata for given specIDs (order preserved)."""
184184
cols = ["spec_id"] + self.metadata_fields
185185
rows = self._fetch_rows_by_ids(specIDs, cols=", ".join(cols))

tests/test_spectral_database.py

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ def test_add_and_retrieve_single(tmp_db):
6060
sid = ids[0]
6161
assert isinstance(sid, int)
6262

63-
out = tmp_db.retrieve_spectra_by_ids([sid])
63+
out = tmp_db.get_spectra_by_ids([sid])
6464
assert len(out) == 1
6565
sp_out = out[0]
6666

@@ -81,19 +81,19 @@ def test_add_and_retrieve_multiple_order_preserved(tmp_db, spectra_small):
8181

8282
# request in a permuted order; results should follow request order
8383
req = [ids[2], ids[0], ids[1]]
84-
out = tmp_db.retrieve_spectra_by_ids(req)
84+
out = tmp_db.get_spectra_by_ids(req)
8585
assert [sp.metadata["spec_id"] for sp in out] == req
8686

8787
# spot-check one item’s content
8888
s2 = out[1] # corresponds to ids[0]
8989
assert s2.metadata["precursor_mz"] == pytest.approx(240.0)
9090

9191

92-
def test_retrieve_fragments_by_ids(tmp_db, spectra_small):
92+
def test_get_fragments_by_ids(tmp_db, spectra_small):
9393
ids = tmp_db.add_spectrum(spectra_small)
9494
req = [ids[1], ids[1], 9999999, ids[0]] # includes duplicate + missing
9595
# Implementation skips missing IDs and preserves order for the present ones
96-
frags = tmp_db.retrieve_fragments_by_ids(req)
96+
frags = tmp_db.get_fragments_by_ids(req)
9797
# We expect two results (the duplicate is returned twice; missing is skipped)
9898
assert len(frags) == 3
9999
(mz_a, in_a), (mz_b, in_b), (mz_c, in_c) = frags
@@ -107,9 +107,9 @@ def test_retrieve_fragments_by_ids(tmp_db, spectra_small):
107107
assert mz_c.shape[0] == spectra_small[0].mz.shape[0]
108108

109109

110-
def test_retrieve_metadata_by_ids_df(tmp_db, spectra_small):
110+
def test_get_metadata_by_ids_df(tmp_db, spectra_small):
111111
ids = tmp_db.add_spectrum(spectra_small)
112-
df = tmp_db.retrieve_metadata_by_ids([ids[2], ids[0]])
112+
df = tmp_db.get_metadata_by_ids([ids[2], ids[0]])
113113

114114
# Expected columns: spec_id + configured metadata fields
115115
expected_cols = ["spec_id"] + tmp_db.metadata_fields
@@ -141,9 +141,9 @@ def test_sql_query_simple(tmp_db, spectra_small):
141141
def test_missing_ids_handling(tmp_db, spectra_small):
142142
ids = tmp_db.add_spectrum(spectra_small)
143143
req = [999999, ids[1]]
144-
out_spectra = tmp_db.retrieve_spectra_by_ids(req)
145-
out_meta = tmp_db.retrieve_metadata_by_ids(req)
146-
out_frags = tmp_db.retrieve_fragments_by_ids(req)
144+
out_spectra = tmp_db.get_spectra_by_ids(req)
145+
out_meta = tmp_db.get_metadata_by_ids(req)
146+
out_frags = tmp_db.get_fragments_by_ids(req)
147147

148148
# Implementation skips missing IDs but preserves order of the ones that exist
149149
assert [s.metadata["spec_id"] for s in out_spectra] == [ids[1]]

0 commit comments

Comments
 (0)