peptdeep.model.building_block

Classes:

AATransformerEncoding

AA_Mod_Embedding(out_features[, ...])

Concatenates the AA (128 ASCII codes) embedding with the modifcation vector

Decoder_GRU(in_features, out_features)

Decode with GRU

Decoder_LSTM(in_features, out_features)

Decode with LSTM

Decoder_Linear(in_features, out_features)

Decode w linear NN

Encoder_26AA_Mod_CNN_LSTM(out_features[, ...])

Encode AAs (26 AA letters) and modifications by CNN and LSTM layers

Encoder_26AA_Mod_CNN_LSTM_AttnSum(out_features)

Encode AAs (26 AA letters) and modifications by CNN and LSTM layers, then by 'SeqAttentionSum'.

Encoder_26AA_Mod_Charge_CNN_LSTM_AttnSum(...)

Encode AAs (26 AA letters), modifications and charge by transformers, and then by 'SeqAttentionSum'

Encoder_26AA_Mod_LSTM(out_features[, ...])

Two LSTM layers on AA (26 AA letters) and modifications.

Encoder_AA_Mod_CNN_LSTM_AttnSum(out_features)

Encode AAs (128 ASCII codes) and modifications by CNN and LSTM layers, and then by 'SeqAttentionSum'.

Encoder_AA_Mod_Charge_Transformer(out_features)

Encode AAs (128 ASCII codes), modifications and charge by transformers.

Encoder_AA_Mod_Charge_Transformer_AttnSum(...)

Encode AAs (128 ASCII codes), modifications and charge by transformers, and then by 'SeqAttentionSum'

Encoder_AA_Mod_Transformer(out_features[, ...])

AAs (128 ASCII codes) and modifications embedded by Bert, then encoded by 'SeqAttentionSum'.

Encoder_AA_Mod_Transformer_AttnSum(out_features)

Encode AAs (128 ASCII codes) and modifications by transformers.

HFace_Transformer_with_PositionalEncoder(...)

HuggingFace transformer with a positional encoder in front.

HiddenBert

Hidden_HFace_Transformer(hidden_dim[, ...])

Transformer NN based on HuggingFace's BertEncoder class

Hidden_Transformer(hidden[, hidden_expand, ...])

Transformer NN based on pytorch's built-in TransformerLayer class

InputAAEmbedding

InputAALSTM

InputAALSTM_cat_Charge

InputAALSTM_cat_Meta

InputMetaNet

InputModNet

InputModNetFixFirstK

Input_26AA_Mod_Charge_LSTM(out_features)

Applies a LSTM network to a AA (26 AA letters) sequence and modifications, and concatenates with charge state information

Input_26AA_Mod_LSTM(out_features[, ...])

Applies an LSTM network to a AA (26 AA letters) sequence & modifications

Input_26AA_Mod_Meta_LSTM(out_features)

Applies a LSTM network to a AA (26 AA letters) sequence and modifications, and concatenates with 'meta' information (charge, nce, instrument_indices)

Input_26AA_Mod_PositionalEncoding(out_features)

Encodes AA (26 AA letters) and modification vector

Input_AA_CNN_Encoder

Input_AA_CNN_LSTM_Encoder

Input_AA_CNN_LSTM_cat_Charge_Encoder

Input_AA_LSTM_Encoder

Input_AA_Mod_Charge_PositionalEncoding(...)

Embed AA (128 ASCII codes), modification, and charge state

Input_AA_Mod_PositionalEncoding(out_features)

Encodes AA (ASCII codes) and modification vector

LinearDecoder

Meta_Embedding(out_features)

Encodes Charge state, Normalized Collision Energy (NCE) and Instrument for a given spectrum into a 'meta' single layer network

Mod_Embedding(out_features)

Encodes the modification vector in a single layer feed forward network

Mod_Embedding_FixFirstK(out_features)

Encodes the modification vector in a single layer feed forward network, but not transforming the first k features

OutputLSTM_cat_Meta

OutputLinear_cat_Meta

PositionalEmbedding([out_features, max_len])

transform sequence with the standard embedding function

PositionalEncoding([out_features, max_len])

transform sequence input into a positional representation

SeqAttentionSum(in_features)

apply linear transformation and tensor rescaling with softmax

SeqCNN(embedding_hidden)

Extract sequence features using torch.nn.Conv1D with different kernel sizes (1(residue connection),3,5,7), and then concatenate the outputs of these Conv1Ds.

SeqCNN_MultiKernel(out_features)

Extract sequence features using torch.nn.Conv1D with different kernel sizes (1(residue connection),3,5,7), and then concatenate the outputs of these Conv1Ds.

SeqGRU(in_features, out_features[, ...])

returns GRU applied on sequence input

SeqGRUDecoder

