cellmaps_coembedding.proteinprojector package
Submodules
cellmaps_coembedding.proteinprojector.architecture module
- class cellmaps_coembedding.proteinprojector.architecture.Modality(training_data, name, transform, device)[source]
Bases:
objectRepresents a single modality of data, containing training features and labels.
Initialize the Modality object with given training data, a name, a transformation, and the device.
- Parameters:
training_data – The data to use for training. Expects a list of lists where each sublist contains the label followed by feature values.
name – The name of the modality.
transform – The transformation to apply to the data, converting it to a tensor.
device – The device to transfer the tensors to.
- class cellmaps_coembedding.proteinprojector.architecture.Protein_Dataset(modalities_dict)[source]
Bases:
DatasetA dataset class for handling protein data across multiple modalities.
Initialize the dataset using a dictionary of modalities.
- Parameters:
modalities_dict – A dictionary where keys are modality names and values are Modality objects.
- class cellmaps_coembedding.proteinprojector.architecture.ToTensor[source]
Bases:
objectA class that converts a numpy ndarray to a torch tensor.
- class cellmaps_coembedding.proteinprojector.architecture.TrainingDataWrapper(modality_data, modality_names, device, l2_norm, dropout, latent_dim, hidden_size_1, hidden_size_2, resultsdir)[source]
Bases:
objectWraps training data for all modalities.
Initialize the wrapper with the given configuration.
- cellmaps_coembedding.proteinprojector.architecture.init_weights(module)[source]
Initialize weights for linear layers using Xavier normal distribution and biases to zero.
- class cellmaps_coembedding.proteinprojector.architecture.uniembed_nn(data_wrapper)[source]
Bases:
ModuleA neural network model for embedding proteins using multiple modalities.
Initialize the model using a data wrapper that contains modality data configurations.
- forward(inputs)[source]
Forward pass of the model, processing inputs through encoders and decoders.
- Parameters:
inputs – Dictionary of inputs where keys are modality names and values are corresponding tensors.
- Returns:
Tuple of dictionaries containing latent representations and outputs for all modalities.
Module contents
ProteinProjector co-embedding algorithm.
This module provides the ProteinProjector implementation, formerly known as ProteinGPS. It exposes utilities for training the neural network, saving results, and yielding co-embeddings.
- class cellmaps_coembedding.proteinprojector.Modality(training_data, name, transform, device)[source]
Bases:
objectRepresents a single modality of data, containing training features and labels.
Initialize the Modality object with given training data, a name, a transformation, and the device.
- Parameters:
training_data – The data to use for training. Expects a list of lists where each sublist contains the label followed by feature values.
name – The name of the modality.
transform – The transformation to apply to the data, converting it to a tensor.
device – The device to transfer the tensors to.
- class cellmaps_coembedding.proteinprojector.Protein_Dataset(modalities_dict)[source]
Bases:
DatasetA dataset class for handling protein data across multiple modalities.
Initialize the dataset using a dictionary of modalities.
- Parameters:
modalities_dict – A dictionary where keys are modality names and values are Modality objects.
- class cellmaps_coembedding.proteinprojector.ToTensor[source]
Bases:
objectA class that converts a numpy ndarray to a torch tensor.
- class cellmaps_coembedding.proteinprojector.TrainingDataWrapper(modality_data, modality_names, device, l2_norm, dropout, latent_dim, hidden_size_1, hidden_size_2, resultsdir)[source]
Bases:
objectWraps training data for all modalities.
Initialize the wrapper with the given configuration.
- cellmaps_coembedding.proteinprojector.fit_predict(resultsdir: str, modality_data: Iterable[Iterable[Iterable[float]]], modality_names: Iterable[str] = (), batch_size: int = 16, latent_dim: int = 128, n_epochs: int = 250, triplet_margin: float = 1.0, lambda_reconstruction: float = 1.0, lambda_triplet: float = 1.0, lambda_l2: float = 0.001, l2_norm: bool = False, dropout: float = 0.0, save_epoch: int = 50, learn_rate: float = 0.0001, hidden_size_1: int = 512, hidden_size_2: int = 256, save_update_epochs: bool = False, mean_losses: bool = False, negative_from_batch: bool = False) Generator[List[float], None, None][source]
Trains and predicts using a deep learning model with the given configuration and data.
- Parameters:
resultsdir – Directory to save training results and models.
modality_data – Input data for the model.
modality_names – Names of modalities; autogenerated if not provided.
batch_size – Batch size for training.
latent_dim – Dimensionality of the latent embeddings.
n_epochs – Number of training epochs.
triplet_margin – Margin for triplet loss.
lambda_reconstruction – Weight for reconstruction loss.
lambda_triplet – Weight for triplet loss.
lambda_l2 – Weight for L2 regularization.
l2_norm – Whether to use L2 normalization.
dropout – Dropout rate.
save_epoch – Epoch interval at which to save the model.
learn_rate – Learning rate for the optimizer.
hidden_size_1 – Size of the first hidden layer.
hidden_size_2 – Size of the second hidden layer.
save_update_epochs – Flag to save model state at specified epoch intervals.
mean_losses – Whether to average losses or not.
negative_from_batch – Whether to use negative samples from the same batch for triplet loss.
- Returns:
Generator of average embeddings for each protein.
- cellmaps_coembedding.proteinprojector.save_results(model: Module, protein_dataset: Protein_Dataset, data_wrapper: TrainingDataWrapper, results_suffix: str = '') Dict[str, Dict[str, ndarray]][source]
Evaluates the model, saves the state, and exports embeddings for each protein.
- Parameters:
model – The neural network model.
protein_dataset – The dataset containing protein data.
data_wrapper – Data handling and configurations as an object.
results_suffix – Suffix to append to results directory for saving.
- Returns:
Dictionary keyed by protein containing modality embeddings.
- class cellmaps_coembedding.proteinprojector.uniembed_nn(data_wrapper)[source]
Bases:
ModuleA neural network model for embedding proteins using multiple modalities.
Initialize the model using a data wrapper that contains modality data configurations.
- forward(inputs)[source]
Forward pass of the model, processing inputs through encoders and decoders.
- Parameters:
inputs – Dictionary of inputs where keys are modality names and values are corresponding tensors.
- Returns:
Tuple of dictionaries containing latent representations and outputs for all modalities.
- cellmaps_coembedding.proteinprojector.write_embedding_dictionary_to_file(filepath: str, dictionary: Dict[str, ndarray], dims: int) None[source]
Writes a dictionary of embeddings to a tab-separated file with headers.
- Parameters:
filepath – Path to the file where embeddings will be saved.
dictionary – Dictionary of embeddings with keys as names and values as embedding vectors.
dims – Dimension of embedding vectors.