- Snakefile: modules -> plain include: (single namespace; fixed cross-module helper resolution), rule all with stage-A/stage-B target sets driven by flat --config stage_b_arch/budget/stride switches. - config/main.yaml: v2 run matrix (ladder 12-grid, control 1M cnn s4), store excludes (DCS spike-in, in-corpus escherichia trap reads), barcoding kit (SQK-RBK114-96 classified during dorado basecalls), removes v1 quota. - baseline_pipeline: CUDA branch streams per-chunk dorado emit-sam through minimap2 (-N 10, tags preserved) and samtools view into per-batch BAMs, merged with samtools cat; ROCm/slorado fallback kept. - ml_pipeline: label parquets -> signal stores (main / windows-ablation w4 / trap store) -> 12 ladder trainings + shuffled control -> custom_models test with the trap store (TP2) -> custom_models gate over the g11 runs; stage B adds windows ablation, holdout/core_clade(/bacillus_group) variants and the dorado-fast alignment baseline on the winner's identical test split. - scripts: bam2annotation now emits source_run (barcoded -> barcodeNN from the dorado tags, dataset fallback); new label_qc.py (TP1 capture counts) and baseline_eval.py. - custom_models submodule: bump to test_split.parquet export commit. - README: two-stage run instructions (dev dry-run vs runner GPU).
52 lines
2.0 KiB
Python
52 lines
2.0 KiB
Python
"""TP1 label-side QC: trap-capture counts from a labelled corpus.
|
|
|
|
Any read whose best alignment lands on a trap-genus reference is a *trap
|
|
capture* — direct evidence that the labeller itself pulled a read into a
|
|
genus that carries no real data in the corpus (v2 §3; expected count 0,
|
|
which the in-corpus E. coli barcode reads consciously violate as the trap
|
|
source-one pool). Counts/breakdown are reported for the owner review.
|
|
"""
|
|
|
|
import json
|
|
|
|
import pandas as pd
|
|
|
|
if __name__ == '__main__':
|
|
labels_path = snakemake.input[0]
|
|
output_path = snakemake.output[0]
|
|
trap_genera = [str(g).lower() for g in snakemake.params.trap_genera]
|
|
|
|
df = pd.read_parquet(labels_path)
|
|
payload = {
|
|
'labels_path': str(labels_path),
|
|
'n_labelled_reads': int(df.shape[0]),
|
|
'n_unique_reads': int(df['read_id'].nunique()),
|
|
'per_genus': {
|
|
genus: int(n) for genus, n in df.groupby('genus')['read_id'].nunique().items()
|
|
},
|
|
'trap_expected_captures': 0,
|
|
'trap_captures': {},
|
|
}
|
|
|
|
captures = df[df['genus'].isin(trap_genera)]
|
|
for genus, group in captures.groupby('genus'):
|
|
payload['trap_captures'][genus] = {
|
|
'n_reads': int(group['read_id'].nunique()),
|
|
'n_source_runs': int(group['source_run'].nunique()),
|
|
'per_ref_name': {
|
|
ref: int(n) for ref, n in group.groupby('ref_name')['read_id'].nunique().items()
|
|
},
|
|
'identity': {
|
|
'mean': float(group['identity'].mean()),
|
|
'min': float(group['identity'].min()),
|
|
'max': float(group['identity'].max()),
|
|
},
|
|
}
|
|
|
|
with open(output_path, 'w') as out:
|
|
json.dump(payload, out, indent=2, sort_keys=True)
|
|
print(f'TP1 label QC -> {output_path}')
|
|
print(f' labelled reads: {payload["n_labelled_reads"]} ({payload["n_unique_reads"]} unique)')
|
|
for genus, stats in payload['trap_captures'].items():
|
|
print(f' trap captures {genus}: {stats["n_reads"]} reads over {stats["n_source_runs"]} source runs')
|