Skip to content

Commit 074cb9c

Browse files
committed
Further fixes
1 parent e3c0a18 commit 074cb9c

3 files changed

Lines changed: 37 additions & 27 deletions

File tree

im2deep/_model_ops.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
from __future__ import annotations
55
import copy
66
import logging
7+
import warnings
78
from os import PathLike
89
from pathlib import Path
910

@@ -12,6 +13,14 @@
1213
from torch.utils.data import DataLoader, Dataset
1314
import lightning as L
1415

16+
# Suppress PyTorch padding warning for conv1d with even kernels and odd dilation
17+
warnings.filterwarnings(
18+
"ignore",
19+
message="Using padding='same' with even kernel lengths and odd dilation.*",
20+
category=UserWarning,
21+
module="torch.nn.modules.conv",
22+
)
23+
1524
LOGGER = logging.getLogger(__name__)
1625

1726

im2deep/calibration.py

Lines changed: 20 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -112,37 +112,35 @@ def fit(
112112
)
113113
self.charge_shifts = {charge: 0.0 for charge in range(1, 7)}
114114

115-
# Also calculate a general shift for reference (using charge 2 as default)
116-
try:
117-
self.general_shift = self._compute_ccs_shift(
118-
psm_df_target,
119-
psm_df_source,
120-
2,
121-
)
122-
except Exception:
123-
# If charge 2 fails, try to get any available charge
124-
available_charges = [
125-
c
126-
for c in self.charge_shifts.keys()
127-
if self.charge_shifts[c] is not None and self.charge_shifts[c] != 0.0
115+
# Set general shift as the mean of calculated charge shifts or charge 2 if available
116+
if 2 in self.charge_shifts and self.charge_shifts[2] != 0.0:
117+
self.general_shift = self.charge_shifts[2]
118+
else:
119+
# Use mean of non-zero charge shifts
120+
available_shifts = [
121+
shift
122+
for shift in self.charge_shifts.values()
123+
if shift is not None and shift != 0.0
128124
]
129-
if available_charges:
130-
self.general_shift = self.charge_shifts[available_charges[0]]
125+
if available_shifts:
126+
self.general_shift = float(np.mean(available_shifts))
131127
else:
132128
self.general_shift = 0.0
133129

134130
# Fill in missing charge states with general shift
131+
no_shift_calculated = []
135132
for charge in range(1, 7):
136133
if (
137134
charge not in self.charge_shifts
138135
or self.charge_shifts[charge] is None
139136
or self.charge_shifts[charge] == 0.0
140137
):
141-
LOGGER.debug(
142-
f"No shift factor calculated for charge state {charge}. "
143-
f"Using general shift: {self.general_shift:.3f}."
144-
)
145-
self.charge_shifts[charge] = float(self.general_shift)
138+
no_shift_calculated.append(charge)
139+
LOGGER.debug(
140+
f"No shift factor calculated for charge states: {no_shift_calculated}. "
141+
f"Using general shift: {self.general_shift:.3f}."
142+
)
143+
self.charge_shifts[charge] = float(self.general_shift)
146144
else:
147145
# For global calibration, calculate a single shift
148146
try:
@@ -286,8 +284,8 @@ def _compute_ccs_shift(
286284
# Extract peptide keys and charges
287285
def get_peptide_key(pf):
288286
if isinstance(pf, Peptidoform):
289-
# For Peptidoform objects, use proforma property which excludes charge
290-
return pf.proforma
287+
# For Peptidoform objects, convert proforma to string and strip charge suffix
288+
return str(pf.proforma).rsplit("/", 1)[0]
291289
else:
292290
# For strings in format "PEPTIDE/charge", split off charge
293291
return str(pf).rsplit("/", 1)[0]
@@ -426,10 +424,6 @@ def get_charge(pf):
426424
# Log information for each charge state
427425
charge_counts = merged.groupby("charge").size()
428426
for charge, count in charge_counts.items():
429-
LOGGER.debug(
430-
f"Calculated shift for charge {charge} based on {count} overlapping peptides: "
431-
f"{shift_factors[charge]:.3f}"
432-
)
433427
if count < 10:
434428
LOGGER.warning(
435429
f"Only {count} overlapping peptides found for charge state {charge}. "

im2deep/core.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,14 @@ def predict_and_calibrate(
113113
# Perform calibration
114114
if calibration is None:
115115
LOGGER.info("No calibration provided, using LinearCCSCalibration by default.")
116-
calibration = LinearCCSCalibration()
116+
calibration = LinearCCSCalibration(
117+
per_charge=kwargs.get("calibrate_per_charge", True),
118+
use_charge_state=(
119+
kwargs.get("use_charge_state", 2)
120+
if not kwargs.get("calibrate_per_charge", True)
121+
else None
122+
),
123+
)
117124
elif not isinstance(calibration, Calibration):
118125
raise TypeError(
119126
f"Calibration must be an instance of Calibration, got {type(calibration)} instead."

0 commit comments

Comments
 (0)