SeqLSTM(in_features, out_features[, ...])

returns LSTM applied on sequence input

SeqLSTMDecoder

Seq_Meta_LSTM(in_features, out_features)

Takes a hidden layer which processes the hidden tensor as well as the 'meta' information of NCE, Instrument, Charge

Seq_Meta_Linear(in_features, out_features)

takes a hidden linear which processed the 'meta' information of NCE, Instrument, Charge

Seq_Transformer(in_features, hidden_features)

Using PyTorch built-in Transformer layers

Functions:

aa_embedding(hidden_size)

aa_one_hot(aa_indices, *cat_others)

ascii_embedding(hidden_size)

init_state(*shape)

instrument_embedding(hidden_size)

invert_attention_mask(encoder_attention_mask)

See invert_attention_mask() in https://github.com/huggingface/transformers/blob/main/src/transformers/modeling_utils.py#L737.

xavier_param(*shape)

zero_param(*shape)

peptdeep.model.building_block.AATransformerEncoding[source]

alias of Input_26AA_Mod_PositionalEncoding

class peptdeep.model.building_block.AA_Mod_Embedding(out_features, mod_feature_size=8)[source][source]

Bases: Module

Concatenates the AA (128 ASCII codes) embedding with the modifcation vector

Methods:

__init__(out_features[, mod_feature_size])

Initialize internal Module state, shared by both nn.Module and ScriptModule.

forward(aa_indices, mod_x)

Define the computation performed at every call.

__init__(out_features, mod_feature_size=8)[source][source]

Initialize internal Module state, shared by both nn.Module and ScriptModule.

forward(aa_indices, mod_x)[source][source]

Define the computation performed at every call.

Should be overridden by all subclasses.

Note

Although the recipe for forward pass needs to be defined within this function, one should call the Module instance afterwards instead of this since the former takes care of running the registered hooks while the latter silently ignores them.

class peptdeep.model.building_block.Decoder_GRU(in_features, out_features)[source][source]

Bases: Module

Decode with GRU

Methods:

__init__(in_features, out_features)

Initialize internal Module state, shared by both nn.Module and ScriptModule.

forward(x, output_len)

Define the computation performed at every call.

__init__(in_features, out_features)[source][source]

Initialize internal Module state, shared by both nn.Module and ScriptModule.

forward(x: tensor, output_len)[source][source]

Define the computation performed at every call.

Should be overridden by all subclasses.

Note

Although the recipe for forward pass needs to be defined within this function, one should call the Module instance afterwards instead of this since the former takes care of running the registered hooks while the latter silently ignores them.

class peptdeep.model.building_block.Decoder_LSTM(in_features, out_features)[source][source]

Bases: Module

Decode with LSTM

Methods:

__init__(in_features, out_features)

Initialize internal Module state, shared by both nn.Module and ScriptModule.

forward(x, output_len)

Define the computation performed at every call.

__init__(in_features, out_features)[source][source]

Initialize internal Module state, shared by both nn.Module and ScriptModule.

forward(x: tensor, output_len)[source][source]

Define the computation performed at every call.

Should be overridden by all subclasses.

Note

Although the recipe for forward pass needs to be defined within this function, one should call the Module instance afterwards instead of this since the former takes care of running the registered hooks while the latter silently ignores them.

class peptdeep.model.building_block.Decoder_Linear(in_features, out_features)[source][source]

Bases: Module

Decode w linear NN

Methods:

__init__(in_features, out_features)

Initialize internal Module state, shared by both nn.Module and ScriptModule.

forward(x)

Define the computation performed at every call.

__init__(in_features, out_features)[source][source]

Initialize internal Module state, shared by both nn.Module and ScriptModule.

forward(x)[source][source]

Define the computation performed at every call.

Should be overridden by all subclasses.

Note

Although the recipe for forward pass needs to be defined within this function, one should call the Module instance afterwards instead of this since the former takes care of running the registered hooks while the latter silently ignores them.

class peptdeep.model.building_block.Encoder_26AA_Mod_CNN_LSTM(out_features, n_lstm_layers=1)[source][source]

Bases: Module

Encode AAs (26 AA letters) and modifications by CNN and LSTM layers

Methods:

__init__(out_features[, n_lstm_layers])

Initialize internal Module state, shared by both nn.Module and ScriptModule.

forward(aa_indices, mod_x)

Define the computation performed at every call.

__init__(out_features, n_lstm_layers=1)[source][source]

Initialize internal Module state, shared by both nn.Module and ScriptModule.

forward(aa_indices, mod_x)[source][source]

Define the computation performed at every call.

Should be overridden by all subclasses.

Note

Although the recipe for forward pass needs to be defined within this function, one should call the Module instance afterwards instead of this since the former takes care of running the registered hooks while the latter silently ignores them.

