Outputs of MIDAS
================

In this section, we explain the outputs generated by MIDAS and show how to retrieve them.

Embedding Space Outputs
~~~~~~~~~~~~~~~~~~~~~~~
 
MIDAS generate reduction outputs including joint latents and modality-specific latents:

.. list-table:: 
    :widths: 8, 20
    :header-rows: 1

    * - Type
      - Description
    * - **Modality-specific Latents**
      - Latents corresponding to individual input modalities, consisting of biological information (denoted as `c`) and technical noise (denoted as `u`).
    * - **Joint Latents**
      - The combined latent representation that integrates all modalities, along with the batch indices. This representation consists of biological information (denoted as `c`) and technical noise (denoted as `u`).

Feature Space Outputs
~~~~~~~~~~~~~~~~~~~~~~

As a generative model, MIDAS can also generate outputs such as imputed data, batch-corrected data, and translated data.

.. list-table:: 
    :widths: 8, 20
    :header-rows: 1

    * - Type
      - Description
    * - **Imputed Data**
      - Data for all modalities imputed from the joint latent representation.
    * - **Batch-corrected Data**
      - Imputed data with batch effects removed, generated by passing a standard noise latent instead of the real noise latent.
    * - **Translated Data**
      - Data translation between modalities, where input from one or more modalities is used to generate the corresponding data in other modalities.


.. note::

    By default, MIDAS performs sampling when generating batch-corrected data, based on the distribution settings. 
    To apply sampling to other types of outputs, or to disable sampling entirely, modify the ``gen_real_data()`` in ``scmidas.model.predict()``.

Additionally, for debugging or other purposes, MIDAS can save the original input data:

.. list-table:: 
    :widths: 8, 20
    :header-rows: 1

    * - Type
      - Description
    * - **Input**
      - The original input data before being fed into the model.

Predicting Outputs
~~~~~~~~~~~~~~~~~~~~

After training, you can use the ``predict`` method to generate and save predictions. Here's the example:

.. code-block:: python

    model.predict(output_dir,   
            joint_latent=True,
            mod_latent=True,
            impute=True,
            batch_correct=True,
            translate=True,
            input=True)

Where the parameters are:

- ``pred_dir``: The directory where prediction results will be saved.
- ``joint_latent``: Whether to calculate and save joint latent representations.
- ``mod_latent``: Whether to calculate and save modality-specific latent representations.
- ``impute``: Whether to perform data imputation, filling in missing or incomplete data.
- ``batch_correct``: Whether to apply batch correction to the data to reduce batch effects.
- ``translate``: Whether to perform modality translation.
- ``input`` : Whether to save the original input data.

Loading Predicted Outputs
~~~~~~~~~~~~~~~~~~~~~~~~~~

To retrieve and load the predicted outputs, you can use the ``scmidas.utils.load_predicted()`` function. Here's how to do it:

.. code-block:: python

    from scmidas.utils import load_predicted
    load_predicted( output_dir, 
                    model.combs, # a list of modality combinations per batch
                    joint_latent=True, 
                    mod_latend=True, 
                    impute=True, 
                    batch_correct=True, 
                    translate=True, 
                    input=True)

