Spaces:
Build error
Build error
Upload 2 files
Browse filesFiles changed (2)
- README(20260811-220901).mdAdded+44
- compare_outputs.pyAdded+109
1234567891011121314151617181920212223242526272829303132333435363738394041424344# WOLOJI biological validation harness
Software tests demonstrate that the WOLOJI code behaves as implemented. They do not establish biological concordance with the standalone tools. Before manuscript submission, perform validation runs with public or curated bacterial WGS datasets and archive both the WOLOJI run package and the direct-tool outputs.
## Required concordance comparisons
| WOLOJI module | Direct comparator | Recommended primary endpoint ||---|---|---|| Read QC | fastp / FastQC run directly | retained reads and QC summaries || Assembly | SPAdes, Flye or Unicycler directly | assembly size, contig count, N50, QUAST metrics || Taxonomy | skani and GTDB-Tk directly | species call, ANI, aligned fraction || Annotation | Bakta or Prokka directly | CDS and feature counts, selected annotations || AMR | AMRFinderPlus directly | gene and mutation concordance, precision, recall, F1 || Virulence | ABRicate/VFDB directly | detected locus concordance at identical thresholds || MLST | mlst directly | exact sequence type and allele profile concordance || cgMLST/wgMLST | chewBBACA directly | exact allele profile concordance || Pan-genome | Panaroo directly | core/accessory counts and gene presence/absence matrix || Core SNP | Snippy directly | core SNP counts and pairwise SNP distances || Recombination | Gubbins directly | retained alignment and recombinant regions || Phylogeny | IQ-TREE directly | topology and support values with identical settings || Plasmids | MOB-suite directly | plasmid cluster/type concordance || Prophages/plasmids | geNomad directly | sequence-level detection concordance || Population | PopPUNK directly | cluster assignment concordance |
## Generic table comparison
`compare_outputs.py` compares two CSV/TSV files by one or more key columns, reports records unique to either output, and checks shared values with a configurable numeric tolerance.
Example:
```bashpython validation/compare_outputs.py \ woloji_mlst.csv direct_mlst.csv \ --keys sample,scheme,ST \ --json-out validation_mlst.json```
Use module-specific parsers where direct tool formats differ substantially. Do not transform outputs in a way that makes non-concordant results appear concordant.
## Validation record
For every benchmark dataset record the accession, organism, sequencing technology, expected phenotype or genotype where available, database versions, software versions, command lines, hardware, wall-clock time, peak RAM, disk usage, and whether the run completed successfully.
The final manuscript should clearly separate software verification, biological concordance, and external performance comparison.123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109from __future__ import annotations
import argparseimport jsonimport mathfrom pathlib import Path
import pandas as pd
def read_table(path: Path) -> pd.DataFrame: suffixes = "".join(path.suffixes).lower() if suffixes.endswith(".tsv") or suffixes.endswith(".txt"): return pd.read_csv(path, sep="\t") return pd.read_csv(path)
def compare_tables( observed: pd.DataFrame, expected: pd.DataFrame, keys: list[str], numeric_tolerance: float,) -> dict[str, object]: missing_keys = [key for key in keys if key not in observed.columns or key not in expected.columns] if missing_keys: raise ValueError(f"Missing key columns: {', '.join(missing_keys)}")
observed = observed.copy() expected = expected.copy() observed["__source_observed"] = True expected["__source_expected"] = True
merged = observed.merge(expected, how="outer", on=keys, suffixes=("_observed", "_expected"), indicator=True) only_observed = merged[merged["_merge"] == "left_only"] only_expected = merged[merged["_merge"] == "right_only"] shared = merged[merged["_merge"] == "both"].copy()
compared_columns: list[str] = [] disagreements: list[dict[str, object]] = [] common_nonkey = sorted((set(observed.columns) & set(expected.columns)) - set(keys) - {"__source_observed", "__source_expected"})
for column in common_nonkey: left = f"{column}_observed" right = f"{column}_expected" if left not in shared.columns or right not in shared.columns: continue compared_columns.append(column) left_values = shared[left] right_values = shared[right]
if pd.api.types.is_numeric_dtype(left_values) and pd.api.types.is_numeric_dtype(right_values): delta = (pd.to_numeric(left_values, errors="coerce") - pd.to_numeric(right_values, errors="coerce")).abs() mismatch = delta > numeric_tolerance mismatch &= ~(left_values.isna() & right_values.isna()) else: mismatch = left_values.fillna("<NA>").astype(str) != right_values.fillna("<NA>").astype(str)
if mismatch.any(): for _, row in shared.loc[mismatch, keys + [left, right]].head(100).iterrows(): record = {key: row[key] for key in keys} record.update({"column": column, "observed": row[left], "expected": row[right]}) disagreements.append(record)
tp = len(shared) fp = len(only_observed) fn = len(only_expected) precision = tp / (tp + fp) if tp + fp else math.nan recall = tp / (tp + fn) if tp + fn else math.nan f1 = 2 * precision * recall / (precision + recall) if precision + recall else math.nan
return { "observed_rows": int(len(observed)), "expected_rows": int(len(expected)), "matched_key_rows": int(tp), "only_observed_rows": int(fp), "only_expected_rows": int(fn), "key_precision": precision, "key_recall": recall, "key_f1": f1, "compared_columns": compared_columns, "value_disagreement_count": len(disagreements), "value_disagreements_first_100": disagreements, }
def main() -> int: parser = argparse.ArgumentParser(description="Compare WOLOJI tabular output with a direct-tool reference output.") parser.add_argument("observed", type=Path, help="WOLOJI output CSV/TSV") parser.add_argument("expected", type=Path, help="Direct-tool reference CSV/TSV") parser.add_argument("--keys", required=True, help="Comma-separated key columns used to match records") parser.add_argument("--numeric-tolerance", type=float, default=1e-8) parser.add_argument("--json-out", type=Path, default=None) args = parser.parse_args()
result = compare_tables( read_table(args.observed), read_table(args.expected), [item.strip() for item in args.keys.split(",") if item.strip()], args.numeric_tolerance, ) payload = json.dumps(result, indent=2, default=str) print(payload) if args.json_out: args.json_out.write_text(payload + "\n", encoding="utf-8") return 0
if __name__ == "__main__": raise SystemExit(main())README(20260811-220901).mdAdded+44
compare_outputs.pyAdded+109