class peptdeep.model.building_block.Encoder_26AA_Mod_CNN_LSTM_AttnSum(out_features, n_lstm_layers=2)[source][source]

Bases: Module

Encode AAs (26 AA letters) and modifications by CNN and LSTM layers, then by ‘SeqAttentionSum’.

Methods:

__init__(out_features[, n_lstm_layers])

Initialize internal Module state, shared by both nn.Module and ScriptModule.

forward(aa_indices, mod_x)

Define the computation performed at every call.

__init__(out_features, n_lstm_layers=2)[source][source]

Initialize internal Module state, shared by both nn.Module and ScriptModule.

forward(aa_indices, mod_x)[source][source]

Define the computation performed at every call.

Should be overridden by all subclasses.

Note

Although the recipe for forward pass needs to be defined within this function, one should call the Module instance afterwards instead of this since the former takes care of running the registered hooks while the latter silently ignores them.

class peptdeep.model.building_block.Encoder_26AA_Mod_Charge_CNN_LSTM_AttnSum(out_features)[source][source]

Bases: Module

Encode AAs (26 AA letters), modifications and charge by transformers, and then by ‘SeqAttentionSum’

Methods:

__init__(out_features)

Initialize internal Module state, shared by both nn.Module and ScriptModule.

forward(aa_indices, mod_x, charges)

Define the computation performed at every call.

__init__(out_features)[source][source]

Initialize internal Module state, shared by both nn.Module and ScriptModule.

forward(aa_indices, mod_x, charges)[source][source]

Define the computation performed at every call.

Should be overridden by all subclasses.

Note

Although the recipe for forward pass needs to be defined within this function, one should call the Module instance afterwards instead of this since the former takes care of running the registered hooks while the latter silently ignores them.

class peptdeep.model.building_block.Encoder_26AA_Mod_LSTM(out_features, n_lstm_layers=1)[source][source]

Bases: Module

Two LSTM layers on AA (26 AA letters) and modifications.

Methods:

__init__(out_features[, n_lstm_layers])

Initialize internal Module state, shared by both nn.Module and ScriptModule.

forward(aa_indices, mod_x)

Define the computation performed at every call.

__init__(out_features, n_lstm_layers=1)[source][source]

Initialize internal Module state, shared by both nn.Module and ScriptModule.

forward(aa_indices, mod_x)[source][source]

Define the computation performed at every call.

Should be overridden by all subclasses.

Note

Although the recipe for forward pass needs to be defined within this function, one should call the Module instance afterwards instead of this since the former takes care of running the registered hooks while the latter silently ignores them.

class peptdeep.model.building_block.Encoder_AA_Mod_CNN_LSTM_AttnSum(out_features, n_lstm_layers=2)[source][source]

Bases: Module

Encode AAs (128 ASCII codes) and modifications by CNN and LSTM layers, and then by ‘SeqAttentionSum’.

Methods:

__init__(out_features[, n_lstm_layers])

Initialize internal Module state, shared by both nn.Module and ScriptModule.

forward(aa_indices, mod_x)

Define the computation performed at every call.

__init__(out_features, n_lstm_layers=2)[source][source]

Initialize internal Module state, shared by both nn.Module and ScriptModule.

forward(aa_indices, mod_x)[source][source]

Define the computation performed at every call.

Should be overridden by all subclasses.

Note

Although the recipe for forward pass needs to be defined within this function, one should call the Module instance afterwards instead of this since the former takes care of running the registered hooks while the latter silently ignores them.

class peptdeep.model.building_block.Encoder_AA_Mod_Charge_Transformer(out_features, dropout=0.1, nlayers=4, output_attentions=False)[source][source]

Bases: Module

Encode AAs (128 ASCII codes), modifications and charge by transformers.

Methods:

__init__(out_features[, dropout, nlayers, ...])

Initialize internal Module state, shared by both nn.Module and ScriptModule.

forward(aa_indices, mod_x, charges[, ...])

Define the computation performed at every call.

__init__(out_features, dropout=0.1, nlayers=4, output_attentions=False)[source][source]

Initialize internal Module state, shared by both nn.Module and ScriptModule.

forward(aa_indices, mod_x, charges, attention_mask=None)[source][source]

Define the computation performed at every call.

Should be overridden by all subclasses.

Note

Although the recipe for forward pass needs to be defined within this function, one should call the Module instance afterwards instead of this since the former takes care of running the registered hooks while the latter silently ignores them.

class peptdeep.model.building_block.Encoder_AA_Mod_Charge_Transformer_AttnSum(out_features, dropout=0.1, nlayers=4, output_attentions=False)[source][source]

Bases: Module

Encode AAs (128 ASCII codes), modifications and charge by transformers, and then by ‘SeqAttentionSum’

Methods:

