Documentation

41.5 Case 1: the gate and the handover

qc-data as a gate in front of the analysis

What you will learn

  • Turn quality control from a report into a gate with --fail-on.
  • Choose between stopping on errors, on warnings, or never, and say why.
  • Write the handover record that carries the hashes and the accepted exceptions to the next step.
  • See how a failed gate looks to a pipeline.

Prerequisites: 41.3, 41.4 and Chapter 39, errors and exit codes.

The question: how do we make sure that nothing downstream ever runs on the defective file?

The evidence: the same defective.qcd, which sets fail_on = "never"; the validation package's test OQ-QCD-003, which runs qc-data four times and requires the exit codes 0, 7, 0, 7 (clean data with --fail-on error; a defective file with error, with never, and with warning; page 42.14); and the Chapter 11 results folder.

A report is not a gate

The run of page 41.3 reported NOT READY and then exited normally. That is exactly what its settings asked for: fail_on = "never" means "write the report and succeed". It is the right setting for exploring a file by hand; it is the wrong setting in a pipeline, where the next command starts if and only if the previous one exits 0. A report no program reads protects nothing.

The gate is one line. Setting the level to error, in the settings file or on the command line, makes the same run end with exit code 7, the documented class for data validation failure:

fail_on Stops (exit 7) when Use it for
never never exploration: you want the report whatever it says
error any FAIL check the default gate for analysis: no known structural defect passes
warning any FAIL or WARN check a locked analysis or a submission: every unusual value needs a written decision

Choosing warning is not "stricter is better". A real file always has some warnings (a rare category, an extreme but true body weight), so a warning gate with no exception mechanism fails every time and gets switched off, which is worse than no gate. The choice is between a gate people respect and one they bypass.

What a failed gate looks like

For the defective file with fail_on = error:

  1. The program still writes its findings: the validation test checks that qc_findings.csv exists in the output folder of a run that exits 7. The report is the explanation.
  2. It ends with exit code 7, the documented class for data validation failure.
  3. In a script the next command does not run. In a scheduler the job is marked failed, and the person who reads the failure sees the reason, not just the code.

A good negative test of a gate asserts three things (page 42.14): the exit code, an explanatory message, and that the inputs are untouched. That last point is what makes the gate trustworthy: a failing quality check never edits the file it is checking.

Exceptions: accepting a warning properly

Because a warning gate needs an exception route, the case ends with the one the repair plan of 41.4 used: accept, with a written reason. In practice that means a short table kept with the run:

Finding Check Accepted by Reason
33 % BLQ in a 9-record file OBS05 analyst Property of the study; handled by one BLQ rule applied to every record, not by deleting rows
SEX = 1 in one individual COV05 analyst True category; will be dropped from the covariate search if fewer than three subjects

(The table is an illustration of the form. The first two rows are the real findings OBS05 and COV05; the reasons are the analyst's.) The test of a good exception is that a colleague can read it six months later and agree that it was reasonable.

The handover record

Once the file passes, the next step needs three things from this one. Write them down together:

  1. The identity of the analysis dataset: file name and SHA-256 of the repaired file (the program's input manifest and checksum list give both).
  2. The identity of the evidence: the two qc_summary.txt files (defective and repaired) and the findings tables, with their hashes.
  3. The decisions: the repair plan, the accepted exceptions, and the covariate types and categorical levels the check established, which are the settings the next commands need (for example the continuous and categorical covariates of the covariates block).

The next case begins here: with a file that has a hash and a known layout, the first analysis step is to describe exposure by non-compartmental analysis (41.6).

The decision

Question Evidence Decision Reversible?
Can the pipeline start without a human reading the report? exit code 7 on --fail-on error Gate at error; keep a written exception table for warnings yes

What this case does not show

A gate catches what the checks encode. It cannot catch an error that is consistent (a wrong unit applied to every record) or a question that is not in the 99 (a particular site's rule). Site rules are added as tests of your own (page 42.3 shows the qc-data gate as a worked requirement).

Review checklist

  • Does your pipeline stop on exit code 7, or only record it?
  • Is the gate level written in the settings file, not in someone's shell history?
  • Does every accepted warning have a reason a stranger would accept?
  • Does the handover record carry the hashes of the file and of the summaries?

See the previous page, the next page and the complete case-study reference.