Skip to content

leafletfa.waypoints

leafletfa.waypoints

calculate_centered_psi(junction_counts, cluster_counts, rho=0.1)

Calculates centered PSI values and other related matrices based on the input junction counts and cluster counts.

Weighting is used to: - Account for variability in junction counts using the beta-binomial variance model. - Adjust the PSI values based on the reliability of the cluster (or junction) counts.

Parameters: - junction_counts: A sparse matrix (COO format) with junction counts. - cluster_counts: A sparse matrix (COO format) with cluster counts (ATSE counts). - rho: A float value (default: 0.1) representing the overdispersion parameter for the beta-binomial variance model.

Returns: - Y_sparse: A sparse matrix with centered PSI values. - psi: A sparse matrix with calculated PSI values. - w_psi: A sparse matrix with weighted PSI values. - junc_means: A dense array with the mean junction usage ratios.

generate_initializations(rho_hat, waypoints_dict, metacell_dicts, epsilon=0.01)

Generate multiple psi and phi initializations based on different waypoint sets and metacell dictionaries.

Parameters: rho_hat (ndarray): Observed probabilities (n_cells, n_junctions). waypoints_dict (dict): Dictionary with keys as waypoint sizes and values as waypoint sets. metacell_dicts (dict): Dictionary with keys as waypoint sizes and values as metacell dictionaries. epsilon (float): Small value to use as fallback if all junction values are zero.

Returns: psi_list (list): List of psi initializations. phi_list (list): List of phi initializations.

initialize_psi_phi_with_random_non_zero(rho_hat, metacell_dict, epsilon=0.01)

Initialize psi and phi using waypoints based on observed rho_hat, choosing random non-zero values for each junction.

Parameters: rho_hat (ndarray): Observed probabilities (n_cells, n_junctions). metacell_dict (dict): Dictionary of metacells with waypoints as keys and cell indices as values. epsilon (float): Small value to use as fallback if all junction values are zero.

Returns: psi (ndarray): Initialized psi values (n_junctions, n_metacells). phi (ndarray): Initialized phi values (n_cells, n_metacells) with each row summing to 1.

plot_PCA_with_waypoints(adata, waypoints_dict, color_by='tissue', n_waypoints=20, save_plot=False, waypoint_color='red', first_waypoint_color='blue', size=10)

Plots PCA with cells colored by a specified annotation (e.g., 'tissue', 'cell_type') and overlays waypoints on top.

sparse_sum(x, dim)

Compute the sum of a sparse matrix along a specified dimension and return a squeezed array.

Parameters: x (spmatrix): A sparse matrix whose elements are to be summed. dim (int): The dimension along which the sum is computed. For example, dim=0 sums along the rows, while dim=1 sums along the columns.

Returns: ndarray: The resulting dense array with the sums, with single-dimensional entries removed from its shape.