0

I have a dataframe that looks like this (pictured below), and essentially I want a heatmap that shows the REF -> ALT counts. The heat map should have the x-axis as REF, y-axis as ALT, and the the darker the color- the higher the count.

    REF ALT COUNT
0   A   C   3328
1   A   G   11321
2   A   T   3477
3   C   A   3920
4   C   G   3367
5   C   T   11778
6   G   A   11612
7   G   C   3199
8   G   T   3772
9   T   A   3463
10  T   C   11288
11  T   G   3420
Hannah
  • 51
  • 5
  • For a heat map in seaboard you'll need to reshape the dataframe to a matrix format where the rows represent the REF, the columns represent the ALT, and the values are the COUNT. – Joaquin Aug 29 '23 at 02:27

1 Answers1

2

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.

Joaquin
  • 452
  • 7