Skip to content

Encoders (depthcharge.encoders)

PositionalEncoder(d_model, min_wavelength=1.0, max_wavelength=100000.0)

Bases: FloatEncoder

The positional encoder for sequences.

PARAMETER DESCRIPTION
d_model

The number of features to output.

TYPE: int

min_wavelength

The shortest wavelength in the geometric progression.

TYPE: float DEFAULT: 1.0

max_wavelength

The longest wavelength in the geometric progression.

TYPE: float DEFAULT: 100000.0

Functions

forward(X)

Encode positions in a sequence.

PARAMETER DESCRIPTION
X

The first dimension should be the batch size (i.e. each is one peptide) and the second dimension should be the sequence (i.e. each should be an amino acid representation).

TYPE: torch.Tensor of shape (batch_size, n_sequence, n_features)

RETURNS DESCRIPTION
torch.Tensor of shape (batch_size, n_sequence, n_features)

The encoded features for the mass spectra.

FloatEncoder(d_model, min_wavelength=0.001, max_wavelength=10000, learnable_wavelengths=False)

Bases: Module

Encode floating point values using sine and cosine waves.

PARAMETER DESCRIPTION
d_model

The number of features to output.

TYPE: int

min_wavelength

The minimum wavelength to use.

TYPE: float DEFAULT: 0.001

max_wavelength

The maximum wavelength to use.

TYPE: float DEFAULT: 10000

learnable_wavelengths

Allow the selected wavelengths to be fine-tuned by the model.

TYPE: bool DEFAULT: False

Functions

forward(X)

Encode m/z values.

PARAMETER DESCRIPTION
X

The masses to embed.

TYPE: torch.Tensor of shape (batch_size, n_float)

RETURNS DESCRIPTION
torch.Tensor of shape (batch_size, n_float, d_model)

The encoded features for the floating point numbers.

PeakEncoder(d_model, min_mz_wavelength=0.001, max_mz_wavelength=10000, min_intensity_wavelength=1e-06, max_intensity_wavelength=1, learnable_wavelengths=False)

Bases: Module

Encode mass spectrum.

PARAMETER DESCRIPTION
d_model

The number of features to output.

TYPE: int

min_mz_wavelength

The minimum wavelength to use for m/z.

TYPE: float DEFAULT: 0.001

max_mz_wavelength

The maximum wavelength to use for m/z.

TYPE: float DEFAULT: 10000

min_intensity_wavelength

The minimum wavelength to use for intensity. The default assumes intensities between [0, 1].

TYPE: float DEFAULT: 1e-06

max_intensity_wavelength

The maximum wavelength to use for intensity. The default assumes intensities between [0, 1].

TYPE: float DEFAULT: 1

learnable_wavelengths

Allow the selected wavelengths to be fine-tuned by the model.

TYPE: bool DEFAULT: False

Functions

forward(X)

Encode m/z values and intensities.

Note that we expect intensities to fall within the interval [0, 1].

PARAMETER DESCRIPTION
X

The spectra to embed. Axis 0 represents a mass spectrum, axis 1 contains the peaks in the mass spectrum, and axis 2 is essentially a 2-tuple specifying the m/z-intensity pair for each peak. These should be zero-padded, such that all of the spectra in the batch are the same length.

TYPE: torch.Tensor of shape (n_spectra, n_peaks, 2)

RETURNS DESCRIPTION
torch.Tensor of shape (n_spectra, n_peaks, d_model)

The encoded features for the mass spectra.