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
//! Reading a list of named entities, and the space its names live in.
//!
//! Two kinds are loaded from here: [`DataKind::EntitySet`], the gene or
//! protein list, and [`DataKind::RankedList`], the same list with its rows
//! in rank order. They share this module because reading one is reading the
//! other: a TSV with a header, an identifier column named by the caller,
//! every other column carried without being read, and four dimensions —
//! `organism`, `identifier_namespace`, `subject` and `release` — of which
//! the loader can usually work out one.
//!
//! The two kinds differ in their **canonical form** and in nothing else
//! (D41), so that is the one place they have separate code:
//! [`canon::entity_set`](crate::canon) discards row order and
//! `canon::ranked_list` keeps it. Sharing the reader is what keeps the
//! difference in one place; copying it would have copied the part that is
//! subtle, which is the next section.
//!
//! # Why a declaration is recorded rather than checked
//!
//! When the user declares `identifier_namespace`, the identifiers are not
//! consulted at all. That looks like a missed chance to catch a wrong
//! declaration, and it is deliberate: the catalogue
//! ([`KnownNamespace`](crate::dim::KnownNamespace)) knows seven spaces and
//! there are more than seven, so a curated list's own spelling is a
//! namespace the engine has never heard of and must still accept. Checking
//! a declaration against the catalogue would make the dimension unusable
//! for exactly the in-house truth sets that most need it. A declaration is
//! a user telling the engine something it cannot read; `map_identifiers` is
//! where a wrong one surfaces.
//!
//! Inference is therefore the fallback, not the authority, and it declines
//! in every case it cannot be sure of — see
//! [`KnownNamespace::infer`](crate::dim::KnownNamespace::infer).
use Path;
use ;
use crate;
use crateNote;
use crate;
/// The column the identifiers are in when the caller does not say.
pub const DEFAULT_ID_COLUMN: &str = "id";
/// Why a namespace is unknown when nothing declared one and the identifiers
/// did not settle it.
const NOT_INFERRED: &str = "not declared, and the identifiers do not all match one \
namespace's pattern -- declare identifier_namespace";
/// Why a namespace is unknown when every identifier is a bare symbol.
///
/// The third reason, and the one a consumer measured: these identifiers are
/// perfectly readable, they all fit one shape, and that shape is the only
/// one in the catalogue with no marker. A gene symbol, a ChEMBL component
/// synonym and a lab's own panel are the same string shape, so a value here
/// would be a guess — and two files guessing alike is how an undeclared
/// cross-space join came to pass `check` (D56). The advice is the short one
/// because the fix is one argument.
const INDISTINGUISHABLE: &str = "not declared, and the identifiers are bare gene-symbol \
shapes -- symbols and several synonym spaces are \
indistinguishable by pattern, so declare \
identifier_namespace";
/// The same, for a file holding an identifier a spreadsheet turned into a
/// date.
///
/// A separate reason because the advice differs, and the difference matters
/// more than it looks. "Declare identifier_namespace" is sound advice for a
/// file whose identifiers are merely unrecognised, and it is the **worst**
/// advice for this one: declare it and the file is accepted from then on
/// with `SEPT7` missing from every join, which is the corruption made
/// permanent. The reason a dimension is unknown is what a user reads and
/// acts on, so it has to arrive with the cause rather than beside it in a
/// note nobody thought to look at.
const DATES_AMONG_THEM: &str = "not declared, and some identifiers are dates rather than \
names -- see this dataset's notes, and re-export the file \
with the identifier column typed as text";
/// What a kind says about itself when it cannot supply a dimension.
///
/// The three sentences are the only thing that differs between the two
/// kinds loaded here, and they differ because each is advice a user reads:
/// "a gene list does not record which organism its genes belong to" tells
/// someone what to do, and a message that named the wrong kind of file
/// would be a loader describing something the user is not holding. So they
/// stay the caller's, as [`super::organism`] and its siblings already have
/// them be.
pub
/// Load a list of named entities as `kind`, from a TSV with a header.
///
/// `id_column` names the column holding the identifiers, defaulting to
/// [`DEFAULT_ID_COLUMN`]. Every other column is an attribute and is carried
/// without being read: what a list says about its entities is the user's
/// business, and the dimension is about the names.
///
/// # Errors
///
/// [`LoadError::Io`] if the file cannot be read, and [`LoadError::Format`]
/// if it has no header row, has no column of the name asked for, or holds a
/// row the header cannot account for.
pub
/// One row's identifier, trimmed.
///
/// A row the header accounts for always has the column, so the fallback is
/// unreachable in practice; it is an empty identifier rather than a panic
/// because an empty one is simply a name no namespace claims, which is the
/// honest answer and stops inference as any other unreadable name would.
/// The namespace dimension: declared if stated, else read off the names.