Spaces:
Sleeping
Sleeping
| """Validate our port reproduces the original model's saved prediction exactly. | |
| PichiaArch1_HerHC.xlsx was generated by the reference apply-notebook using the | |
| SAME checkpoint we deployed (2Target_AllData/FinArch1_AttnCorr_cp). We recover | |
| the input protein from that ground-truth output, run it through our model, and | |
| compare codon-for-codon. | |
| """ | |
| import pandas as pd | |
| import model as clm | |
| BASE = (r"C:\Users\ChemEGrad2025\MIT Dropbox\Love Lab\Love Lab Member Archives" | |
| r"\Harini Narayanan April 2022 - July 2025\CodonOptimization\CO_Application") | |
| REFS = { | |
| "Herceptin HC": BASE + r"\Herceptin_HC\PredictedSequences\PichiaArch1_HerHC.xlsx", | |
| "Herceptin LC": BASE + r"\Herceptin_LC\PredictedSequences\PichiaArch1_HerLC.xlsx", | |
| "Lactoferrin": BASE + r"\Lactoferrin\PredictedSequences\PichiaArch1_Lactoferrin.xlsx", | |
| } | |
| CODON_TO_AA = {c: aa for aa, cs in clm.DIC_AA_CODON.items() for c in cs} | |
| opt = clm.CodonOptimizer() | |
| for name, path in REFS.items(): | |
| row = pd.read_excel(path).iloc[0].tolist() | |
| ref_tokens = [int(t) for t in row[1:] if pd.notna(t)] # drop index column | |
| assert ref_tokens[0] == clm.CODON_START and ref_tokens[-1] == clm.CODON_STOP | |
| ref_dna = clm.detokenize_codons(ref_tokens[1:-1]) # strip 65 / 66 | |
| ref_codons = [ref_dna[i:i+3] for i in range(0, len(ref_dna), 3)] | |
| aa_input = "".join(CODON_TO_AA[c] for c in ref_codons) # recover protein (+'*') | |
| our_dna = opt.optimize(aa_input) | |
| our_codons = [our_dna[i:i+3] for i in range(0, len(our_dna), 3)] | |
| exact = our_dna == ref_dna | |
| n = min(len(ref_codons), len(our_codons)) | |
| same = sum(a == b for a, b in zip(ref_codons[:n], our_codons[:n])) | |
| print(f"{name:14s} {len(aa_input.rstrip('*')):4d} aa | ref {len(ref_codons)} / " | |
| f"ours {len(our_codons)} codons | agree {same}/{n} " | |
| f"({100*same/n:.2f}%) | EXACT={exact}") | |