mantispy.io.from_dataframe#

mantispy.io.from_dataframe(df, metadata_prefixes=('Image_Metadata_', 'Metadata_', 'metadata_', 'meta_'), metadata_columns=(), channels=None, sentinels=None, keep_non_features=False, objects=('Cells', 'Cytoplasm', 'Nuclei'), resolution='well', grouped_by=None, convention='cellprofiler', object_type='Object')[source]#

Build an AnnData from a wide profile table.

Numeric columns that parse as features become X; text and Metadata_ columns become obs. Numeric columns that follow no CellProfiler naming (a learned embedding, a proprietary feature table) are kept as features with feature_kind="embedding". Numeric columns that parse as non-features (object numbers, parent links, centroids) are dropped and logged by default, because published profile tables often carry dozens of them and they mean nothing at well level.

Parameters:
df DataFrame

The table to convert.

metadata_prefixes Sequence[str] (default: ('Image_Metadata_', 'Metadata_', 'metadata_', 'meta_'))

Prefixes marking metadata columns. The matching prefix is normalized to Metadata_.

metadata_columns Sequence[str] (default: ())

Columns to treat as metadata even though they are numeric and unprefixed.

channels Sequence[str] | None (default: None)

Channel vocabulary passed to the feature-name parser.

sentinels float | Collection[float] | None (default: None)

Values in the feature matrix that stand for missing, replaced with NaN.

keep_non_features bool (default: False)

Keep those dropped numeric non-feature columns in obs instead.

objects Sequence[str] | None (default: ('Cells', 'Cytoplasm', 'Nuclei'))

Which CellProfiler objects count as features. The default is the three compartments, matching pycytominer.infer_cp_features. None keeps every object, including the whole-field Image measurements.

resolution str (default: 'well')

Resolution to record. Profile tables are usually well-level. The 1.0 names "cell" and "perturbation" are read as "object" and "aggregate".

grouped_by Sequence[str] | None (default: None)

For "aggregate" resolution, the obs columns that define one row, such as ["Metadata_Perturbation"]; required there, since only the table’s author knows its grouping.

convention Literal['cellprofiler', 'cp_measure'] (default: 'cellprofiler')

The feature-name grammar. "cellprofiler" reads <Object>_<Group>_<Feature>_<Channel>. "cp_measure" reads <Group>_<Feature>[__<Channel>[__<Channel2>]]; these names carry no object, so objects is ignored.

object_type str (default: 'Object')

For "object" resolution, the Metadata_ObjectType written when the table does not carry one.

Return type:

AnnData

Returns:

An AnnData of observations by features at the recorded resolution, with the parsed feature annotation in var and the schema stamp, the resolution and the channel vocabulary it parsed with in uns["mantispy"]. pycytominer’s per-well Metadata_Count_Cells, or Metadata_Object_Count without it, and Metadata_Site_Count are copied to Metadata_CellCount and Metadata_SiteCount.

Raises:
  • ValueError – df has no rows, no column parses as a feature on objects and none is kept as an embedding, or two metadata prefixes normalize onto the same column name.

  • KeyError – A name in metadata_columns is not in df.