cohort

data.cohort

Read a cohort: a named subset of a dataset’s subjects, each holding its own files under the dataset root.

A Dataset says where per-subject files live and a Cohort (Dataset.cohorts) names which subjects count. A DataRef whose WHERE is cohort reads one array from each member’s own file, the file chosen by a BIDS entity query and the array by output. This module is that read, and the one definition of how a subject’s file is found under a dataset root, shared with the per-subject fit targets of an experiment (source: [dataset.subject.<measure>]).

Nothing here aggregates. A cohort read returns every member, labelled, on a leading subject axis; a mean, a presence count or a normalisation constant over the cohort is an Analysis that uses it, so the reduction is declared in the recipe rather than performed by the reader.

Attributes

Name Description
BIDS_ENTITY_SHORT_KEYS BidsEntities attribute names to the short keys a file name spells them with; suffix is the trailing file-name component, not an entity.
MISSING_CELLS What a table cell without a value reads as, compared case-insensitively; n/a is the BIDS spelling.
RECORD_SUFFIXES File suffixes read with the recipe loader, so the file holds what the slot it stands in for would hold.
TABLE_DELIMITERS File suffixes read as a table with one row per subject under participant_id (the BIDS participants and phenotype layout), each with the delimiter its cells are split by.
TABLE_SUFFIXES

Functions

Name Description
admission How cohort of dataset admits its members, in words a frozen record keeps in place of the list: the file that lists them, or the rule and the table it reads, each by file name. None for a cohort that types its members.
cohort_members The cohort’s members, checked against the dataset’s own subject list when it has one.
dataset_root dataset.bids_root as a path, a relative one resolved against the directory of the declaring spec.
dataset_subjects The subjects dataset lists, as {subject id: entry} in declared order: its subjects, or the content of its subjects_file (:func:declared_file, read against source_dir). Empty for a dataset that lists none; one that states both raises, and so does a file that lists nobody.
declared_file The file a dataset record names by path, found as every such path is: members_file, subjects_file and phenotype_file.
describe_selection One line stating how cohorts narrowed a per-subject fan-out, from SimulationExperiment.subject_selection().
find_cohort The (dataset, cohort) pair declaring cohort_id among datasets.
follows_run Whether ref reads the running subject’s own member of a cohort: it names a cohort and pins no member. Such a reference needs a run with a subject that belongs to the cohort, so it narrows a per-subject fan-out; a pinned one reads the same members whichever subject runs and narrows nothing.
lists_from_file Whether cohort keeps its members out of the recipe: read from members_file or admitted by rule. Whatever freezes such a cohort writes its members to a file again and never into a specification.
match_subject_files Yield (subject, path) for the files whose parsed entities match ents and suffix.
members_read The members of its cohort ref reads in a run of subject, and whether they come back stacked along subject; source_dir is where a member list kept in a file is found (:func:cohort_members).
network_array output of the network net as a labelled DataArray, as the network delivers it; name is how an error names the network.
network_members The subjects a network that reads per subject can be bound to: the members of the cohorts it follows the run on, in declared order (:func:cohort_members, with source_dir).
phenotype_measure The subjects of the phenotype table at path and their values of measure (:func:_read_measure), read again only when the table or the companion that holds its values has changed. A file of neither kind is refused by its suffix, and a subject the table lists twice raises with a count.
pinned_members The members a cohort reference’s sel on subject pins it to, as (members, several), or None for a reference that follows the run. several tells a list, read stacked in the order it gives, from one named member, read as that member’s own array.
query_entities Split a BidsEntities query into its key-value entities and its suffix.
read_cohort Resolve a cohort reference to its labelled array, from the files of the members it reads in a run of subject (:func:members_read) and no other member’s.
read_member One subject’s array output from the file query selects, as a labelled DataArray.
read_network Resolve a reference whose iri names the network at path to that network’s array output, as the network delivers it (:func:network_array).
short_entities A BidsEntities object as {short_key: value} for the entities it sets.
subject_entries A subjects slot as {subject id: entry} in declared order, each id without its sub- prefix. The slot holds bare ids, Subject records or a mapping keyed by id, and this is the one place the three are read, so the fan-out, a cohort’s member check and a kit’s frozen subject list name every subject the same way.
subject_file The one sidecar of subject under root matching ents and suffix; none raises FileNotFoundError, several ValueError.
subject_sidecars Every sidecar in the subject directories under root, or in one subject’s, at any depth: BIDS keeps a subject’s files in session and datatype folders.

admission

data.cohort.admission(dataset, cohort)

How cohort of dataset admits its members, in words a frozen record keeps in place of the list: the file that lists them, or the rule and the table it reads, each by file name. None for a cohort that types its members.

cohort_members

data.cohort.cohort_members(dataset, cohort, source_dir=None)

The cohort’s members, checked against the dataset’s own subject list when it has one.

A cohort states them in one way: typed (members, in declared order), read from a file (members_file, in the file’s order, found by :func:declared_file against source_dir) or admitted by a rule on a phenotype measure (rule, :func:_rule_members). A list that is read or computed is read or computed on each call, so it follows its file, and a message about it gives counts and never an identifier.

dataset_root

data.cohort.dataset_root(dataset, source_dir=None)

dataset.bids_root as a path, a relative one resolved against the directory of the declaring spec.

dataset_subjects

data.cohort.dataset_subjects(dataset, source_dir=None)

The subjects dataset lists, as {subject id: entry} in declared order: its subjects, or the content of its subjects_file (:func:declared_file, read against source_dir). Empty for a dataset that lists none; one that states both raises, and so does a file that lists nobody.

declared_file

data.cohort.declared_file(path, source_dir=None, *, what)

The file a dataset record names by path, found as every such path is: members_file, subjects_file and phenotype_file.

