import pymzml

mzml_path = "/home/user/LabData/XianghuData/Test_incremental_2000/results/batch_26_results/consensus.mzML"

skipped = set()
kept = set()
with pymzml.run.Reader(mzml_path) as run:
    for spec in run:
        scan_id_str = str(spec.ID)
        if '_' in scan_id_str:
            if len(skipped) < 20:
                skipped.add(scan_id_str)
            continue
        try:
            if "scan=" in scan_id_str:
                scan_id = int(scan_id_str.split("scan=")[-1].split()[0])
            else:
                scan_id = int(scan_id_str)
            if len(kept) < 20:
                kept.add(scan_id_str)
        except Exception:
            continue
        if len(skipped) >= 20 and len(kept) >= 20:
            break

print("样例（被跳过的scan id，含下划线）:")
for s in list(skipped):
    print("  ", s)
print("\n样例（被保留的scan id，纯整数）:")
for s in list(kept):
    print("  ", s) 