Spaces:
Sleeping
Sleeping
Fix: Remove unused plotly/numpy imports
Browse files
app.py
CHANGED
|
@@ -1,1038 +1,1036 @@
|
|
| 1 |
-
"""
|
| 2 |
-
TopoGrammar - Grammar-Aware 3D Genome Engine Demo
|
| 3 |
-
==================================================
|
| 4 |
-
|
| 5 |
-
Hugging Face Spaces Demo for TopoGrammar v2.1.0
|
| 6 |
-
The Industry's First Grammar-Aware Engine for Balanced Structural Variants
|
| 7 |
-
|
| 8 |
-
Copyright (c) 2026 Bryan Daugherty, Gregory Ward & Shawn Ryan. All Rights Reserved.
|
| 9 |
-
|
| 10 |
-
This demo showcases TopoGrammar's capabilities without exposing proprietary algorithms.
|
| 11 |
-
All results are pre-computed demonstrations for educational purposes.
|
| 12 |
-
"""
|
| 13 |
-
|
| 14 |
-
import gradio as gr
|
| 15 |
-
import hashlib
|
| 16 |
-
import random
|
| 17 |
-
import time
|
| 18 |
-
import httpx
|
| 19 |
-
import json
|
| 20 |
-
import os
|
| 21 |
-
from datetime import datetime
|
| 22 |
-
from typing import Optional, Dict, List, Tuple
|
| 23 |
-
|
| 24 |
-
|
| 25 |
-
|
| 26 |
-
# =============================================================================
|
| 27 |
-
|
| 28 |
-
|
| 29 |
-
|
| 30 |
-
|
| 31 |
-
|
| 32 |
-
|
| 33 |
-
|
| 34 |
-
|
| 35 |
-
|
| 36 |
-
|
| 37 |
-
|
| 38 |
-
|
| 39 |
-
|
| 40 |
-
|
| 41 |
-
|
| 42 |
-
|
| 43 |
-
|
| 44 |
-
|
| 45 |
-
|
| 46 |
-
|
| 47 |
-
|
| 48 |
-
|
| 49 |
-
|
| 50 |
-
|
| 51 |
-
|
| 52 |
-
|
| 53 |
-
|
| 54 |
-
|
| 55 |
-
|
| 56 |
-
|
| 57 |
-
|
| 58 |
-
|
| 59 |
-
|
| 60 |
-
|
| 61 |
-
|
| 62 |
-
|
| 63 |
-
|
| 64 |
-
|
| 65 |
-
|
| 66 |
-
|
| 67 |
-
|
| 68 |
-
|
| 69 |
-
|
| 70 |
-
|
| 71 |
-
|
| 72 |
-
|
| 73 |
-
|
| 74 |
-
# =============================================================================
|
| 75 |
-
|
| 76 |
-
#
|
| 77 |
-
|
| 78 |
-
|
| 79 |
-
|
| 80 |
-
|
| 81 |
-
"
|
| 82 |
-
"
|
| 83 |
-
"
|
| 84 |
-
"
|
| 85 |
-
"
|
| 86 |
-
"
|
| 87 |
-
"
|
| 88 |
-
"
|
| 89 |
-
|
| 90 |
-
|
| 91 |
-
|
| 92 |
-
|
| 93 |
-
"
|
| 94 |
-
"
|
| 95 |
-
"
|
| 96 |
-
"
|
| 97 |
-
"
|
| 98 |
-
"
|
| 99 |
-
"
|
| 100 |
-
"
|
| 101 |
-
|
| 102 |
-
|
| 103 |
-
|
| 104 |
-
|
| 105 |
-
"
|
| 106 |
-
"
|
| 107 |
-
"
|
| 108 |
-
"
|
| 109 |
-
"
|
| 110 |
-
"
|
| 111 |
-
"
|
| 112 |
-
"
|
| 113 |
-
|
| 114 |
-
|
| 115 |
-
|
| 116 |
-
|
| 117 |
-
"
|
| 118 |
-
"
|
| 119 |
-
"
|
| 120 |
-
"
|
| 121 |
-
"
|
| 122 |
-
"
|
| 123 |
-
"
|
| 124 |
-
"
|
| 125 |
-
|
| 126 |
-
|
| 127 |
-
|
| 128 |
-
|
| 129 |
-
"
|
| 130 |
-
"
|
| 131 |
-
"
|
| 132 |
-
"
|
| 133 |
-
"
|
| 134 |
-
"
|
| 135 |
-
"
|
| 136 |
-
"
|
| 137 |
-
|
| 138 |
-
|
| 139 |
-
|
| 140 |
-
|
| 141 |
-
|
| 142 |
-
|
| 143 |
-
|
| 144 |
-
|
| 145 |
-
"
|
| 146 |
-
"
|
| 147 |
-
"
|
| 148 |
-
"
|
| 149 |
-
"
|
| 150 |
-
|
| 151 |
-
|
| 152 |
-
|
| 153 |
-
|
| 154 |
-
"
|
| 155 |
-
"
|
| 156 |
-
"
|
| 157 |
-
"
|
| 158 |
-
"
|
| 159 |
-
|
| 160 |
-
|
| 161 |
-
|
| 162 |
-
|
| 163 |
-
"
|
| 164 |
-
"
|
| 165 |
-
"
|
| 166 |
-
"
|
| 167 |
-
"
|
| 168 |
-
|
| 169 |
-
|
| 170 |
-
|
| 171 |
-
|
| 172 |
-
|
| 173 |
-
|
| 174 |
-
|
| 175 |
-
|
| 176 |
-
"
|
| 177 |
-
"
|
| 178 |
-
"
|
| 179 |
-
"
|
| 180 |
-
"
|
| 181 |
-
"
|
| 182 |
-
|
| 183 |
-
|
| 184 |
-
|
| 185 |
-
|
| 186 |
-
"
|
| 187 |
-
"
|
| 188 |
-
"
|
| 189 |
-
"
|
| 190 |
-
"
|
| 191 |
-
"
|
| 192 |
-
|
| 193 |
-
|
| 194 |
-
|
| 195 |
-
|
| 196 |
-
"
|
| 197 |
-
"
|
| 198 |
-
"
|
| 199 |
-
"
|
| 200 |
-
"
|
| 201 |
-
"
|
| 202 |
-
|
| 203 |
-
|
| 204 |
-
|
| 205 |
-
|
| 206 |
-
|
| 207 |
-
|
| 208 |
-
|
| 209 |
-
|
| 210 |
-
"
|
| 211 |
-
"
|
| 212 |
-
|
| 213 |
-
|
| 214 |
-
|
| 215 |
-
|
| 216 |
-
"
|
| 217 |
-
|
| 218 |
-
|
| 219 |
-
|
| 220 |
-
|
| 221 |
-
"
|
| 222 |
-
|
| 223 |
-
|
| 224 |
-
|
| 225 |
-
|
| 226 |
-
|
| 227 |
-
|
| 228 |
-
# =============================================================================
|
| 229 |
-
|
| 230 |
-
|
| 231 |
-
|
| 232 |
-
|
| 233 |
-
|
| 234 |
-
|
| 235 |
-
|
| 236 |
-
|
| 237 |
-
|
| 238 |
-
|
| 239 |
-
|
| 240 |
-
|
| 241 |
-
|
| 242 |
-
|
| 243 |
-
|
| 244 |
-
|
| 245 |
-
|
| 246 |
-
|
| 247 |
-
|
| 248 |
-
|
| 249 |
-
row += "
|
| 250 |
-
|
| 251 |
-
row += "
|
| 252 |
-
|
| 253 |
-
|
| 254 |
-
|
| 255 |
-
|
| 256 |
-
|
| 257 |
-
|
| 258 |
-
|
| 259 |
-
|
| 260 |
-
|
| 261 |
-
|
| 262 |
-
"
|
| 263 |
-
lines
|
| 264 |
-
|
| 265 |
-
|
| 266 |
-
|
| 267 |
-
|
| 268 |
-
|
| 269 |
-
|
| 270 |
-
|
| 271 |
-
|
| 272 |
-
|
| 273 |
-
|
| 274 |
-
|
| 275 |
-
|
| 276 |
-
|
| 277 |
-
|
| 278 |
-
|
| 279 |
-
|
| 280 |
-
|
| 281 |
-
β
|
| 282 |
-
|
| 283 |
-
β
|
| 284 |
-
β
|
| 285 |
-
β
|
| 286 |
-
β
|
| 287 |
-
β
|
| 288 |
-
β
|
| 289 |
-
β
|
| 290 |
-
β
|
| 291 |
-
β
|
| 292 |
-
β
|
| 293 |
-
β
|
| 294 |
-
β
|
| 295 |
-
β
|
| 296 |
-
β
|
| 297 |
-
β β’
|
| 298 |
-
β
|
| 299 |
-
|
| 300 |
-
|
| 301 |
-
|
| 302 |
-
"""
|
| 303 |
-
|
| 304 |
-
|
| 305 |
-
|
| 306 |
-
β
|
| 307 |
-
|
| 308 |
-
β
|
| 309 |
-
β
|
| 310 |
-
β
|
| 311 |
-
β β
|
| 312 |
-
β β
|
| 313 |
-
β
|
| 314 |
-
β
|
| 315 |
-
β
|
| 316 |
-
β
|
| 317 |
-
β
|
| 318 |
-
β
|
| 319 |
-
β
|
| 320 |
-
β β
|
| 321 |
-
β β
|
| 322 |
-
β
|
| 323 |
-
β
|
| 324 |
-
β
|
| 325 |
-
β β
|
| 326 |
-
|
| 327 |
-
|
| 328 |
-
|
| 329 |
-
"""
|
| 330 |
-
|
| 331 |
-
|
| 332 |
-
|
| 333 |
-
β
|
| 334 |
-
|
| 335 |
-
β
|
| 336 |
-
β
|
| 337 |
-
β
|
| 338 |
-
β
|
| 339 |
-
β
|
| 340 |
-
β
|
| 341 |
-
β
|
| 342 |
-
β
|
| 343 |
-
β
|
| 344 |
-
β
|
| 345 |
-
β
|
| 346 |
-
β
|
| 347 |
-
β
|
| 348 |
-
β
|
| 349 |
-
β
|
| 350 |
-
|
| 351 |
-
|
| 352 |
-
|
| 353 |
-
"""
|
| 354 |
-
|
| 355 |
-
|
| 356 |
-
|
| 357 |
-
β
|
| 358 |
-
|
| 359 |
-
β β
|
| 360 |
-
β
|
| 361 |
-
β
|
| 362 |
-
β β’
|
| 363 |
-
β β’
|
| 364 |
-
β
|
| 365 |
-
|
| 366 |
-
|
| 367 |
-
|
| 368 |
-
|
| 369 |
-
|
| 370 |
-
|
| 371 |
-
|
| 372 |
-
"
|
| 373 |
-
|
| 374 |
-
|
| 375 |
-
|
| 376 |
-
|
| 377 |
-
|
| 378 |
-
|
| 379 |
-
|
| 380 |
-
|
| 381 |
-
|
| 382 |
-
|
| 383 |
-
|
| 384 |
-
|
| 385 |
-
|
| 386 |
-
|
| 387 |
-
|
| 388 |
-
|
| 389 |
-
|
| 390 |
-
|
| 391 |
-
|
| 392 |
-
|
| 393 |
-
|
| 394 |
-
|
| 395 |
-
|
| 396 |
-
|
| 397 |
-
|
| 398 |
-
|
| 399 |
-
|
| 400 |
-
|
| 401 |
-
|
| 402 |
-
|
| 403 |
-
|
| 404 |
-
|
| 405 |
-
|
| 406 |
-
|
| 407 |
-
|
| 408 |
-
|
| 409 |
-
|
| 410 |
-
|
| 411 |
-
|
| 412 |
-
"
|
| 413 |
-
"
|
| 414 |
-
"
|
| 415 |
-
"
|
| 416 |
-
"
|
| 417 |
-
"
|
| 418 |
-
|
| 419 |
-
|
| 420 |
-
|
| 421 |
-
|
| 422 |
-
|
| 423 |
-
|
| 424 |
-
|
| 425 |
-
|
| 426 |
-
|
| 427 |
-
|
| 428 |
-
|
| 429 |
-
|
| 430 |
-
|
| 431 |
-
|
| 432 |
-
|
| 433 |
-
|
| 434 |
-
|
| 435 |
-
|
| 436 |
-
β
|
| 437 |
-
|
| 438 |
-
|
| 439 |
-
|
| 440 |
-
|
| 441 |
-
|
| 442 |
-
|
| 443 |
-
β
|
| 444 |
-
|
| 445 |
-
|
| 446 |
-
|
| 447 |
-
|
| 448 |
-
|
| 449 |
-
|
| 450 |
-
β
|
| 451 |
-
|
| 452 |
-
β
|
| 453 |
-
β
|
| 454 |
-
β
|
| 455 |
-
β
|
| 456 |
-
β β
|
| 457 |
-
β
|
| 458 |
-
β
|
| 459 |
-
β
|
| 460 |
-
β
|
| 461 |
-
β
|
| 462 |
-
β β
|
| 463 |
-
β
|
| 464 |
-
β
|
| 465 |
-
β
|
| 466 |
-
|
| 467 |
-
β β
|
| 468 |
-
|
| 469 |
-
β
|
| 470 |
-
β
|
| 471 |
-
|
| 472 |
-
|
| 473 |
-
|
| 474 |
-
|
| 475 |
-
|
| 476 |
-
|
| 477 |
-
|
| 478 |
-
|
| 479 |
-
|
| 480 |
-
|
| 481 |
-
|
| 482 |
-
|
| 483 |
-
|
| 484 |
-
|
| 485 |
-
|
| 486 |
-
|
| 487 |
-
|
| 488 |
-
|
| 489 |
-
<a
|
| 490 |
-
|
| 491 |
-
|
| 492 |
-
<a
|
| 493 |
-
|
| 494 |
-
|
| 495 |
-
|
| 496 |
-
|
| 497 |
-
|
| 498 |
-
|
| 499 |
-
# =============================================================================
|
| 500 |
-
|
| 501 |
-
|
| 502 |
-
|
| 503 |
-
|
| 504 |
-
|
| 505 |
-
|
| 506 |
-
|
| 507 |
-
|
| 508 |
-
|
| 509 |
-
|
| 510 |
-
|
| 511 |
-
|
| 512 |
-
|
| 513 |
-
|
| 514 |
-
|
| 515 |
-
#
|
| 516 |
-
|
| 517 |
-
|
| 518 |
-
|
|
| 519 |
-
|
|
| 520 |
-
| **
|
| 521 |
-
|
| 522 |
-
|
| 523 |
-
|
| 524 |
-
|
| 525 |
-
|
| 526 |
-
##
|
| 527 |
-
|
| 528 |
-
|
| 529 |
-
|
|
| 530 |
-
|
| 531 |
-
|
| 532 |
-
|
| 533 |
-
|
| 534 |
-
|
| 535 |
-
|
| 536 |
-
|
| 537 |
-
|
| 538 |
-
|
| 539 |
-
|
| 540 |
-
-
|
| 541 |
-
|
| 542 |
-
|
| 543 |
-
|
| 544 |
-
|
| 545 |
-
|
| 546 |
-
|
| 547 |
-
|
| 548 |
-
|
| 549 |
-
|
| 550 |
-
|
| 551 |
-
|
| 552 |
-
|
| 553 |
-
|
| 554 |
-
|
| 555 |
-
|
| 556 |
-
|
| 557 |
-
|
| 558 |
-
|
| 559 |
-
|
| 560 |
-
|
| 561 |
-
|
| 562 |
-
|
| 563 |
-
|
| 564 |
-
|
| 565 |
-
|
| 566 |
-
|
| 567 |
-
|
| 568 |
-
|
| 569 |
-
|
| 570 |
-
|
| 571 |
-
|
| 572 |
-
|
| 573 |
-
|
| 574 |
-
|
| 575 |
-
|
| 576 |
-
|
| 577 |
-
|
| 578 |
-
|
| 579 |
-
|
| 580 |
-
|
| 581 |
-
|
| 582 |
-
#
|
| 583 |
-
|
| 584 |
-
|
| 585 |
-
|
|
| 586 |
-
|
|
| 587 |
-
| **
|
| 588 |
-
| **
|
| 589 |
-
|
| 590 |
-
|
| 591 |
-
|
| 592 |
-
|
| 593 |
-
|
| 594 |
-
|
| 595 |
-
|
| 596 |
-
|
| 597 |
-
|
| 598 |
-
|
| 599 |
-
|
| 600 |
-
|
| 601 |
-
```
|
| 602 |
-
|
| 603 |
-
|
| 604 |
-
|
| 605 |
-
|
| 606 |
-
|
| 607 |
-
|
| 608 |
-
|
| 609 |
-
```
|
| 610 |
-
|
| 611 |
-
|
| 612 |
-
|
| 613 |
-
|
| 614 |
-
|
| 615 |
-
|
| 616 |
-
|
| 617 |
-
|
| 618 |
-
- **
|
| 619 |
-
|
| 620 |
-
|
| 621 |
-
|
| 622 |
-
|
| 623 |
-
|
| 624 |
-
|
| 625 |
-
|
| 626 |
-
|
| 627 |
-
|
| 628 |
-
|
| 629 |
-
|
| 630 |
-
|
| 631 |
-
|
|
| 632 |
-
|
|
| 633 |
-
|
|
| 634 |
-
|
|
| 635 |
-
|
| 636 |
-
|
| 637 |
-
|
| 638 |
-
|
| 639 |
-
|
| 640 |
-
|
| 641 |
-
|
| 642 |
-
|
| 643 |
-
|
| 644 |
-
|
| 645 |
-
|
| 646 |
-
|
| 647 |
-
|
| 648 |
-
|
| 649 |
-
|
| 650 |
-
|
| 651 |
-
|
| 652 |
-
|
| 653 |
-
|
| 654 |
-
|
| 655 |
-
|
| 656 |
-
|
| 657 |
-
|
| 658 |
-
|
| 659 |
-
|
| 660 |
-
#
|
| 661 |
-
|
| 662 |
-
|
| 663 |
-
|
|
| 664 |
-
|
|
| 665 |
-
| **
|
| 666 |
-
|
| 667 |
-
|
| 668 |
-
|
| 669 |
-
|
| 670 |
-
|
| 671 |
-
##
|
| 672 |
-
|
| 673 |
-
|
| 674 |
-
|
| 675 |
-
|
| 676 |
-
|
| 677 |
-
|
| 678 |
-
|
| 679 |
-
|
| 680 |
-
|
| 681 |
-
|
| 682 |
-
|
| 683 |
-
|
| 684 |
-
|
| 685 |
-
|
| 686 |
-
|
| 687 |
-
|
| 688 |
-
β
|
| 689 |
-
|
| 690 |
-
β
|
| 691 |
-
β
|
| 692 |
-
β
|
| 693 |
-
β
|
| 694 |
-
β
|
| 695 |
-
β
|
| 696 |
-
β
|
| 697 |
-
β
|
| 698 |
-
β
|
| 699 |
-
β
|
| 700 |
-
β
|
| 701 |
-
β β
|
| 702 |
-
β
|
| 703 |
-
β
|
| 704 |
-
β
|
| 705 |
-
β
|
| 706 |
-
β
|
| 707 |
-
|
| 708 |
-
|
| 709 |
-
|
| 710 |
-
|
| 711 |
-
|
| 712 |
-
|
| 713 |
-
|
| 714 |
-
|
| 715 |
-
|
| 716 |
-
|
| 717 |
-
|
| 718 |
-
|
| 719 |
-
|
| 720 |
-
|
| 721 |
-
|
| 722 |
-
|
| 723 |
-
|
| 724 |
-
|
| 725 |
-
|
| 726 |
-
|
| 727 |
-
|
| 728 |
-
|
| 729 |
-
|
| 730 |
-
|
| 731 |
-
|
| 732 |
-
|
| 733 |
-
|
| 734 |
-
|
| 735 |
-
|
| 736 |
-
|
| 737 |
-
|
| 738 |
-
|
| 739 |
-
|
| 740 |
-
|
| 741 |
-
|
| 742 |
-
#
|
| 743 |
-
|
| 744 |
-
|
| 745 |
-
|
| 746 |
-
|
|
| 747 |
-
|
|
| 748 |
-
|
|
| 749 |
-
|
|
| 750 |
-
|
| 751 |
-
|
| 752 |
-
|
| 753 |
-
|
| 754 |
-
|
| 755 |
-
|
| 756 |
-
|
| 757 |
-
|
|
| 758 |
-
|
|
| 759 |
-
| **
|
| 760 |
-
|
| 761 |
-
|
| 762 |
-
|
| 763 |
-
|
| 764 |
-
|
| 765 |
-
|
| 766 |
-
|
| 767 |
-
|
|
| 768 |
-
|
|
| 769 |
-
|
|
| 770 |
-
|
| 771 |
-
|
| 772 |
-
|
| 773 |
-
|
| 774 |
-
|
| 775 |
-
##
|
| 776 |
-
|
| 777 |
-
|
| 778 |
-
|
| 779 |
-
|
| 780 |
-
|
| 781 |
-
|
| 782 |
-
|
| 783 |
-
|
| 784 |
-
|
| 785 |
-
|
| 786 |
-
|
| 787 |
-
|
| 788 |
-
|
| 789 |
-
|
| 790 |
-
|
| 791 |
-
|
| 792 |
-
|
| 793 |
-
|
|
| 794 |
-
|
|
| 795 |
-
|
|
| 796 |
-
|
| 797 |
-
|
| 798 |
-
|
| 799 |
-
|
| 800 |
-
|
| 801 |
-
|
| 802 |
-
- β
|
| 803 |
-
|
| 804 |
-
|
| 805 |
-
|
| 806 |
-
|
| 807 |
-
|
| 808 |
-
|
| 809 |
-
|
| 810 |
-
|
| 811 |
-
|
| 812 |
-
|
|
| 813 |
-
|
|
| 814 |
-
| **
|
| 815 |
-
| **
|
| 816 |
-
|
| 817 |
-
|
| 818 |
-
|
| 819 |
-
|
| 820 |
-
|
| 821 |
-
# =============================================================================
|
| 822 |
-
|
| 823 |
-
|
| 824 |
-
|
| 825 |
-
|
| 826 |
-
#
|
| 827 |
-
|
| 828 |
-
|
| 829 |
-
|
| 830 |
-
**
|
| 831 |
-
|
| 832 |
-
|
| 833 |
-
|
| 834 |
-
|
| 835 |
-
|
| 836 |
-
|
|
| 837 |
-
|
|
| 838 |
-
|
|
| 839 |
-
|
|
| 840 |
-
|
| 841 |
-
|
| 842 |
-
|
| 843 |
-
|
| 844 |
-
"""
|
| 845 |
-
|
| 846 |
-
|
| 847 |
-
#
|
| 848 |
-
|
| 849 |
-
|
| 850 |
-
|
| 851 |
-
|
| 852 |
-
|
| 853 |
-
|
| 854 |
-
|
| 855 |
-
|
| 856 |
-
|
| 857 |
-
|
| 858 |
-
|
| 859 |
-
##
|
| 860 |
-
|
| 861 |
-
|
| 862 |
-
|
| 863 |
-
|
| 864 |
-
|
| 865 |
-
|
| 866 |
-
|
| 867 |
-
|
| 868 |
-
|
| 869 |
-
|
| 870 |
-
|
| 871 |
-
|
| 872 |
-
|
| 873 |
-
|
| 874 |
-
|
| 875 |
-
|
| 876 |
-
|
| 877 |
-
|
| 878 |
-
|
| 879 |
-
|
| 880 |
-
- **
|
| 881 |
-
|
| 882 |
-
-
|
| 883 |
-
|
| 884 |
-
|
| 885 |
-
|
| 886 |
-
|
| 887 |
-
|
| 888 |
-
- **
|
| 889 |
-
- **
|
| 890 |
-
- **
|
| 891 |
-
|
| 892 |
-
-
|
| 893 |
-
|
| 894 |
-
|
| 895 |
-
|
| 896 |
-
|
| 897 |
-
|
| 898 |
-
- **
|
| 899 |
-
|
| 900 |
-
-
|
| 901 |
-
|
| 902 |
-
|
| 903 |
-
|
| 904 |
-
|
| 905 |
-
|
| 906 |
-
|
| 907 |
-
|
| 908 |
-
|
| 909 |
-
|
| 910 |
-
*
|
| 911 |
-
|
| 912 |
-
|
| 913 |
-
|
| 914 |
-
|
| 915 |
-
|
| 916 |
-
|
| 917 |
-
|
| 918 |
-
|
| 919 |
-
|
| 920 |
-
|
| 921 |
-
|
| 922 |
-
|
| 923 |
-
|
| 924 |
-
|
| 925 |
-
|
| 926 |
-
|
| 927 |
-
|
| 928 |
-
|
| 929 |
-
|
| 930 |
-
|
| 931 |
-
|
| 932 |
-
|
| 933 |
-
|
| 934 |
-
|
| 935 |
-
|
| 936 |
-
|
| 937 |
-
|
| 938 |
-
|
| 939 |
-
|
| 940 |
-
)
|
| 941 |
-
|
| 942 |
-
gr.
|
| 943 |
-
|
| 944 |
-
|
| 945 |
-
|
| 946 |
-
|
| 947 |
-
|
| 948 |
-
|
| 949 |
-
|
| 950 |
-
|
| 951 |
-
|
| 952 |
-
|
| 953 |
-
|
| 954 |
-
|
| 955 |
-
gr.
|
| 956 |
-
|
| 957 |
-
|
| 958 |
-
|
| 959 |
-
|
| 960 |
-
|
| 961 |
-
|
| 962 |
-
|
| 963 |
-
|
| 964 |
-
|
| 965 |
-
|
| 966 |
-
|
| 967 |
-
|
| 968 |
-
|
| 969 |
-
|
| 970 |
-
|
| 971 |
-
|
| 972 |
-
|
| 973 |
-
|
| 974 |
-
|
| 975 |
-
|
| 976 |
-
|
| 977 |
-
|
| 978 |
-
|
| 979 |
-
|
| 980 |
-
|
| 981 |
-
gr.
|
| 982 |
-
|
| 983 |
-
|
| 984 |
-
|
| 985 |
-
|
| 986 |
-
|
| 987 |
-
|
| 988 |
-
|
| 989 |
-
|
| 990 |
-
|
| 991 |
-
|
| 992 |
-
|
| 993 |
-
|
| 994 |
-
|
| 995 |
-
|
| 996 |
-
|
| 997 |
-
|
| 998 |
-
|
| 999 |
-
|
| 1000 |
-
|
| 1001 |
-
|
| 1002 |
-
|
| 1003 |
-
gr.
|
| 1004 |
-
|
| 1005 |
-
|
| 1006 |
-
|
| 1007 |
-
|
| 1008 |
-
|
| 1009 |
-
|
| 1010 |
-
|
| 1011 |
-
|
| 1012 |
-
|
| 1013 |
-
|
| 1014 |
-
|
| 1015 |
-
|
| 1016 |
-
|
| 1017 |
-
|
| 1018 |
-
|
| 1019 |
-
|
| 1020 |
-
|
| 1021 |
-
|
| 1022 |
-
|
| 1023 |
-
|
| 1024 |
-
|
| 1025 |
-
|
| 1026 |
-
|
| 1027 |
-
|
| 1028 |
-
|
| 1029 |
-
|
| 1030 |
-
|
| 1031 |
-
|
| 1032 |
-
|
| 1033 |
-
|
| 1034 |
-
|
| 1035 |
-
|
| 1036 |
-
|
| 1037 |
-
if __name__ == "__main__":
|
| 1038 |
-
demo.launch()
|
|
|
|
| 1 |
+
"""
|
| 2 |
+
TopoGrammar - Grammar-Aware 3D Genome Engine Demo
|
| 3 |
+
==================================================
|
| 4 |
+
|
| 5 |
+
Hugging Face Spaces Demo for TopoGrammar v2.1.0
|
| 6 |
+
The Industry's First Grammar-Aware Engine for Balanced Structural Variants
|
| 7 |
+
|
| 8 |
+
Copyright (c) 2026 Bryan Daugherty, Gregory Ward & Shawn Ryan. All Rights Reserved.
|
| 9 |
+
|
| 10 |
+
This demo showcases TopoGrammar's capabilities without exposing proprietary algorithms.
|
| 11 |
+
All results are pre-computed demonstrations for educational purposes.
|
| 12 |
+
"""
|
| 13 |
+
|
| 14 |
+
import gradio as gr
|
| 15 |
+
import hashlib
|
| 16 |
+
import random
|
| 17 |
+
import time
|
| 18 |
+
import httpx
|
| 19 |
+
import json
|
| 20 |
+
import os
|
| 21 |
+
from datetime import datetime
|
| 22 |
+
from typing import Optional, Dict, List, Tuple
|
| 23 |
+
|
| 24 |
+
# =============================================================================
|
| 25 |
+
# BSV Blockchain Configuration
|
| 26 |
+
# =============================================================================
|
| 27 |
+
|
| 28 |
+
BSV_API_URL = "https://simplebsv.codenlighten.org"
|
| 29 |
+
BSV_API_KEY = os.getenv("BSV_API_KEY") # Set via HF Secrets
|
| 30 |
+
|
| 31 |
+
|
| 32 |
+
def publish_to_bsv(data: Dict) -> Optional[str]:
|
| 33 |
+
"""
|
| 34 |
+
Publish attestation data to BSV blockchain via SimpleBSV API.
|
| 35 |
+
|
| 36 |
+
Args:
|
| 37 |
+
data: Dictionary containing attestation data (no trade secrets)
|
| 38 |
+
|
| 39 |
+
Returns:
|
| 40 |
+
Transaction ID if successful, None otherwise
|
| 41 |
+
"""
|
| 42 |
+
# Guard clause: fail gracefully if no key configured
|
| 43 |
+
if not BSV_API_KEY:
|
| 44 |
+
print("BSV_API_KEY not configured - running in offline mode")
|
| 45 |
+
return None
|
| 46 |
+
|
| 47 |
+
try:
|
| 48 |
+
headers = {
|
| 49 |
+
"Content-Type": "application/json",
|
| 50 |
+
"x-api-key": BSV_API_KEY
|
| 51 |
+
}
|
| 52 |
+
|
| 53 |
+
# Use ?wait=true for synchronous response with txid
|
| 54 |
+
response = httpx.post(
|
| 55 |
+
f"{BSV_API_URL}/publish/json?wait=true",
|
| 56 |
+
headers=headers,
|
| 57 |
+
json={"json": data},
|
| 58 |
+
timeout=30.0
|
| 59 |
+
)
|
| 60 |
+
|
| 61 |
+
if response.status_code == 200:
|
| 62 |
+
result = response.json()
|
| 63 |
+
return result.get("txid")
|
| 64 |
+
else:
|
| 65 |
+
print(f"BSV API error: {response.status_code} - {response.text}")
|
| 66 |
+
return None
|
| 67 |
+
|
| 68 |
+
except Exception as e:
|
| 69 |
+
print(f"BSV publish error: {e}")
|
| 70 |
+
return None
|
| 71 |
+
|
| 72 |
+
# =============================================================================
|
| 73 |
+
# Demo Configuration - Pre-computed results (no trade secrets exposed)
|
| 74 |
+
# =============================================================================
|
| 75 |
+
|
| 76 |
+
# Demo VUS Examples with pre-computed classifications
|
| 77 |
+
VUS_EXAMPLES = {
|
| 78 |
+
"brca1_boundary": {
|
| 79 |
+
"name": "BRCA1 TAD Boundary Disruption",
|
| 80 |
+
"variant_id": "chr17:43,044,295 G>A",
|
| 81 |
+
"gene": "BRCA1",
|
| 82 |
+
"initial_class": "VUS",
|
| 83 |
+
"final_class": "Pathogenic",
|
| 84 |
+
"confidence": 0.93,
|
| 85 |
+
"mechanism": "TAD Boundary Disruption",
|
| 86 |
+
"evidence_codes": ["PS3_insulation", "PM1_boundary", "PS3_ctcf"],
|
| 87 |
+
"insulation_change": -0.52,
|
| 88 |
+
"description": "This intronic variant disrupts a CTCF binding site at a critical TAD boundary, causing enhancer-promoter miscommunication affecting BRCA1 expression.",
|
| 89 |
+
},
|
| 90 |
+
"myc_enhancer_hijack": {
|
| 91 |
+
"name": "MYC Enhancer Hijacking",
|
| 92 |
+
"variant_id": "chr8:128,750,000 inv(500kb)",
|
| 93 |
+
"gene": "MYC",
|
| 94 |
+
"initial_class": "VUS",
|
| 95 |
+
"final_class": "Pathogenic",
|
| 96 |
+
"confidence": 0.89,
|
| 97 |
+
"mechanism": "Enhancer Hijacking",
|
| 98 |
+
"evidence_codes": ["PS3_neoloop", "PS2_oncogene", "PM1_boundary"],
|
| 99 |
+
"insulation_change": -0.68,
|
| 100 |
+
"description": "Balanced inversion creates a neo-loop connecting MYC to a hijacked super-enhancer, causing oncogene activation without copy number change.",
|
| 101 |
+
},
|
| 102 |
+
"sonic_hedgehog": {
|
| 103 |
+
"name": "SHH Limb Enhancer",
|
| 104 |
+
"variant_id": "chr7:156,584,000 del(50kb)",
|
| 105 |
+
"gene": "SHH",
|
| 106 |
+
"initial_class": "VUS",
|
| 107 |
+
"final_class": "Likely Pathogenic",
|
| 108 |
+
"confidence": 0.85,
|
| 109 |
+
"mechanism": "Enhancer Deletion",
|
| 110 |
+
"evidence_codes": ["PM1_regulatory", "PP3_conservation", "PS3_insulation"],
|
| 111 |
+
"insulation_change": -0.41,
|
| 112 |
+
"description": "Deletion removes the ZRS limb enhancer from SHH regulatory domain, disrupting developmental gene expression.",
|
| 113 |
+
},
|
| 114 |
+
"benign_intronic": {
|
| 115 |
+
"name": "Benign Intronic SNP",
|
| 116 |
+
"variant_id": "chr12:25,398,284 C>T",
|
| 117 |
+
"gene": "KRAS",
|
| 118 |
+
"initial_class": "VUS",
|
| 119 |
+
"final_class": "Benign",
|
| 120 |
+
"confidence": 0.91,
|
| 121 |
+
"mechanism": "No 3D Impact",
|
| 122 |
+
"evidence_codes": ["BS1_frequency", "BP4_no_disruption"],
|
| 123 |
+
"insulation_change": 0.02,
|
| 124 |
+
"description": "Deep intronic variant with no effect on TAD structure, CTCF binding, or regulatory grammar. Common in population databases.",
|
| 125 |
+
},
|
| 126 |
+
"tp53_scramble": {
|
| 127 |
+
"name": "TP53 Grammar Scrambling",
|
| 128 |
+
"variant_id": "chr17:7,670,000 inv(120kb)",
|
| 129 |
+
"gene": "TP53",
|
| 130 |
+
"initial_class": "VUS",
|
| 131 |
+
"final_class": "Pathogenic",
|
| 132 |
+
"confidence": 0.96,
|
| 133 |
+
"mechanism": "Regulatory Grammar Scrambling",
|
| 134 |
+
"evidence_codes": ["PS3_semantic", "PS3_insulation", "PM1_boundary", "PP3_conservation"],
|
| 135 |
+
"insulation_change": -0.71,
|
| 136 |
+
"description": "Balanced inversion scrambles the regulatory grammar of TP53, inverting enhancer-promoter orientation and disrupting tumor suppressor expression.",
|
| 137 |
+
},
|
| 138 |
+
}
|
| 139 |
+
|
| 140 |
+
# Demo TAD examples
|
| 141 |
+
TAD_EXAMPLES = {
|
| 142 |
+
"chr21_dscr": {
|
| 143 |
+
"name": "Chromosome 21 - Down Syndrome Critical Region",
|
| 144 |
+
"region": "chr21:35,000,000-40,000,000",
|
| 145 |
+
"n_tads": 4,
|
| 146 |
+
"n_boundaries": 5,
|
| 147 |
+
"ctcf_sites": 12,
|
| 148 |
+
"genes": ["DSCR1", "DSCR3", "DSCR4", "RUNX1"],
|
| 149 |
+
"boundary_strength": [0.85, 0.92, 0.78, 0.88, 0.81],
|
| 150 |
+
},
|
| 151 |
+
"chr7_egfr": {
|
| 152 |
+
"name": "Chromosome 7 - EGFR Locus",
|
| 153 |
+
"region": "chr7:55,000,000-56,500,000",
|
| 154 |
+
"n_tads": 3,
|
| 155 |
+
"n_boundaries": 4,
|
| 156 |
+
"ctcf_sites": 8,
|
| 157 |
+
"genes": ["EGFR", "LANCL2", "VOPP1"],
|
| 158 |
+
"boundary_strength": [0.91, 0.87, 0.94, 0.82],
|
| 159 |
+
},
|
| 160 |
+
"chr8_myc": {
|
| 161 |
+
"name": "Chromosome 8 - MYC Oncogene",
|
| 162 |
+
"region": "chr8:127,500,000-129,500,000",
|
| 163 |
+
"n_tads": 2,
|
| 164 |
+
"n_boundaries": 3,
|
| 165 |
+
"ctcf_sites": 6,
|
| 166 |
+
"genes": ["MYC", "PVT1"],
|
| 167 |
+
"boundary_strength": [0.96, 0.89, 0.93],
|
| 168 |
+
},
|
| 169 |
+
}
|
| 170 |
+
|
| 171 |
+
# Demo Neo-Loop examples
|
| 172 |
+
NEOLOOP_EXAMPLES = {
|
| 173 |
+
"burkitt_myc": {
|
| 174 |
+
"name": "Burkitt Lymphoma - MYC Translocation",
|
| 175 |
+
"sv_type": "Translocation t(8;14)",
|
| 176 |
+
"oncogene": "MYC",
|
| 177 |
+
"hijacked_enhancer": "IGH Super-Enhancer",
|
| 178 |
+
"loop_strength": 0.92,
|
| 179 |
+
"clinical_priority": "Critical",
|
| 180 |
+
"cancer_type": "Burkitt Lymphoma",
|
| 181 |
+
"description": "Classic t(8;14) translocation juxtaposes MYC with immunoglobulin heavy chain enhancers, creating pathogenic neo-loop.",
|
| 182 |
+
},
|
| 183 |
+
"ewing_ewsr1": {
|
| 184 |
+
"name": "Ewing Sarcoma - EWSR1-FLI1",
|
| 185 |
+
"sv_type": "Translocation t(11;22)",
|
| 186 |
+
"oncogene": "EWSR1-FLI1 fusion",
|
| 187 |
+
"hijacked_enhancer": "GGAA microsatellite enhancers",
|
| 188 |
+
"loop_strength": 0.88,
|
| 189 |
+
"clinical_priority": "Critical",
|
| 190 |
+
"cancer_type": "Ewing Sarcoma",
|
| 191 |
+
"description": "Fusion protein creates neo-loops at GGAA microsatellites, aberrantly activating developmental genes.",
|
| 192 |
+
},
|
| 193 |
+
"aml_runx1": {
|
| 194 |
+
"name": "AML - RUNX1 Disruption",
|
| 195 |
+
"sv_type": "Inversion inv(16)",
|
| 196 |
+
"oncogene": "CBFB-MYH11 fusion",
|
| 197 |
+
"hijacked_enhancer": "Myeloid enhancer cluster",
|
| 198 |
+
"loop_strength": 0.85,
|
| 199 |
+
"clinical_priority": "High",
|
| 200 |
+
"cancer_type": "Acute Myeloid Leukemia",
|
| 201 |
+
"description": "Pericentric inversion disrupts normal RUNX1 regulation, creating aberrant chromatin loops.",
|
| 202 |
+
},
|
| 203 |
+
}
|
| 204 |
+
|
| 205 |
+
# Benchmark comparisons
|
| 206 |
+
BENCHMARK_DATA = {
|
| 207 |
+
"tad_detection": {
|
| 208 |
+
"TopoGrammar (CTCF-gated)": {"accuracy": 91, "f1": 0.91, "subtad": True},
|
| 209 |
+
"HiCCUPS": {"accuracy": 80, "f1": 0.76, "subtad": False},
|
| 210 |
+
"Arrowhead": {"accuracy": 78, "f1": 0.74, "subtad": False},
|
| 211 |
+
"TopDom": {"accuracy": 75, "f1": 0.71, "subtad": False},
|
| 212 |
+
},
|
| 213 |
+
"vus_resolution": {
|
| 214 |
+
"reclassification_rate": 68,
|
| 215 |
+
"pathogenic_accuracy": 93,
|
| 216 |
+
"mean_confidence": 87,
|
| 217 |
+
},
|
| 218 |
+
"insulation_density": {
|
| 219 |
+
"major_tads": 9.11,
|
| 220 |
+
"all_boundaries": 15.57,
|
| 221 |
+
"improvement": 70.9,
|
| 222 |
+
},
|
| 223 |
+
}
|
| 224 |
+
|
| 225 |
+
|
| 226 |
+
# =============================================================================
|
| 227 |
+
# Visualization Functions
|
| 228 |
+
# =============================================================================
|
| 229 |
+
|
| 230 |
+
def create_contact_map_ascii(region: str, n_tads: int) -> str:
|
| 231 |
+
"""Create ASCII representation of a Hi-C contact map with TADs."""
|
| 232 |
+
size = 40
|
| 233 |
+
map_lines = []
|
| 234 |
+
|
| 235 |
+
# Create diagonal pattern with TAD blocks
|
| 236 |
+
tad_size = size // n_tads
|
| 237 |
+
|
| 238 |
+
for i in range(size):
|
| 239 |
+
row = ""
|
| 240 |
+
for j in range(size):
|
| 241 |
+
if abs(i - j) <= 2:
|
| 242 |
+
row += "ββ" # Diagonal
|
| 243 |
+
elif (i // tad_size) == (j // tad_size):
|
| 244 |
+
# Within same TAD
|
| 245 |
+
distance = abs(i - j)
|
| 246 |
+
if distance < tad_size // 2:
|
| 247 |
+
row += "ββ"
|
| 248 |
+
elif distance < tad_size:
|
| 249 |
+
row += "ββ"
|
| 250 |
+
else:
|
| 251 |
+
row += " "
|
| 252 |
+
else:
|
| 253 |
+
row += " "
|
| 254 |
+
map_lines.append(row)
|
| 255 |
+
|
| 256 |
+
return "\n".join(map_lines)
|
| 257 |
+
|
| 258 |
+
|
| 259 |
+
def create_insulation_profile(boundary_strengths: List[float]) -> str:
|
| 260 |
+
"""Create ASCII insulation score profile."""
|
| 261 |
+
lines = []
|
| 262 |
+
lines.append("Insulation Score Profile:")
|
| 263 |
+
lines.append("=" * 60)
|
| 264 |
+
|
| 265 |
+
for i, strength in enumerate(boundary_strengths):
|
| 266 |
+
bar_len = int(strength * 40)
|
| 267 |
+
bar = "β" * bar_len + "β" * (40 - bar_len)
|
| 268 |
+
lines.append(f"Boundary {i+1}: [{bar}] {strength:.2f}")
|
| 269 |
+
|
| 270 |
+
lines.append("=" * 60)
|
| 271 |
+
return "\n".join(lines)
|
| 272 |
+
|
| 273 |
+
|
| 274 |
+
def create_grammar_diagram(mechanism: str) -> str:
|
| 275 |
+
"""Create regulatory grammar visualization."""
|
| 276 |
+
if mechanism == "Regulatory Grammar Scrambling":
|
| 277 |
+
return """
|
| 278 |
+
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
|
| 279 |
+
β REGULATORY GRAMMAR ANALYSIS β
|
| 280 |
+
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ€
|
| 281 |
+
β β
|
| 282 |
+
β REFERENCE GRAMMAR: β
|
| 283 |
+
β ββββββββ ββββββββββββ ββββββββββββ ββββββββ β
|
| 284 |
+
β βCTCF+ β β β ENHANCER β β β PROMOTER β β β GENE β β
|
| 285 |
+
β ββββββββ ββββββββββββ ββββββββββββ ββββββββ β
|
| 286 |
+
β "The enhancer activates the gene" β
|
| 287 |
+
β β
|
| 288 |
+
β VARIANT GRAMMAR (SCRAMBLED): β
|
| 289 |
+
β ββββββββ ββββββββββββ ββββββββββββ ββββββββ β
|
| 290 |
+
β β GENE β β β PROMOTER β β β ENHANCER β β βCTCF- β β
|
| 291 |
+
β ββββββββ ββββββββββββ ββββββββββββ ββββββββ β
|
| 292 |
+
β "Gene the activates enhancer the" β SCRAMBLED β
|
| 293 |
+
β β
|
| 294 |
+
β SEMANTIC BREAK SCORE: 0.85 (CRITICAL) β
|
| 295 |
+
β β’ Token Disruption: 30% weight β
|
| 296 |
+
β β’ Order Inversion: 40% weight β
|
| 297 |
+
β β’ Orientation Flip: 30% weight β
|
| 298 |
+
β β
|
| 299 |
+
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
|
| 300 |
+
"""
|
| 301 |
+
elif mechanism == "Enhancer Hijacking":
|
| 302 |
+
return """
|
| 303 |
+
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
|
| 304 |
+
β ENHANCER HIJACKING ANALYSIS β
|
| 305 |
+
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ€
|
| 306 |
+
β β
|
| 307 |
+
β NORMAL TOPOLOGY: β
|
| 308 |
+
β βββββββββββββββββββ βββββββββββββββββββ β
|
| 309 |
+
β β TAD A β β TAD B β β
|
| 310 |
+
β β [Enhancer]ββββββββXββββββββββ[Oncogene] β β
|
| 311 |
+
β β β β β β β
|
| 312 |
+
β β [Target Gene] β β β οΏ½οΏ½
|
| 313 |
+
β βββββββββββββββββββ βββββββββββββββββββ β
|
| 314 |
+
β BOUNDARY BLOCKS CONTACT β
|
| 315 |
+
β β
|
| 316 |
+
β AFTER STRUCTURAL VARIANT: β
|
| 317 |
+
β ββββββββββββββββββββββββββββββββββββββββββββ β
|
| 318 |
+
β β FUSED TAD β β
|
| 319 |
+
β β [Enhancer]βββββββββββββββββββ[Oncogene] β β
|
| 320 |
+
β β β NEO-LOOP FORMED β β β
|
| 321 |
+
β β [Target Gene] β ONCOGENE ACTIVATED β β β
|
| 322 |
+
β ββββββββββββββββββββββββββββββββββββββββββββ β
|
| 323 |
+
β β
|
| 324 |
+
β LOOP STRENGTH: 0.89 | PRIORITY: CRITICAL β
|
| 325 |
+
β β
|
| 326 |
+
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
|
| 327 |
+
"""
|
| 328 |
+
elif mechanism == "TAD Boundary Disruption":
|
| 329 |
+
return """
|
| 330 |
+
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
|
| 331 |
+
β TAD BOUNDARY DISRUPTION ANALYSIS β
|
| 332 |
+
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ€
|
| 333 |
+
β β
|
| 334 |
+
β NORMAL INSULATION: β
|
| 335 |
+
β ββββββββββββββββ β ββββββββββββββββ β
|
| 336 |
+
β TAD A β TAD B β
|
| 337 |
+
β CTCFβCTCF β
|
| 338 |
+
β β²β²β²β²β²ββ²β²β²β²β² β
|
| 339 |
+
β Strong Boundary β
|
| 340 |
+
β β
|
| 341 |
+
β AFTER VARIANT (CTCF SITE DISRUPTED): β
|
| 342 |
+
β ββββββββββββββββ ββββββββββββββββ β
|
| 343 |
+
β TAD A βββββββ TAD B β
|
| 344 |
+
β βββββ β
|
| 345 |
+
β Insulation Leak β
|
| 346 |
+
β β
|
| 347 |
+
β INSULATION CHANGE: -52% β
|
| 348 |
+
β BOUNDARY LOSS: MAJOR β
|
| 349 |
+
β β
|
| 350 |
+
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
|
| 351 |
+
"""
|
| 352 |
+
else:
|
| 353 |
+
return """
|
| 354 |
+
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
|
| 355 |
+
β 3D GENOME ANALYSIS β
|
| 356 |
+
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ€
|
| 357 |
+
β β
|
| 358 |
+
β No significant 3D structural impact detected. β
|
| 359 |
+
β β
|
| 360 |
+
β β’ TAD boundaries: INTACT β
|
| 361 |
+
β β’ Insulation scores: NORMAL β
|
| 362 |
+
β β’ Regulatory grammar: PRESERVED β
|
| 363 |
+
β β’ CTCF binding: UNAFFECTED β
|
| 364 |
+
β β
|
| 365 |
+
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
|
| 366 |
+
"""
|
| 367 |
+
|
| 368 |
+
|
| 369 |
+
def create_confidence_bars(evidence_codes: List[str], confidence: float) -> str:
|
| 370 |
+
"""Create evidence code visualization."""
|
| 371 |
+
lines = []
|
| 372 |
+
lines.append("\n### Evidence Summary\n")
|
| 373 |
+
|
| 374 |
+
for code in evidence_codes:
|
| 375 |
+
# Determine strength from code prefix
|
| 376 |
+
if code.startswith("PS"):
|
| 377 |
+
strength = "Strong"
|
| 378 |
+
bar = "ββββββββββββββββββββ"
|
| 379 |
+
color = "π’"
|
| 380 |
+
elif code.startswith("PM"):
|
| 381 |
+
strength = "Moderate"
|
| 382 |
+
bar = "ββββββββββββββββββββ"
|
| 383 |
+
color = "π‘"
|
| 384 |
+
elif code.startswith("PP"):
|
| 385 |
+
strength = "Supporting"
|
| 386 |
+
bar = "ββββββββββββββββββββ"
|
| 387 |
+
color = "π "
|
| 388 |
+
elif code.startswith("BS") or code.startswith("BP"):
|
| 389 |
+
strength = "Benign"
|
| 390 |
+
bar = "ββββββββββββββββββββ"
|
| 391 |
+
color = "π΅"
|
| 392 |
+
else:
|
| 393 |
+
strength = "Unknown"
|
| 394 |
+
bar = "ββββββββββββββββββββ"
|
| 395 |
+
color = "βͺ"
|
| 396 |
+
|
| 397 |
+
lines.append(f"{color} **{code}** ({strength}): `{bar}`")
|
| 398 |
+
|
| 399 |
+
lines.append(f"\n**Overall Confidence**: {confidence:.0%}")
|
| 400 |
+
|
| 401 |
+
return "\n".join(lines)
|
| 402 |
+
|
| 403 |
+
|
| 404 |
+
def generate_bsv_attestation(variant_id: str, classification: str, confidence: float) -> str:
|
| 405 |
+
"""Generate and publish BSV blockchain attestation."""
|
| 406 |
+
timestamp = datetime.now().strftime("%Y-%m-%d %H:%M:%S UTC")
|
| 407 |
+
|
| 408 |
+
# Create attestation data (no trade secrets - only results summary)
|
| 409 |
+
attestation_data = {
|
| 410 |
+
"platform": "TopoGrammar",
|
| 411 |
+
"version": "v2.1.0",
|
| 412 |
+
"timestamp": timestamp,
|
| 413 |
+
"analysis_type": "VUS_Resolution",
|
| 414 |
+
"variant_id": variant_id,
|
| 415 |
+
"classification": classification,
|
| 416 |
+
"confidence": round(confidence, 2),
|
| 417 |
+
"attestation_type": "demo"
|
| 418 |
+
}
|
| 419 |
+
|
| 420 |
+
# Create hash of the attestation data
|
| 421 |
+
data_str = json.dumps(attestation_data, sort_keys=True)
|
| 422 |
+
query_hash = hashlib.sha256(data_str.encode()).hexdigest()[:16]
|
| 423 |
+
full_hash = hashlib.sha256(data_str.encode()).hexdigest()
|
| 424 |
+
|
| 425 |
+
# Publish to BSV blockchain
|
| 426 |
+
txid = publish_to_bsv(attestation_data)
|
| 427 |
+
|
| 428 |
+
if txid:
|
| 429 |
+
# Real blockchain attestation
|
| 430 |
+
whatsonchain_url = f"https://whatsonchain.com/tx/{txid}"
|
| 431 |
+
status_line = f"Status: β RECORDED ON BSV MAINNET"
|
| 432 |
+
txid_display = txid[:20] + "..." if len(txid) > 20 else txid
|
| 433 |
+
verify_section = f"""β Transaction ID: {txid_display}
|
| 434 |
+
β β
|
| 435 |
+
β π Verify on WhatsOnChain: β
|
| 436 |
+
β {whatsonchain_url[:54]}"""
|
| 437 |
+
else:
|
| 438 |
+
# Fallback if API fails
|
| 439 |
+
status_line = "Status: β OFFLINE MODE (BSV API unavailable)"
|
| 440 |
+
verify_section = f"""β Data Hash: {full_hash[:32]}...
|
| 441 |
+
β β
|
| 442 |
+
β βΉ Blockchain recording temporarily unavailable. β
|
| 443 |
+
β Result hash preserved for later attestation."""
|
| 444 |
+
|
| 445 |
+
return f"""
|
| 446 |
+
```
|
| 447 |
+
ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
|
| 448 |
+
β TOPOGRAMMAR BSV ATTESTATION CERTIFICATE β
|
| 449 |
+
β βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ£
|
| 450 |
+
β β
|
| 451 |
+
β Query Hash: {query_hash} β
|
| 452 |
+
β Timestamp: {timestamp} β
|
| 453 |
+
β Model Version: TopoGrammar v2.1.0 β
|
| 454 |
+
β β
|
| 455 |
+
β βββββββββββββββββββββββββββββββββββββββββββββββββββββββββ β
|
| 456 |
+
β β
|
| 457 |
+
β Variant: {variant_id}
|
| 458 |
+
β Classification: {classification}
|
| 459 |
+
β Confidence: {confidence:.1%}
|
| 460 |
+
β β
|
| 461 |
+
β βββββββββββββββββββββββββββββββββββββββββββββββββββββββββ β
|
| 462 |
+
β β
|
| 463 |
+
β {status_line}
|
| 464 |
+
β Network: BSV Mainnet β
|
| 465 |
+
β β
|
| 466 |
+
{verify_section}
|
| 467 |
+
β β
|
| 468 |
+
β This attestation is immutably recorded on BSV blockchain. β
|
| 469 |
+
β No proprietary algorithms or trade secrets are published. β
|
| 470 |
+
β β
|
| 471 |
+
ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
|
| 472 |
+
```
|
| 473 |
+
"""
|
| 474 |
+
|
| 475 |
+
|
| 476 |
+
def create_share_links(variant_id: str, classification: str) -> str:
|
| 477 |
+
"""Create social sharing buttons."""
|
| 478 |
+
import urllib.parse
|
| 479 |
+
|
| 480 |
+
text = f"𧬠TopoGrammar reclassified {variant_id} as {classification}! Grammar-aware 3D genome analysis for precision medicine. #Genomics #AI #PrecisionMedicine"
|
| 481 |
+
|
| 482 |
+
twitter_url = f"https://twitter.com/intent/tweet?text={urllib.parse.quote(text)}&url=https://huggingface.co/spaces/GotThatData/TopoGrammar"
|
| 483 |
+
linkedin_url = f"https://www.linkedin.com/sharing/share-offsite/?url=https://huggingface.co/spaces/GotThatData/TopoGrammar"
|
| 484 |
+
|
| 485 |
+
return f"""
|
| 486 |
+
<div style="display: flex; gap: 10px; margin-top: 20px;">
|
| 487 |
+
<a href="{twitter_url}" target="_blank" style="background: #1DA1F2; color: white; padding: 10px 20px; border-radius: 5px; text-decoration: none;">
|
| 488 |
+
π¦ Share on X
|
| 489 |
+
</a>
|
| 490 |
+
<a href="{linkedin_url}" target="_blank" style="background: #0077B5; color: white; padding: 10px 20px; border-radius: 5px; text-decoration: none;">
|
| 491 |
+
πΌ Share on LinkedIn
|
| 492 |
+
</a>
|
| 493 |
+
</div>
|
| 494 |
+
"""
|
| 495 |
+
|
| 496 |
+
|
| 497 |
+
# =============================================================================
|
| 498 |
+
# Main Demo Functions
|
| 499 |
+
# =============================================================================
|
| 500 |
+
|
| 501 |
+
def run_vus_analysis(example_key: str) -> str:
|
| 502 |
+
"""Run VUS resolution demo."""
|
| 503 |
+
if example_key not in VUS_EXAMPLES:
|
| 504 |
+
return "β Example not found. Please select a valid example."
|
| 505 |
+
|
| 506 |
+
# Simulate processing delay
|
| 507 |
+
time.sleep(1.5)
|
| 508 |
+
|
| 509 |
+
example = VUS_EXAMPLES[example_key]
|
| 510 |
+
|
| 511 |
+
# Build result markdown
|
| 512 |
+
result = f"""
|
| 513 |
+
# 𧬠VUS Resolution Analysis
|
| 514 |
+
|
| 515 |
+
## Variant Information
|
| 516 |
+
| Field | Value |
|
| 517 |
+
|-------|-------|
|
| 518 |
+
| **Variant ID** | `{example['variant_id']}` |
|
| 519 |
+
| **Gene** | {example['gene']} |
|
| 520 |
+
| **Initial Classification** | {example['initial_class']} |
|
| 521 |
+
|
| 522 |
+
---
|
| 523 |
+
|
| 524 |
+
## TopoGrammar Analysis Result
|
| 525 |
+
|
| 526 |
+
### Classification Update
|
| 527 |
+
| Before | β | After |
|
| 528 |
+
|--------|---|-------|
|
| 529 |
+
| **{example['initial_class']}** | π | **{example['final_class']}** |
|
| 530 |
+
|
| 531 |
+
### Confidence Score
|
| 532 |
+
{"β" * int(example['confidence'] * 20)}{"β" * (20 - int(example['confidence'] * 20))} **{example['confidence']:.0%}**
|
| 533 |
+
|
| 534 |
+
### Primary Mechanism
|
| 535 |
+
**{example['mechanism']}**
|
| 536 |
+
|
| 537 |
+
### 3D Structural Impact
|
| 538 |
+
- **Insulation Change**: {example['insulation_change']:+.0%}
|
| 539 |
+
|
| 540 |
+
---
|
| 541 |
+
|
| 542 |
+
## Mechanism Visualization
|
| 543 |
+
|
| 544 |
+
{create_grammar_diagram(example['mechanism'])}
|
| 545 |
+
|
| 546 |
+
---
|
| 547 |
+
|
| 548 |
+
{create_confidence_bars(example['evidence_codes'], example['confidence'])}
|
| 549 |
+
|
| 550 |
+
---
|
| 551 |
+
|
| 552 |
+
## Clinical Interpretation
|
| 553 |
+
|
| 554 |
+
{example['description']}
|
| 555 |
+
|
| 556 |
+
---
|
| 557 |
+
|
| 558 |
+
## BSV Verification
|
| 559 |
+
|
| 560 |
+
{generate_bsv_attestation(example['variant_id'], example['final_class'], example['confidence'])}
|
| 561 |
+
|
| 562 |
+
---
|
| 563 |
+
|
| 564 |
+
{create_share_links(example['variant_id'], example['final_class'])}
|
| 565 |
+
"""
|
| 566 |
+
|
| 567 |
+
return result
|
| 568 |
+
|
| 569 |
+
|
| 570 |
+
def run_tad_analysis(example_key: str) -> str:
|
| 571 |
+
"""Run TAD detection demo."""
|
| 572 |
+
if example_key not in TAD_EXAMPLES:
|
| 573 |
+
return "β Example not found. Please select a valid example."
|
| 574 |
+
|
| 575 |
+
time.sleep(1.0)
|
| 576 |
+
|
| 577 |
+
example = TAD_EXAMPLES[example_key]
|
| 578 |
+
|
| 579 |
+
result = f"""
|
| 580 |
+
# π¬ TAD Detection Analysis
|
| 581 |
+
|
| 582 |
+
## Region Information
|
| 583 |
+
| Field | Value |
|
| 584 |
+
|-------|-------|
|
| 585 |
+
| **Region** | `{example['region']}` |
|
| 586 |
+
| **TADs Detected** | {example['n_tads']} |
|
| 587 |
+
| **Boundaries** | {example['n_boundaries']} |
|
| 588 |
+
| **CTCF Sites** | {example['ctcf_sites']} |
|
| 589 |
+
|
| 590 |
+
---
|
| 591 |
+
|
| 592 |
+
## Genes in Region
|
| 593 |
+
{', '.join([f"**{g}**" for g in example['genes']])}
|
| 594 |
+
|
| 595 |
+
---
|
| 596 |
+
|
| 597 |
+
## Contact Map Visualization
|
| 598 |
+
|
| 599 |
+
```
|
| 600 |
+
{create_contact_map_ascii(example['region'], example['n_tads'])}
|
| 601 |
+
```
|
| 602 |
+
|
| 603 |
+
---
|
| 604 |
+
|
| 605 |
+
## Boundary Strength Profile
|
| 606 |
+
|
| 607 |
+
```
|
| 608 |
+
{create_insulation_profile(example['boundary_strength'])}
|
| 609 |
+
```
|
| 610 |
+
|
| 611 |
+
---
|
| 612 |
+
|
| 613 |
+
## Detection Method
|
| 614 |
+
|
| 615 |
+
TopoGrammar uses **CTCF-gated boundary detection** which achieves:
|
| 616 |
+
- **91% TAD accuracy** (vs 80% for HiCCUPS)
|
| 617 |
+
- **0.91 F1 score** for boundary detection
|
| 618 |
+
- **Sub-TAD detection** capability
|
| 619 |
+
|
| 620 |
+
The CTCF-gating mechanism ensures boundaries are only called where:
|
| 621 |
+
1. Insulation score shows local minimum
|
| 622 |
+
2. CTCF binding evidence is present
|
| 623 |
+
3. Gradient analysis confirms boundary
|
| 624 |
+
|
| 625 |
+
---
|
| 626 |
+
|
| 627 |
+
## Benchmark Comparison
|
| 628 |
+
|
| 629 |
+
| Method | TAD Accuracy | Boundary F1 | Sub-TAD |
|
| 630 |
+
|--------|-------------|-------------|---------|
|
| 631 |
+
| **TopoGrammar** | **91%** | **0.91** | β |
|
| 632 |
+
| HiCCUPS | 80% | 0.76 | β |
|
| 633 |
+
| Arrowhead | 78% | 0.74 | β |
|
| 634 |
+
| TopDom | 75% | 0.71 | β |
|
| 635 |
+
"""
|
| 636 |
+
|
| 637 |
+
return result
|
| 638 |
+
|
| 639 |
+
|
| 640 |
+
def run_neoloop_analysis(example_key: str) -> str:
|
| 641 |
+
"""Run neo-loop detection demo."""
|
| 642 |
+
if example_key not in NEOLOOP_EXAMPLES:
|
| 643 |
+
return "β Example not found. Please select a valid example."
|
| 644 |
+
|
| 645 |
+
time.sleep(1.2)
|
| 646 |
+
|
| 647 |
+
example = NEOLOOP_EXAMPLES[example_key]
|
| 648 |
+
|
| 649 |
+
# Priority styling
|
| 650 |
+
if example['clinical_priority'] == "Critical":
|
| 651 |
+
priority_emoji = "π΄"
|
| 652 |
+
priority_style = "color: red; font-weight: bold;"
|
| 653 |
+
else:
|
| 654 |
+
priority_emoji = "π‘"
|
| 655 |
+
priority_style = "color: orange; font-weight: bold;"
|
| 656 |
+
|
| 657 |
+
result = f"""
|
| 658 |
+
# οΏ½οΏ½οΏ½ Neo-Loop Detection Analysis
|
| 659 |
+
|
| 660 |
+
## Structural Variant
|
| 661 |
+
| Field | Value |
|
| 662 |
+
|-------|-------|
|
| 663 |
+
| **SV Type** | `{example['sv_type']}` |
|
| 664 |
+
| **Cancer Type** | {example['cancer_type']} |
|
| 665 |
+
| **Clinical Priority** | {priority_emoji} **{example['clinical_priority']}** |
|
| 666 |
+
|
| 667 |
+
---
|
| 668 |
+
|
| 669 |
+
## Oncogene Activation
|
| 670 |
+
|
| 671 |
+
### Activated Oncogene
|
| 672 |
+
**{example['oncogene']}**
|
| 673 |
+
|
| 674 |
+
### Hijacked Enhancer
|
| 675 |
+
**{example['hijacked_enhancer']}**
|
| 676 |
+
|
| 677 |
+
### Neo-Loop Strength
|
| 678 |
+
{"β" * int(example['loop_strength'] * 20)}{"β" * (20 - int(example['loop_strength'] * 20))} **{example['loop_strength']:.0%}**
|
| 679 |
+
|
| 680 |
+
---
|
| 681 |
+
|
| 682 |
+
## Mechanism Visualization
|
| 683 |
+
|
| 684 |
+
```
|
| 685 |
+
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
|
| 686 |
+
β NEO-LOOP FORMATION β
|
| 687 |
+
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ€
|
| 688 |
+
β β
|
| 689 |
+
β BEFORE: {example['sv_type']}
|
| 690 |
+
β ββββββββββββββ ββββββββββββββ β
|
| 691 |
+
β β Enhancer ββ β X β ββ Oncogene β β
|
| 692 |
+
β β Domain A β β Domain B β β
|
| 693 |
+
β ββββββββββββββ ββββββββββββββ β
|
| 694 |
+
β β β
|
| 695 |
+
β Normal Target β
|
| 696 |
+
β β
|
| 697 |
+
β AFTER: {example['sv_type']}
|
| 698 |
+
β ββββββββββββββββββββββββββββββββββββββββ β
|
| 699 |
+
β β Enhancer ββββββββββ Oncogene β β
|
| 700 |
+
β β β NEO-LOOP β β β
|
| 701 |
+
β β ABERRANT ACTIVATION β β
|
| 702 |
+
β ββββββββββββββββββββββββββββββββββββββββ β
|
| 703 |
+
β β
|
| 704 |
+
β Loop Strength: {example['loop_strength']:.2f}
|
| 705 |
+
β Priority: {example['clinical_priority']}
|
| 706 |
+
β β
|
| 707 |
+
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
|
| 708 |
+
```
|
| 709 |
+
|
| 710 |
+
---
|
| 711 |
+
|
| 712 |
+
## Clinical Interpretation
|
| 713 |
+
|
| 714 |
+
{example['description']}
|
| 715 |
+
|
| 716 |
+
---
|
| 717 |
+
|
| 718 |
+
## Actionable Insights
|
| 719 |
+
|
| 720 |
+
Based on this neo-loop detection:
|
| 721 |
+
|
| 722 |
+
1. **Molecular Testing**: Confirm {example['sv_type']} by FISH or karyotyping
|
| 723 |
+
2. **Targeted Therapy**: Consider therapies targeting {example['oncogene']} pathway
|
| 724 |
+
3. **Clinical Trial**: Patient may be eligible for trials targeting this mechanism
|
| 725 |
+
4. **Monitoring**: Track {example['oncogene']} expression as biomarker
|
| 726 |
+
|
| 727 |
+
---
|
| 728 |
+
|
| 729 |
+
## BSV Verification
|
| 730 |
+
|
| 731 |
+
{generate_bsv_attestation(example['sv_type'], f"Neo-loop: {example['oncogene']}", example['loop_strength'])}
|
| 732 |
+
"""
|
| 733 |
+
|
| 734 |
+
return result
|
| 735 |
+
|
| 736 |
+
|
| 737 |
+
def show_benchmarks() -> str:
|
| 738 |
+
"""Show benchmark results."""
|
| 739 |
+
return f"""
|
| 740 |
+
# π TopoGrammar Benchmarks
|
| 741 |
+
|
| 742 |
+
## TAD Detection Performance
|
| 743 |
+
|
| 744 |
+
| Method | TAD Accuracy | Boundary F1 | Sub-TAD Detection |
|
| 745 |
+
|--------|-------------|-------------|-------------------|
|
| 746 |
+
| **TopoGrammar (CTCF-gated)** | **91%** | **0.91** | β Yes |
|
| 747 |
+
| HiCCUPS | 80% | 0.76 | β No |
|
| 748 |
+
| Arrowhead | 78% | 0.74 | β No |
|
| 749 |
+
| TopDom | 75% | 0.71 | β No |
|
| 750 |
+
|
| 751 |
+
---
|
| 752 |
+
|
| 753 |
+
## VUS Resolution Performance
|
| 754 |
+
|
| 755 |
+
| Metric | Value |
|
| 756 |
+
|--------|-------|
|
| 757 |
+
| **Reclassification Rate** | 68% of VUS variants |
|
| 758 |
+
| **Pathogenic Accuracy** | 93% |
|
| 759 |
+
| **Mean Confidence Score** | 87% |
|
| 760 |
+
|
| 761 |
+
---
|
| 762 |
+
|
| 763 |
+
## Insulation Density Improvement
|
| 764 |
+
|
| 765 |
+
| Boundary Set | Insulation Ratio | P-value |
|
| 766 |
+
|--------------|------------------|---------|
|
| 767 |
+
| Major TADs only | 9.11x | <0.0001 |
|
| 768 |
+
| **All Boundaries** | **15.57x** | **<0.0001** |
|
| 769 |
+
| **Improvement** | **+70.9%** | β |
|
| 770 |
+
|
| 771 |
+
---
|
| 772 |
+
|
| 773 |
+
## What Makes TopoGrammar Different
|
| 774 |
+
|
| 775 |
+
### 1. Grammar-Aware Architecture
|
| 776 |
+
|
| 777 |
+
Traditional tools see DNA as a string of letters. TopoGrammar sees it as **sentences with grammar**:
|
| 778 |
+
|
| 779 |
+
```
|
| 780 |
+
Reference: [CTCF+] [Enhancer] [Promoter] [Gene]
|
| 781 |
+
"The enhancer activates the gene"
|
| 782 |
+
|
| 783 |
+
Inversion: [Gene] [Promoter] [Enhancer] [CTCF-]
|
| 784 |
+
"Gene the activates enhancer the" β SCRAMBLED
|
| 785 |
+
```
|
| 786 |
+
|
| 787 |
+
### 2. Physics + Semantics Concordance
|
| 788 |
+
|
| 789 |
+
When both physics (insulation collapse) AND semantics (grammar scramble) agree:
|
| 790 |
+
|
| 791 |
+
| Evidence Type | Alone | Concordant |
|
| 792 |
+
|--------------|-------|------------|
|
| 793 |
+
| Physics | PM1 (Moderate) | β |
|
| 794 |
+
| Semantics | PM1 (Moderate) | β |
|
| 795 |
+
| **Both** | β | **PS3 (Strong)** β UPGRADE |
|
| 796 |
+
|
| 797 |
+
### 3. CTCF-Gated Detection
|
| 798 |
+
|
| 799 |
+
Unlike other tools, TopoGrammar only calls boundaries where:
|
| 800 |
+
- β Insulation score shows local minimum
|
| 801 |
+
- β CTCF binding evidence is present
|
| 802 |
+
- β Gradient analysis confirms boundary
|
| 803 |
+
|
| 804 |
+
This reduces false positives by **40%** compared to insulation-only methods.
|
| 805 |
+
|
| 806 |
+
---
|
| 807 |
+
|
| 808 |
+
## Clinical Value Pillars
|
| 809 |
+
|
| 810 |
+
| Pillar | Clinical Value | Technical Foundation |
|
| 811 |
+
|--------|---------------|---------------------|
|
| 812 |
+
| **Architectural Fidelity** | Eliminates VUS by proving physical boundary collapse | PINN Physics (15.57x insulation) |
|
| 813 |
+
| **Semantic Intelligence** | Detects "scrambled" instructions in balanced inversions | Regulatory Grammar Encoder |
|
| 814 |
+
| **Privacy-First Growth** | Global model evolution without data leakage | Async Federated Learning |
|
| 815 |
+
| **Clinician Clarity** | High-level medical prose instead of raw math | LLM Interpretation Layer |
|
| 816 |
+
"""
|
| 817 |
+
|
| 818 |
+
|
| 819 |
+
# =============================================================================
|
| 820 |
+
# Gradio Interface
|
| 821 |
+
# =============================================================================
|
| 822 |
+
|
| 823 |
+
HEADER_MD = """
|
| 824 |
+
# 𧬠TopoGrammar
|
| 825 |
+
|
| 826 |
+
## The Industry's First Grammar-Aware 3D Genome Engine
|
| 827 |
+
|
| 828 |
+
**Balanced Structural Variants (BSVs)** - inversions, translocations, complex rearrangements - appear "silent" to standard sequencers because they don't change gene dosage. But they **scramble the regulatory grammar** that controls gene expression.
|
| 829 |
+
|
| 830 |
+
**TopoGrammar solves this.** It's the first engine that understands chromatin as a *language* with grammar rules that can be broken.
|
| 831 |
+
|
| 832 |
+
---
|
| 833 |
+
|
| 834 |
+
| Capability | Performance |
|
| 835 |
+
|------------|-------------|
|
| 836 |
+
| π― VUS Reclassification | 68% of variants |
|
| 837 |
+
| π Pathogenic Accuracy | 93% confidence |
|
| 838 |
+
| π¬ TAD Detection F1 | 0.91 (vs 0.76 HiCCUPS) |
|
| 839 |
+
| β‘ Sub-TAD Detection | Yes (unique capability) |
|
| 840 |
+
|
| 841 |
+
---
|
| 842 |
+
"""
|
| 843 |
+
|
| 844 |
+
ABOUT_MD = """
|
| 845 |
+
# βΉοΈ About TopoGrammar
|
| 846 |
+
|
| 847 |
+
## Overview
|
| 848 |
+
|
| 849 |
+
TopoGrammar is part of the **OmniPrime Enterprise Platform**, integrating:
|
| 850 |
+
- **TopoGrammar v2.1.0** - Grammar-Aware 3D Genome Engine
|
| 851 |
+
- **BioPrime v4.0 "Golden"** - Physics-First Molecular Docking
|
| 852 |
+
|
| 853 |
+
Together, they enable a seamless **Patient Genome β Drug Candidate** workflow.
|
| 854 |
+
|
| 855 |
+
---
|
| 856 |
+
|
| 857 |
+
## Core Innovation
|
| 858 |
+
|
| 859 |
+
### Regulatory Grammar Analysis
|
| 860 |
+
|
| 861 |
+
TopoGrammar treats regulatory elements as a **language**:
|
| 862 |
+
|
| 863 |
+
```
|
| 864 |
+
CTCF β Enhancer β Promoter β Gene
|
| 865 |
+
"The enhancer activates the gene"
|
| 866 |
+
```
|
| 867 |
+
|
| 868 |
+
When structural variants **scramble** this grammar, TopoGrammar detects it:
|
| 869 |
+
|
| 870 |
+
```
|
| 871 |
+
Gene β Promoter β Enhancer β CTCF
|
| 872 |
+
"Gene the activates enhancer the" β PATHOGENIC
|
| 873 |
+
```
|
| 874 |
+
|
| 875 |
+
### Semantic Break Score
|
| 876 |
+
|
| 877 |
+
Quantifies regulatory disruption:
|
| 878 |
+
- **Token Disruption (30%)**: Elements removed or duplicated
|
| 879 |
+
- **Order Inversion (40%)**: Sequence rearranged
|
| 880 |
+
- **Orientation Flip (30%)**: Strand direction reversed
|
| 881 |
+
|
| 882 |
+
---
|
| 883 |
+
|
| 884 |
+
## Technology Stack
|
| 885 |
+
|
| 886 |
+
- **Physics-Informed Neural Networks (PINNs)** for 3D reconstruction
|
| 887 |
+
- **CTCF-Gated Boundary Detection** for precise TAD calling
|
| 888 |
+
- **Federated Learning** for privacy-preserving multi-site training
|
| 889 |
+
- **LLM Interpretation** for clinical reporting
|
| 890 |
+
- **BSV Blockchain** for result attestation
|
| 891 |
+
|
| 892 |
+
---
|
| 893 |
+
|
| 894 |
+
## Creators
|
| 895 |
+
|
| 896 |
+
- **Bryan Daugherty**
|
| 897 |
+
- **Gregory Ward**
|
| 898 |
+
- **Shawn Ryan**
|
| 899 |
+
|
| 900 |
+
---
|
| 901 |
+
|
| 902 |
+
## Learn More
|
| 903 |
+
|
| 904 |
+
π [bioprime.one](https://bioprime.one) | 𧬠[OmniPrime Platform](https://github.com/Saifullah62/OmniPrime_v1.0)
|
| 905 |
+
|
| 906 |
+
---
|
| 907 |
+
|
| 908 |
+
**Copyright (c) 2026 Bryan Daugherty, Gregory Ward & Shawn Ryan. All Rights Reserved.**
|
| 909 |
+
|
| 910 |
+
*This demo showcases TopoGrammar capabilities. Actual clinical use requires the full OmniPrime Enterprise Platform.*
|
| 911 |
+
"""
|
| 912 |
+
|
| 913 |
+
# Custom CSS
|
| 914 |
+
CUSTOM_CSS = """
|
| 915 |
+
.gradio-container {
|
| 916 |
+
background: linear-gradient(135deg, #1a1a2e 0%, #16213e 50%, #0f3460 100%);
|
| 917 |
+
}
|
| 918 |
+
.gr-button-primary {
|
| 919 |
+
background: linear-gradient(90deg, #00d4ff, #00ff88) !important;
|
| 920 |
+
border: none !important;
|
| 921 |
+
}
|
| 922 |
+
.gr-button-secondary {
|
| 923 |
+
background: linear-gradient(90deg, #667eea, #764ba2) !important;
|
| 924 |
+
border: none !important;
|
| 925 |
+
color: white !important;
|
| 926 |
+
}
|
| 927 |
+
"""
|
| 928 |
+
|
| 929 |
+
# Build the interface
|
| 930 |
+
with gr.Blocks(
|
| 931 |
+
title="TopoGrammar - Grammar-Aware 3D Genome Engine",
|
| 932 |
+
theme=gr.themes.Base(
|
| 933 |
+
primary_hue="cyan",
|
| 934 |
+
secondary_hue="purple",
|
| 935 |
+
neutral_hue="slate",
|
| 936 |
+
),
|
| 937 |
+
css=CUSTOM_CSS,
|
| 938 |
+
) as demo:
|
| 939 |
+
|
| 940 |
+
gr.Markdown(HEADER_MD)
|
| 941 |
+
|
| 942 |
+
with gr.Tabs():
|
| 943 |
+
# Tab 1: VUS Resolution
|
| 944 |
+
with gr.TabItem("𧬠VUS Resolution"):
|
| 945 |
+
gr.Markdown("""
|
| 946 |
+
## Variant of Uncertain Significance β Clinical Classification
|
| 947 |
+
|
| 948 |
+
Select a demo variant to see how TopoGrammar reclassifies VUS using 3D genome analysis.
|
| 949 |
+
""")
|
| 950 |
+
|
| 951 |
+
with gr.Row():
|
| 952 |
+
with gr.Column(scale=1):
|
| 953 |
+
gr.Markdown("### Select Example")
|
| 954 |
+
vus_brca1 = gr.Button("π΄ BRCA1 Boundary Disruption", variant="secondary")
|
| 955 |
+
vus_myc = gr.Button("π΄ MYC Enhancer Hijacking", variant="secondary")
|
| 956 |
+
vus_shh = gr.Button("π‘ SHH Limb Enhancer", variant="secondary")
|
| 957 |
+
vus_tp53 = gr.Button("π΄ TP53 Grammar Scrambling", variant="secondary")
|
| 958 |
+
vus_benign = gr.Button("π’ Benign Intronic SNP", variant="secondary")
|
| 959 |
+
|
| 960 |
+
with gr.Column(scale=3):
|
| 961 |
+
vus_output = gr.Markdown("*Select an example to run VUS analysis*")
|
| 962 |
+
|
| 963 |
+
vus_brca1.click(fn=lambda: run_vus_analysis("brca1_boundary"), outputs=vus_output)
|
| 964 |
+
vus_myc.click(fn=lambda: run_vus_analysis("myc_enhancer_hijack"), outputs=vus_output)
|
| 965 |
+
vus_shh.click(fn=lambda: run_vus_analysis("sonic_hedgehog"), outputs=vus_output)
|
| 966 |
+
vus_tp53.click(fn=lambda: run_vus_analysis("tp53_scramble"), outputs=vus_output)
|
| 967 |
+
vus_benign.click(fn=lambda: run_vus_analysis("benign_intronic"), outputs=vus_output)
|
| 968 |
+
|
| 969 |
+
# Tab 2: TAD Detection
|
| 970 |
+
with gr.TabItem("π¬ TAD Detection"):
|
| 971 |
+
gr.Markdown("""
|
| 972 |
+
## Topologically Associating Domain Detection
|
| 973 |
+
|
| 974 |
+
See how TopoGrammar detects TAD boundaries with CTCF-gating for 91% accuracy.
|
| 975 |
+
""")
|
| 976 |
+
|
| 977 |
+
with gr.Row():
|
| 978 |
+
with gr.Column(scale=1):
|
| 979 |
+
gr.Markdown("### Select Region")
|
| 980 |
+
tad_dscr = gr.Button("Chr21 - Down Syndrome Region", variant="secondary")
|
| 981 |
+
tad_egfr = gr.Button("Chr7 - EGFR Locus", variant="secondary")
|
| 982 |
+
tad_myc = gr.Button("Chr8 - MYC Oncogene", variant="secondary")
|
| 983 |
+
|
| 984 |
+
with gr.Column(scale=3):
|
| 985 |
+
tad_output = gr.Markdown("*Select a region to analyze TAD structure*")
|
| 986 |
+
|
| 987 |
+
tad_dscr.click(fn=lambda: run_tad_analysis("chr21_dscr"), outputs=tad_output)
|
| 988 |
+
tad_egfr.click(fn=lambda: run_tad_analysis("chr7_egfr"), outputs=tad_output)
|
| 989 |
+
tad_myc.click(fn=lambda: run_tad_analysis("chr8_myc"), outputs=tad_output)
|
| 990 |
+
|
| 991 |
+
# Tab 3: Neo-Loop Detection
|
| 992 |
+
with gr.TabItem("π§ͺ Neo-Loop Detection"):
|
| 993 |
+
gr.Markdown("""
|
| 994 |
+
## Cancer Neo-Loop & Enhancer Hijacking Detection
|
| 995 |
+
|
| 996 |
+
Identify oncogene activation through structural variant-induced neo-loops.
|
| 997 |
+
""")
|
| 998 |
+
|
| 999 |
+
with gr.Row():
|
| 1000 |
+
with gr.Column(scale=1):
|
| 1001 |
+
gr.Markdown("### Select Cancer Example")
|
| 1002 |
+
neo_burkitt = gr.Button("π΄ Burkitt Lymphoma (MYC)", variant="secondary")
|
| 1003 |
+
neo_ewing = gr.Button("π΄ Ewing Sarcoma (EWSR1)", variant="secondary")
|
| 1004 |
+
neo_aml = gr.Button("π‘ AML (RUNX1)", variant="secondary")
|
| 1005 |
+
|
| 1006 |
+
with gr.Column(scale=3):
|
| 1007 |
+
neo_output = gr.Markdown("*Select a cancer example to detect neo-loops*")
|
| 1008 |
+
|
| 1009 |
+
neo_burkitt.click(fn=lambda: run_neoloop_analysis("burkitt_myc"), outputs=neo_output)
|
| 1010 |
+
neo_ewing.click(fn=lambda: run_neoloop_analysis("ewing_ewsr1"), outputs=neo_output)
|
| 1011 |
+
neo_aml.click(fn=lambda: run_neoloop_analysis("aml_runx1"), outputs=neo_output)
|
| 1012 |
+
|
| 1013 |
+
# Tab 4: Benchmarks
|
| 1014 |
+
with gr.TabItem("π Benchmarks"):
|
| 1015 |
+
gr.Markdown(show_benchmarks())
|
| 1016 |
+
|
| 1017 |
+
# Tab 5: About
|
| 1018 |
+
with gr.TabItem("βΉοΈ About"):
|
| 1019 |
+
gr.Markdown(ABOUT_MD)
|
| 1020 |
+
|
| 1021 |
+
gr.Markdown("---")
|
| 1022 |
+
gr.Markdown("""
|
| 1023 |
+
<center>
|
| 1024 |
+
|
| 1025 |
+
**TopoGrammar v2.1.0** | Part of **OmniPrime Enterprise Platform**
|
| 1026 |
+
|
| 1027 |
+
[π bioprime.one](https://bioprime.one) | [𧬠GitHub](https://github.com/Saifullah62/OmniPrime_v1.0) | [π§ Contact](mailto:info@bioprime.one)
|
| 1028 |
+
|
| 1029 |
+
*This is a demonstration. Clinical use requires the full OmniPrime Enterprise Platform.*
|
| 1030 |
+
|
| 1031 |
+
</center>
|
| 1032 |
+
""")
|
| 1033 |
+
|
| 1034 |
+
|
| 1035 |
+
if __name__ == "__main__":
|
| 1036 |
+
demo.launch()
|
|
|
|
|
|