ms2pip.spectrum

MS2 spectrum handling.

class ms2pip.spectrum.Spectrum(*, mz, intensity, annotations=None, identifier=None, peptidoform=None, precursor_mz=None, precursor_charge=None, retention_time=None, mass_tolerance=None, mass_tolerance_unit=None)[source]

Bases: BaseModel

MS2 spectrum.

Parameters:
  • mz (numpy.ndarray) – Array of m/z values.

  • intensity (numpy.ndarray) – Array of intensity values.

  • annotations (numpy.ndarray | None) – Array of peak annotations.

  • identifier (str | None) – Spectrum identifier.

  • peptidoform (psm_utils.peptidoform.Peptidoform | str | None) – Peptidoform.

  • precursor_mz (float | None) – Precursor m/z.

  • precursor_charge (int | None) – Precursor charge.

  • retention_time (float | None) – Retention time.

  • mass_tolerance (float | None) – Mass tolerance for spectrum annotation.

  • mass_tolerance_unit (str | None) – Unit of mass tolerance for spectrum annotation.

model_config: ClassVar[ConfigDict] = {'arbitrary_types_allowed': True}

Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].

property tic

Total ion current.

remove_reporter_ions(label_type=None)[source]

Set the intensity of reporter ions to 0.

Return type:

None

remove_precursor(tolerance=0.02)[source]

Set the intensity of the precursor peak to 0.

Return type:

None

tic_norm()[source]

Normalize spectrum to total ion current.

Return type:

None

log2_transform()[source]

Log2-tranform spectrum.

Return type:

None

clip_intensity(min_intensity=0.0)[source]

Clip intensity values.

Return type:

None

to_spectrum_utils()[source]

Convert to spectrum_utils.spectrum.MsmsSpectrum.

Notes

  • Requires spectrum_utils to be installed.

  • If the precursor_mz or precursor_charge attributes are not set, the theoretical m/z and precursor charge of the peptidoform attribute are used, if present. Otherwise, ValueError is raised.

model_computed_fields: ClassVar[Dict[str, ComputedFieldInfo]] = {}

A dictionary of computed field names and their corresponding ComputedFieldInfo objects.

model_fields: ClassVar[Dict[str, FieldInfo]] = {'annotations': FieldInfo(annotation=Union[ndarray, NoneType], required=False, default=None), 'identifier': FieldInfo(annotation=Union[str, NoneType], required=False, default=None), 'intensity': FieldInfo(annotation=ndarray, required=True), 'mass_tolerance': FieldInfo(annotation=Union[float, NoneType], required=False, default=None), 'mass_tolerance_unit': FieldInfo(annotation=Union[str, NoneType], required=False, default=None), 'mz': FieldInfo(annotation=ndarray, required=True), 'peptidoform': FieldInfo(annotation=Union[Peptidoform, str, NoneType], required=False, default=None), 'precursor_charge': FieldInfo(annotation=Union[int, NoneType], required=False, default=None), 'precursor_mz': FieldInfo(annotation=Union[float, NoneType], required=False, default=None), 'retention_time': FieldInfo(annotation=Union[float, NoneType], required=False, default=None)}

Metadata about the fields defined on the model, mapping of field names to [FieldInfo][pydantic.fields.FieldInfo] objects.

This replaces Model.__fields__ from Pydantic V1.

class ms2pip.spectrum.ObservedSpectrum(*, mz, intensity, annotations=None, identifier=None, peptidoform=None, precursor_mz=None, precursor_charge=None, retention_time=None, mass_tolerance=None, mass_tolerance_unit=None)[source]

Bases: Spectrum

MS2 spectrum.

Parameters:
  • mz (np.ndarray) – Array of m/z values.

  • intensity (np.ndarray) – Array of intensity values.

  • annotations (Optional[np.ndarray]) – Array of peak annotations.

  • identifier (Optional[str]) – Spectrum identifier.

  • peptidoform (Optional[Union[Peptidoform, str]]) – Peptidoform.

  • precursor_mz (Optional[float]) – Precursor m/z.

  • precursor_charge (Optional[int]) – Precursor charge.

  • retention_time (Optional[float]) – Retention time.

  • mass_tolerance (Optional[float]) – Mass tolerance for spectrum annotation.

  • mass_tolerance_unit (Optional[str]) – Unit of mass tolerance for spectrum annotation.

