imspy.algorithm.ccs package

Submodules

imspy.algorithm.ccs.predictors module

class imspy.algorithm.ccs.predictors.DeepPeptideIonMobilityApex(model, tokenizer, verbose=False, name='gru_predictor')

Bases: PeptideIonMobilityApex

fine_tune_model(data, batch_size=64, re_compile=False, verbose=False, decoys_separate=True)
simulate_ion_mobilities(sequences, charges, mz, batch_size=1024)
Return type:

ndarray[Any, dtype[TypeVar(_ScalarType_co, bound= generic, covariant=True)]]

simulate_ion_mobilities_pandas(data, batch_size=1024, return_ccs=False, decoys_separate=True)
Return type:

DataFrame

class imspy.algorithm.ccs.predictors.GRUCCSPredictor(*args, **kwargs)

Bases: Model

build(input_shape)

Builds the model based on input shapes received.

This is to be used for subclassed models, which do not know at instantiation time what their inputs look like.

This method only exists for users who want to call model.build() in a standalone way (as a substitute for calling the model on real data to build it). It will never be called by the framework (and thus it will never throw unexpected errors in an unrelated workflow).

Parameters:

input_shape – Single tuple, TensorShape instance, or list/dict of shapes, where shapes are tuples, integers, or TensorShape instances.

Raises:
  • ValueError

    1. In case of invalid user-provided data (not of type tuple, list, TensorShape, or dict). 2. If the model requires call arguments that are agnostic to the input shapes (positional or keyword arg in call signature). 3. If not all layers were properly built. 4. If float type inputs are not supported within the layers.

  • In each of these cases, the user should build their model by calling

  • it on real tensor data.

call(inputs, training=False)

Calls the model on new inputs and returns the outputs as tensors.

In this case call() just reapplies all ops in the graph to the new inputs (e.g. build a new computational graph from the provided inputs).

Note: This method should not be called directly. It is only meant to be overridden when subclassing tf.keras.Model. To call a model on an input, always use the __call__() method, i.e. model(inputs), which relies on the underlying call() method.

