예제 #1
0
def get_vo_frame(
    adata: AnnData,
    name: Union[str, utt.Matrix] = "__x__",
    *,
    layout: Optional[str] = None,
    formatter: Optional[Callable[[Any], Any]] = None,
) -> utt.PandasFrame:
    """
    Get per-variable-per-observation (per-gene-per-cell) data as a pandas data frame.

    Rows are observations (cells), indexed by the observation names (typically cell barcode).
    Columns are variables (genes), indexed by their names.

    If ``name`` is a string, it is the name of a per-variable annotation to fetch.
    Otherwise, it should be some matrix of data of the appropriate size.

    If ``layout`` (default: {layout}) is specified, it must be one of ``row_major`` or
    ``column_major``. If this requires relayout of the data, the result is cached in a hidden data
    member for future reuse.
    """
    data = _get_vo_data(adata, name, layout=layout, formatter=formatter)
    frame = utt.maybe_pandas_frame(data)
    if frame is None:
        frame = utt.to_pandas_frame(utt.to_proper_matrix(data),
                                    index=adata.obs_names,
                                    columns=adata.var_names)
    return frame
예제 #2
0
def get_va_frame(
    adata: AnnData,
    name: Union[str, utt.Matrix],
    *,
    columns: Optional[Collection],
    layout: Optional[str] = None,
    formatter: Optional[Callable[[Any], Any]] = None,
) -> utt.PandasFrame:
    """
    Get per-variable-per-any (per-cell-per-any) data as a pandas data frame.

    Rows are variables (genes), indexed by their names.
    Columns are "something" - specify ``columns`` to specify an index.

    If ``name`` is a string, it is the name of a per-variable annotation to fetch.
    Otherwise, it should be some matrix of data of the appropriate size.

    If ``layout`` (default: {layout}) is specified, it must be one of ``row_major`` or
    ``column_major``. If this requires relayout of the data, the result is cached in a hidden data
    member for future reuse.
    """
    data = _get_va_data(adata, name, layout=layout, formatter=formatter)
    frame = utt.maybe_pandas_frame(data)
    if frame is None:
        frame = utt.to_pandas_frame(utt.to_proper_matrix(data),
                                    index=adata.var_names,
                                    columns=columns)
    return frame