Clustermap

Protein Interaction Matrix

Binary interaction heatmap with hierarchical clustering

Output
Protein Interaction Matrix
Python
import matplotlib.pyplot as plt
import seaborn as sns
import pandas as pd
import numpy as np
from matplotlib.colors import LinearSegmentedColormap

np.random.seed(42)

# Simulated protein interaction data
proteins = [f'Protein_{chr(65+i)}' for i in range(18)]
n = len(proteins)

# Create symmetric interaction matrix
interactions = np.zeros((n, n))
for i in range(n):
    for j in range(i+1, n):
        if np.random.rand() > 0.7:  # 30% interaction rate
            strength = np.random.rand()
            interactions[i, j] = strength
            interactions[j, i] = strength

df = pd.DataFrame(interactions, index=proteins, columns=proteins)

# Protein families
families = ['Kinase']*6 + ['Receptor']*6 + ['Enzyme']*6
fam_palette = {'Kinase': '#F5276C', 'Receptor': '#27D3F5', 'Enzyme': '#6CF527'}
colors = pd.Series(families, index=proteins).map(fam_palette)

# NEON purple colormap
neon_purple = LinearSegmentedColormap.from_list('neon_p', ['#0a0a0f', '#4927F5', '#F527B0'])

g = sns.clustermap(df, cmap=neon_purple, row_colors=colors, col_colors=colors,
                   method='ward', linewidths=0.2, linecolor='#1a1a2e',
                   figsize=(8, 7), dendrogram_ratio=(0.1, 0.1),
                   cbar_pos=(0.01, 0.08, 0.008, 0.12),
                   tree_kws={'linewidths': 1.5, 'colors': '#27D3F5'})

g.fig.patch.set_facecolor('#0a0a0f')
g.ax_heatmap.set_facecolor('#0a0a0f')
g.ax_heatmap.tick_params(colors='white', labelsize=8)

for ax in [g.ax_row_dendrogram, g.ax_col_dendrogram]:
    ax.set_facecolor('#0a0a0f')

g.fig.suptitle('Protein Interaction Network', color='white', fontsize=14, fontweight='bold', y=1.02)


plt.show()
Library

Matplotlib

Category

Heatmaps & Density

Did this help you?

Support PyLucid to keep it free & growing

Support