model_computed_fields: ClassVar[Dict[str, ComputedFieldInfo]] = {}

A dictionary of computed field names and their corresponding ComputedFieldInfo objects.

model_config: ClassVar[ConfigDict] = {'arbitrary_types_allowed': True}

Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].

model_fields: ClassVar[Dict[str, FieldInfo]] = {'annotations': FieldInfo(annotation=Union[ndarray, NoneType], required=False, default=None), 'identifier': FieldInfo(annotation=Union[str, NoneType], required=False, default=None), 'intensity': FieldInfo(annotation=ndarray, required=True), 'mass_tolerance': FieldInfo(annotation=Union[float, NoneType], required=False, default=None), 'mass_tolerance_unit': FieldInfo(annotation=Union[str, NoneType], required=False, default=None), 'mz': FieldInfo(annotation=ndarray, required=True), 'peptidoform': FieldInfo(annotation=Union[Peptidoform, str, NoneType], required=False, default=None), 'precursor_charge': FieldInfo(annotation=Union[int, NoneType], required=False, default=None), 'precursor_mz': FieldInfo(annotation=Union[float, NoneType], required=False, default=None), 'retention_time': FieldInfo(annotation=Union[float, NoneType], required=False, default=None)}

Metadata about the fields defined on the model, mapping of field names to [FieldInfo][pydantic.fields.FieldInfo] objects.

This replaces Model.__fields__ from Pydantic V1.

class ms2pip.spectrum.PredictedSpectrum(*, mz, intensity, annotations=None, identifier=None, peptidoform=None, precursor_mz=None, precursor_charge=None, retention_time=None, mass_tolerance=0.001, mass_tolerance_unit='Da')[source]

Bases: Spectrum

MS2 spectrum.

Parameters:
  • mz (ndarray) – Array of m/z values.

  • intensity (ndarray) – Array of intensity values.

  • annotations (ndarray | None) – Array of peak annotations.

  • identifier (str | None) – Spectrum identifier.

  • peptidoform (Peptidoform | str | None) – Peptidoform.

  • precursor_mz (float | None) – Precursor m/z.

  • precursor_charge (int | None) – Precursor charge.

  • retention_time (float | None) – Retention time.

  • mass_tolerance (Optional[float]) – Mass tolerance for spectrum annotation.

  • mass_tolerance_unit (Optional[str]) – Unit of mass tolerance for spectrum annotation.

model_computed_fields: ClassVar[Dict[str, ComputedFieldInfo]] = {}

A dictionary of computed field names and their corresponding ComputedFieldInfo objects.

model_config: ClassVar[ConfigDict] = {'arbitrary_types_allowed': True}

Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].

model_fields: ClassVar[Dict[str, FieldInfo]] = {'annotations': FieldInfo(annotation=Union[ndarray, NoneType], required=False, default=None), 'identifier': FieldInfo(annotation=Union[str, NoneType], required=False, default=None), 'intensity': FieldInfo(annotation=ndarray, required=True), 'mass_tolerance': FieldInfo(annotation=Union[float, NoneType], required=False, default=0.001), 'mass_tolerance_unit': FieldInfo(annotation=Union[str, NoneType], required=False, default='Da'), 'mz': FieldInfo(annotation=ndarray, required=True), 'peptidoform': FieldInfo(annotation=Union[Peptidoform, str, NoneType], required=False, default=None), 'precursor_charge': FieldInfo(annotation=Union[int, NoneType], required=False, default=None), 'precursor_mz': FieldInfo(annotation=Union[float, NoneType], required=False, default=None), 'retention_time': FieldInfo(annotation=Union[float, NoneType], required=False, default=None)}

Metadata about the fields defined on the model, mapping of field names to [FieldInfo][pydantic.fields.FieldInfo] objects.

This replaces Model.__fields__ from Pydantic V1.