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
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
//! Reading a table of molecules, and what its names were arrived at by.
//!
//! Two kinds are loaded from here: [`DataKind::MoleculeSet`], the compound
//! library or hit list, and [`DataKind::MoleculeRanking`], the same table
//! with its rows in rank order. They share this module because reading one
//! is reading the other, exactly as the two named lists do: a TSV with a
//! header, an identity column, every other column carried without being
//! read, and four dimensions — `organism`, `representation`, `subject` and
//! `release` — of which the file can speak to one.
//!
//! The two kinds differ in their **canonical form** and in nothing else
//! (D41, D48), so that is the one place they have separate code.
//!
//! # No chemistry is read here, or anywhere in the core
//!
//! This loader does not parse a structure, perceive a ring or compute a key.
//! It reads a column of strings and a line of prose. The engine core knows
//! no chemistry at all (D49): computing an InChIKey needs RDKit, RDKit is a
//! Python package, and a core that linked an InChI library would end the
//! promise that `pip install ligase-bio` needs no toolchain beyond Rust —
//! which is the promise `tests/default_build.rs` exists to defend.
//!
//! What the engine does instead is refuse to connect two sets whose
//! representations disagree, which needs no chemistry and is the whole of
//! what the dimension is for.
//!
//! # The identity column, and why there are two
//!
//! `inchikey` if the table has one, `smiles` otherwise. Both are admitted
//! because a set named by structures has to be loadable: it is what
//! `ligase.chem.standardize` is handed, and a conversion whose input could
//! not be typed would have nothing to convert. They are not equivalent, and
//! the measurement is why — RDKit's canonical SMILES for cisplatin changed
//! between 2024.09.6 and 2025.09.6 while its InChIKey did not, so a set
//! named by structure strings has an identity its own toolkit can move under
//! it. The dimension says which of the two a file is in, and the two never
//! compare equal.
//!
//! # Why a missing representation is a gap and not `as given`
//!
//! A file with keys and no representation line could be a ChEMBL download,
//! which *is* standardised, or a vendor list, which is not. Assuming the
//! weaker state would be the engine inventing the most dangerous of the
//! possible answers, and it would be a *known* value, so two such files
//! would agree. So the axis is unknown with a reason, and because
//! `representation` is demanded wherever two of these kinds are joined, the
//! file cannot quietly join anything until somebody says.
use Path;
use ;
use crate;
use crate;
/// The line a standardiser writes, and this loader reads.
///
/// Ligase's own prefix, so that reading it is not a guess about somebody
/// else's comment. The rest of the line is what [`Representation::parse`]
/// reads, which is the same spelling a declaration and a conversion target
/// use.
pub const REPRESENTATION_LINE: &str = "#ligase representation:";
/// Why the organism is unknown: a compound table does not record it.
const NO_ORGANISM: &str = "a molecule table does not record which organisms its compounds were \
measured against";
/// Why the subject is unknown.
const NO_SUBJECT: &str = "a molecule table does not record what it is a set of -- the target, \
the assay, the therapeutic area";
/// Why the release is unknown.
const NO_RELEASE: &str = "a molecule table does not record which release of a compound \
collection it was drawn from";
/// Why the representation is unknown when nothing stated one.
///
/// It deliberately does **not** mention `as given`, which is the state it
/// has just refused to assume: a reason that named the weakest state would
/// invite a user to declare it, and declaring it wrongly is the failure.
const NOT_STATED: &str = "this table names its molecules by InChIKey but does not say what \
standardisation produced them, and the keys cannot say -- declare \
representation, or standardise the table";
/// What each kind says about itself when it cannot supply a dimension.
///
/// Shared between the two kinds here because they are the same file read two
/// ways: unlike the named lists, where a gene list and a ranking differ in
/// what a user is holding, a molecule set and a molecule ranking are one
/// table and one sentence is true of both.
/// Load a table of molecules as `kind`.
///
/// The table needs an `inchikey` column or a `smiles` column; every other
/// column is carried without being read, a score column included. What a
/// table says about its compounds is the user's business, and the dimension
/// is about what its names mean.
///
/// # Errors
///
/// [`LoadError::Io`] if the file cannot be read, and [`LoadError::Format`]
/// if it has no header row, has neither identity column, holds a row the
/// header cannot account for, or carries a representation line naming an
/// identity or a standardisation the engine does not know.
pub
/// What a representation line spells, if the file has one.
pub
/// The representation dimension: declared if stated, else read off the line.
///
/// A declaration wins and is **recorded, not verified**, which is D38's
/// position on a declared namespace applied to this axis and for a sharper
/// reason: the engine has no chemistry, so it could not check the claim if
/// it wanted to. The step that does the standardising checks its own work
/// instead, which is the half that can be checked.
/// Load a set of molecules, whose row order says nothing.
///
/// # Errors
///
/// As [`molecule_table`].
/// Load a ranking of molecules, whose row order is the answer.
///
/// # Errors
///
/// As [`molecule_table`].