CardamomOT.model.base ===================== .. py:module:: CardamomOT.model.base .. autoapi-nested-parse:: Core implementation of the NetworkModel used for inference and simulation. This module defines the :class:`NetworkModel` class which encapsulates parameters, state, and algorithms for fitting gene regulatory networks from single-cell expression data, performing stochastic or deterministic simulations, and managing mixture models. All documentation and comments are maintained in English. Classes ------- .. autoapisummary:: CardamomOT.model.base.NetworkModel Module Contents --------------- .. py:class:: NetworkModel(n_genes=None, n_stimuli=1, times=None) Encapsulates the state and parameters of a regulatory network. The class stores kinetic, mixture and network parameters as well as trajectories produced during inference. It provides methods for initialization, calibration and simulation used by the higher-level pipeline script. .. py:method:: core_binarization(data_rna, gene_names, vect_t, G_tot, min_components=1, max_components=5, refilter=0, max_iter_kinetics=100, cell_rd=None, verb=True, kov_cell_mask=None, scboolseq_matrix=None, scboolseq_dropouts=None) :param cell_rd: :type cell_rd: (N_cells,) array or None :param kov_cell_mask: Per-cell KO/OV constraints derived from KO_OV_inference. - -1: gene is KO for this cell (force to lowest mode) - +1: gene is OV for this cell (force to highest mode) - 0: no constraint :type kov_cell_mask: (N_cells, G_tot) int8 array or None .. py:method:: fit_mixture(data, refilter=0, gene_names=np.arange(1, 50000), min_components=2, max_components=2, max_iter_kinetics=0, cell_rd=None, verb=True, stimulus_schedule=None, time_key='time', kov_cell_mask=None) Fit the mixture model parameters to the data. :param cell_rd: Facteurs de read depth par cellule, typiquement issus de adata.obs['rd'] (calculés par infer_rd.py). Si None, le modèle NB classique sans correction est utilisé. :type cell_rd: (N_cells,) array, pd.Series, ou None :param Exemple d'appel avec correction de read depth::: rd = np.asarray(adata.obs['rd']) model.fit_mixture(data_rna, ..., cell_rd=rd) .. py:method:: estimate_trajectories_given_model(vect_t, times, vect_samples_id, samples_id, vect_rna, y_prot_old, prot_formodes, y_kon_old, y_rna_old, y_proba_old, alpha_old, vect_samples_id_modified, basal, inter, s1, ks, nb_cells, init_cells, R_opt_traj, to_keep_for_update, offset_init=[0], n_iter=1, N_full=[100], N_samples=[100], intensity_prior=10) Infer the protein trajectories when d1 is known and theta is not. .. py:method:: loop_trajectories(data_rna, vect_t, vect_samples_id, times, samples_id, ks, s1, init_cells_full, nb_cells, N_full, N_samples, G_tot, min_n_loops, count_max, intensity_prior, basal_init=None, inter_init=None, basal_ref=None, inter_ref=None, verb=True, compute_theta=True, initialize_alpha=True, kov_cell_mask=None, hard_forcing_ref=False, ref_constraint_pct=0.1) Alternating optimization of trajectories and network (theta). basal_init / inter_init : (G_tot, n_networks) / (G_tot, G_tot, n_networks) or None Starting point for theta. Zeros if None. kov_cell_mask : (N_cells, G_tot) int8 array or None Per-cell KO/OV constraints. -1 → KO (force lowest mode), +1 → OV (force highest mode), 0 → no constraint. Applied after each update_modes step as a hard override. basal_ref / inter_ref : same shape or None Regularization target passed to inference_network. Zeros if None (no prior). .. py:method:: fit_network(data, intensity_prior=10, vect_samples_id=None, basal_init=None, inter_init=None, basal_ref=None, inter_ref=None, verb=True, stimulus_schedule=None, transition_rates=None, time_key='time', hard_forcing_ref=None, ref_constraint_pct=None) Fit the gene regulatory network to the RNA expression data. :param data: RNA expression matrix (cells × genes). :type data: ndarray or AnnData :param intensity_prior: Regularization intensity for optimal transport. :type intensity_prior: float :param vect_samples_id: Array of sample labels (same size as data), or None if only one sample. :type vect_samples_id: ndarray or None :param basal_init: Initial basal rates: shape (G,) broadcast to all networks, or (G, n_networks). :type basal_init: ndarray or None :param inter_init: Initial interaction matrix: shape (G, G) or (G, G, n_networks). :type inter_init: ndarray or None :param basal_ref: Regularization target for basal rates, same shape rules as basal_init. Defaults to zeros (no penalization towards a prior). :type basal_ref: ndarray or None :param inter_ref: Regularization target for interactions, same shape rules as inter_init. Defaults to zeros. :type inter_ref: ndarray or None :param verb: Whether to print progress. :type verb: bool .. py:method:: estimate_trajectories(y_prot, times, d1, N=100, kon_beta=None, s=None) Estimate protein trajectories when d1, theta, and alpha are known. :param kon_beta: Pre-computed burst frequencies. If None, uses ``self.kon_beta``. :type kon_beta: array of shape (T*N, G_tot), optional :param s: Per-gene protein scale. Defaults to ``self.scale_proteins``. Must match the s used in my_otdistance when building y_prot; pass ``s`` to reproduce protein trajectories exactly. :type s: float or array of shape (G_genes,), optional .. py:method:: refine_network_degradations(verb=True, stimulus_schedule=None, test=False) Refine network parameters and infer degradation rates for simulation. When ``test=True``, only runs the trajectory estimation step and recomputes ``kon_theta`` using the current (pre-loaded simul) network. No inference, MLP training, or parameter update is performed. .. py:method:: simulate_trajectories_unitary(times, times_train, ks, N=100, verb=True, samples_data=None) Simulate protein trajectories with unitary scale .. py:method:: simulate_trajectories_full(times, times_train, ks, N=100, verb=True, samples_data=None) Simulate protein AND mRNA trajectories using the Harissa bursty PDMP. Uses the inferred basal_t / inter_t (in absolute burst-rate units when simulate_full_with_harissa=True) as the Harissa network. Mimics simulate_trajectories_unitary but returns mRNA levels in addition to proteins. Only supports ns == 1. :returns: * **prot_modified** (*(N * len(times), G_tot)*) * **mrna_modified** (*(N * len(times), G_tot)*) * **kon_vector** (*(N * len(times), G_tot)*) * **times_simulation** (*(N * len(times),)*) .. py:method:: simulate_network(times, verb=True, stimulus_schedule=None) Simulate the protein trajectories using the final inferred network. .. py:method:: fit_mixture_test(data_rna, ks, c, verb=False) Classify test cells into mixture modes using fixed kinetic parameters. Sets self.modes, self.proba, self.proba_init, and self.pi_init so that update_modes in loop_trajectories works on test data without re-fitting kz/c. .. py:method:: infer_test(data, vect_samples_id=None, verb=True, stimulus_schedule=None, basal_ref=None, transition_rates=None, time_key='time') Run inference pipeline on test data: kon estimation, trajectory inference, and alpha initialization. basal_ref : (n_samples, G_tot, n_networks) array or None Per-sample KO/OV prior (±100 entries) used to build kov_cell_mask. transition_rates : DataFrame or array or None Cell-type transition rate matrix for OT cost adjustment.