loki2.psdtime

Utility helpers for pseudotime inference, clustering, and visualization.

Module Contents

loki2.psdtime.write_txt(file_path: str | pathlib.Path, data: Iterable[str]) None

Write one entry per line to a text file.

Parameters:
  • file_path – Path to the output text file.

  • data – Iterable of strings to write, one per line.

loki2.psdtime.load_txt(file_path: str | pathlib.Path) numpy.ndarray

Read a text file that has one value per line and return a string array.

Parameters:

file_path – Path to the input text file.

Returns:

Array of strings, one per line in the file.

Return type:

np.ndarray

loki2.psdtime.get_kmeans(x: numpy.ndarray, target_clusters: int = 10, scale: bool = False) numpy.ndarray

Cluster observations using k-means and return the cluster labels.

Parameters:
  • x – Input data array of shape (n_samples, n_features).

  • target_clusters – Number of clusters to form. Defaults to 10.

  • scale – Whether to standardize the data before clustering. Defaults to False.

Returns:

Cluster labels as string array of shape (n_samples,).

Return type:

np.ndarray

loki2.psdtime.get_umap(embedding: Any, n_components: int = 3, random_state: int | None = 2024, n_neighbors: int = 15, init: str = 'pca', metric: str = 'cosine') numpy.ndarray

Run UMAP on the provided embedding and return the transformed coordinates.

Parameters:
  • embedding – Input embedding matrix (will be converted to NumPy array).

  • n_components – Number of dimensions for the reduced space. Defaults to 3.

  • random_state – Random seed for reproducibility. Defaults to 2024.

  • n_neighbors – Number of neighbors for UMAP. Defaults to 15.

  • init – Initialization method. Defaults to ‘pca’.

  • metric – Distance metric. Defaults to ‘cosine’.

Returns:

UMAP-transformed coordinates of shape (n_samples, n_components).

Return type:

np.ndarray

loki2.psdtime.get_pca(embedding: Any, n_components: int = 15) numpy.ndarray

Project embedding onto PCA axes.

Parameters:
  • embedding – Input embedding matrix (will be converted to NumPy array).

  • n_components – Number of principal components. Defaults to 15.

Returns:

PCA-transformed coordinates of shape (n_samples, n_components).

Return type:

np.ndarray

loki2.psdtime.infer_pseudotime_palantir(ad: Any, start_cell: str, output_dir: str | pathlib.Path, name: str, *, n_components: int = 15, knn: int = 100, num_waypoints: int = 500) None

Run Palantir pseudotime inference on AnnData object and persist plots/results.

The defaults mirror prior behavior; override if you want a different UMAP dimensionality, neighborhood size, or waypoint density.

Parameters:
  • ad – AnnData object containing single-cell data.

  • start_cell – Cell ID to use as the starting point for pseudotime.

  • output_dir – Directory to save output plots and results.

  • name – Name identifier for output files.

  • n_components – Number of components for multiscale space. Defaults to 15.

  • knn – Number of nearest neighbors for graph construction. Defaults to 100.

  • num_waypoints – Number of waypoints for trajectory inference. Defaults to 500.