__init__(out_features[, dropout, nlayers, ...])

Initialize internal Module state, shared by both nn.Module and ScriptModule.

forward(aa_indices, mod_x, charges)

Define the computation performed at every call.

__init__(out_features, dropout=0.1, nlayers=4, output_attentions=False)[source][source]

Initialize internal Module state, shared by both nn.Module and ScriptModule.

forward(aa_indices, mod_x, charges)[source][source]

Define the computation performed at every call.

Should be overridden by all subclasses.

Note

Although the recipe for forward pass needs to be defined within this function, one should call the Module instance afterwards instead of this since the former takes care of running the registered hooks while the latter silently ignores them.

class peptdeep.model.building_block.Encoder_AA_Mod_Transformer(out_features, dropout=0.1, nlayers=4, output_attentions=False)[source][source]

Bases: Module

AAs (128 ASCII codes) and modifications embedded by Bert, then encoded by ‘SeqAttentionSum’.

Methods:

__init__(out_features[, dropout, nlayers, ...])

Initialize internal Module state, shared by both nn.Module and ScriptModule.

forward(aa_indices, mod_x[, attention_mask])

Define the computation performed at every call.

__init__(out_features, dropout=0.1, nlayers=4, output_attentions=False)[source][source]

Initialize internal Module state, shared by both nn.Module and ScriptModule.

forward(aa_indices, mod_x, attention_mask=None)[source][source]

Define the computation performed at every call.

Should be overridden by all subclasses.

Note

Although the recipe for forward pass needs to be defined within this function, one should call the Module instance afterwards instead of this since the former takes care of running the registered hooks while the latter silently ignores them.

class peptdeep.model.building_block.Encoder_AA_Mod_Transformer_AttnSum(out_features, dropout=0.1, nlayers=4, output_attentions=False)[source][source]

Bases: Module

Encode AAs (128 ASCII codes) and modifications by transformers.

Methods:

__init__(out_features[, dropout, nlayers, ...])

Initialize internal Module state, shared by both nn.Module and ScriptModule.

forward(aa_indices, mod_x)

Define the computation performed at every call.

__init__(out_features, dropout=0.1, nlayers=4, output_attentions=False)[source][source]

Initialize internal Module state, shared by both nn.Module and ScriptModule.

forward(aa_indices, mod_x)[source][source]

Define the computation performed at every call.

Should be overridden by all subclasses.

Note

Although the recipe for forward pass needs to be defined within this function, one should call the Module instance afterwards instead of this since the former takes care of running the registered hooks while the latter silently ignores them.

class peptdeep.model.building_block.HFace_Transformer_with_PositionalEncoder(hidden_dim: int, hidden_expand=4, nheads=8, nlayers=4, dropout=0.1, output_attentions=False, max_len=200)[source][source]

Bases: Module

HuggingFace transformer with a positional encoder in front.

Parameters:
  • hidden_dim (int) – Input and output feature dimension.

  • hidden_expand (int, optional) – FFN hidden size = hidden*hidden_expand. Defaults to 4.

  • nhead (int, optional) – Multi-head attention number. Defaults to 8.

  • nlayers (int, optional) – Number of transformer layers. Defaults to 4.

  • dropout (float, optional) – Dropout rate. Defaults to 0.1.

  • output_attentions (bool, optional) – If output attention values. Defaults to False.

  • max_len (int, optional) – Max input sequence length. Defaults to 200.

Methods:

__init__(hidden_dim[, hidden_expand, ...])

Initialize internal Module state, shared by both nn.Module and ScriptModule.

forward(x[, attention_mask])

__init__(hidden_dim: int, hidden_expand=4, nheads=8, nlayers=4, dropout=0.1, output_attentions=False, max_len=200)[source][source]

Initialize internal Module state, shared by both nn.Module and ScriptModule.

forward(x: Tensor, attention_mask: Tensor = None) tuple[source][source]
Parameters:

x (torch.Tensor) – Input tensor

Returns:

Tensor: Output tensor. [Tensor]: Attention tensor, returned only if output_attentions is True.

Return type:

tuple

peptdeep.model.building_block.HiddenBert[source]

alias of Hidden_HFace_Transformer

class peptdeep.model.building_block.Hidden_HFace_Transformer(hidden_dim, hidden_expand=4, nheads=8, nlayers=4, dropout=0.1, output_attentions=False)[source][source]

Bases: Module

Transformer NN based on HuggingFace’s BertEncoder class

Methods:

__init__(hidden_dim[, hidden_expand, ...])

Initialize internal Module state, shared by both nn.Module and ScriptModule.

forward(x[, attention_mask])

__init__(hidden_dim, hidden_expand=4, nheads=8, nlayers=4, dropout=0.1, output_attentions=False)[source][source]

Initialize internal Module state, shared by both nn.Module and ScriptModule.

