spateo.external.STAGATE_pyG¶
# Author: Kangning Dong # File Name: __init__.py # Description:
Submodules¶
Attributes¶
Classes¶
Base class for all neural network modules. |
Functions¶
|
Training graph attention auto-encoder. |
|
|
|
Construct the spatial neighbor networks. |
|
Construct the spatial neighbor networks. |
|
|
|
|
|
Clustering using the mclust algorithm. |
Package Contents¶
- class spateo.external.STAGATE_pyG.STAGATE(hidden_dims)[source]¶
Bases:
torch.nn.Module
Base class for all neural network modules.
Your models should also subclass this class.
Modules can also contain other Modules, allowing to nest them in a tree structure. You can assign the submodules as regular attributes:
import torch.nn as nn import torch.nn.functional as F class Model(nn.Module): def __init__(self): super().__init__() self.conv1 = nn.Conv2d(1, 20, 5) self.conv2 = nn.Conv2d(20, 20, 5) def forward(self, x): x = F.relu(self.conv1(x)) return F.relu(self.conv2(x))
Submodules assigned in this way will be registered, and will have their parameters converted too when you call
to()
, etc.Note
As per the example above, an
__init__()
call to the parent class must be made before assignment on the child.- Variables:
- training bool
Boolean represents whether this module is in training or evaluation mode.
- conv1¶
- conv2¶
- conv3¶
- conv4¶
- spateo.external.STAGATE_pyG.train_STAGATE(adata, hidden_dims=[512, 30], n_epochs=1000, lr=0.001, key_added='STAGATE', gradient_clipping=5.0, weight_decay=0.0001, verbose=True, random_seed=0, save_loss=False, save_reconstrction=False, device=torch.device('cuda:0' if torch.cuda.is_available() else 'cpu'))[source]¶
Training graph attention auto-encoder.
- Parameters:
- adata
AnnData object of scanpy package.
- hidden_dims
The dimension of the encoder.
- n_epochs
Number of total epochs in training.
- lr
Learning rate for AdamOptimizer.
- key_added
The latent embeddings are saved in adata.obsm[key_added].
- gradient_clipping
Gradient Clipping.
- weight_decay
Weight decay for AdamOptimizer.
- save_loss
If True, the training loss is saved in adata.uns[‘STAGATE_loss’].
- save_reconstrction
If True, the reconstructed expression profiles are saved in adata.layers[‘STAGATE_ReX’].
- device
See torch.device.
- Return type:
AnnData
- spateo.external.STAGATE_pyG.Batch_Data(adata, num_batch_x, num_batch_y, spatial_key=['X', 'Y'], plot_Stats=False)[source]¶
- spateo.external.STAGATE_pyG.Cal_Spatial_Net(adata, rad_cutoff=None, k_cutoff=None, model='Radius', verbose=True)[source]¶
Construct the spatial neighbor networks.
- Parameters:
- adata
AnnData object of scanpy package.
- rad_cutoff
radius cutoff when model=’Radius’
- k_cutoff
The number of nearest neighbors when model=’KNN’
- model
The network construction model. When model==’Radius’, the spot is connected to spots whose distance is less than rad_cutoff. When model==’KNN’, the spot is connected to its first k_cutoff nearest neighbors.
- Return type:
The spatial networks are saved in adata.uns[‘Spatial_Net’]
- spateo.external.STAGATE_pyG.Cal_Spatial_Net_3D(adata, rad_cutoff_2D, rad_cutoff_Zaxis, key_section='Section_id', section_order=None, verbose=True)[source]¶
Construct the spatial neighbor networks.
- Parameters:
- adata
AnnData object of scanpy package.
- rad_cutoff_2D
radius cutoff for 2D SNN construction.
- rad_cutoff_Zaxis
radius cutoff for 2D SNN construction for consturcting SNNs between adjacent sections.
- key_section
The columns names of section_ID in adata.obs.
- section_order
The order of sections. The SNNs between adjacent sections are constructed according to this order.
- Return type:
The 3D spatial networks are saved in adata.uns[‘Spatial_Net’].