Project: s41467-025-56378-9 | Function: genomepredict (python)

system: You are an expert Python programmer implementing algorithms from scientific papers.
Complete the masked function based on the algorithm description.
Follow Python best practices and maintain consistent code style.
Return **only** the complete Python function code.

user: Complete this Python function:

**DESCRIPTION:** Multiscale prediction for 32Mb sequence input, generating hierarchical predictions at multiple resolutions (1Mb to 32Mb) with increasing detail up to 4kb resolution. Implements the core ORCA algorithm for genomic interaction prediction using deep neural networks.

**KEY TERMS:** {
  "genomepredict": "Orca multiscale prediction",
  "sequence": "one-hot sequence encoding",
  "models": "H1-ESC and HFF Orca models",
  "eval_step": "multiscale evaluation step",
  "encodings": "neural network encodings at different scales"
}

**CONTEXT CODE:**             ["r4000"],
            (8000, 8000),
            cg=True,
        )
        target_hff_256m = Genomic2DFeatures(
            [ORCA_PATH + "/resources/4DNFI643OYP9.rebinned.mcool::/resolutions/32000"],
            ["r32000"],
            (8000, 8000),
            cg=True,
        )
        target_hff_1m = Genomic2DFeatures(
            [ORCA_PATH + "/resources/4DNFI643OYP9.rebinned.mcool::/resolutions/1000"],
            ["r1000"],
            (8000, 8000),
            cg=True,
        )
        target_dict_global['hff'] = target_hff
        target_dict_global['hff_256m'] = target_hff_256m
        target_dict_global['hff_1m'] = target_hff_1m
    else:
        target_available = False

    if os.path.exists(ORCA_PATH + "/resources/4DNFI9GMP2J8.rebinned.mcool"):
        target_h1esc = Genomic2DFeatures(
            [ORCA_PATH + "/resources/4DNFI9GMP2J8.rebinned.mcool::/resolutions/4000"],
            ["r4000"],
            (8000, 8000),
            cg=True,
        )

        target_h1esc_256m = Genomic2DFeatures(
            [ORCA_PATH + "/resources/4DNFI9GMP2J8.rebinned.mcool::/resolutions/32000"],
            ["r32000"],
            (8000, 8000),
            cg=True,
        )

        target_h1esc_1m = Genomic2DFeatures(
            [ORCA_PATH + "/resources/4DNFI9GMP2J8.rebinned.mcool::/resolutions/1000"],
            ["r1000"],
            (8000, 8000),
            cg=True,
        )
        target_dict_global['h1esc'] = target_h1esc
        target_dict_global['h1esc_256m'] = target_h1esc_256m
        target_dict_global['h1esc_1m'] = target_h1esc_1m
    else:
        target_available = False


def genomepredict(
    sequence, mchr, mpos=-1, wpos=-1, models=["h1esc", "hff"], targets=None, annotation=None, use_cuda=True, nan_thresh=1,
):
    """Multiscale prediction for a 32Mb sequence
    input, zooming into the position specified when generating a series
    of 32Mb, 16Mb, 8Mb, 4Mb, 2Mb and 1Mb predictions with increasing
    resolutions (up to 4kb). This function also processes
    information used only for plotting including targets and annotation.

    For larger sequence and interchromosomal predictions, you can use
    256Mb input with genomepredict_256Mb.

    Parameters
    ----------
    sequence : numpy.ndarray
        One-hot sequence encoding of shape 1 x 32000000 x 4.
        The encoding can be generated with `selene_sdk.Genome.sequence_to_encoding()`.
    mchr : str
        Chromosome name. This is used for annotation purpose only.
    mpos : int, optional
        The coordinate to zoom into for multiscale prediction.
    wpos : int, optional
        The coordinate of the center position of the sequence, which is
        start position + 16000000.
    models : list(torch.nn.Module or str), optional
        Models to use. Default is H1-ESC and HFF Orca models.
    targets : list(numpy.ndarray), optional
        The observed balanced contact matrices from the
        32Mb region. Used only for plotting when used with genomeplot. The length and
        order of the list of targets should match the models specified (default is
        H1-ESC and HFF Orca models).
        The dimensions of the arrays should be 8000 x 8000 (1kb resolution).
    annotation : str or None, optional
        List of annotations for plotting. The annotation can be generated with
        See orca_utils.process_anno and see its documentation for more details.
    use_cuda : bool, optional
        Default is True. If False, use CPU.
    nan_thresh : int, optional
        Default is 1. Specify the threshold of the proportion of NaNs values
        allowed during downsampling for the observed matrices. Only relevant for plotting.
        The lower resolution observed matrix value are computed by averaging multiple
        bins into one. By default, we allow missing values and only average over the
        non-missing values, and the values with more than the specified proprotion
        of missing values will be filled with NaN.

    Returns
    ----------
    output : dict
        Result dictionary that can be used as input for genomeplot. The dictionary
        has the following keys:
            - predictions : list(list(numpy.ndarray), list(numpy.ndarray))
                Multi-level predictions for H1-ESC and HFF cell types.
            - experiments : list(list(numpy.ndarray), list(numpy.ndarray))
                Observations for H1-ESC and HFF cell types that matches the predictions.
                Exists if `targets` is specified.
            - normmats : list(list(numpy.ndarray), list(numpy.ndarray))
                Background distance-based expected balanced contact matrices for
                H1-ESC and HFF cell types that matches the predictions.
            - start_coords : list(int)
                Start coordinates for the prediction at each level.
            - end_coords : list(int)
                End coordinates for the prediction at each level.
            - chr : str
                The chromosome name.
            - annos : list(list(...))
                Annotation information. The format is as outputed by orca_utils.process_anno
                Exists if `annotation` is specified.


    """
    # MASKED: Multiscale prediction for 32Mb sequence input, generating hierarchical predictions at multiple resolutions (1Mb to 32Mb) with increasing detail up to 4kb resolution. Implements the core ORCA algorithm for genomic interaction prediction using deep neural networks.
    raise NotImplementedError("This function is masked for testing purposes.")


def genomepredict_256Mb(
    sequence,
    mchr,
    normmats,
    chrlen,
    mpos=-1,
    wpos=-1,
    models=["h1esc_256m", "hff_256m"],
    targets=None,
    annotation=None,
    padding_chr=None,
    use_cuda=True,
    nan_thresh=1,
):
    """Multiscale prediction for a 256Mb sequence
    input, zooming into the position specified when generating a series
    of 256Mb, 128Mb, 64Mb, and 32Mb predictions with increasing
    resolutions (up to 128kb). This function also processes 
    information used only for plotting including targets and annotation.

    This function accepts multichromosal input sequence. Thus it needs an
    extra input `normmats` to encode the chromosomal information. See documentation
    for normmats argument for details.

    Parameters
    ----------


Complete the function implementation replacing "raise NotImplementedError".