forward(x: Tensor, attention_mask: Tensor = None) tuple[source][source]
Parameters:
  • x (torch.Tensor) – shape = (batch, seq_len, dim)

  • attention_mask (torch.Tensor) – shape = (batch, seq_len), [0,1] tensor , 1=enable

Returns:

out[0] is the hidden layer output, and out[1] is the output attention if self.output_attentions==True

Return type:

(Tensor, [Tensor])

class peptdeep.model.building_block.Hidden_Transformer(hidden, hidden_expand=4, nheads=8, nlayers=4, dropout=0.1)[source][source]

Bases: Module

Transformer NN based on pytorch’s built-in TransformerLayer class

Methods:

__init__(hidden[, hidden_expand, nheads, ...])

Initialize internal Module state, shared by both nn.Module and ScriptModule.

forward(x)

Define the computation performed at every call.

__init__(hidden, hidden_expand=4, nheads=8, nlayers=4, dropout=0.1)[source][source]

Initialize internal Module state, shared by both nn.Module and ScriptModule.

forward(x)[source][source]

Define the computation performed at every call.

Should be overridden by all subclasses.

Note

Although the recipe for forward pass needs to be defined within this function, one should call the Module instance afterwards instead of this since the former takes care of running the registered hooks while the latter silently ignores them.

peptdeep.model.building_block.InputAAEmbedding[source]

alias of AA_Mod_Embedding

peptdeep.model.building_block.InputAALSTM[source]

alias of Input_26AA_Mod_LSTM

peptdeep.model.building_block.InputAALSTM_cat_Charge[source]

alias of Input_26AA_Mod_Charge_LSTM

peptdeep.model.building_block.InputAALSTM_cat_Meta[source]

alias of Input_26AA_Mod_Meta_LSTM

peptdeep.model.building_block.InputMetaNet[source]

alias of Meta_Embedding

peptdeep.model.building_block.InputModNet[source]

alias of Mod_Embedding

peptdeep.model.building_block.InputModNetFixFirstK[source]

alias of Mod_Embedding_FixFirstK

class peptdeep.model.building_block.Input_26AA_Mod_Charge_LSTM(out_features)[source][source]

Bases: Module

Applies a LSTM network to a AA (26 AA letters) sequence and modifications, and concatenates with charge state information

Methods:

__init__(out_features)

Initialize internal Module state, shared by both nn.Module and ScriptModule.

forward(aa_indices, mod_x, charges)

Define the computation performed at every call.

__init__(out_features)[source][source]

Initialize internal Module state, shared by both nn.Module and ScriptModule.

forward(aa_indices, mod_x, charges)[source][source]

Define the computation performed at every call.

Should be overridden by all subclasses.

Note

Although the recipe for forward pass needs to be defined within this function, one should call the Module instance afterwards instead of this since the former takes care of running the registered hooks while the latter silently ignores them.

class peptdeep.model.building_block.Input_26AA_Mod_LSTM(out_features, n_lstm_layers=1)[source][source]

Bases: Module

Applies an LSTM network to a AA (26 AA letters) sequence & modifications

Methods:

__init__(out_features[, n_lstm_layers])

Initialize internal Module state, shared by both nn.Module and ScriptModule.

forward(aa_indices, mod_x)

Define the computation performed at every call.

__init__(out_features, n_lstm_layers=1)[source][source]

Initialize internal Module state, shared by both nn.Module and ScriptModule.

forward(aa_indices, mod_x)[source][source]

Define the computation performed at every call.

Should be overridden by all subclasses.

Note

Although the recipe for forward pass needs to be defined within this function, one should call the Module instance afterwards instead of this since the former takes care of running the registered hooks while the latter silently ignores them.

class peptdeep.model.building_block.Input_26AA_Mod_Meta_LSTM(out_features)[source][source]

Bases: Module

Applies a LSTM network to a AA (26 AA letters) sequence and modifications, and concatenates with ‘meta’ information (charge, nce, instrument_indices)

Methods:

__init__(out_features)

Initialize internal Module state, shared by both nn.Module and ScriptModule.

forward(aa_indices, mod_x, charges, NCEs, ...)

Define the computation performed at every call.

__init__(out_features)[source][source]

Initialize internal Module state, shared by both nn.Module and ScriptModule.

forward(aa_indices, mod_x, charges, NCEs, instrument_indices)[source][source]

Define the computation performed at every call.

Should be overridden by all subclasses.

Note

Although the recipe for forward pass needs to be defined within this function, one should call the Module instance afterwards instead of this since the former takes care of running the registered hooks while the latter silently ignores them.

class peptdeep.model.building_block.Input_26AA_Mod_PositionalEncoding(out_features, max_len=200)[source][source]

Bases: Module

