Samad14 commited on
Commit
9356b27
·
verified ·
1 Parent(s): 2ae7415

Upload folder using huggingface_hub

Browse files
benchmark/case-studies/hbb-variant-mapping/run.py ADDED
@@ -0,0 +1,123 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ """Executable BioNexus case study: deterministic HBB E7V variant mapping.
2
+
3
+ This is a reproducibility demonstration, not a clinical diagnostic workflow.
4
+ The canonical human beta-globin precursor sequence used here is UniProt
5
+ P68871 (HBB_HUMAN). The substitution is expressed in precursor numbering as
6
+ E7V, corresponding to the classic sickle beta-globin substitution.
7
+ """
8
+ from __future__ import annotations
9
+
10
+ import hashlib
11
+ import json
12
+ from datetime import datetime, timezone
13
+ from pathlib import Path
14
+
15
+ from app.tools.alignment_insights import alignment_insights
16
+
17
+ UNIPROT_ACCESSION = "P68871"
18
+ SOURCE_NAME = "UniProtKB/Swiss-Prot"
19
+ HBB_WILDTYPE = (
20
+ "MVHLTPEEKSAVTALWGKVNVDEVGGEALGRLLVVYPWTQRFFESFGDLSTPDAVMGNPKVKAHGKK"
21
+ "VLGAFSDGLAHLDNLKGTFATLSELHCDKLHVDPENFRLLGNVLVCVLAHHFGKEFTPPVQAAYQKVV"
22
+ "AGVANALAHKYH"
23
+ )
24
+ VARIANT = {"id": "HBB-E7V", "position": 7, "ref": "E", "alt": "V"}
25
+ EXPECTED_WT_SHA256 = "9ebf320eb707d71644444fe5006ed58af56a0bf0ec9568eb6a3a65e0e8191465"
26
+ EXPECTED_MUTANT_SHA256 = "5b53af628d9be96c8e95abf0de0f88df7e7e69d330b9e70941443ba3e5f1667d"
27
+
28
+
29
+ def sha256_text(value: str) -> str:
30
+ return hashlib.sha256(value.encode("utf-8")).hexdigest()
31
+
32
+
33
+ def build_mutant() -> str:
34
+ index = VARIANT["position"] - 1
35
+ observed = HBB_WILDTYPE[index]
36
+ if observed != VARIANT["ref"]:
37
+ raise ValueError(
38
+ f"reference residue mismatch at position {VARIANT['position']}: "
39
+ f"expected {VARIANT['ref']}, observed {observed}"
40
+ )
41
+ return HBB_WILDTYPE[:index] + VARIANT["alt"] + HBB_WILDTYPE[index + 1 :]
42
+
43
+
44
+ def run_case() -> dict:
45
+ mutant = build_mutant()
46
+ wt_sha = sha256_text(HBB_WILDTYPE)
47
+ mutant_sha = sha256_text(mutant)
48
+ if wt_sha != EXPECTED_WT_SHA256 or mutant_sha != EXPECTED_MUTANT_SHA256:
49
+ raise ValueError("sequence checksum mismatch; case-study fixture changed")
50
+
51
+ insights = alignment_insights(
52
+ [HBB_WILDTYPE, mutant],
53
+ reference_index=0,
54
+ variants=[VARIANT],
55
+ )
56
+ mapping = insights["variant_mapping"][0]
57
+ column = insights["columns"][VARIANT["position"] - 1]
58
+
59
+ if mapping["status"] != "mapped":
60
+ raise ValueError("variant did not map to the reference alignment")
61
+ if mapping["reference_symbol"] != VARIANT["ref"]:
62
+ raise ValueError("mapped reference symbol does not match declared variant")
63
+
64
+ return {
65
+ "case_study": "HBB-E7V-variant-mapping",
66
+ "status": "executed",
67
+ "generated_at_utc": datetime.now(timezone.utc).isoformat(),
68
+ "source": {
69
+ "database": SOURCE_NAME,
70
+ "accession": UNIPROT_ACCESSION,
71
+ "sequence_length": len(HBB_WILDTYPE),
72
+ "sequence_sha256": wt_sha,
73
+ "source_semantics": "reference sequence fixture; accession must be independently revalidated when source releases change",
74
+ },
75
+ "variant": {
76
+ **VARIANT,
77
+ "numbering": "precursor protein numbering",
78
+ "mutant_sequence_sha256": mutant_sha,
79
+ },
80
+ "deterministic_result": {
81
+ "alignment_position": mapping["alignment_position"],
82
+ "reference_symbol": mapping["reference_symbol"],
83
+ "conservation": mapping["conservation"],
84
+ "entropy_bits": mapping["entropy_bits"],
85
+ "column_consensus": column["consensus"],
86
+ "column_logo": column["logo"],
87
+ "alignment_length": insights["alignment_length"],
88
+ "sequence_count": insights["sequence_count"],
89
+ "mean_conservation": insights["mean_conservation"],
90
+ "mean_entropy_bits": insights["mean_entropy_bits"],
91
+ },
92
+ "evidence": {
93
+ "classes": ["reference_retrieval", "deterministic_computation"],
94
+ "claims": [
95
+ {
96
+ "id": "variant-mapped",
97
+ "claim": "The declared precursor E7V substitution maps deterministically to alignment position 7 in this ungapped two-sequence comparison.",
98
+ "evidence_refs": ["UniProt:P68871", "BioNexus:alignment_insights"],
99
+ }
100
+ ],
101
+ },
102
+ "reproducibility": {
103
+ "algorithm": "app.tools.alignment_insights.alignment_insights",
104
+ "fixture_checksums_locked": True,
105
+ "random_seed_required": False,
106
+ },
107
+ "scientific_boundary": (
108
+ "This case demonstrates deterministic sequence provenance and variant mapping only. "
109
+ "It does not establish diagnostic validity, pathogenicity classification, clinical utility, "
110
+ "or superiority over external bioinformatics platforms."
111
+ ),
112
+ }
113
+
114
+
115
+ def main() -> None:
116
+ result = run_case()
117
+ output_path = Path(__file__).with_name("result.json")
118
+ output_path.write_text(json.dumps(result, indent=2, sort_keys=True) + "\n", encoding="utf-8")
119
+ print(json.dumps(result, indent=2, sort_keys=True))
120
+
121
+
122
+ if __name__ == "__main__":
123
+ main()