@@ -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 } . "
0 commit comments