Once the dataframe is reshaped correctly you can use the heatmap
function from seaborn
to visualize the data.
Try this:
import pandas as pd
import seaborn as sns
import matplotlib.pyplot as plt
# Sample data
data = {
'REF': ['A', 'A', 'A', 'C', 'C', 'C', 'G', 'G', 'G', 'T', 'T', 'T'],
'ALT': ['C', 'G', 'T', 'A', 'G', 'T', 'A', 'C', 'T', 'A', 'C', 'G'],
'COUNT': [3328, 11321, 3477, 3920, 3367, 11778, 11612, 3199, 3772, 3463, 11288, 3420]
}
df = pd.DataFrame(data)
# Reshape the dataframe to a matrix format
pivot_df = df.pivot(index='REF', columns='ALT', values='COUNT')
# Plot the heatmap
plt.figure(figsize=(10, 8))
sns.heatmap(pivot_df, annot=True, cmap='YlGnBu', fmt='g', linewidths=.5)
plt.title('REF -> ALT Counts Heatmap')
plt.show()
This code will generate a heatmap where the x-axis represents the REF
, the y-axis represents the ALT
, and the color intensity is based on the COUNT
value. The darker the color, the higher the count.