Parameters:
  • inputs – Input tensor, or dict/list/tuple of input tensors.

  • training – Boolean or boolean scalar tensor, indicating whether to run the Network in training mode or inference mode.

  • mask – A mask or list of masks. A mask can be either a boolean tensor or None (no mask). For more details, check the guide [here](https://www.tensorflow.org/guide/keras/masking_and_padding).

Returns:

A tensor if there is a single output, or a list of tensors if there are more than one outputs.

classmethod from_config(config)

Creates a layer from its config.

This method is the reverse of get_config, capable of instantiating the same layer from the config dictionary. It does not handle layer connectivity (handled by Network), nor weights (handled by set_weights).

Parameters:

config – A Python dictionary, typically the output of get_config.

Returns:

A layer instance.

get_config()

Returns the config of the Model.

Config is a Python dictionary (serializable) containing the configuration of an object, which in this case is a Model. This allows the Model to be be reinstantiated later (without its trained weights) from this configuration.

Note that get_config() does not guarantee to return a fresh copy of dict every time it is called. The callers should make a copy of the returned dict if they want to modify it.

Developers of subclassed Model are advised to override this method, and continue to update the dict from super(MyModel, self).get_config() to provide the proper configuration of this Model. The default config will return config dict for init parameters if they are basic types. Raises NotImplementedError when in cases where a custom get_config() implementation is required for the subclassed model.

Returns:

Python dictionary containing the configuration of this Model.

class imspy.algorithm.ccs.predictors.PeptideIonMobilityApex

Bases: ABC

abstractmethod simulate_ion_mobilities(sequences, charges)
Return type:

ndarray[Any, dtype[TypeVar(_ScalarType_co, bound= generic, covariant=True)]]

abstractmethod simulate_ion_mobilities_pandas(data)
Return type:

DataFrame

class imspy.algorithm.ccs.predictors.SquareRootProjectionLayer(slopes, intercepts, trainable=True, **kwargs)

Bases: Layer

build(input_shape)

Creates the variables of the layer (for subclass implementers).

This is a method that implementers of subclasses of Layer or Model can override if they need a state-creation step in-between layer instantiation and layer call. It is invoked automatically before the first execution of call().

This is typically used to create the weights of Layer subclasses (at the discretion of the subclass implementer).

Parameters:

input_shape – Instance of TensorShape, or list of instances of TensorShape if the layer expects a list of inputs (one instance per input).

call(inputs)

This is where the layer’s logic lives.

The call() method may not create state (except in its first invocation, wrapping the creation of variables or other resources in tf.init_scope()). It is recommended to create state, including tf.Variable instances and nested Layer instances,

in __init__(), or in the build() method that is

called automatically before call() executes for the first time.

Parameters:
  • inputs

    Input tensor, or dict/list/tuple of input tensors. The first positional inputs argument is subject to special rules: - inputs must be explicitly passed. A layer cannot have zero

    arguments, and inputs cannot be provided via the default value of a keyword argument.

    • NumPy array or Python scalar values in inputs get cast as tensors.

    • Keras mask metadata is only collected from inputs.

    • Layers are built (build(input_shape) method) using shape info from inputs only.

    • input_spec compatibility is only checked against inputs.

    • Mixed precision input casting is only applied to inputs. If a layer has tensor arguments in *args or **kwargs, their casting behavior in mixed precision should be handled manually.

    • The SavedModel input specification is generated using inputs only.

    • Integration with various ecosystem packages like TFMOT, TFLite, TF.js, etc is only supported for inputs and not for tensors in positional and keyword arguments.

  • *args – Additional positional arguments. May contain tensors, although this is not recommended, for the reasons above.

  • **kwargs

    Additional keyword arguments. May contain tensors, although this is not recommended, for the reasons above. The following optional keyword arguments are reserved: - training: Boolean scalar tensor of Python boolean indicating

    whether the call is meant for training or inference.

    • mask: Boolean input mask. If the layer’s call() method takes a mask argument, its default value will be set to the mask generated for inputs by the previous layer (if input did come from a layer that generated a corresponding mask, i.e. if it came from a Keras layer with masking support).

Returns:

A tensor or list/tuple of tensors.

classmethod from_config(config)

Creates a layer from its config.

This method is the reverse of get_config, capable of instantiating the same layer from the config dictionary. It does not handle layer connectivity (handled by Network), nor weights (handled by set_weights).

Parameters:

config – A Python dictionary, typically the output of get_config.

Returns:

A layer instance.

get_config()

Returns the config of the layer.

A layer config is a Python dictionary (serializable) containing the configuration of a layer. The same layer can be reinstantiated later (without its trained weights) from this configuration.

The config of a layer does not include connectivity information, nor the layer class name. These are handled by Network (one layer of abstraction above).

Note that get_config() does not guarantee to return a fresh copy of dict every time it is called. The callers should make a copy of the returned dict if they want to modify it.

Returns:

Python dictionary.

imspy.algorithm.ccs.predictors.get_sqrt_slopes_and_intercepts(mz, charge, ccs, fit_charge_state_one=False)

Fit the square root model to the provided data. :type mz: ndarray[Any, dtype[TypeVar(_ScalarType_co, bound= generic, covariant=True)]] :param mz: The m/z values. :type charge: ndarray[Any, dtype[TypeVar(_ScalarType_co, bound= generic, covariant=True)]] :param charge: The charge states. :type ccs: ndarray[Any, dtype[TypeVar(_ScalarType_co, bound= generic, covariant=True)]] :param ccs: The collision cross sections. :type fit_charge_state_one: bool :param fit_charge_state_one: Whether to fit the charge state one.

Return type:

Tuple[ndarray[Any, dtype[TypeVar(_ScalarType_co, bound= generic, covariant=True)]], ndarray[Any, dtype[TypeVar(_ScalarType_co, bound= generic, covariant=True)]]]

Returns:

The slopes and intercepts of the square root model fit.

imspy.algorithm.ccs.predictors.load_deep_ccs_predictor()
Return type:

Model

imspy.algorithm.ccs.predictors.predict_inverse_ion_mobility(psm_collection, refine_model=True, verbose=False)

Predicts the inverse ion mobility for a collection of peptide spectrum matches. :type psm_collection: List[Psm] :param psm_collection: A list of peptide spectrum matches. :type refine_model: bool :param refine_model: Whether to refine the model by fine-tuning it on the provided data. :type verbose: bool :param verbose: Whether to print additional information during the prediction.

Return type:

None

Returns:

None, the inverse ion mobility is set in the peptide spectrum matches in place.

Module contents