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 andMetadata_columns becomeobs. Numeric columns that follow no CellProfiler naming (a learned embedding, a proprietary feature table) are kept as features withfeature_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
obsinstead.- 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.Nonekeeps every object, including the whole-fieldImagemeasurements.- 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, theobscolumns 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, soobjectsis ignored.- object_type
str(default:'Object') For
"object"resolution, theMetadata_ObjectTypewritten when the table does not carry one.
- df
- Return type:
- Returns:
An
AnnDataof observations by features at the recorded resolution, with the parsed feature annotation invarand the schema stamp, the resolution and the channel vocabulary it parsed with inuns["mantispy"]. pycytominer’s per-wellMetadata_Count_Cells, orMetadata_Object_Countwithout it, andMetadata_Site_Countare copied toMetadata_CellCountandMetadata_SiteCount.- Raises:
ValueError –
dfhas no rows, no column parses as a feature onobjectsand none is kept as an embedding, or two metadata prefixes normalize onto the same column name.KeyError – A name in
metadata_columnsis not indf.