Encodes AA (26 AA letters) and modification vector

Methods:

__init__(out_features[, max_len])

Initialize internal Module state, shared by both nn.Module and ScriptModule.

forward(aa_indices, mod_x)

Define the computation performed at every call.

__init__(out_features, max_len=200)[source][source]

Initialize internal Module state, shared by both nn.Module and ScriptModule.

forward(aa_indices, mod_x)[source][source]

Define the computation performed at every call.

Should be overridden by all subclasses.

Note

Although the recipe for forward pass needs to be defined within this function, one should call the Module instance afterwards instead of this since the former takes care of running the registered hooks while the latter silently ignores them.

peptdeep.model.building_block.Input_AA_CNN_Encoder[source]

alias of Encoder_26AA_Mod_CNN_LSTM

peptdeep.model.building_block.Input_AA_CNN_LSTM_Encoder[source]

alias of Encoder_26AA_Mod_CNN_LSTM_AttnSum

peptdeep.model.building_block.Input_AA_CNN_LSTM_cat_Charge_Encoder[source]

alias of Encoder_26AA_Mod_Charge_CNN_LSTM_AttnSum

peptdeep.model.building_block.Input_AA_LSTM_Encoder[source]

alias of Encoder_26AA_Mod_LSTM

class peptdeep.model.building_block.Input_AA_Mod_Charge_PositionalEncoding(out_features, max_len=200)[source][source]

Bases: Module

Embed AA (128 ASCII codes), modification, and charge state

Methods:

__init__(out_features[, max_len])

Initialize internal Module state, shared by both nn.Module and ScriptModule.

forward(aa_indices, mod_x, charges)

Define the computation performed at every call.

__init__(out_features, max_len=200)[source][source]

Initialize internal Module state, shared by both nn.Module and ScriptModule.

forward(aa_indices, mod_x, charges)[source][source]

Define the computation performed at every call.

Should be overridden by all subclasses.

Note

Although the recipe for forward pass needs to be defined within this function, one should call the Module instance afterwards instead of this since the former takes care of running the registered hooks while the latter silently ignores them.

class peptdeep.model.building_block.Input_AA_Mod_PositionalEncoding(out_features, max_len=200)[source][source]

Bases: Module

Encodes AA (ASCII codes) and modification vector

Methods:

__init__(out_features[, max_len])

Initialize internal Module state, shared by both nn.Module and ScriptModule.

forward(aa_indices, mod_x)

Define the computation performed at every call.

__init__(out_features, max_len=200)[source][source]

Initialize internal Module state, shared by both nn.Module and ScriptModule.

forward(aa_indices, mod_x)[source][source]

Define the computation performed at every call.

Should be overridden by all subclasses.

Note

Although the recipe for forward pass needs to be defined within this function, one should call the Module instance afterwards instead of this since the former takes care of running the registered hooks while the latter silently ignores them.

peptdeep.model.building_block.LinearDecoder[source]

alias of Decoder_Linear

class peptdeep.model.building_block.Meta_Embedding(out_features)[source][source]

Bases: Module

Encodes Charge state, Normalized Collision Energy (NCE) and Instrument for a given spectrum into a ‘meta’ single layer network

Methods:

__init__(out_features)

Initialize internal Module state, shared by both nn.Module and ScriptModule.

forward(charges, NCEs, instrument_indices)

Define the computation performed at every call.

__init__(out_features)[source][source]

Initialize internal Module state, shared by both nn.Module and ScriptModule.

forward(charges, NCEs, instrument_indices)[source][source]

Define the computation performed at every call.

Should be overridden by all subclasses.

Note

Although the recipe for forward pass needs to be defined within this function, one should call the Module instance afterwards instead of this since the former takes care of running the registered hooks while the latter silently ignores them.

class peptdeep.model.building_block.Mod_Embedding(out_features)[source][source]

Bases: Module

Encodes the modification vector in a single layer feed forward network

Methods:

__init__(out_features)

Initialize internal Module state, shared by both nn.Module and ScriptModule.

forward(mod_x)

Define the computation performed at every call.

__init__(out_features)[source][source]

Initialize internal Module state, shared by both nn.Module and ScriptModule.

forward(mod_x)[source][source]

Define the computation performed at every call.

Should be overridden by all subclasses.

Note

Although the recipe for forward pass needs to be defined within this function, one should call the Module instance afterwards instead of this since the former takes care of running the registered hooks while the latter silently ignores them.

class peptdeep.model.building_block.Mod_Embedding_FixFirstK(out_features)[source][source]

Bases: Module

Encodes the modification vector in a single layer feed forward network, but not transforming the first k features

Methods:

__init__(out_features)

Initialize internal Module state, shared by both nn.Module and ScriptModule.

forward(mod_x)

Define the computation performed at every call.

