| derive_split_constraints | R Documentation |
Convert dataset dependency structure into deterministic sample-level grouping constraints suitable for leakage-aware evaluation design.
derive_split_constraints(
graph,
mode = c("subject", "batch", "study", "time", "site", "region", "platform", "assay",
"relatedness", "spatial", "composite"),
samples = NULL,
strategy = c("strict", "rule_based"),
via = NULL,
priority = NULL,
include_warnings = TRUE
)
grouping_vector(x)
graph |
A |
mode |
Constraint derivation mode. |
samples |
Optional sample identifiers or sample node IDs used to
restrict the returned |
strategy |
Composite grouping strategy. Ignored for non-composite modes. |
via |
Optional dependency sources used for composite grouping. May be
given as lower-case modes such as |
priority |
Optional priority order used for
|
include_warnings |
Whether to retain human-readable warnings in the returned metadata. |
x |
A |
Constraint derivation rules:
mode = "subject"Groups samples by the target of
sample_belongs_to_subject. All samples linked to the same
Subject receive the same group_id.
mode = "batch"Groups samples by the target of
sample_processed_in_batch. Samples with no batch assignment are
retained as singleton unlinked groups and recorded in metadata warnings.
mode = "study"Groups samples by the target of
sample_from_study.
mode = "site"Groups samples by the target of
sample_collected_at_site. Samples with no site assignment are
retained as singleton unlinked groups and recorded in metadata warnings.
mode = "region"Groups samples by the target of
sample_located_in_region (e.g. a categorical tissue or anatomical
region). Samples with no region assignment are retained as singleton
unlinked groups and recorded in metadata warnings.
mode = "platform"Groups samples by the target of
sample_run_on_platform (the sequencing / measurement platform or
instrument). Samples with no platform assignment are retained as singleton
unlinked groups and recorded in metadata warnings.
mode = "assay"Groups samples by the target of
sample_measured_by_assay (the assay / modality). Samples with no
assay assignment are retained as singleton unlinked groups and recorded in
metadata warnings.
mode = "relatedness"Groups samples by transitive closure
over thresholded subject_related_to edges (genetic relatedness).
Samples that share a subject, or whose subjects are directly or indirectly
related above threshold, land in the same connected-component group. Build
the edges with relatedness_edges_from_kinship. Samples with
no subject are retained as singleton groups (recorded in metadata
warnings).
mode = "spatial"Groups samples by transitive closure over
thresholded sample_adjacent_to edges (spatial proximity). Build the
edges with spatial_edges_from_coords. Isolated samples form
singleton groups.
mode = "time"Groups samples by the target of
sample_collected_at_timepoint. When Timepoint nodes have
time_index metadata, that value is used to derive
order_rank. If time_index is unavailable, the function
attempts to derive ordering from timepoint_precedes edges over the
timepoint subgraph.
mode = "composite", strategy = "strict"Projects the
selected dependency relations onto a sample graph and assigns one
group_id per connected component. This is the transitive-closure
interpretation of composite dependency grouping.
mode = "composite", strategy = "rule_based"Evaluates dependency assignments in deterministic priority order and groups each sample by the highest-priority available dependency source. Lower-priority available dependencies are retained in the explanation field.
The returned split_constraint$sample_map always contains
sample_id, sample_node_id, group_id,
constraint_type, group_label, and explanation.
Time-aware constraints also include time_index, timepoint_id,
and order_rank when available.
Ambiguous direct assignments are rejected. A sample cannot be assigned to multiple batches, studies, or timepoints when deriving direct split constraints.
derive_split_constraints() returns a split_constraint
whose sample_map contains grouping assignments and, for time-aware
constraints, ordering metadata. grouping_vector() returns a named
character vector of group_id values keyed by sample_id.
meta <- data.frame(
sample_id = c("S1", "S2", "S3", "S4"),
subject_id = c("P1", "P1", "P2", "P2"),
batch_id = c("B1", "B2", "B1", "B2")
)
g <- graph_from_metadata(meta)
constraint <- derive_split_constraints(g, mode = "subject")
grouping_vector(constraint)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.