{# Reusable section fragments shared by the single-sample (report.html) and longitudinal (timeline.html) reports. Each macro only places already-formatted, HTML-safe values from the render context (see allomix.html.context); the number formatting comes from the registered Jinja filters/globals (pct, pval, ci, count, badge, ...). No analysis happens here. A lab can override this file via --template to restructure or reword any section while keeping the rest of the built-in report. #} {# A small, collapsed "how this works" disclosure. Body supplied by the caller. #} {% macro help(summary) %}
{{ summary }}
{{ caller() }}
{% endmacro %} {# Single-sourced "how it works" prose. Each is emitted inline in the HTML report (next to the section it explains) and collected into the PDF "Methods and notes" appendix, so the wording lives in exactly one place. #} {% macro help_fractions() %} {% call help("How the donor and host fractions are estimated") %}

The donor fraction is a maximum-likelihood estimate from the alternate and reference read depths at informative markers (loci where the host and donor genotypes differ), following Crysup and Woerner (2022). The host (recipient) fraction is the remainder. The 95% confidence interval reflects sampling at the sequenced depth.

Limit of blank is the highest donor fraction expected from a true-zero sample at this sample's depth and marker set; limit of detection is the lowest fraction reliably distinguished from blank. Both are specific to this sample.

{% endcall %} {% endmacro %} {% macro help_host_presence() %} {% call help("How host-presence detection works") %}

At markers where every donor is homozygous for the same allele and the host carries the other allele, that donor-absent allele appears only at the sequencing-error background in a pure-donor sample. A one-sided test (a likelihood ratio, with a pooled-Poisson cross-check) asks whether the observed donor-absent reads exceed that background, that is, whether any host signal is present.

This answers "is the host detectable?" directly, separately from the size of the donor fraction estimated above, and is most informative near the detection limit.

{% endcall %} {% endmacro %} {% macro help_qc() %} {% call help("How the quality-control checks work") %}

Goodness-of-fit compares the observed allele depths to those predicted by the fitted fraction; a low p-value means the single-fraction model fits poorly (an unexpected marker, an extra contributor, or a genotyping error).

Contamination measures third-party DNA at markers where the host and every donor share the same homozygote: minor-allele reads there cannot come from either contributor, so their excess over the sequencing-error floor estimates contamination (for example index hopping or cross-contamination).

Sample-swap counts those same shared-homozygote sites where the minor allele is individually significant; many such sites indicate a whole extra genome (a swap or wrong-patient VCF).

Shared-het balance checks the admixture allele fraction at markers heterozygous in the host and every donor, where it should sit near 50% whatever the mixing fraction. Many sites skewed away from balance point to contamination, copy-number or allelic imbalance, or a sample mix-up.

Relatedness is a kinship coefficient between the reference samples, compared against the declared relationship to catch mislabelled or unexpectedly related inputs.

The robust refit re-fits after dropping markers whose residuals are large outliers; dropping a large fraction is itself flagged, since it points at host copy-number change or a genotyping problem.

{% endcall %} {% endmacro %} {# Collapsed "run command" provenance block. Single-sourced so the HTML footer and the PDF appendix render it identically. #} {% macro run_command(params) %} {% if params.command %}
Run command
{{ params.command }}
{% endif %} {% endmacro %} {# One headline figure card (label, big value, optional CI line). #} {% macro figure_card(label, value, ci_str="") %}
{{ label }}
{{ value }}
{{ ci_str }}
{% endmacro %} {# Header identification band. `rows` is a list of (label, value) pairs. #} {% macro header(rows) %}

Chimerism report

{% for label, value in rows %}
{{ label }}:{{ value }}
{% endfor %}
{% endmacro %} {# Host-presence detection callout. `hp` is the detector sub-object (or none); `detected` is the precomputed verdict. Never silently omitted. `show_help` emits the inline "how it works" disclosure (HTML); the PDF sets it False and collects the same prose into its appendix. #} {% macro host_presence(hp, detected, show_help=True) %}

Host-presence detection

{% if hp is none %}
Detection disabled
The dedicated host-presence detector was not run for this sample.
{% elif (hp.n_markers or 0) == 0 %}
Not assessable
No donor-homozygous markers were available to test for a host signal (artifact-filtered: {{ hp.n_artifact_filtered | count }}).
{% else %}
{{ 'Low-level host signal detected' if detected else 'No host signal above background' }}
Detection p-value (LRT): {{ hp.lrt_pval | pval }}; pooled-Poisson p-value: {{ hp.poisson_pval | pval }}.
Estimated host fraction: {{ hp.f_host_mle | pct(3) }} {{ ci(hp.f_host_ci_lo, hp.f_host_ci_hi) }}.
Markers used: {{ hp.n_markers | count }}; error-rate source: {{ hp.error_rate_source }}; artifact-filtered: {{ hp.n_artifact_filtered | count }}.
{% endif %} {% if show_help %}{{ help_host_presence() }}{% endif %}
{% endmacro %} {# A (Check, Value, Reference) metrics table. `rows` is a list of (label, value, reference) triples; value/reference are already safe text. #} {% macro metrics(rows) %} {% for label, value, ref in rows %} {% endfor %}
CheckValueReference
{{ label }}{{ value }}{{ ref }}
{% endmacro %} {# Quality-control panel. `ctx` carries the analysis dict, the two clinician summary lines, and the reference-threshold strings. `show_help` emits the inline "how it works" disclosure (HTML); the PDF sets it False and collects the same prose into its appendix. #} {% macro qc_panel(ctx, show_help=True) %} {% set a = ctx.analysis %} {% set refs = ctx.refs %}

Quality control

Overall verdict: {{ badge(a.qc_status) }}

{{ ctx.marker_accounting }}

{{ ctx.flag_summary }}

Markers

{% if a.per_donor_n_informative %} {% endif %}
CheckValueReference
Total markers (input){{ a.n_total_markers | count }}
Shared across samples{{ a.n_shared_markers | count }}
Informative{{ a.n_informative | count }}
Used in fit{{ a.n_used | count }}
Informative per donor{% for n in a.per_donor_n_informative %}donor {{ loop.index }}: {{ n }}{{ ", " if not loop.last else "" }}{% endfor %}
Excluded: low depth{{ a.n_excluded_depth | count }}
Excluded: quality{{ a.n_excluded_quality | count }}
Excluded: outlier{{ a.n_excluded_outlier | count }}
Robust refit dropped{{ (a.robust_drop_fraction or 0.0) | pct(0) }}{{ refs.robust }}

Sequencing depth (admixture)

CheckValueReference
Mean depth{{ a.mean_depth | num(0) }}x{{ refs.depth }}
Median depth{{ a.median_depth | num(0) }}x
Minimum depth{{ a.min_depth | count }}x

Model fit

{% if a.gof_pval_pretrim is not none %} {% endif %}
CheckValueReference
Goodness-of-fit p{{ a.gof_pval | pval }}{{ refs.gof }}
Goodness-of-fit p (pre-trim){{ a.gof_pval_pretrim | pval }}

Contamination

{% if a.contamination is none %} {% else %} {% endif %}
CheckValueReference
Contaminationnot assessed
Contamination fraction{{ a.contamination.contamination_fraction | pct(3) }}{{ refs.contamination }}
Contamination p{{ a.contamination.p_value | pval }}
Contamination markers{{ a.contamination.n_markers | count }}

Sample-swap

{% if a.admix_consistency is none %} {% else %} {% endif %}
CheckValueReference
Sample-swap checknot assessed
Swap discordant fraction{{ a.admix_consistency.discordant_fraction | pct(2) }}
Swap p{{ a.admix_consistency.swap_pval | pval }}{{ refs.swap }}
Consensus-homozygous markers{{ a.admix_consistency.n_consensus_hom | count }}

Shared-het balance

{% if a.shared_het_balance is none or a.shared_het_balance.n_shared_het == 0 %} {% else %} {% endif %}
CheckValueReference
Shared-het balancenot assessed
Imbalanced fraction{{ a.shared_het_balance.imbalanced_fraction | pct(1) }}{{ refs.shared_het }}
Pooled VAF{{ a.shared_het_balance.pooled_vaf | num(3) }}
Shared-het markers{{ a.shared_het_balance.n_shared_het | count }}
{% if a.run_unit is not none %} {% set shares = a.run_unit.shares_run_with_host %}

Run provenance

CheckValueReference
Run unit{{ a.run_unit.run_unit if a.run_unit.run_unit else NA }}
Run-unit source{{ a.run_unit.source if a.run_unit.source else NA }}
Shares run with host{{ NA if shares is none else ("yes" if shares else "no") }}index-hopping risk if yes
{% endif %} {% if a.relatedness %}

Reference-sample relatedness

{% for r in a.relatedness %} {% endfor %}
PairCoefficient95% CIRelationshipConfidenceMarkers
{{ r.a_name }} vs {{ r.b_name }}{{ r.coefficient | num(3) }}{{ ci(r.ci_low, r.ci_high, 3, as_pct=False) }}{{ r.relationship }}{{ r.confidence }}{{ r.n_sites | count }}
{% endif %} {% if show_help %}{{ help_qc() }}{% endif %} {% if a.warnings %}

Warnings

{% else %}

No QC warnings raised.

{% endif %}
{% endmacro %} {# Methods / provenance footer. `show_run_command` emits the collapsed run-command block inline (HTML); the PDF sets it False and re-emits the same block in its "Methods and notes" appendix (browsers collapse
, so a printed report would otherwise hide it). #} {% macro footer(version, params, citation, timestamp, show_run_command=True) %} {% endmacro %}