An absolute path is taken as written. A relative one is read from source_dir, the directory of the experiment or network file the dataset is part of (also for a dataset that file brings in by !include from elsewhere), and when the file is not there from the root of the study that directory belongs to (:func:tvbo.utils.study_layout.study_root), so a study names the lists it keeps by their place in the study and a kit names its own copies by their place beside its frozen spec. With no source_dir a relative path is read from the working directory. what names the declaring slot in the error a missing file raises, which lists the places tried.

describe_selection

data.cohort.describe_selection(selection)

One line stating how cohorts narrowed a per-subject fan-out, from SimulationExperiment.subject_selection().

find_cohort

data.cohort.find_cohort(datasets, cohort_id)

The (dataset, cohort) pair declaring cohort_id among datasets.

A cohort identifier is unique within a study, so a reference names it alone and the dataset follows. One dataset reached twice (an experiment’s own that the study also lists) is one declaration, so the first copy that declares the cohort is taken, and a copy that does not declare it hides nothing. None declaring it, or two datasets, raises with the identifiers that do exist.

follows_run

data.cohort.follows_run(ref)

Whether ref reads the running subject’s own member of a cohort: it names a cohort and pins no member. Such a reference needs a run with a subject that belongs to the cohort, so it narrows a per-subject fan-out; a pinned one reads the same members whichever subject runs and narrows nothing.

lists_from_file

data.cohort.lists_from_file(cohort)

Whether cohort keeps its members out of the recipe: read from members_file or admitted by rule. Whatever freezes such a cohort writes its members to a file again and never into a specification.

match_subject_files

data.cohort.match_subject_files(files, ents, suffix)

Yield (subject, path) for the files whose parsed entities match ents and suffix.

members_read

data.cohort.members_read(ref, datasets, subject=None, source_dir=None)

The members of its cohort ref reads in a run of subject, and whether they come back stacked along subject; source_dir is where a member list kept in a file is found (:func:cohort_members).

The one rule the reader, the per-subject fan-out, a kit’s bundle and the on-device refusal share. A sel on subject pins the reference to the member or members it names, whichever subject runs (:func:pinned_members). A reference that pins none follows the run: the run’s own member, and in a run with no subject the whole cohort, stacked in declared order. A member the cohort does not declare raises rather than being read anyway.

network_array

data.cohort.network_array(net, output, name)

output of the network net as a labelled DataArray, as the network delivers it; name is how an error names the network.

An edge layer comes back on (node_i, node_j) with the transforms the network declares on it applied, and a per-node quantity on node. Both carry the network’s own node labels, so whatever consumes the array aligns by name.

network_members

data.cohort.network_members(net, datasets, source_dir=None)

The subjects a network that reads per subject can be bound to: the members of the cohorts it follows the run on, in declared order (:func:cohort_members, with source_dir).

Cohorts with different members raise, because no one list then names every subject the network holds a layer for.

phenotype_measure

data.cohort.phenotype_measure(path, measure)

The subjects of the phenotype table at path and their values of measure (:func:_read_measure), read again only when the table or the companion that holds its values has changed. A file of neither kind is refused by its suffix, and a subject the table lists twice raises with a count.

pinned_members

data.cohort.pinned_members(ref)

The members a cohort reference’s sel on subject pins it to, as (members, several), or None for a reference that follows the run. several tells a list, read stacked in the order it gives, from one named member, read as that member’s own array.

query_entities

data.cohort.query_entities(query)

Split a BidsEntities query into its key-value entities and its suffix.

read_cohort

data.cohort.read_cohort(ref, datasets, *, subject=None, source_dir=None)

Resolve a cohort reference to its labelled array, from the files of the members it reads in a run of subject (:func:members_read) and no other member’s.

One member comes back as its own array. Several come back stacked along a leading subject axis in the order they are read, each laid out on the first one’s node labels by name.

read_member

data.cohort.read_member(root, subject, query, output)

One subject’s array output from the file query selects, as a labelled DataArray.

An edge matrix comes back on (node_i, node_j) and a per-node quantity on node, both carrying the file’s own node labels, so whatever consumes it aligns by name.

read_network

data.cohort.read_network(
    ref,
    path,
    *,
    subject=None,
    datasets=None,
    results_root=None,
    source_dir=None,
)

Resolve a reference whose iri names the network at path to that network’s array output, as the network delivers it (:func:network_array).

A network that holds its own arrays has one such array. One that reads a layer or a transform argument per subject has one per subject, and the reference follows the rule a cohort reference does: a sel on subject pins it to the member or members it names whichever subject runs (:func:pinned_members), and otherwise inside a run of subject it is that subject’s, and with no subject it is every member’s (:func:network_members). Several members come back stacked along a leading subject axis, each laid out on the first one’s node labels by name. datasets, results_root and source_dir are what the network’s own references resolve against.

Raises

Name Type Description
ValueError If the reference pins no member, or pins members of a network that reads nothing per subject, which holds one array for every subject.

short_entities

data.cohort.short_entities(obj)

A BidsEntities object as {short_key: value} for the entities it sets.

subject_entries

data.cohort.subject_entries(subjects)

A subjects slot as {subject id: entry} in declared order, each id without its sub- prefix. The slot holds bare ids, Subject records or a mapping keyed by id, and this is the one place the three are read, so the fan-out, a cohort’s member check and a kit’s frozen subject list name every subject the same way.

subject_file

data.cohort.subject_file(root, subject, ents, suffix)

The one sidecar of subject under root matching ents and suffix; none raises FileNotFoundError, several ValueError.

subject_sidecars

data.cohort.subject_sidecars(root, subject='*')

Every sidecar in the subject directories under root, or in one subject’s, at any depth: BIDS keeps a subject’s files in session and datatype folders.