Exemple #1
0
def get_v_names(adata: AnnData, ) -> utt.NumpyVector:
    """
    Get a numpy vector of variable names.
    """
    data = utt.to_numpy_vector(adata.var_names)
    utl.log_get(adata, "v", "__name__", data)
    return data
Exemple #2
0
def _get_v_data(
    adata: AnnData,
    name: Union[str, utt.Shaped],
    *,
    sum: bool,  # pylint: disable=redefined-builtin
    formatter: Optional[Callable[[Any], Any]] = None,
) -> Any:
    if not isinstance(name, str):
        log_name = "<data>"
    else:
        if isinstance(name, str) and name.endswith("|sum"):
            name = name[:-4]
            assert not sum
            sum = True
        log_name = name

    if sum:
        if formatter is None:
            formatter = utl.sizes_description
        data = _get_vo_sum_data(adata, "column", name)
        log_name += "|sum"
    else:
        data = _get_shaped_data(adata,
                                "v",
                                adata.var,
                                shape=(adata.n_vars, ),
                                name=name)
    utl.log_get(adata, "v", log_name, data, formatter=formatter)
    return data
Exemple #3
0
def get_o_names(adata: AnnData, ) -> utt.NumpyVector:
    """
    Get a numpy vector of observation names.
    """
    data = utt.to_numpy_vector(adata.obs_names)
    utl.log_get(adata, "o", "__name__", data)
    return data
Exemple #4
0
def get_m_data(
    adata: AnnData,
    name: str,
    *,
    formatter: Optional[Callable[[Any], Any]] = None,
) -> Any:
    """
    Get metadata (unstructured annotation) in ``adata`` by its ``name``.
    """
    data = adata.uns.get(name)
    if data is None:
        raise _unknown_data(adata, name, "m")
    utl.log_get(adata, "m", name, data, formatter=formatter)
    return data
Exemple #5
0
def _get_va_data(
    adata: AnnData,
    name: Union[str, utt.Matrix],
    *,
    layout: Optional[str] = None,
    formatter: Optional[Callable[[Any], Any]] = None,
) -> utt.Matrix:
    data = _get_layout_data(adata,
                            "va",
                            adata.varm,
                            shape=(adata.n_vars, 0),
                            name=name,
                            layout=layout)
    utl.log_get(adata, "va", name, data, formatter=formatter)
    return data
Exemple #6
0
def _get_vo_data(
    adata: AnnData,
    name: Union[str, utt.Matrix],
    *,
    layout: Optional[str] = None,
    formatter: Optional[Callable[[Any], Any]] = None,
) -> utt.Matrix:
    if name is None:
        name = "__x__"

    data = _get_layout_data(adata,
                            "vo",
                            adata.layers,
                            shape=(adata.n_obs, adata.n_vars),
                            name=name,
                            layout=layout)
    utl.log_get(adata, "vo", name, data, formatter=formatter)
    return data