imspy.algorithm.intensity package¶
Submodules¶
imspy.algorithm.intensity.predictors module¶
- class imspy.algorithm.intensity.predictors.IonIntensityPredictor¶
Bases:
ABC
ABSTRACT INTERFACE for simulation of ion-mobility apex value
- abstractmethod simulate_ion_intensities(sequences, charges, collision_energies)¶
- Return type:
ndarray
[Any
,dtype
[TypeVar
(_ScalarType_co
, bound=generic
, covariant=True)]]
- abstractmethod simulate_ion_intensities_pandas(data)¶
- Return type:
DataFrame
- class imspy.algorithm.intensity.predictors.Prosit2023TimsTofWrapper(verbose=True, model_name='deep_ion_intensity_predictor')¶
Bases:
IonIntensityPredictor
Wrapper for the Prosit 2023 TIMS-TOF predictor
- predict_intensities(sequences, charges, collision_energies, divide_collision_energy_by=100.0, batch_size=512, flatten=False)¶
- Return type:
List
[ndarray
[Any
,dtype
[TypeVar
(_ScalarType_co
, bound=generic
, covariant=True)]]]
- simulate_ion_intensities(sequences, charges, collision_energies, divide_collision_energy_by=100.0, batch_size=512)¶
- Return type:
- simulate_ion_intensities_pandas(data, batch_size=512, divide_collision_energy_by=100.0, verbose=False, flatten=False)¶
- Return type:
DataFrame
- simulate_ion_intensities_pandas_batched(data, batch_size_tf_ds=1024, batch_size=400000, divide_collision_energy_by=100.0)¶
- Return type:
DataFrame
- imspy.algorithm.intensity.predictors.get_collision_energy_calibration_factor(sample, model, lower=-30, upper=30, verbose=False)¶
Get the collision energy calibration factor for a given sample. :type sample:
List
[Psm
] :param sample: a list of PeptideSpectrumMatch objects :type model:Prosit2023TimsTofWrapper
:param model: a Prosit2023TimsTofWrapper object :type lower:int
:param lower: lower bound for the search :type upper:int
:param upper: upper bound for the search :type verbose:bool
:param verbose: whether to print progress- Returns:
the collision energy calibration factor and the angle similarities
- Return type:
Tuple[float, List[float]]
- imspy.algorithm.intensity.predictors.load_prosit_2023_timsTOF_predictor()¶
Get a pretrained deep predictor model This model was downloaded from ZENODO: https://zenodo.org/records/8211811 PAPER : https://doi.org/10.1101/2023.07.17.549401 :returns: The pretrained deep predictor model
- imspy.algorithm.intensity.predictors.predict_intensities_prosit(psm_collection, calibrate_collision_energy=True, verbose=False, num_threads=-1)¶
Predict the fragment ion intensities using Prosit. :type psm_collection:
List
[Psm
] :param psm_collection: a list of peptide-spectrum matches :type calibrate_collision_energy:bool
:param calibrate_collision_energy: whether to calibrate the collision energy :type verbose:bool
:param verbose: whether to print progress :type num_threads:int
:param num_threads: number of threads to use- Return type:
None
- Returns:
None, the fragment ion intensities are stored in the PeptideSpectrumMatch objects
- imspy.algorithm.intensity.predictors.remove_unimod_annotation(sequence)¶
Remove the unimod annotation from a peptide sequence. :type sequence:
str
:param sequence: a peptide sequence- Returns:
the peptide sequence without unimod annotation
- Return type:
str
imspy.algorithm.intensity.utility module¶
- imspy.algorithm.intensity.utility.beta_score(fragments_observed, fragments_predicted)¶
The beta score is a variant of the OpenMS proposed score calculation, using predicted intensities instead of a constant value for the expected intensity. :type fragments_observed: :param fragments_observed: The Sage Fragment object containing the observed intensities :type fragments_predicted: :param fragments_predicted: The Sage Fragment object containing the predicted intensities, e.g. from Prosit
- Returns:
The beta score, hyper score variant using predicted intensities instead of a constant value for the expected intensity
- Return type:
float
- imspy.algorithm.intensity.utility.generate_prosit_intensity_prediction_dataset(sequences, charges, collision_energies=None, remove_mods=False)¶
Generate a dataset for predicting fragment intensities using Prosit. :type sequences:
List
[str
] :param sequences: A list of peptide sequences. :type charges:ndarray
[Any
,dtype
[TypeVar
(_ScalarType_co
, bound=generic
, covariant=True)]] :param charges: A numpy array of precursor charges. :type collision_energies:ndarray
[Any
,dtype
[TypeVar
(_ScalarType_co
, bound=generic
, covariant=True)]] |None
:param collision_energies: A numpy array of collision energies. :type remove_mods:bool
:param remove_mods: Whether to remove modifications from the sequences.- Returns:
A tf.data.Dataset object that yields batches of data in the format expected by the model.
- imspy.algorithm.intensity.utility.get_prosit_intensity_flat_labels()¶
Get the list of fragment ion labels for Prosit. :rtype:
List
[str
] :returns: List of fragment ion labels, giving the returned order of fragment intensities.
- imspy.algorithm.intensity.utility.post_process_predicted_fragment_spectra(data_pred)¶
post process the predicted fragment intensities :type data_pred:
DataFrame
:param data_pred: dataframe containing the predicted fragment intensities- Return type:
ndarray
[Any
,dtype
[TypeVar
(_ScalarType_co
, bound=generic
, covariant=True)]]- Returns:
numpy array of fragment intensities
- imspy.algorithm.intensity.utility.seq_to_index(seq, max_length=30)¶
Convert a sequence to a list of indices into the alphabet.
- Parameters:
seq (
str
) – A string representing a sequence of amino acids.max_length (
int
) – The maximum length of the sequence to allow.
- Return type:
ndarray
[Any
,dtype
[TypeVar
(_ScalarType_co
, bound=generic
, covariant=True)]]- Returns:
A list of integers, each representing an index into the alphabet.
- imspy.algorithm.intensity.utility.to_prosit_tensor(sequences)¶
translate a list of fixed length numpy arrays into a tensorflow tensor :type sequences:
List
:param sequences: list of numpy arrays, representing peptide sequences- Return type:
Tensor
- Returns:
tensorflow tensor
- imspy.algorithm.intensity.utility.unpack_dict(features)¶
Unpack the dictionary of features into the expected inputs for the model.
- Parameters:
features – A dictionary of features, with keys ‘peptides_in’, ‘precursor_charge_in’, and ‘collision_energy_in’
- Returns:
(peptides, precursor_charge, collision_energy)
- Return type:
A tuple of the expected inputs for the model