ms2pip
Advanced tools
| """Module for ion mobility prediction with IM²Deep.""" | ||
| import logging | ||
| import pandas as pd | ||
| from psm_utils import PSMList | ||
| logger = logging.getLogger(__name__) | ||
| class IonMobility: | ||
| """Predict ion mobility using IM²Deep.""" | ||
| def __init__(self, processes=1) -> None: | ||
| # Lazy import to avoid loading loading heavy dependencies when not needed | ||
| try: | ||
| from im2deep.im2deep import predict_ccs # noqa: F401 | ||
| self.predict_fn = predict_ccs | ||
| self.processes = processes | ||
| except ImportError as e: | ||
| raise ImportError( | ||
| "The 'im2deep' package is required for ion mobility prediction." | ||
| ) from e | ||
| def add_im_predictions(self, psm_list: PSMList) -> None: | ||
| """Add ion mobility predictions to the PSMList.""" | ||
| logger.info("Predicting ion mobility...") | ||
| predictions: pd.Series = self.predict_fn( | ||
| psm_list, write_output=False, n_jobs=self.processes | ||
| ) | ||
| psm_list["ion_mobility"] = predictions.values |
| Metadata-Version: 2.1 | ||
| Name: ms2pip | ||
| Version: 4.0.0.dev13 | ||
| Version: 4.0.0.dev14 | ||
| Summary: MS2PIP: Accurate and versatile peptide fragmentation spectrum prediction. | ||
@@ -5,0 +5,0 @@ Author: Ana Sílvia C. Silva |
@@ -41,2 +41,3 @@ LICENSE | ||
| ms2pip/_utils/feature_names.py | ||
| ms2pip/_utils/ion_mobility.py | ||
| ms2pip/_utils/psm_input.py | ||
@@ -43,0 +44,0 @@ ms2pip/_utils/retention_time.py |
| # isort: skip_file | ||
| """MS2PIP: Accurate and versatile peptide fragmentation spectrum prediction.""" | ||
| __version__ = "4.0.0-dev13" | ||
| __version__ = "4.0.0-dev14" | ||
@@ -6,0 +6,0 @@ from warnings import filterwarnings |
@@ -89,5 +89,7 @@ import logging | ||
| @click.argument("psms", required=True) | ||
| @click.option("--psm-filetype", "-t", type=click.Choice(PSM_FILETYPES), default=None) | ||
| @click.option("--output-name", "-o", type=str) | ||
| @click.option("--output-format", "-f", type=click.Choice(SUPPORTED_FORMATS), default="tsv") | ||
| @click.option("--add-retention-time", "-r", is_flag=True) | ||
| @click.option("--add-ion-mobility", "-i", is_flag=True) | ||
| @click.option("--model", type=click.Choice(MODELS), default="HCD") | ||
@@ -114,2 +116,3 @@ @click.option("--model-dir") | ||
| @click.option("--add-retention-time", "-r", is_flag=True) | ||
| @click.option("--add-ion-mobility", "-i", is_flag=True) | ||
| @click.option("--model", type=click.Choice(MODELS), default="HCD") | ||
@@ -141,2 +144,3 @@ @click.option("--model-dir") | ||
| @click.option("--add-retention-time", "-r", is_flag=True) | ||
| @click.option("--add-ion-mobility", "-i", is_flag=True) | ||
| @click.option("--model", type=click.Choice(MODELS), default="HCD") | ||
@@ -143,0 +147,0 @@ @click.option("--model-dir") |
+28
-2
@@ -26,2 +26,3 @@ #!/usr/bin/env python | ||
| from ms2pip._utils.retention_time import RetentionTime | ||
| from ms2pip._utils.ion_mobility import IonMobility | ||
| from ms2pip._utils.xgb_models import get_predictions_xgb, validate_requested_xgb_model | ||
@@ -78,2 +79,3 @@ from ms2pip.constants import MODELS | ||
| add_retention_time: bool = False, | ||
| add_ion_mobility: bool = False, | ||
| psm_filetype: Optional[str] = None, | ||
@@ -96,2 +98,4 @@ model: Optional[str] = "HCD", | ||
| Add retention time predictions with DeepLC (Requires optional DeepLC dependency). | ||
| add_ion_mobility | ||
| Add ion mobility predictions with IM2Deep (Requires optional IM2Deep dependency). | ||
| model | ||
@@ -119,2 +123,7 @@ Model to use for prediction. Default: "HCD". | ||
| if add_ion_mobility: | ||
| logger.info("Adding ion mobility predictions") | ||
| im_predictor = IonMobility(processes=processes) | ||
| im_predictor.add_im_predictions(psm_list) | ||
| with Encoder.from_psm_list(psm_list) as encoder: | ||
@@ -137,2 +146,3 @@ ms2pip_parallelized = _Parallelized( | ||
| add_retention_time: bool = False, | ||
| add_ion_mobility: bool = False, | ||
| model: Optional[str] = "HCD", | ||
@@ -156,2 +166,4 @@ model_dir: Optional[Union[str, Path]] = None, | ||
| Add retention time predictions with DeepLC (Requires optional DeepLC dependency). | ||
| add_ion_mobility | ||
| Add ion mobility predictions with IM2Deep (Requires optional IM2Deep dependency). | ||
| model | ||
@@ -166,2 +178,7 @@ Model to use for prediction. Default: "HCD". | ||
| Yields | ||
| ------ | ||
| predictions: List[ProcessingResult] | ||
| Predicted spectra with theoretical m/z and predicted intensity values. | ||
| """ | ||
@@ -193,2 +210,3 @@ if fasta_file and config: | ||
| add_retention_time=add_retention_time, | ||
| add_ion_mobility=add_ion_mobility, | ||
| model=model, | ||
@@ -208,2 +226,3 @@ model_dir=model_dir, | ||
| add_retention_time: bool = False, | ||
| add_ion_mobility: bool = False, | ||
| model: Optional[str] = "HCD", | ||
@@ -233,2 +252,4 @@ model_dir: Optional[Union[str, Path]] = None, | ||
| Add retention time predictions with DeepLC (Requires optional DeepLC dependency). | ||
| add_ion_mobility | ||
| Add ion mobility predictions with IM2Deep (Requires optional IM2Deep dependency). | ||
| model | ||
@@ -258,2 +279,7 @@ Model to use for prediction. Default: "HCD". | ||
| if add_ion_mobility: | ||
| logger.info("Adding ion mobility predictions") | ||
| im_predictor = IonMobility(processes=processes) | ||
| im_predictor.add_im_predictions(psm_list) | ||
| with Encoder.from_psm_list(psm_list) as encoder: | ||
@@ -860,4 +886,4 @@ ms2pip_parallelized = _Parallelized( | ||
| raise exceptions.TitlePatternError( | ||
| "Spectrum title pattern could not be matched to spectrum IDs " | ||
| f"`{spectrum.identifier}`. " | ||
| f"Spectrum title pattern `{spectrum_id_pattern}` could not be matched to " | ||
| f"spectrum ID `{spectrum.identifier}`. " | ||
| " Are you sure that the regex contains a capturing group?" | ||
@@ -864,0 +890,0 @@ ) |
@@ -37,3 +37,3 @@ """Read MS2 spectra.""" | ||
| for spectrum in get_ms2_spectra(str(spectrum_file)): | ||
| yield ObservedSpectrum( | ||
| obs_spectrum = ObservedSpectrum( | ||
| mz=np.array(spectrum.mz, dtype=np.float32), | ||
@@ -46,2 +46,10 @@ intensity=np.array(spectrum.intensity, dtype=np.float32), | ||
| ) | ||
| # Workaround for mobiusklein/mzdata#3 | ||
| if ( | ||
| obs_spectrum.identifier == "" | ||
| or obs_spectrum.mz.shape[0] == 0 | ||
| or obs_spectrum.intensity.shape[0] == 0 | ||
| ): | ||
| continue | ||
| yield obs_spectrum | ||
@@ -48,0 +56,0 @@ |
@@ -160,2 +160,3 @@ """ | ||
| "rt", | ||
| "im", | ||
| ] | ||
@@ -198,2 +199,3 @@ | ||
| "rt": result.psm.retention_time if result.psm.retention_time else None, | ||
| "im": result.psm.ion_mobility if result.psm.ion_mobility else None, | ||
| } | ||
@@ -248,5 +250,8 @@ | ||
| if len(modifications) > 1: | ||
| raise ValueError("Multiple modifications per amino acid not supported.") | ||
| raise ValueError("Multiple modifications per amino acid not supported in MSP.") | ||
| modification = modifications[0] | ||
| return f"{position},{amino_acid},{modification.name}" | ||
| try: | ||
| return f"{position},{amino_acid},{modification.name}" | ||
| except AttributeError: # MassModification has no attribute `name` | ||
| return f"{position},{amino_acid},{modification.value}" | ||
@@ -293,2 +298,10 @@ sequence_mods = [ | ||
| @staticmethod | ||
| def _format_ion_mobility(psm: PSM) -> Union[str, None]: | ||
| """Format ion mobility as string.""" | ||
| if psm.ion_mobility: | ||
| return f"IonMobility={psm.ion_mobility}" | ||
| else: | ||
| return None | ||
| @staticmethod | ||
| def _format_identifier(psm: PSM) -> str: | ||
@@ -309,2 +322,3 @@ """Format MS2PIP ID as string.""" | ||
| MSP._format_retention_time(psm), | ||
| MSP._format_ion_mobility(psm), | ||
| MSP._format_identifier(psm), | ||
@@ -318,4 +332,8 @@ ], | ||
| class MGF(_Writer): | ||
| """Write MGF files from MS2PIP processing results.""" | ||
| """ | ||
| Write MGF files from MS2PIP processing results. | ||
| See http://www.matrixscience.com/help/data_file_help.html for documentation on the MGF format. | ||
| """ | ||
| suffix = ".mgf" | ||
@@ -342,2 +360,3 @@ | ||
| f"RTINSECONDS={result.psm.retention_time}" if result.psm.retention_time else None, | ||
| f"ION_MOBILITY={result.psm.ion_mobility}" if result.psm.ion_mobility else None, | ||
| ] | ||
@@ -438,3 +457,5 @@ | ||
| Bibliospec SSL and MS2 files are also compatible with Skyline. | ||
| Bibliospec SSL and MS2 files are also compatible with Skyline. See | ||
| https://skyline.ms/wiki/home/software/BiblioSpec/page.view?name=BiblioSpec%20input%20and%20output%20file%20formats | ||
| for documentation on the Bibliospec file formats. | ||
@@ -453,2 +474,3 @@ """ | ||
| "retention-time", | ||
| "ion-mobility", | ||
| ] | ||
@@ -563,2 +585,3 @@ | ||
| "retention-time": result.psm.retention_time if result.psm.retention_time else None, | ||
| "ion-mobility": result.psm.ion_mobility if result.psm.ion_mobility else None, | ||
| } | ||
@@ -565,0 +588,0 @@ ) |
+1
-1
| Metadata-Version: 2.1 | ||
| Name: ms2pip | ||
| Version: 4.0.0.dev13 | ||
| Version: 4.0.0.dev14 | ||
| Summary: MS2PIP: Accurate and versatile peptide fragmentation spectrum prediction. | ||
@@ -5,0 +5,0 @@ Author: Ana Sílvia C. Silva |
Alert delta unavailable
Currently unable to show alert delta for PyPI packages.
35502734
0.01%50
2.04%3960
2.06%