"""Independent referee, prepared for mscr; never run on the Mini. No imports from the claim's search or verifier. Run from the job directory. """ import csv, hashlib, json, re, subprocess from decimal import Decimal, localcontext from pathlib import Path from pypdf import PdfReader root=Path(__file__).resolve().parent source=root/'evidence' text='\n'.join(page.extract_text() for page in PdfReader(source/'shah_s2.pdf').pages) starts=list(re.finditer(r'(?m)^([A-Z])\s+([ACGU]{3})\s+',text)) rates={} for k,m in enumerate(starts): segment=text[m.end(): starts[k+1].start() if k+10 subprocess.run(['Rscript',str(root/'standard_referee.R')],check=True,cwd=root) r_rank=[int(x)-1 for x in (root/'native_order.txt').read_text().split()] assert rank==r_rank,'Exact-vs-native tie order differs; investigate before certifying.' def evaluate(path,precision): with open(path,newline='') as f: coordinates=list(csv.DictReader(f)) assert len(coordinates)==23 with localcontext() as ctx: ctx.prec=precision xy=[[Decimal(row[c]) for c in ['x','y']] for row in coordinates] distances=[sum((xy[i][c]-xy[j][c])**2 for c in range(2)).sqrt() for i,j in pairs] y=[distances[k] for k in rank] # Pool adjacent violators: least-squares monotone fit in MASS rank order. blocks=[] for value in y: blocks.append([value,1]) while len(blocks)>1 and blocks[-2][0]*blocks[-1][1]>blocks[-1][0]*blocks[-2][1]: b=blocks.pop();a=blocks.pop();blocks.append([a[0]+b[0],a[1]+b[1]]) fitted=[s/n for s,n in blocks for _ in range(n)] numerator=sum((a-b)**2 for a,b in zip(y,fitted)) denominator=sum(a*a for a in y) return str(100*(numerator/denominator).sqrt()),len(blocks) results={} for label,file in [('submitted',source/'witness.csv'),('native_default',root/'native_default.csv')]: results[label]={str(p):evaluate(file,p) for p in [80,120]} results.update(sequence_count=23,codons=len(profiles[0]),pair_count=len(pairs), unique_squared_distances=len(set(squared)), hashes={p.name:hashlib.sha256(p.read_bytes()).hexdigest() for p in source.iterdir() if p.is_file()}, caveat='Decimal precision cross-check, not an interval certificate') (root/'independent_result.json').write_text(json.dumps(results,indent=2)+'\n') print(json.dumps(results,indent=2))