STATISTICAL CODE AND SOURCE EXTRACTION FOR THE HEPATIC CYSTIC ECHINOCOCCOSIS STUDY
Version 2.1 | Prepared 5 October 2026 | Proposed Additional file 7

This package accompanies the manuscript "Incremental value of preoperative unenhanced CT attenuation for cystobiliary communication in single-cyst hepatic cystic echinococcosis: model development and internal evaluation using shared surgical data" by Li Wang, Yuezhen Liu and Zhan Wang. Correspondence: Zhan Wang, ufofu01@163.com.

The authors have chosen to make this code publicly available as a supplementary file with the article. This local package is prepared for that route; it has not yet been uploaded, submitted or published. No repository URL, DOI or separate open-source licence has been assigned. Publication and any applicable supplementary-file licence will be recorded through the journal's actual publication process. See PUBLICATION_STATUS.txt.

Version 2.1 changes documentation and release-status metadata only. All nine Python source files, numerical settings, dependency files and aggregate reference CSVs are byte-identical to version 2.0. The input workbook and patient-level datasets are not included. Extract this ZIP into C:\HCE_reproduction\code; paths shown below are examples to replace with your own local paths. Keep private-source, private-inputs and aggregate-output directories outside the code directory. The original internal workflow documentation and its notices are not redistributed as part of this scientific code attachment.

The package covers source-to-cohort extraction and the numerical model/performance pipeline. It does not include the original project-specific figure-generation workflow; final figures are supplied separately with the manuscript. self_check.py is a historical comparison tool that needs the authors' legacy project scripts. External users can use test_source_extraction.py without that project, and can reproduce the analysis from the public source workbook using the documented entry points.

Version 2 closes the source-extraction gap: `extract_source_workbook.py` starts directly from the locally obtained, hash-locked public-source workbook, reproduces the three four-field analysis cohorts, and defaults to checking them in memory. An actual read of the study workbook matched every numeric value and its order against the three frozen analysis CSVs; all three whole-cohort numeric fingerprints match. **This is an extraction verification, not a new full study-bootstrap run.** The numerical core and aggregate runner remain unchanged from version 1.

The attachment contains code, configuration, version records and aggregate reference results. It contains **no workbook, patient-level input, individual prediction, actual identifier, record-key value, physical source-row number or sampled-row array**. The optional four-field outputs still contain patient-level measurements and outcomes. Removing direct identifiers does not prove anonymisation or authorise public release. Those files must stay outside the code package and any submission upload unless an appropriate, separate release decision is made.

## Source, authorisation and entry points

