nyxus.Nested

class Nested(aggregate=[])

Bases: object

Nyxus image feature extraction library / ROI hierarchy analyzer

Valid aggregate functions are any functions available in pandas.DatFrame.aggregate, e.g. min, max, count, std. Lambda functions can also be passed. To provide a name to the aggregate function, pass in a list of tuples where the first element in the name and the second is the function, e.g. aggregate=[(‘nanmean’, lambda x: np.nanmean(x))].

Parameters
  • aggregate (list) – List of aggregate functions. Any aggregate function from Pandas can be used along with lambda functions.

  • Example

  • -------

  • Nested (from nyxus import) –

  • Nyxus

int_path = ‘/home/data/6234838c6b123e21c8b736f5/tissuenet_tif/int’ seg_path = ‘/home/data/6234838c6b123e21c8b736f5/tissuenet_tif/seg’

nyx = Nyxus([”ALL”])

features = nyx.featurize(int_path, seg_path, file_pattern=’p[0-9]_y[0-9]_r[0-9]_c0.ome.tif’)

nn = Nested()

parent_filepattern = ‘p{r}_y{c}_r{z}_c1.ome.tif’

child_filepattern = ‘p{r}_y{c}_r{z}_c0.ome.tif’

rels = nn.find_relations (seg_path, parent_filepattern, child_filepattern)

df = nn.featurize(rels, features)

__init__(aggregate=[])
Parameters

aggregate (Optional[list]) –

Methods

__init__([aggregate])

featurize(parent_child_map, child_features)

Join child ROI features to the parent-child map.

find_relations(label_dir, ...)

Finds parent-child relationships.

featurize(parent_child_map, child_features)

Join child ROI features to the parent-child map.

Joins parent-child map from the find_relations method with the features from Nyxus. When aggregate functions are provided from the constructor this method will apply the aggregate functions to the joined DataFrame. When aggregate functions are not provided, this method will return a pivoted DataFrame where the columns are grouped by the child labels and the rows are the ROI labels.

Parameters
  • parent_child_map (pd.DataFrame) – Map of parent child relations from the find_relations method.

  • child_features (pd.DataFrame) – Features of the child channel ROIs from Nyxus.find_relations method.

Returns

DataFrame containing aggregated features for each ROI when aggregate functions are provided. Pivoted DataFrame containing features the child ROI for each label when no aggregate functions are provided.

Return type

pd.DataFrame

find_relations(label_dir, parent_file_pattern, child_file_pattern)

Finds parent-child relationships.

Find parent-child relationships of parent files matching the parent_file_pattern and child files matching the child_file_pattern.

Parameters
  • label_dir (str) – Path to directory containing label images.

  • parent_file_pattern (str) – Regex filepattern to filter the parent files e.g. “p.*_c1.ome.tif”.

  • child_file_pattern (str) – Regex filepattern to filter the child files e.g. “p.*_c0.ome.tif”.

Returns

rel – array of <parent label>,<child label> structure

Return type

array