spacr.regression_layout¶
Lossless long/wide conversions for regression predictor tables.
The screen pipeline historically receives one row per (well, gRNA) and
the low-level estimators receive a conventional wide design matrix. These
helpers make that boundary explicit and also accept count tables that arrive
with one guide per column. Conversion is deliberately strict: a value is
never silently selected when duplicate rows disagree.
Functions¶
|
Infer |
|
Pivot one row per observation/predictor to one predictor per column. |
|
Return a canonical long |
|
Melt one-predictor-per-column data to one row per predictor. |
Module Contents¶
- spacr.regression_layout.infer_regression_layout(frame: pandas.DataFrame, *, predictor_column: str = 'grna', value_column: str = 'count') str[source]¶
Infer
longonly from the paired predictor/value columns.A table containing exactly one of the two columns is malformed rather than wide. Treating it as wide would accidentally melt the existing value column into a gRNA.
- spacr.regression_layout.long_to_wide_regression_data(frame: pandas.DataFrame, *, index_columns: collections.abc.Sequence[str] | str = 'prc', predictor_column: str = 'grna', value_column: str = 'fraction', metadata_columns: collections.abc.Sequence[str] | None = None, fill_value: float = 0.0, predictor_prefix: str = '') pandas.DataFrame[source]¶
Pivot one row per observation/predictor to one predictor per column.
Metadata must be constant inside each observation, and duplicate observation/predictor rows must agree. Repeated identical rows (for example after a harmless join) are collapsed once; conflicting values are refused.
- spacr.regression_layout.normalise_count_table_layout(frame: pandas.DataFrame, *, layout: str = 'auto', guide_column: str = 'grna', count_column: str = 'count', wide_predictor_columns: collections.abc.Sequence[str] | None = None) tuple[pandas.DataFrame, str][source]¶
Return a canonical long
grna/countcount table and its input layout.
- spacr.regression_layout.wide_to_long_regression_data(frame: pandas.DataFrame, *, predictor_columns: collections.abc.Sequence[str] | None = None, id_columns: collections.abc.Sequence[str] | None = None, predictor_name: str = 'grna', value_name: str = 'count', drop_zero: bool = False) pandas.DataFrame[source]¶
Melt one-predictor-per-column data to one row per predictor.
When
predictor_columnsis omitted, every numeric column not named as observation metadata is used. Non-numeric unclassified columns are rejected because guessing whether they are metadata or a predictor would change the model silently.