{
  "filename": "plot_2.png",
  "iteration": 2,
  "description": "Create comprehensive multi-panel provenance figure summarizing all evidence",
  "timestamp": "2026-07-05 10:40:42",
  "code": "\nimport matplotlib\nmatplotlib.use('Agg')\nimport matplotlib.pyplot as plt\nimport matplotlib.patches as mpatches\nimport numpy as np\n\nfig = plt.figure(figsize=(16, 14))\n\n# Create grid layout\ngs = fig.add_gridspec(3, 2, height_ratios=[1.2, 1.5, 1.0], hspace=0.35, wspace=0.3)\n\n# ============================================\n# Panel A: Catalytic tetrad comparison table\n# ============================================\nax_table = fig.add_subplot(gs[0, :])\nax_table.axis('off')\nax_table.set_title('A. Catalytic Tetrad Conservation in PIWI Domain\\n(Aligned to HsAGO2 D597-E637-D669-H807)', \n                    fontsize=13, fontweight='bold', loc='left', pad=10)\n\n# Table data\nproteins = ['HsAGO2\\n(reference)', 'CSR-1\\n(slicer \u2713)', 'WAGO-4\\n(test)']\npositions = ['D1\\n(D597)', 'E\\n(E637)', 'D2\\n(D669)', 'H\\n(H807)']\n\ncell_text = [\n    ['D597', 'E637', 'D669', 'H807'],\n    ['D743', 'E785', 'D817', 'D955'],\n    ['G676', 'D714/M620', 'T756', 'N913'],\n]\n\n# Color coding\ncell_colors = [\n    ['#27ae60', '#27ae60', '#27ae60', '#27ae60'],  # HsAGO2 - all green (reference)\n    ['#27ae60', '#27ae60', '#27ae60', '#f39c12'],  # CSR-1 - D/H variant at H\n    ['#e74c3c', '#f39c12', '#e74c3c', '#e74c3c'],  # WAGO-4 - mostly red\n]\n\ntable = ax_table.table(\n    cellText=cell_text,\n    rowLabels=proteins,\n    colLabels=positions,\n    cellColours=cell_colors,\n    loc='center',\n    cellLoc='center'\n)\ntable.auto_set_font_size(False)\ntable.set_fontsize(11)\ntable.scale(1.4, 1.8)\n\nfor (row, col), cell in table.get_celld().items():\n    if row == 0:\n        cell.set_text_props(weight='bold', fontsize=10, color='white')\n        cell.set_facecolor('#2c3e50')\n    if col == -1:\n        cell.set_text_props(weight='bold', fontsize=10)\n        cell.set_facecolor('#ecf0f1')\n    cell.set_text_props(fontsize=11)\n\n# ============================================\n# Panel B: Motif conservation detail\n# ============================================\nax_motif = fig.add_subplot(gs[1, :])\nax_motif.axis('off')\nax_motif.set_title('B. Conserved Sequence Motif Analysis around Catalytic Sites', \n                    fontsize=13, fontweight='bold', loc='left', pad=10)\n\nmotif_data = [\n    {\n        'label': 'D1 site (DVTH motif)',\n        'ref':   'PVIFLGADVTHPPAG',\n        'csr1':  'PTMVVGIDVTHPTQA',\n        'wago4': 'SHLIIGVGISAPPAG',\n        'ref_cat': 8,  # position of D in the motif\n    },\n    {\n        'label': 'D2 site (RDGV motif)',\n        'ref':   'TRIIFYRDGVSEGQF',\n        'csr1':  'ARIIVYRDGVSEGQF',\n        'wago4': 'RRVIVYRTGTSEGNH',\n        'ref_cat': 7,\n    },\n    {\n        'label': 'H site (YxHLVA motif)',\n        'ref':   'PAPAYYAHLVAFRAR',\n        'csr1':  'PTPVYYADLVATRAR',\n        'wago4': 'PTPLYVANEYAKRGR',\n        'ref_cat': 8,\n    },\n]\n\ny_start = 0.92\nfor idx, md in enumerate(motif_data):\n    y = y_start - idx * 0.32\n    \n    # Label\n    ax_motif.text(0.02, y, md['label'], fontsize=11, fontweight='bold',\n                  transform=ax_motif.transAxes, va='top', family='sans-serif')\n    \n    y_line = y - 0.06\n    labels = ['HsAGO2:', 'CSR-1: ', 'WAGO-4:']\n    seqs = [md['ref'], md['csr1'], md['wago4']]\n    colors_list = ['#2c3e50', '#27ae60', '#e74c3c']\n    \n    for j, (lbl, seq, clr) in enumerate(zip(labels, seqs, colors_list)):\n        yy = y_line - j * 0.07\n        ax_motif.text(0.05, yy, lbl, fontsize=10, fontweight='bold', color=clr,\n                      transform=ax_motif.transAxes, va='top', family='monospace')\n        \n        for k, ch in enumerate(seq):\n            x_pos = 0.16 + k * 0.022\n            # Highlight catalytic position\n            if k == md['ref_cat']:\n                if j == 0:\n                    bg_color = '#27ae60'\n                elif seq[k] == md['ref'][k]:\n                    bg_color = '#27ae60'\n                elif seq[k] in 'DE' and md['ref'][k] in 'DE':\n                    bg_color = '#f39c12'\n                elif seq[k] in 'DH' and md['ref'][k] in 'DH':\n                    bg_color = '#f39c12'\n                else:\n                    bg_color = '#e74c3c'\n                \n                ax_motif.text(x_pos, yy, ch, fontsize=11, fontweight='bold',\n                             transform=ax_motif.transAxes, va='top', family='monospace',\n                             bbox=dict(boxstyle='round,pad=0.15', facecolor=bg_color, \n                                      edgecolor='black', alpha=0.8),\n                             color='white')\n            else:\n                # Color matching residues\n                match = seq[k] == md['ref'][k]\n                text_color = '#2c3e50' if match else '#95a5a6'\n                weight = 'bold' if match else 'normal'\n                ax_motif.text(x_pos, yy, ch, fontsize=10, fontweight=weight,\n                             transform=ax_motif.transAxes, va='top', family='monospace',\n                             color=text_color)\n\n# ============================================\n# Panel C: Evidence summary\n# ============================================\nax_summary = fig.add_subplot(gs[2, 0])\nax_summary.axis('off')\nax_summary.set_title('C. Evidence Summary', fontsize=13, fontweight='bold', loc='left', pad=10)\n\nevidence_text = (\n    \"\u2022 PMID:17110334 (Yigit et al.): WAGOs \\\"lack key\\n\"\n    \"  residues required for mRNA cleavage\\\"\\n\\n\"\n    \"\u2022 PMID:29791857 (Xu et al.): WAGO-4 binds 22G-RNAs;\\n\"\n    \"  functions in RNAi inheritance (no cleavage reported)\\n\\n\"\n    \"\u2022 PMID:37505984 (Du et al.): WAGO-4 is \\\"carrier of\\n\"\n    \"  gene silencing memories\\\"\\n\\n\"\n    \"\u2022 PMID:38477356 (Pal et al.): ALG-1/ALG-2 are \\\"the\\n\"\n    \"  only two slicing Argonautes\\\" in C. elegans miRNA pathway\"\n)\nax_summary.text(0.05, 0.95, evidence_text, fontsize=9, transform=ax_summary.transAxes,\n               va='top', family='sans-serif', linespacing=1.3)\n\n# ============================================\n# Panel D: Verdict\n# ============================================\nax_verdict = fig.add_subplot(gs[2, 1])\nax_verdict.axis('off')\nax_verdict.set_title('D. Curation Verdict', fontsize=13, fontweight='bold', loc='left', pad=10)\n\nverdict_box = mpatches.FancyBboxPatch(\n    (0.05, 0.15), 0.9, 0.75, boxstyle=\"round,pad=0.05\",\n    facecolor='#fadbd8', edgecolor='#e74c3c', linewidth=2,\n    transform=ax_verdict.transAxes\n)\nax_verdict.add_patch(verdict_box)\n\nax_verdict.text(0.5, 0.72, 'OVER-ANNOTATED', fontsize=18, fontweight='bold',\n               color='#c0392b', ha='center', transform=ax_verdict.transAxes)\nax_verdict.text(0.5, 0.55, 'GO:0004521 (RNA endonuclease activity)',\n               fontsize=10, ha='center', transform=ax_verdict.transAxes, color='#2c3e50')\nax_verdict.text(0.5, 0.42, 'should be REMOVED from WAGO-4',\n               fontsize=11, fontweight='bold', ha='center', transform=ax_verdict.transAxes,\n               color='#c0392b')\nax_verdict.text(0.5, 0.28, 'IBA phylogenetic transfer does not\\naccount for catalytic residue loss',\n               fontsize=9, ha='center', transform=ax_verdict.transAxes, color='#7f8c8d',\n               linespacing=1.4)\n\n# Add legend for colors at bottom\nfig.text(0.5, 0.01, \n         '\u25a0 Conserved    \u25a0 Conservative substitution (D/E or D/H)    \u25a0 Non-conservative substitution (catalytic activity lost)',\n         ha='center', fontsize=10,\n         bbox=dict(boxstyle='round', facecolor='white', edgecolor='gray', alpha=0.8))\n\n# Color the legend squares\nfig.text(0.21, 0.01, '\u25a0', ha='center', fontsize=14, color='#27ae60')\nfig.text(0.385, 0.01, '\u25a0', ha='center', fontsize=14, color='#f39c12')\nfig.text(0.59, 0.01, '\u25a0', ha='center', fontsize=14, color='#e74c3c')\n\nplt.suptitle('WAGO-4 (O62275) GO:0004521 Hypothesis Evaluation\\nCatalytic Tetrad Analysis of the PIWI Domain',\n            fontsize=15, fontweight='bold', y=0.99)\n\nplt.savefig('wago4_catalytic_analysis.png', dpi=150, bbox_inches='tight')\nplt.show()\nprint(\"Comprehensive figure saved: wago4_catalytic_analysis.png\")\n",
  "plot_number": 2
}