{
  "filename": "alignment_visualization.png",
  "iteration": 1,
  "description": "Visualize active site region alignment between human and Drosophila ECHS1",
  "timestamp": "2026-07-01 07:02:03",
  "code": "\nimport matplotlib\nmatplotlib.use('Agg')\nimport matplotlib.pyplot as plt\nimport numpy as np\n\n# Create the sequence alignment visualization with catalytic residues highlighted\nfig, ax = plt.subplots(figsize=(16, 5))\n\n# Show the key aligned region around the active site\nhuman_region = \"VKKPVIAAVNGYAFGGGCELAMMCDIIYAGEKAQFAQPEILIGTIPGAGGTQRLTR\"\ndrome_region = \"QKPIIAAVNGYALGGGCELAMMCDIIYAGDKAKFGQPEIALGTIPGAGGTQRLTR\"\n\n# Mark positions (relative to this alignment block)\n# GGCELAMMCDIIYAG starts at position 16 in human_region\n# Catalytic Glu1 (human Glu144) is at position 32 (the E in EKAQ) \u2192 but actually...\n# Let me recount. In the full human seq:\n# Position 144 = E\n# VKKPVIA starts at human position 126\n# So Glu144 is at index 144-126 = 18 in this block\n# Glu164 is at index 164-126 = 38 in this block\n\n# For Drosophila:\n# QKPIIA starts at drome position 131\n# Glu149 is at index 149-131 = 18 in this block\n# Glu169 is at index 169-131 = 38 in this block\n\n# Wait, these sequences are different lengths. Let me align them properly.\n# From our analysis:\n# Human:  VKKPVIAAVNGYAFGGGCELAMMCDIIYAGEKAQFAQPEILIGTIPGAGGTQRLTR\n# Drome:  -QKPIIAAVNGYALGGGCELAMMCDIIYAGDKAKFGQPEIALGTIPGAGGTQRLTR\n\n# Actually the alignment shows the gap is at the start\n# Human 126: V K K P V I A A V N G Y A F G G G C E L A M M C D I I Y A G E K A Q F A Q P E I L I G T I P G A G G T Q R L T R\n# Drome 131: Q K P I I A A V N G Y A L G G G C E L A M M C D I I Y A G D K A K F G Q P E I A L G T I P G A G G T Q R L T R\n\ny_h = 0.7\ny_d = 0.3\ny_mid = 0.5\n\n# Use the aligned sequences from our NW alignment\nh_aligned = \"VKKPVIAAVNGYAFGGGCELAMMCDIIYAGEKAQFAQPEILIGTIPGAGGTQRLTR\"\nd_aligned = \"-QKPIIAAVNGYALGGGCELAMMCDIIYAGDKAKFGQPEIALGTIPGAGGTQRLTR\"\n\n# Pad to same length\nmax_len = max(len(h_aligned), len(d_aligned))\nh_aligned = h_aligned.ljust(max_len, ' ')\nd_aligned = d_aligned.ljust(max_len, ' ')\n\n# Human Glu144 corresponds to the 'E' in GGCELAM \u2192 that's position 18 in h_aligned (0-indexed)\n# Actually let me find it\ncat_e1_h = h_aligned.find('CDIIYAGE') + 7  # The E after CDIIYAG\ncat_e2_h = None  # Not in this short block - Glu164 is further downstream\n\n# Let me find all E positions\nfor i, (h, d) in enumerate(zip(h_aligned, d_aligned)):\n    if h == 'E' or d == 'E':\n        pass  # Will highlight below\n\n# Draw the alignment\nax.set_xlim(-1, max_len + 1)\nax.set_ylim(0, 1)\n\n# Highlight the active site motif region\nmotif_start = h_aligned.find('GGCELAMMCDIIYAG')\nmotif_end = motif_start + 15\nax.axvspan(motif_start - 0.5, motif_end - 0.5, alpha=0.15, color='blue', label='Active site motif')\n\n# Plot each residue\nfor i in range(max_len):\n    h_res = h_aligned[i] if i < len(h_aligned) else ' '\n    d_res = d_aligned[i] if i < len(d_aligned) else ' '\n    \n    # Color coding\n    if h_res == d_res and h_res != '-' and h_res != ' ':\n        h_color = '#2d8a4e'  # green for identity\n        d_color = '#2d8a4e'\n        mid_char = '|'\n    elif h_res == '-' or d_res == '-':\n        h_color = '#888888'\n        d_color = '#888888'\n        mid_char = ' '\n    else:\n        h_color = '#c44e52'  # red for mismatch\n        d_color = '#c44e52'\n        mid_char = '\u00b7'\n    \n    # Highlight catalytic Glu residues\n    # In h_aligned: The E in EKAQ (after CDIIYAG) and the E in PEIL (further right)\n    # Glu144 (human) = first E after CDIIYAG\n    e1_pos = h_aligned.find('CDIIYAGE') + 7  # position of first catalytic E\n    \n    is_catalytic = False\n    if i == e1_pos:  # First catalytic Glu\n        is_catalytic = True\n    \n    fontweight = 'bold' if is_catalytic else 'normal'\n    fontsize = 12 if is_catalytic else 9\n    \n    if is_catalytic:\n        ax.plot(i, y_h, 'o', markersize=18, color='gold', zorder=0)\n        ax.plot(i, y_d, 'o', markersize=18, color='gold', zorder=0)\n    \n    ax.text(i, y_h, h_res, ha='center', va='center', fontsize=fontsize, \n            fontweight=fontweight, color=h_color, fontfamily='monospace')\n    ax.text(i, y_d, d_res, ha='center', va='center', fontsize=fontsize,\n            fontweight=fontweight, color=d_color, fontfamily='monospace')\n    ax.text(i, y_mid, mid_char, ha='center', va='center', fontsize=7, color='gray', fontfamily='monospace')\n\nax.text(-0.8, y_h, 'Human', ha='right', va='center', fontsize=10, fontweight='bold')\nax.text(-0.8, y_d, 'Drome', ha='right', va='center', fontsize=10, fontweight='bold')\n\nax.set_title('Active Site Region Alignment: Human ECHS1 vs Drosophila Echs1\\n(Blue = active site motif; Gold = catalytic Glu)', \n             fontsize=12, fontweight='bold')\nax.axis('off')\n\nplt.tight_layout()\nplt.savefig('alignment_visualization.png', dpi=150, bbox_inches='tight')\nplt.show()\nprint(\"Figure saved: alignment_visualization.png\")\n"
}