Skip to content

Aggregate

Aggregate raw compound and target data into one CompoundActivity object per compound.

CONVERTIBLE_TYPES = frozenset({'Kd', 'Ki', 'Kb', 'Kieq', 'Kic', 'IC50', 'EC50', 'fIC50', 'fEC50'})

The assay types that convert to a comparable pActivity. Anything outside this set is ignored.

DEFAULT_SPREAD_GATE = 1.0

Maximum allowed spread in log scale among the winning-type values before the quality gate fails.

Measurement(type, value, unit, cid='', assay_id='', is_active=True)

A single raw, exact measurement row for a compound-target pair.

assay_id = ''

The assay id (aid) attached to the measurement.

cid = ''

The comppound id for the activity measurement

is_active = True

True if the compound is active from the source assay outcome.

type

The assay type e.g kd, Ki, IC50, EC50, etc. It is used to select the winning type for aggregation.

unit

The unit of value which is used in the pActivity conversion to a log scale.

value

The raw activity value, expressed in unit.

aggregate_activity(measurements, spread_gate=DEFAULT_SPREAD_GATE, convertible=CONVERTIBLE_TYPES)

Aggregate the per-compound measurements into a single CompoundActivity for each compound.

PARAMETER DESCRIPTION
measurements

The output of group_measurements, keyed on the compound key.

TYPE: dict[str, list[Measurement]]

spread_gate

The quality gate fails when the winning-type spread exceeds this (in log units).

TYPE: float DEFAULT: DEFAULT_SPREAD_GATE

convertible

The assay types that convert to pActivity.

TYPE: frozenset[str] DEFAULT: CONVERTIBLE_TYPES

RETURNS DESCRIPTION
dict[str, CompoundActivity]

A dictionary with the compound keys as the keys and their CompoundActivity records as the

dict[str, CompoundActivity]

values. Compounds with no convertible, exact measurement are omitted (they still cluster;

dict[str, CompoundActivity]

cliff detection skips them through the missing-activity path).

cid_crosswalk(measurements)

Build the compound key to source CIDs map, for provenance and per-CID output expansion.

PARAMETER DESCRIPTION
measurements

The output of group_measurements, keyed on the compound InChIKey.

TYPE: dict[str, list[Measurement]]

RETURNS DESCRIPTION
dict[str, set[str]]

A dictionary with the compound InChIKey as the keys and the set of CIDs that resolved to each

dict[str, set[str]]

as the values. Use it to expand InChIKey-keyed cluster or cliff outputs back to per-CID rows.

group_measurements(rows, key_col='InChIKey', cid_col='cid', assay_col='aid', outcome_col='outcome', type_col='activity_name', value_col='activity_value', unit_col='activity_unit', qualifier_col='activity_qualifier')

Group parquet rows for a single target into a list of exact measurements per compound.

PARAMETER DESCRIPTION
rows

An iterable of row dictionaries for a single target_geneid.

TYPE: Iterable[dict]

key_col

The column holding the compound key. Default is "InChIKey" which gives one structural node per standardized parent; pass "cid" only to deliberately key per-CID.

TYPE: str DEFAULT: 'InChIKey'

cid_col

The column holding the source CID, retained on each Measurement for the crosswalk.

TYPE: str DEFAULT: 'cid'

assay_col

The column holding the source assay id (aid).

TYPE: str DEFAULT: 'aid'

outcome_col

The column holding the active/inactive outcome label.

TYPE: str DEFAULT: 'outcome'

type_col

The column holding the assay type (e.g. activity_name).

TYPE: str DEFAULT: 'activity_name'

value_col

The column holding the raw activity value.

TYPE: str DEFAULT: 'activity_value'

unit_col

The column holding the value unit.

TYPE: str DEFAULT: 'activity_unit'

qualifier_col

The column holding the relation qualifier ('=', '>', '<'); only literal '=' rows are kept. Blank/missing qualifiers are treated as relative and dropped.

TYPE: str DEFAULT: 'activity_qualifier'

RETURNS DESCRIPTION
dict[str, list[Measurement]]

A dictionary with the compound keys as the keys and the list of their exact Measurement

dict[str, list[Measurement]]

records as the values.