phenotype

behaviour.phenotype

What a Phenotype record does: read and write its h5 companion, and answer for one measure or one subject.

Classes

Name Description
PhenotypeBehaviour A cohort’s per-subject phenotype scores, on both generated forms.

PhenotypeBehaviour

behaviour.phenotype.PhenotypeBehaviour()

A cohort’s per-subject phenotype scores, on both generated forms.

The record is the YAML-side descriptor — subjects, measure names, provenance, optional Cognitive Atlas IRIs via measure_specs — and the values live in an h5 companion beside it, measures/<measure> as a 1-D array of len(subjects), read on first use through :attr:values. BIDS-aligned with the phenotype/ directory standard.

Example

ph = Phenotype.from_file(“Schirner2023_HCPYA_phenotype.yaml”) ph.subjects[:5] # [‘100206’, ‘100307’, …] ph.get(“PMAT24_A_RTCR”) # ndarray shape (50,)

Attributes

Name Description
values Dict of {measure_name: ndarray}, loaded lazily.

Methods

Name Description
from_file Load a Phenotype sidecar from a YAML descriptor.
get Return one measure’s array. Raises KeyError if missing.
measure_spec Return the optional MeasureSpec for name (or None).
subject_index Return the row index of subject_id in every measure array.
to_file Write the YAML descriptor + h5 companion to path.
from_file
behaviour.phenotype.PhenotypeBehaviour.from_file(path)

Load a Phenotype sidecar from a YAML descriptor.

Resolves data_file relative to the YAML’s directory so the h5 companion can sit next to it. Numeric arrays are NOT loaded eagerly — call :meth:get (or read :attr:values) to fault one in.

get
behaviour.phenotype.PhenotypeBehaviour.get(measure)

Return one measure’s array. Raises KeyError if missing.

measure_spec
behaviour.phenotype.PhenotypeBehaviour.measure_spec(name)

Return the optional MeasureSpec for name (or None).

subject_index
behaviour.phenotype.PhenotypeBehaviour.subject_index(subject_id)

Return the row index of subject_id in every measure array.

to_file
behaviour.phenotype.PhenotypeBehaviour.to_file(
    path,
    values=None,
    provenance_comment=None,
)

Write the YAML descriptor + h5 companion to path.

Parameters
Name Type Description Default
path str | os.PathLike Target .yaml path. The .h5 companion is written next to it, named after self.data_file or the yaml basename. required
values Mapping[str, Sequence[float]] | None {measure_name: 1-D array} mapping covering every name in self.measures, each array of length len(self.subjects); the values already read when omitted. None
provenance_comment str | None Optional block of #-prefixed lines prepended to the yaml for provenance. None