deconvatac.tl.simulate
======================

.. py:module:: deconvatac.tl.simulate


Classes
-------

.. autoapisummary::

   deconvatac.tl.simulate.Sampler


Functions
---------

.. autoapisummary::

   deconvatac.tl.simulate.conway_maxwell_poisson
   deconvatac.tl.simulate.generate_spatial_data


Module Contents
---------------

.. py:function:: conway_maxwell_poisson(lambda_, nu)

   Sample from the Conway-Maxwell-Poisson distribution.


.. py:class:: Sampler(reference: [muon.MuData, anndata.AnnData], cell_type_key: str, num_spots: int, n_regions: int, region_type: str = 'stripes', cell_number_mean: [int, list] = 6, cell_number_nu: [float, list] = 20.0, cell_type_number: [int, list] = 4, balance: Optional[str] = 'balanced')

   Class to sample cells and clusters from a given dataset.


   .. py:attribute:: reference


   .. py:attribute:: cell_type_key


   .. py:attribute:: num_spots


   .. py:attribute:: obs


   .. py:attribute:: n_regions


   .. py:attribute:: region_type
      :value: 'stripes'



   .. py:method:: init_sample_prob(balance='unbalanced')

      Initialize the sample probabilities based on cell type counts.

      Returns
      -------
      None



   .. py:method:: define_regions(used_clusters)

      Define the regions to sample from.

      Parameters
      ----------
      used_clusters : dict
          A dictionary containing the clusters to be used in each region.

      Returns
      -------
      None

      Raises
      ------
      ValueError
          If the region_type parameter is not one of ['stripes', 'circles', 'gradient_number', 'gradient_celltype']



   .. py:method:: stripe_regions()

      Define regions as stripes.

      Returns
      -------
      None



   .. py:method:: circle_regions()

      Define regions in circles.

      Returns
      -------
      None



   .. py:method:: gradient_number_regions()

      Define regions as a gradient.

      Returns
      -------
      None



   .. py:method:: gradient_celltype_regions(used_clusters)

      Define regions as a gradient.

      Parameters
      ----------
      used_clusters : list
          The clusters to be used in the gradient cell type regions.

      Returns
      -------
      None



   .. py:method:: sample_data()

      Sample data from the given dataset.

      Returns
      -------
      tuple
          A tuple of expression and density arrays.



   .. py:method:: sample_spots(params)

      Sample cells based on given parameters.

      Parameters
      ----------
      params : np.ndarray
          Array of cell and cluster counts.

      Returns
      -------
      tuple
          A tuple of expression and density arrays.

      Raises
      ------
      None



   .. py:method:: get_coords()

      Get the coordinates for the spots.

      Returns
      -------
      tuple
          A tuple of X and Y coordinates.



.. py:function:: generate_spatial_data(reference: [muon.MuData, anndata.AnnData], cell_type_key: str, num_spots: int = 1024, n_regions: int = 5, balance: Optional[str] = None, cell_number_mean: [int, list] = 6, cell_number_nu: [float, list] = 20.0, cell_type_number: [int, list] = 4, **kwargs) -> [anndata.AnnData, muon.MuData]

   Generate spatial data.

   Parameters
   ----------
   reference : Union[mu.MuData, ad.AnnData]
       The reference dataset used for generating spatial data.
   cell_type_key : str
       The key in the reference dataset that specifies the cell type information.
   num_spots : int, optional
       The number of spots (locations) to generate, by default 1024.
   n_regions : int, optional
       The number of spatial regions to generate, by default 5.
   balance : str, optional
       The balancing method to use for generating spatial data, by default None.
   cell_number_mean : Union[int, list], optional
       The mean number of cells per spot, by default 6.
   cell_number_nu : Union[float, list], optional
       The dispersion parameter for the negative binomial distribution used to model cell numbers, by default 20.0.
   cell_type_number : Union[int, list], optional
       The number of cell types to generate, by default 4.
   **kwargs
       Additional keyword arguments.
   reference : Union[mu.MuData, ad.AnnData]
       The reference dataset used for generating spatial data.
   cell_type_key : str
       The key in the reference dataset that specifies the cell type information.
   num_spots : int, optional
       The number of spots (locations) to generate, by default 1024.
   n_regions : int, optional
       The number of spatial regions to generate, by default 5.
   balance : str, optional
       The balancing method to use for generating spatial data, by default None.
   cell_number_mean : Union[int, list], optional
       The mean number of cells per spot, by default 6.
   cell_number_nu : Union[float, list], optional
       The dispersion parameter for the negative binomial distribution used to model cell numbers, by default 20.0.
   cell_type_number : Union[int, list], optional
       The number of cell types to generate, by default 4.
   **kwargs
       Additional keyword arguments.

   Returns
   -------
   Union[ad.AnnData, mu.MuData]
       The generated spatial data.

   Notes
   -----
   This function generates spatial data based on a reference dataset. It uses a sampling approach to generate
   synthetic spatial data with specified characteristics such as cell type composition, cell numbers, and spatial
   organization.

   The generated spatial data is returned as an `AnnData` object if the reference dataset is an `AnnData` object,
   or as a `MuData` object if the reference dataset is a `MuData` object.
   Union[ad.AnnData, mu.MuData]
       The generated spatial data.

   Notes
   -----
   This function generates spatial data based on a reference dataset. It uses a sampling approach to generate
   synthetic spatial data with specified characteristics such as cell type composition, cell numbers, and spatial
   organization.

   The generated spatial data is returned as an `AnnData` object if the reference dataset is an `AnnData` object,
   or as a `MuData` object if the reference dataset is a `MuData` object.


