Skip to content

Commit

Permalink
continue refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
leoschwarz committed Jun 5, 2024
1 parent cfa6ccd commit dc6103d
Showing 1 changed file with 10 additions and 9 deletions.
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
from collections import defaultdict
from pathlib import Path
from typing import Sequence, Annotated

Expand All @@ -9,13 +8,14 @@

from depiction.persistence import ImzmlReadFile


# TODO maybe rename to marker_surroundings


def get_peak_dist(
read_file: ImzmlReadFile, mz_targets: Sequence[float], mz_labels: Sequence[str], mz_max_dist: float
) -> pl.DataFrame:
collect = defaultdict(list)
collect = []
with read_file.get_reader() as reader:
for i_spectrum in tqdm(range(reader.n_spectra)):
spectrum_mz = reader.get_spectrum_mz(i_spectrum)
Expand All @@ -26,13 +26,14 @@ def get_peak_dist(
dist = dist[sel]
marker_mz = spectrum_mz[sel]
if len(dist):
# add to result set
collect["i_spectrum"].append(i_spectrum)
collect["dist"].append(dist)
collect["mz_peak"].append(marker_mz)
collect["mz_target"].append(mz_target)
collect["label"].append(label)
return pl.DataFrame(collect).explode(["dist", "mz_peak"])
collect.append({
"i_spectrum": i_spectrum,
"dist": list(dist),
"mz_peak": list(marker_mz),
"mz_target": mz_target,
"label": label,
})
return pl.from_dicts(collect).explode(["dist", "mz_peak"])


def qc_table_marker_distances(
Expand Down

0 comments on commit dc6103d

Please sign in to comment.