Пример #1
0
def set_vo_data(
    adata: AnnData,
    name: str,
    data: utt.ProperMatrix,
    *,
    formatter: Optional[Callable[[Any], Any]] = None,
) -> Any:
    """
    Set per-variable-per-observation (per-gene-per-cell) data.
    """
    utl.log_set(adata, "vo", name, data, formatter=formatter)

    utt.mustbe_canonical(data)
    if not utt.frozen(data):
        utt.freeze(data)

    if name == "__x__":
        adata.X = data
    else:
        adata.layers[name] = data

    if hasattr(adata, "__derived__"):
        derived = getattr(adata, "__derived__")
        for layout in ["column_major", "row_major"]:
            layout_name = f"vo:{name}:{layout}"
            if layout_name in derived:
                del derived[layout_name]
Пример #2
0
def set_m_data(
    adata: AnnData,
    name: str,
    data: Any,
    *,
    formatter: Optional[Callable[[Any], Any]] = None,
) -> Any:
    """
    Set unstructured data.

    If ``formatter`` is specified, its results is used when logging the operation.
    """
    utl.log_set(adata, "m", name, data, formatter=formatter)
    adata.uns[name] = data
Пример #3
0
def set_va_data(adata: AnnData,
                name: str,
                data: utt.ProperMatrix,
                *,
                formatter: Optional[Callable[[Any], Any]] = None) -> Any:
    """
    Set per-variable-per-any (gene) data.

    If ``formatter`` is specified, its results is used when logging the operation.
    """
    utl.log_set(adata, "va", name, data, formatter=formatter)

    utt.mustbe_canonical(data)
    if not utt.frozen(data):
        utt.freeze(data)

    adata.varm[name] = data
Пример #4
0
def set_o_data(
    adata: AnnData,
    name: str,
    data: utt.NumpyVector,
    *,
    formatter: Optional[Callable[[Any], Any]] = None,
) -> Any:
    """
    Set per-observation (cell) data.

    If ``formatter`` is specified, its results is used when logging the operation.
    """
    utl.log_set(adata, "o", name, data, formatter=formatter)

    if not isinstance(data, list):
        utt.mustbe_canonical(data)
        if not utt.frozen(data):
            utt.freeze(data)

    adata.obs[name] = data