Lookups¶
Lookup classes provide iteration, index access, and query methods over collections of frames, precursors, DIA windows, or PRM targets and transitions. All lookup objects support:
- Iteration —
for item in lookup: - Index access —
lookup[id] - Length —
len(lookup) .get(id)— returnsNone(or a default) instead of raising on a missing ID.query()— filter by m/z, retention time, or ion mobility with tolerances
MS1 Frame Lookup¶
tdfpy.Ms1FrameLookup
¶
Bases: _IdLookup[T, T]
MS1 frames of a reader, indexed by frame ID, with RT queries.
Source code in src/tdfpy/lookup.py
get
¶
ids
¶
query_range
¶
MS1 frames inside an RT range, in frame order.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
rt_range
|
tuple[float, float] | None
|
|
None
|
Yields:
| Type | Description |
|---|---|
T
|
Matching MS1 frames. |
Source code in src/tdfpy/lookup.py
query
¶
MS1 frames within rt_tolerance of rt, in frame order.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
rt
|
float | None
|
Target retention time in seconds. |
None
|
rt_tolerance
|
float
|
RT tolerance in seconds (default 30). |
30.0
|
Yields:
| Type | Description |
|---|---|
T
|
Matching MS1 frames. |
Raises:
| Type | Description |
|---|---|
TdfpyError
|
If |
Source code in src/tdfpy/lookup.py
Precursor Lookup¶
tdfpy.PrecursorLookup
¶
PrecursorLookup(precursors: Mapping[int, Precursor])
Bases: _IdLookup[Precursor, Precursor]
DDA precursors, indexed by precursor ID, with m/z and RT queries.
Source code in src/tdfpy/lookup.py
get
¶
ids
¶
query_range
¶
query_range(
*,
precursor_mz_range: tuple[float, float] | None = None,
rt_range: tuple[float, float] | None = None
) -> Iterator[Precursor]
Precursors inside precursor m/z and/or RT ranges (inclusive).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
precursor_mz_range
|
tuple[float, float] | None
|
|
None
|
rt_range
|
tuple[float, float] | None
|
|
None
|
Yields:
| Type | Description |
|---|---|
Precursor
|
Matching |
Source code in src/tdfpy/lookup.py
query
¶
query(
*,
precursor_mz: float | None = None,
rt: float | None = None,
mz_tolerance: float = 20.0,
mz_tolerance_unit: ToleranceUnit = "ppm",
rt_tolerance: float = 30.0
) -> Iterator[Precursor]
Precursors within a tolerance of precursor_mz and/or rt.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
precursor_mz
|
float | None
|
Target precursor m/z. |
None
|
rt
|
float | None
|
Target retention time in seconds. |
None
|
mz_tolerance
|
float
|
m/z tolerance (default 20). |
20.0
|
mz_tolerance_unit
|
ToleranceUnit
|
|
'ppm'
|
rt_tolerance
|
float
|
RT tolerance in seconds (default 30). |
30.0
|
Yields:
| Type | Description |
|---|---|
Precursor
|
Matching |
Raises:
| Type | Description |
|---|---|
TdfpyError
|
If a tolerance is negative or |
Source code in src/tdfpy/lookup.py
DIA Window Lookup¶
DiaWindowLookup groups windows by window_group_id. Because a single window group
definition repeats across many frames, indexing by window_group_id returns a tuple
of DiaWindow objects — one per frame that used that group.
from tdfpy import DIA
with DIA("experiment.d") as dia:
# Iterate over all windows across all frames
for window in dia.windows:
print(window.frame_id, window.isolation_mz, window.rt)
# All windows belonging to window group 3 (one per frame)
group3 = dia.windows[3]
# Query by retention time (rt_tolerance defaults to 30 s)
for window in dia.windows.query(rt=600.0, rt_tolerance=15.0):
print(window.window_group_id, window.isolation_mz)
# Query by window group AND retention time
for window in dia.windows.query(window_group=5, rt=600.0, rt_tolerance=10.0):
peaks = window.centroid()
tdfpy.DiaWindowLookup
¶
DiaWindowLookup(windows: Iterable[DiaWindow])
Bases: _IdLookup[DiaWindow, tuple[DiaWindow, ...]]
Per-frame DIA windows, indexed by window group ID.
lookup[group_id] returns a tuple: every frame that used the group
contributes one window per window definition.
Source code in src/tdfpy/lookup.py
get
¶
ids
¶
query_range
¶
query_range(
*,
window_group: int | DiaWindowGroup | None = None,
rt_range: tuple[float, float] | None = None
) -> Iterator[DiaWindow]
Windows in a window group and/or retention time range.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
window_group
|
int | DiaWindowGroup | None
|
Window group ID, or a |
None
|
rt_range
|
tuple[float, float] | None
|
|
None
|
Yields:
| Type | Description |
|---|---|
DiaWindow
|
Matching |
Source code in src/tdfpy/lookup.py
query
¶
query(
*,
window_group: int | DiaWindowGroup | None = None,
rt: float | None = None,
rt_tolerance: float = 30.0
) -> Iterator[DiaWindow]
Windows in a window group and/or within rt_tolerance of rt.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
window_group
|
int | DiaWindowGroup | None
|
Window group ID or |
None
|
rt
|
float | None
|
Target retention time in seconds. |
None
|
rt_tolerance
|
float
|
RT tolerance in seconds (default 30). |
30.0
|
Yields:
| Type | Description |
|---|---|
DiaWindow
|
Matching |
Raises:
| Type | Description |
|---|---|
TdfpyError
|
If |
Source code in src/tdfpy/lookup.py
PRM Lookups¶
In a PRM experiment the instrument cycles through a list of targets (predefined precursor ions) and collects MS2 spectra for each. The two lookup classes below reflect that structure:
PrmTargetLookup— the list of analytes being monitored (one entry per analyte)PrmTransitionLookup— the individual MS2 acquisitions (many per target, spread across the chromatographic run)
PRM Target Lookup¶
PrmTargetLookup gives direct access to PrmTarget objects by their integer target_id.
Use .query() to filter targets by m/z, expected retention time, or ion mobility (1/K0).
from tdfpy import PRM
with PRM("experiment.d") as prm:
# Iterate over all targets
for target in prm.targets:
print(target.target_id, target.precursor_mz, target.charge)
# Access a specific target by ID
t = prm.targets[1]
print(t.description, t.rt, t.ook0)
# Query by m/z (20 ppm window)
for target in prm.targets.query(precursor_mz=565.3189, mz_tolerance=20.0):
print(target.target_id, target.precursor_mz)
# Query by m/z and expected RT (±30 s)
for target in prm.targets.query(precursor_mz=565.3189, rt=480.0, rt_tolerance=30.0):
print(target.target_id, target.description)
# Query by 1/K0 (ion mobility)
for target in prm.targets.query(ook0=0.92, ook0_tolerance=0.05):
print(target.target_id, target.ook0)
tdfpy.PrmTargetLookup
¶
PrmTargetLookup(targets: Mapping[int, PrmTarget])
Bases: _IdLookup[PrmTarget, PrmTarget]
PRM targets, indexed by target ID, with m/z, RT and 1/K0 queries.
Source code in src/tdfpy/lookup.py
get
¶
ids
¶
query_range
¶
query_range(
*,
precursor_mz_range: tuple[float, float] | None = None,
rt_range: tuple[float, float] | None = None,
ook0_range: tuple[float, float] | None = None
) -> Iterator[PrmTarget]
Targets inside precursor m/z, RT and/or 1/K0 ranges (inclusive).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
precursor_mz_range
|
tuple[float, float] | None
|
|
None
|
rt_range
|
tuple[float, float] | None
|
|
None
|
ook0_range
|
tuple[float, float] | None
|
|
None
|
Yields:
| Type | Description |
|---|---|
PrmTarget
|
Matching |
Source code in src/tdfpy/lookup.py
query
¶
query(
*,
precursor_mz: float | None = None,
rt: float | None = None,
ook0: float | None = None,
mz_tolerance: float = 20.0,
mz_tolerance_unit: ToleranceUnit = "ppm",
rt_tolerance: float = 30.0,
ook0_tolerance: float = 0.05
) -> Iterator[PrmTarget]
Targets within a tolerance of precursor_mz, rt and/or ook0.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
precursor_mz
|
float | None
|
Target precursor m/z. |
None
|
rt
|
float | None
|
Target retention time in seconds. |
None
|
ook0
|
float | None
|
Target 1/K0. |
None
|
mz_tolerance
|
float
|
m/z tolerance (default 20). |
20.0
|
mz_tolerance_unit
|
ToleranceUnit
|
|
'ppm'
|
rt_tolerance
|
float
|
RT tolerance in seconds (default 30). |
30.0
|
ook0_tolerance
|
float
|
Absolute 1/K0 tolerance (default 0.05). |
0.05
|
Yields:
| Type | Description |
|---|---|
PrmTarget
|
Matching |
Raises:
| Type | Description |
|---|---|
TdfpyError
|
If a tolerance is negative or |
Source code in src/tdfpy/lookup.py
PRM Transition Lookup¶
PrmTransitionLookup gives access to PrmTransition objects — the individual MS2
acquisitions captured during the run. Indexing by target_id returns a tuple of all
transitions collected for that target across the chromatographic run.
from tdfpy import PRM
with PRM("experiment.d") as prm:
# All transitions for target 1 (tuple — one per MS2 frame)
transitions = prm.transitions[1]
for t in transitions:
print(t.frame_id, t.rt, t.collision_energy)
peaks = t.scan_peaks() # list of (N, 2) [m/z, intensity] arrays, one per mobility scan
# Query transitions for a specific target near a retention time
for tr in prm.transitions.query(target=1, rt=480.0, rt_tolerance=30.0):
centroided = tr.centroid() # shape (N, 3): [m/z, intensity, 1/K0]
# Query using a PrmTarget object directly
target = prm.targets[1]
for tr in prm.transitions.query(target=target, rt=target.rt, rt_tolerance=20.0):
print(tr.frame_id, tr.isolation_mz)
tdfpy.PrmTransitionLookup
¶
PrmTransitionLookup(transitions: Iterable[PrmTransition])
Bases: _IdLookup[PrmTransition, tuple[PrmTransition, ...]]
PRM transitions, indexed by target ID.
lookup[target_id] returns a tuple: a target is acquired in many frames.
Source code in src/tdfpy/lookup.py
get
¶
ids
¶
query_range
¶
query_range(
*,
target: int | PrmTarget | None = None,
rt_range: tuple[float, float] | None = None
) -> Iterator[PrmTransition]
Transitions of one target and/or inside an RT range.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
target
|
int | PrmTarget | None
|
Target ID or |
None
|
rt_range
|
tuple[float, float] | None
|
|
None
|
Yields:
| Type | Description |
|---|---|
PrmTransition
|
Matching |
Source code in src/tdfpy/lookup.py
query
¶
query(
*,
target: int | PrmTarget | None = None,
rt: float | None = None,
rt_tolerance: float = 30.0
) -> Iterator[PrmTransition]
Transitions of one target and/or within rt_tolerance of rt.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
target
|
int | PrmTarget | None
|
Target ID or |
None
|
rt
|
float | None
|
Target retention time in seconds. |
None
|
rt_tolerance
|
float
|
RT tolerance in seconds (default 30). |
30.0
|
Yields:
| Type | Description |
|---|---|
PrmTransition
|
Matching |
Raises:
| Type | Description |
|---|---|
TdfpyError
|
If |