obnb.feature

obnb.feature.base.BaseFeature

BaseFeature object.

FeatureVec

FeatureVec object.

MultiFeatureVec

MultiFeatureVec object.

class obnb.feature.base.BaseFeature(dim=None, log_level='INFO', verbose=False)[source]

BaseFeature object.

Parameters:
  • dim (Optional[int]) –

  • log_level (LogLevel) –

  • verbose (bool) –

add_featvec(id_, vec)[source]

Add a new feature vector.

align(new_fvec, join='right', update=False)[source]

Align FeatureVec object with another FeatureVec.

Utilizes the align method of IDmap to align, then update the feature vector matrix based on the returned left and right index.

Parameters:
  • new_fvec (BaseFeature) –

  • join (str) –

  • update (bool) –

align_to_idmap(new_idmap)[source]

Align FeatureVec to a given idmap.

This is essentially right align with update = False, i.e. reorder the current FeatureVec using the new_idmap.

align_to_ids(ids)[source]

Align FeatureVec to a List of node ids.

Parameters:

ids (List[str]) –

property dim

Int: dimension of feature vectors.

classmethod from_anndata(adata, obs_id_name='_index_', **kwargs)[source]

Construct FeatureVec from AnnData.

Parameters:
  • adata – The AnnData object to be loaded.

  • obs_id_name (str) – Name of the observation dataframe column to be used as entity IDs. If set to ‘_index_’ (default), then use the index column.

classmethod from_mat(mat, ids=None, **kwargs)[source]

Construct feature object using IDs and feature matrix.

Parameters:
  • mat (ndarray) – 2D numpy array of the feature matrix

  • ids (Optional[Union[Iterable[str], IDmap]]) – List like object of the entity IDs, or an IDmap object.

get_featvec(ids)[source]

Obtain features given entity IDs.

Return type:

ndarray

Parameters:

ids (Iterable[str] | str | None) –

get_featvec_from_idx(idxs)[source]

Obtain features given entity indexes.

Return type:

ndarray

Parameters:

idxs (Iterable[int] | int | None) –

property idmap: IDmap

Map ID to index.

property ids: Tuple[str, ...]

Return entity IDs as a tuple.

isempty()[source]

Check if the object is empty.

Return type:

bool

read_anndata(adata, obs_id_name='_index_')[source]

Read feature data from AnnData object.

Notes

This will overwrite existing data in the object.

Parameters:
  • adata – The AnnData object to be loaded.

  • obs_id_name (str) – Name of the observation dataframe column to be used as entity IDs. If set to ‘_index_’ (default), then use the index column.

property size: int

Number of entities.

Feature objects.

class obnb.feature.FeatureVec(dim=None, log_level='INFO', verbose=False)[source]

FeatureVec object.

Initialize FeatureVec.

Parameters:
  • dim (int | None) –

  • log_level (Literal['CRITICAL', 'ERROR', 'WARNING', 'INFO', 'DEBUG', 'NOTSET']) –

  • verbose (bool) –

get_featvec(ids)[source]

Obtain features given entity IDs.

Return type:

ndarray

Parameters:

ids (str | Iterable[str] | None) –

class obnb.feature.MultiFeatureVec(log_level='INFO', verbose=False)[source]

MultiFeatureVec object.

Initialize MultiFeatureVec.

Parameters:
  • log_level (Literal['CRITICAL', 'ERROR', 'WARNING', 'INFO', 'DEBUG', 'NOTSET']) –

  • verbose (bool) –

property feature_ids: Tuple[str, ...]

Return feature IDs.

classmethod from_mat(mat, ids=None, *, indptr=None, fset_ids=None, **kwargs)[source]

Construct MultiFeatureVec object.

Parameters:
  • mat (numpy.ndarray) – concatenated feature vector matrix.

  • ids (list of str or IDmap, optional) – node IDs, if not specified, use the default ordering as node IDs.

  • indptr (numpy.ndarray, optional) – index pointers indicating the start and the end of each feature set (columns). If set to None, and the dimension of fset_ids matches the number of columns in the input matrix, then automatically set indptr to corresponding to all ones.

  • fset_ids (list of str or IDmap, optional) – feature set IDs, if not specified, use the default ordering as feature set IDs.

classmethod from_mats(mats, ids=None, *, fset_ids=None, **kwargs)[source]

Construct MultiFeatureVec object from list of matrices.

Parameters:
  • mats (list of numpy.ndarray) – list of feature vector matrices.

  • ids (list of str or IDmap, optional) – node IDs, if not specified, use the default ordering as node IDs.

  • fset_ids (list of str or IDmap, optional) – feature set IDs, if not specified, use the default ordering as feature set IDs.

get_features(ids=None, fset_ids=None)[source]

Return features given node IDs and the selected feature set ID.

Parameters:
  • ids (str or list of str, optional) – node ID(s) of interest, return a 1-d array if input a single id, otherwise return a 2-d array where each row is the feature vector with the corresponding node ID. If not specified, use all rows.

  • fset_ids (str or list of str, optional) – feature set ID(s) of interest. If not specified, use all columns.

Return type:

ndarray

get_features_from_idx(idx, fset_idx)[source]

Return features given node index and feature set inde.

Parameters:
  • idx (int or sequence of int) – node index of interest.

  • fset_id (int or sequence of int) – feature set index of interest.

  • fset_idx (Iterable[int] | int) –

Return type:

ndarray