D.7 Adding a check to a catalogue: qc-data as the model
What you will learn
- Describe a catalogue entry, and what is generated from it.
- Add a check so that the template, the checklist, the listing and the documentation stay in step.
- Choose a check's default severity, and write its question and its action.
Prerequisites: D.4 and Chapter 11, qc-data.
The quality-control commands are built on a catalogue: a list of questions the program asks of a dataset (or, for qc-nm, of a control stream). A catalogue is the best-structured part of the program and the model for any command that is a set of independent checks.
An entry
A catalogue entry (the qc-data tree holds 99 of them in ten categories: file, header, values, records, time, dosing, observations, subjects, covariates and NONMEM readiness) has five fields.
| Field | Example | Rule |
|---|---|---|
id |
FIL02 |
three letters for the category and two digits; stable forever: users put it in settings files and reports |
| category | File | one of the ten; the category names are the section names of the settings file |
question |
"Is the file free of a byte-order mark (BOM) at its start?" | a yes/no question answered yes when all is well |
| default level | error, warning or comment | what a finding costs unless the user changes it |
action |
"Save the file as plain UTF-8 or ASCII without BOM; a BOM makes the first character of the header unreadable." | what to do about a finding: a sentence a data manager can act on |
Phrasing the question so that yes is good keeps the checklist uniform: a row is a pass when the answer is yes, and a finding when it is no.
How a check runs
Each category has a module with one run function that asks its questions of the dataset and reports to a collector: the check's ID, how many items it examined, the list of hits (each with a line number and an explanatory message), a label for the failing case and a label for the passing case. For FIL02 the logic is: if the file starts with the UTF-8 byte-order mark, add one hit on line 1 that explains what NM-TRAN would do with it; if the file is UTF-16, add another; report. The collector applies the level from the catalogue, or the one the user set in the settings file, counts the hits (keeping a bounded number of examples so that a huge file does not produce a huge report) and builds the finding records.
Checks run in a fixed order, and a category is skipped with a reason when its preconditions fail (no data records; no ID and TIME columns) rather than reporting a flood of consequential failures. The skipped rows appear in the checklist as not applicable, with the reason, which is more informative than silence.
What is generated from the entry
Adding one entry to the catalogue changes, without further work:
- the settings template: the template builds its severity block from the catalogue, so every check appears under its category with its default level and its question as a comment;
- the settings reader: a user may set that check's level by ID, and a misspelled ID is an unknown key;
- the checklist (
qc_checklist.csv) and the findings table, and the summary counts; - the listing printed by
--list-checks("99 checks in 10 categories").
Because the template is generated, it cannot drift from the catalogue.
What is not generated, and is tested
The guide (docs/QC-DATA.md) explains each check. It is written by hand, but a unit test reads it and fails if any check ID is not mentioned. The qc-nm guide must likewise match its own catalogue and its list of corrections. So the order of work for a new check is:
- add the entry to the catalogue (the ID, the question, the level, the action);
- write the check in the category's
run, with the hit messages; - run the command on a file that triggers it, and on one that does not; look at the report;
- add the check to the guide, with the same wording of the question and an example of the finding;
- add a unit test for the check on a small in-memory dataset: one that passes and one that produces the hit;
- update the check count wherever it is stated (the listing, the guide and the book), and the changelog.
Choosing the level
| Level | Use it when | Effect on the verdict |
|---|---|---|
| error | the problem makes an analysis invalid or the file unreadable by NONMEM | counts as a failure; with fail_on = "error" the exit code is 7 |
| warning | the problem is likely a mistake but an analysis can proceed | counts as a warning; fails only with fail_on = "warning" |
| comment | a note for the analyst | never fails |
Be conservative with error: every error check is one more way a pipeline can stop. A check that can be correct in unusual but legitimate data should be a warning that the user can raise.
Review checklist
- Is the ID new, three letters plus two digits, and never reused?
- Is the question phrased so that "yes" is the good answer?
- Does the action sentence tell a data manager what to do?
- Does the guide mention the ID, and is there a passing and a failing test?
- Is every stated count of checks updated?
Navigation
See the previous page, the next page and the developer reference.