__init__(out_features)[source][source]

Initialize internal Module state, shared by both nn.Module and ScriptModule.

forward(mod_x)[source][source]

Define the computation performed at every call.

Should be overridden by all subclasses.

Note

Although the recipe for forward pass needs to be defined within this function, one should call the Module instance afterwards instead of this since the former takes care of running the registered hooks while the latter silently ignores them.

peptdeep.model.building_block.OutputLSTM_cat_Meta[source]

alias of Seq_Meta_LSTM

peptdeep.model.building_block.OutputLinear_cat_Meta[source]

alias of Seq_Meta_Linear

class peptdeep.model.building_block.PositionalEmbedding(out_features=128, max_len=200)[source][source]

Bases: Module

transform sequence with the standard embedding function

Methods:

__init__([out_features, max_len])

Initialize internal Module state, shared by both nn.Module and ScriptModule.

forward(x)

Define the computation performed at every call.

__init__(out_features=128, max_len=200)[source][source]

Initialize internal Module state, shared by both nn.Module and ScriptModule.

forward(x: Tensor)[source][source]

Define the computation performed at every call.

Should be overridden by all subclasses.

Note

Although the recipe for forward pass needs to be defined within this function, one should call the Module instance afterwards instead of this since the former takes care of running the registered hooks while the latter silently ignores them.

class peptdeep.model.building_block.PositionalEncoding(out_features=128, max_len=200)[source][source]

Bases: Module

transform sequence input into a positional representation

Methods:

__init__([out_features, max_len])

Initialize internal Module state, shared by both nn.Module and ScriptModule.

forward(x)

Define the computation performed at every call.

__init__(out_features=128, max_len=200)[source][source]

Initialize internal Module state, shared by both nn.Module and ScriptModule.

forward(x)[source][source]

Define the computation performed at every call.

Should be overridden by all subclasses.

Note

Although the recipe for forward pass needs to be defined within this function, one should call the Module instance afterwards instead of this since the former takes care of running the registered hooks while the latter silently ignores them.

class peptdeep.model.building_block.SeqAttentionSum(in_features)[source][source]

Bases: Module

apply linear transformation and tensor rescaling with softmax

Methods:

__init__(in_features)

Initialize internal Module state, shared by both nn.Module and ScriptModule.

forward(x)

Define the computation performed at every call.

__init__(in_features)[source][source]

Initialize internal Module state, shared by both nn.Module and ScriptModule.

forward(x)[source][source]

Define the computation performed at every call.

Should be overridden by all subclasses.

Note

Although the recipe for forward pass needs to be defined within this function, one should call the Module instance afterwards instead of this since the former takes care of running the registered hooks while the latter silently ignores them.

class peptdeep.model.building_block.SeqCNN(embedding_hidden)[source][source]

Bases: Module

Extract sequence features using torch.nn.Conv1D with different kernel sizes (1(residue connection),3,5,7), and then concatenate the outputs of these Conv1Ds. The Output dim is 4*embedding_hidden.

Methods:

__init__(embedding_hidden)

Initialize internal Module state, shared by both nn.Module and ScriptModule.

forward(x)

Define the computation performed at every call.

__init__(embedding_hidden)[source][source]

Initialize internal Module state, shared by both nn.Module and ScriptModule.

forward(x)[source][source]

Define the computation performed at every call.

Should be overridden by all subclasses.

Note

Although the recipe for forward pass needs to be defined within this function, one should call the Module instance afterwards instead of this since the former takes care of running the registered hooks while the latter silently ignores them.

class peptdeep.model.building_block.SeqCNN_MultiKernel(out_features: int)[source][source]

Bases: Module

Extract sequence features using torch.nn.Conv1D with different kernel sizes (1(residue connection),3,5,7), and then concatenate the outputs of these Conv1Ds.

Methods:

__init__(out_features)

forward(x)

Define the computation performed at every call.

__init__(out_features: int)[source][source]
Parameters:

out_features (int) – Must be divided by 4.

Raises:

ValueError – “out_features must be divided by 4”

forward(x)[source][source]

Define the computation performed at every call.

Should be overridden by all subclasses.

Note

Although the recipe for forward pass needs to be defined within this function, one should call the Module instance afterwards instead of this since the former takes care of running the registered hooks while the latter silently ignores them.

class peptdeep.model.building_block.SeqGRU(in_features, out_features, rnn_layer=2, bidirectional=True)[source][source]

Bases: Module

returns GRU applied on sequence input

Methods:

__init__(in_features, out_features[, ...])

Initialize internal Module state, shared by both nn.Module and ScriptModule.

forward(x)

Define the computation performed at every call.

__init__(in_features, out_features, rnn_layer=2, bidirectional=True)[source][source]

Initialize internal Module state, shared by both nn.Module and ScriptModule.

