Skip to content

Commit fc61741

Browse files
committed
feat: better logging on failure to read data
1 parent b775754 commit fc61741

File tree

2 files changed

+29
-15
lines changed

2 files changed

+29
-15
lines changed

timsquery/src/models/indices/expanded_raw_index/model.rs

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ use timsrust::readers::{
3838
};
3939
use tracing::{
4040
info,
41+
error,
4142
instrument,
4243
};
4344

@@ -155,10 +156,30 @@ impl ExpandedRawFrameIndex {
155156
"Building ExpandedRawFrameIndex from path {} config {:?}",
156157
path, centroid_config,
157158
);
158-
let file_reader = FrameReader::new(path)?;
159+
let file_reader = match FrameReader::new(path) {
160+
Ok(x) => x,
161+
Err(e) => {
162+
error!(
163+
"Failed to open file reader for path {}. Error: {}",
164+
path,
165+
e
166+
);
167+
return Err(e.into());
168+
}
169+
};
159170

160171
let sql_path = std::path::Path::new(path).join("analysis.tdf");
161-
let meta_converters = MetadataReader::new(&sql_path)?;
172+
let meta_converters = match MetadataReader::new(&sql_path) {
173+
Ok(x) => x,
174+
Err(e) => {
175+
error!(
176+
"Failed to open metadata reader for path {}. Error: {}",
177+
sql_path.display(),
178+
e
179+
);
180+
return Err(e.into());
181+
}
182+
};
162183
let centroid_config = centroid_config
163184
.with_converters(meta_converters.im_converter, meta_converters.mz_converter);
164185

timsseek_rts/python/receiver.py

Lines changed: 6 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -56,13 +56,17 @@ def dataclass_from_dict(klass, d):
5656
# from: https://stackoverflow.com/a/54769644/4295016
5757
try:
5858
fieldtypes = {f.name: f.type for f in dataclasses.fields(klass)}
59-
return klass(**{f: dataclass_from_dict(fieldtypes[f], d[f]) for f in d})
6059
except TypeError as e:
60+
ALLOWED_PASSTHROUGH_TYPES = (int, float, str, bool)
61+
if type(d) in ALLOWED_PASSTHROUGH_TYPES:
62+
return d
63+
6164
if "must be called with a dataclass type or instance" in str(e):
6265
return d
6366
except Exception as e:
6467
raise KeyError(f"Could not convert to {klass} because {e}") from e
6568

69+
return klass(**{f: dataclass_from_dict(fieldtypes[f], d[f]) for f in d})
6670

6771
def infinite_colour_loop():
6872
options = ["#ff0000", "#00ff00", "#0000ff"]
@@ -150,14 +154,12 @@ class MainScoreElements:
150154
ms2_lazyscore: list[float]
151155
ms2_lazyscore_vs_baseline: list[float]
152156
ref_time_ms: list[int]
153-
# ms1_ms2_correlation: list[float]
154-
cocoscore: list[float]
155157
ms2_lazyscore_vs_baseline_std: float
156158

157159
def plot(self, min_rt_ms, max_rt_ms, vlines_ms: list[int] | None = None):
158160
# Make a plot grid, where each row is a different score element
159161
# but all share the same retention time axis
160-
fig, ax = plt.subplots(nrows=3, ncols=3, figsize=(10, 12))
162+
fig, ax = plt.subplots(nrows=2, ncols=3, figsize=(10, 12))
161163

162164
rt_use = np.array(self.ref_time_ms)
163165
ranges = np.searchsorted(rt_use, [min_rt_ms, max_rt_ms])
@@ -177,9 +179,6 @@ def plot(self, min_rt_ms, max_rt_ms, vlines_ms: list[int] | None = None):
177179
ax[1, 2].plot(rt_plot, self.ms2_lazyscore[ranges[0] : ranges[1]])
178180
ax[1, 2].set_title("MS2 LazyScore")
179181

180-
ax[2, 0].plot(rt_plot, self.cocoscore[ranges[0] : ranges[1]])
181-
ax[2, 0].set_title("CoCoScore")
182-
183182
# ax[2, 0].plot(rt_plot, self.ms2_lazyscore_vs_baseline_std[ranges[0] : ranges[1]])
184183
# ax[2, 0].set_title("MS2 LazyScore Baseline STD")
185184

@@ -204,9 +203,6 @@ def plot(self, min_rt_ms, max_rt_ms, vlines_ms: list[int] | None = None):
204203
ax[1, 2].axvline(
205204
x=vlines_minutes[i], color="k", linestyle="--", alpha=0.5
206205
)
207-
ax[2, 0].axvline(
208-
x=vlines_minutes[i], color="k", linestyle="--", alpha=0.5
209-
)
210206

211207
for i in range(2):
212208
for j in range(3):
@@ -268,9 +264,6 @@ class SearchResults:
268264
ms2_inten_ratio_5: float
269265
ms2_inten_ratio_6: float
270266

271-
# ms1_ms2_correlation: float
272-
cocoscore: float
273-
274267
delta_ms1_ms2_mobility: float
275268
sq_delta_ms1_ms2_mobility: float
276269

0 commit comments

Comments
 (0)