sakura.utils.data_transformations.ToTensor

class sakura.utils.data_transformations.ToTensor

Bases: object

Callable class to convert input data to PyTorch Tensors

Handles input-specific transformations such as transposing gene data or adjusting dimensions.

For ‘gene’ input:

  • DataFrames are transposed (genes x samples → samples x genes).

  • Series become 2D tensors (1 sample x genes).

  • Sparse matrices are densified.

For ‘pheno’ input, no transpose is applied.

Parameters:
  • sample (pd.DataFrame, pd.Series, np.ndarray or scipy.sparse matrix) – Input data to convert

  • input_type (Literal['gene','pheno'], optional) – Type of input data, can be ‘gene’ (gene expression) or ‘pheno’ (phenotype), defaults to ‘gene’

  • force_tensor_type (Literal['float', 'int','double'], optional) – Force output tensor to a specific data type, can be ‘float’, ‘int’ or ‘double’

Returns:

Converted tensor

Return type:

torch.Tensor

Methods