forward(x: Tensor)[source][source]

Define the computation performed at every call.

Should be overridden by all subclasses.

Note

Although the recipe for forward pass needs to be defined within this function, one should call the Module instance afterwards instead of this since the former takes care of running the registered hooks while the latter silently ignores them.

peptdeep.model.building_block.SeqGRUDecoder[source]

alias of Decoder_GRU

class peptdeep.model.building_block.SeqLSTM(in_features, out_features, rnn_layer=2, bidirectional=True)[source][source]

Bases: Module

returns LSTM applied on sequence input

Methods:

__init__(in_features, out_features[, ...])

Initialize internal Module state, shared by both nn.Module and ScriptModule.

forward(x)

Define the computation performed at every call.

__init__(in_features, out_features, rnn_layer=2, bidirectional=True)[source][source]

Initialize internal Module state, shared by both nn.Module and ScriptModule.

forward(x: Tensor)[source][source]

Define the computation performed at every call.

Should be overridden by all subclasses.

Note

Although the recipe for forward pass needs to be defined within this function, one should call the Module instance afterwards instead of this since the former takes care of running the registered hooks while the latter silently ignores them.

peptdeep.model.building_block.SeqLSTMDecoder[source]

alias of Decoder_LSTM

class peptdeep.model.building_block.Seq_Meta_LSTM(in_features, out_features)[source][source]

Bases: Module

Takes a hidden layer which processes the hidden tensor as well as the ‘meta’ information of NCE, Instrument, Charge

Methods:

__init__(in_features, out_features)

Initialize internal Module state, shared by both nn.Module and ScriptModule.

forward(x, charges, NCEs, instrument_indices)

Define the computation performed at every call.

__init__(in_features, out_features)[source][source]

Initialize internal Module state, shared by both nn.Module and ScriptModule.

forward(x, charges, NCEs, instrument_indices)[source][source]

Define the computation performed at every call.

Should be overridden by all subclasses.

Note

Although the recipe for forward pass needs to be defined within this function, one should call the Module instance afterwards instead of this since the former takes care of running the registered hooks while the latter silently ignores them.

class peptdeep.model.building_block.Seq_Meta_Linear(in_features, out_features)[source][source]

Bases: Module

takes a hidden linear which processed the ‘meta’ information of NCE, Instrument, Charge

Methods:

__init__(in_features, out_features)

Initialize internal Module state, shared by both nn.Module and ScriptModule.

forward(x, charges, NCEs, instrument_indices)

Define the computation performed at every call.

__init__(in_features, out_features)[source][source]

Initialize internal Module state, shared by both nn.Module and ScriptModule.

forward(x, charges, NCEs, instrument_indices)[source][source]

Define the computation performed at every call.

Should be overridden by all subclasses.

Note

Although the recipe for forward pass needs to be defined within this function, one should call the Module instance afterwards instead of this since the former takes care of running the registered hooks while the latter silently ignores them.

class peptdeep.model.building_block.Seq_Transformer(in_features, hidden_features, nheads=8, nlayers=2, dropout=0.1)[source][source]

Bases: Module

Using PyTorch built-in Transformer layers

Methods:

__init__(in_features, hidden_features[, ...])

Initialize internal Module state, shared by both nn.Module and ScriptModule.

forward(x)

Define the computation performed at every call.

__init__(in_features, hidden_features, nheads=8, nlayers=2, dropout=0.1)[source][source]

Initialize internal Module state, shared by both nn.Module and ScriptModule.

forward(x)[source][source]

Define the computation performed at every call.

Should be overridden by all subclasses.

Note

Although the recipe for forward pass needs to be defined within this function, one should call the Module instance afterwards instead of this since the former takes care of running the registered hooks while the latter silently ignores them.

peptdeep.model.building_block.aa_embedding(hidden_size)[source][source]
peptdeep.model.building_block.aa_one_hot(aa_indices, *cat_others)[source][source]
peptdeep.model.building_block.ascii_embedding(hidden_size)[source][source]
peptdeep.model.building_block.init_state(*shape)[source]
peptdeep.model.building_block.instrument_embedding(hidden_size)[source][source]
peptdeep.model.building_block.invert_attention_mask(encoder_attention_mask: Tensor, dtype=torch.float32) FloatTensor[source][source]

See invert_attention_mask() in https://github.com/huggingface/transformers/blob/main/src/transformers/modeling_utils.py#L737. Invert an attention mask (e.g., switches 0. and 1.). :param encoder_attention_mask: An attention mask. :type encoder_attention_mask: torch.Tensor

Returns:

The inverted attention mask.

Return type:

torch.Tensor

peptdeep.model.building_block.xavier_param(*shape)[source][source]
peptdeep.model.building_block.zero_param(*shape)[source][source]