The expected source is `Data summary.xlsx`, Figshare file 49003459, accessed 25 September 2026 through [the source article's sharing link](https://figshare.com/s/8c5c0346d9450d45afa8?file=49003459). Its SHA-256 is `eb89b1d75ec69e8e6190d3804277e2b941ae2f898c77008de8237974ebde4155`. The code does not download it or bypass access controls. A user must obtain the source legitimately and point the script to a local file. A different workbook version fails the hash check; do not overwrite the configuration to force it through.

Existing project records contain the investigator's confirmations about the applicable institutional review procedure and source identifiers, and a recorded source licence. This package creates no new ethics approval, independent anonymisation certification, patient-data sharing permission or software licence. It does not redistribute the source or promise that patient inputs will be provided on request. Source access and any future sharing must follow the actual permissions and arrangements.

- `extract_source_workbook.py`: **preferred source-to-input entry**; reads the raw workbook, derives all three cohorts and checks their frozen fingerprints. Default: no patient-file write, no model fit.
- `prepare_local_inputs.py`: retained compatibility adapter for the three original stage13 analysis CSVs; default: check only. It is no longer a prerequisite for source extraction.
- `run_reproduction.py`: validates a private four-field input by default; full computation requires `--execute-bootstrap`. It writes only aggregate model/performance/failure summaries.
- `check_results.py`: compares a future aggregate rerun with accepted full-precision Table S1.
- `test_source_extraction.py`: 16 synthetic extraction/guard/writer boundary checks, with no study data or model fitting.
- `self_check.py`: the earlier small synthetic numerical comparison against original local project scripts; it needs those scripts, not patient data.
- `core/hce_preprocessing.py`: exact frozen preprocessing module. `core/hce_models.py`: frozen solver/metrics/RNG with only its import search path adapted.
- `analysis_config.json`, `provenance.json` and `package_manifest.json`: fixed settings, source/code fingerprints, exact adaptations and file inventory.
- `evidence/TableS1.csv` and `TableS2.csv`: exact accepted 70-row aggregate result table and 30-row parameter table; these are existing study evidence, not results generated by the v2 checks.

## Extraction rules and private schema

The extractor follows the original stage11 rules and subsequent stage13 numeric checks. It selects the active worksheet (index 0 in the frozen workbook), skips its first header row, considers the first 40 cells A:AN, strips surrounding string whitespace and converts numeric strings to numbers. A source record is retained for screening when any of those normalised cells is nonempty. Cells beyond AN are ignored, as in the original extraction.

Screening uses a mutually exclusive first-exclusion rule, in order:

1. G must numerically equal 1; 61 of 331 nonempty records fail this requirement.
2. Among those remaining, S:AN must all be empty after normalisation; 4 fail. A recorded zero is nonempty.
3. R must be 1 or 2; 2 fail. The outcome is never imputed.

The resulting main cohort has 264 patients and 110 CBC-positive records. No adult-only, predictor-completeness, identifier-quality or extreme-value restriction is applied to the main cohort. C supplies age in years, M supplies calcification (1→0, 2→1; blank remains missing), O supplies mother-cyst fluid CT in HU, and R supplies the same-episode composite CBC outcome (1→0, 2→1). CT = 0 is observed, not missing. First-block coding is not extrapolated to other cyst blocks. Unknown ROI, readers, measurement interval and the separate components of the composite outcome remain unknown.

The complete-case subset requires all three predictors to be observed: 259 patients / 109 positive. The identifier-quality subset contains 251 / 105 and may retain missing predictors. To derive it, **raw** D and E identifiers are normalised and compared separately within their own columns across **all 331 nonempty source records**, including records excluded from the main cohort. A repeated value in either column excludes every affected primary-cohort record from this subset; two missing identifiers also exclude a record. A single missing identifier is retained if the other is nonrepeated. Values shared only across D and E do not count as same-column duplicates. String leading zeros are preserved; numeric integer cells are represented without a trailing `.0`. This is a quality restriction, not confirmed patient deduplication or record merging. No identifier or physical row index is created in the returned cohorts or exported.

All three cohorts preserve their original source order. Their only exported columns are:

| Column | Meaning |
|---|---|
| `age_years` | Age, years; continuous |
| `calcification_binary` | No = 0, yes = 1, blank = missing |
| `mother_fluid_CT_HU` | Recorded preoperative unenhanced mother-cyst fluid attenuation, HU; continuous |
| `CBC_composite` | Same-episode composite CBC: absent = 0, present = 1 |

The ordered numeric fingerprint is SHA-256 of UTF-8 compact JSON arrays in that column order, using floats for observed numbers and JSON `null` for missing predictors. The main, complete-case and identifier-quality fingerprints are respectively `9346b55299addf34137f2bb732c0f11ce2330a637a79b92471016e8ea7dfd113`, `e0024dcbdc2e02759abede7adcb61290c1a6e918a56a0ce4ef5686aab306ab3c` and `7c8fd9279e8a0e13ac391cd27240b700b59b35ea346de55d33c023139224a81a`. These describe numeric content/order, not CSV byte identity, permissions or patient independence. The original CSVs also contained a record key, which is deliberately not exported.

## Safe local commands

Run from the extracted code directory in the intended Python environment. The actual preparation used the existing Windows project environment; it did not install dependencies or access a remote account. Python 3.12.14, NumPy 2.3.5, SciPy 1.16.3 and openpyxl 3.1.5 were available. `requirements.txt` includes the fixed numerical/Excel dependencies; the complete historical environment remains in `original_environment.lock.txt`. See ENVIRONMENT.txt.

```powershell
python -X utf8 -B extract_source_workbook.py --help
python -X utf8 -B extract_source_workbook.py --workbook "C:\HCE_reproduction\private-source\Data summary.xlsx"
python -X utf8 -B test_source_extraction.py
```

The extraction command is **check-only by default**, and that default was exercised on the actual source workbook. Its output contains only flow totals, cohort totals/missingness, fingerprints and check status. It emits no row values, identifiers or row numbers.

To deliberately write the verified four-field inputs, an authorised data holder may choose a **new private directory outside this code folder**:

```powershell
python -X utf8 -B extract_source_workbook.py --workbook "C:\HCE_reproduction\private-source\Data summary.xlsx" --write-local --output-dir "C:\HCE_reproduction\private-inputs"
python -X utf8 -B run_reproduction.py --inputs "C:\HCE_reproduction\private-inputs" --scenario main_lambda1
```

The first command creates `main.csv`, `complete_case.csv`, `identifier_quality.csv` and a private manifest, then verifies each CSV by readback. The second only validates input. **The patient-data write command was not executed during v2 preparation.** The writer was exercised only on temporary, explicitly synthetic workbooks/data, with no synthetic files retained. Existing output directories and output inside the code package are refused.

The compatibility route remains available:

```powershell
python -X utf8 -B prepare_local_inputs.py --source-dir "C:\HCE_reproduction\legacy-stage13-output"
```

That checks the original hash-locked stage13 CSVs. Its optional `--write-local --output-dir` route gives the same four-field schema. It does not recompute identifier quality; the preferred workbook extractor does.

## Deliberate statistical rerun

The following operation is computationally expensive and **was not performed in this round**. It needs verified private inputs and a new aggregate output directory. There is no resume support; retain an interrupted run separately and restart in another new directory.

```powershell
python -X utf8 -B run_reproduction.py --inputs "C:\HCE_reproduction\private-inputs" --scenario main_lambda1 --workers 8 --execute-bootstrap --output-dir "C:\HCE_reproduction\aggregate-main"
python -X utf8 -B check_results.py --results "C:\HCE_reproduction\aggregate-main\performance_summary.csv" --scenario main_lambda1
```

| Scenario | Private input | Ridge penalty | Point resamples | Nested interval |
|---|---|---:|---:|---:|
| `main_lambda1` | Main | 1 | 1000 | 1000 × 200 |
| `complete_case_lambda1` | Complete case | 1 | 1000 | 1000 × 200 |
| `identifier_quality_lambda1` | Identifier quality | 1 | 1000 | 1000 × 200 |
| `main_lambda0.1` | Main | 0.1 | 1000 | Not estimated |
| `main_lambda10` | Main | 10 | 1000 | Not estimated |

Each scenario requires a distinct new output directory. The CLI exposes no replicate-count or seed tuning. It repeats training-only preprocessing within ordinary nonstratified resamples, uses paired model draws, the original summed ridge objective/unpenalised intercept, the metric-specific 5% failure rule and linear percentile limits. Penalty sensitivities regenerate the identical main-cohort point indices from the same seed/order/type; no winner is selected. The primary increment is Brier(M0)−Brier(M1); the secondary AUC increment is AUC(M1)−AUC(M0).

Outputs are `performance_summary.csv`, `fitted_models.json`, `failure_counts.csv`, `run_manifest.json` and `run_status.json`. The wrapper intentionally omits individual predictions and sampled-row arrays and aggregates failure logs. The calculations use the original numerical core, but the wrapper is not a byte-identical replacement for the old archival workflow. Compare a future full rerun with the supplied aggregate evidence and investigate mismatches; do not silently widen tolerances to conceal them.

## Actual verification and limits

The v2 source workbook was read in memory with its SHA checked before and after. All sequential exclusions, three cohort totals/events/missingness, all four-field values and their order matched the current frozen stage13 files. All three fingerprints also matched the existing v1 configuration. **No real patient input/export or model fit was created.**

Sixteen synthetic extraction checks cover string/identifier normalisation, leading zeros, same-column duplication across excluded records, no cross-column matching, both/single missing identifiers, sequential exclusion priority, later-block zeros, missingness, minors, invalid numeric data, active-sheet/header handling, source-hash guards, four-field export/readback and no overwrite/package-output safeguards. The temporary synthetic workbook and output files were removed. These tests are not study observations or evidence about clinical performance.

Version 1's unchanged numerical core/wrapper had separate small synthetic checks: 24 artificial rows, 8 point draws, 3 outer × 5 inner draws for the nested case, plus point-only penalty cases. Original versus packaged parameters/predictions/metrics/intervals/valid counts/failures matched within 1e-12; two processes and nine cohort-code × phase seed combinations were checked. Those earlier checks are preserved as historical evidence, not claimed as a new full v2 study rerun. The v2 code compiles and CLI help works. A fresh-machine dependency installation and the full 1000/1000×200 analysis through the packaged entry remain untested in this round.

The package makes local source-to-input reproduction materially more complete. It does not establish that the source table has no measurement/reference-standard limitations, that identifiers prove unique patients, that clinical utility or external validity exists, or that additional patient-level data sharing is authorised. The study was not registered, as stated in the manuscript. The original ROI/time-gap/endpoint limitations cannot be repaired by software packaging. No new full statistical analysis, public upload or journal submission was performed to prepare this code attachment.

Model coefficients in Table S2 are for research reproduction, with each repeated intercept added once and the appropriate raw-unit or standardised preprocessing. They are not a clinically validated calculator, contain no coefficient intervals/P values, and do not authorise patient decisions.
