1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
//! Interpreting variants as drug resistance.
//!
//! Everything above this module is about keeping data straight. This is
//! the one module that says what the data *means*: it takes variant calls
//! against HXB2, works out which amino acids each codon of protease,
//! reverse transcriptase, integrase and capsid holds, and scores them
//! against a vendored Stanford HIVdb algorithm.
//!
//! # The three parts
//!
//! - [`ruleset`] reads a vendored algorithm. The file is derived from
//! Stanford's ASI2 XML, which is committed beside it and pinned by
//! checksum; see `crates/ligase-core/rulesets/README.md`.
//! - [`codon`] turns a reference and a VCF into the amino acids present at
//! each position of each protein. This is where mixtures and coverage
//! are decided.
//! - [`score`] evaluates those amino acids against the algorithm.
//!
//! # Why nothing here reaches the network
//!
//! Stanford runs a web service that does this interpretation. Calling it
//! would make a result depend on the day it was asked for, which no cache
//! key can see and no bundle can reproduce. The algorithm is vendored
//! instead, version and date and checksum and all, so a run from 2026
//! and a rerun in 2030 agree or explain themselves.
pub use ;
pub use ;
pub use ;
use fmt;
use Path;
use crateLoadError;
use crateNote;
/// Why a report could not be written.
///
/// Two variants rather than one string because the two mean different
/// things to a caller: a frame mismatch is the reference being in the wrong
/// coordinate system, which a Python caller catches as a
/// `ReferenceFrameError` and fixes by putting the sequence back where its
/// numbers mean what they say. Everything else is a file, an algorithm name
/// or a score out of range.
/// Interpret one sample's calls and write the report.
///
/// This is the whole of what a `resistance` step does: read the
/// reference and the calls into amino acids, score them against a
/// vendored algorithm, and write the result.
///
/// # Arguments
///
/// - `reference` — the FASTA the variants were called against. Codons
/// cannot be named without it: a VCF holds only the positions that
/// differ, and two of the three bases of a codon are usually not among
/// them.
/// - `variants` — the calls.
/// - `alignment` — the BAM they were called from, for coverage. Without
/// it the reading notes that it is treating every uncalled position as
/// reference, and the caller is expected to hand that note back to the
/// engine (D32).
/// - `algorithm` — which vendored algorithm to use, e.g. `HIVDB_9.8`.
/// - `mixture` — the fraction an allele must reach to count as present.
/// - `depth` — the depth a position must reach to count as read.
/// - `gene_coverage` — the share of a gene's *scored* codons — the ones
/// the chosen algorithm's rules name — that must be read for the gene to
/// be assessed rather than reported as not assessed.
///
/// # Returns
///
/// What the reading noticed about itself: the hedges with a clinical
/// direction that the report it is about cannot state. A caller that drops
/// these has made the assumption silent, which is the one thing it must
/// not be (D29).
///
/// # Errors
///
/// If a file cannot be read, the reference cannot be the frame the gene
/// windows are stated in, the algorithm is not one this engine ships, or a
/// score falls outside the algorithm's own ranges.