Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add python script to produce heatmap automatically #15

Open
hoelzer opened this issue Dec 13, 2023 · 2 comments
Open

Add python script to produce heatmap automatically #15

hoelzer opened this issue Dec 13, 2023 · 2 comments
Assignees
Labels
enhancement New feature or request

Comments

@hoelzer
Copy link
Owner

hoelzer commented Dec 13, 2023

I could also produce a nice heatmap automatically from the resulting POCP TSV.

Here is some example code:

mamba create -n py-pocp seaborn matplotlib pandas
import pandas as pd
import seaborn as sns
import matplotlib.pyplot as plt
import numpy as np

# Read the TSV file
data = pd.read_csv("pocp.tsv", sep="\t", index_col=0)

# Convert values to numeric
data = data.apply(pd.to_numeric, errors="coerce")

# Check if conversion is successful
if data.isnull().values.any():
    raise ValueError("Unable to convert all values to numeric!")

# Use upper or lower triangle of the matrix
upper_triangle = np.triu(data)
lower_triangle = np.tril(data)

# Combine upper and lower triangles
combined_data = upper_triangle + lower_triangle - np.diag(np.diag(data))

# Create a new DataFrame with the original labels
combined_df = pd.DataFrame(combined_data, index=data.index, columns=data.columns)

# Create a heatmap using seaborn
sns.set(font_scale=1.0)
plt.figure(figsize=(16, 8))

heatmap = sns.heatmap(combined_df, cmap="viridis", annot=True, fmt=".1f", linewidths=.5, square=True, cbar_kws={"shrink": 0.6})

# Move the x-axis labels to the top
plt.tick_params(top=True, labeltop=True, bottom=False, labelbottom=False)

# Set axis labels and plot title
plt.xlabel("")
plt.ylabel("")
plt.title("")

# Rotate y-axis labels for better readability
plt.yticks(rotation=0)

# Save the figure as an SVG file
heatmap.get_figure().savefig("pocp-heatmap.svg", format="svg", bbox_inches="tight")

# Show the plot
plt.show()
@hoelzer hoelzer self-assigned this Dec 13, 2023
@hoelzer hoelzer added the enhancement New feature or request label Dec 13, 2023
@hoelzer
Copy link
Owner Author

hoelzer commented Feb 14, 2024

However, this will not look pretty for too many input genomes. I need a way to auto scale

@shlomobl
Copy link

A clustering output could also be nice (a list of the genomes and their respective clusters).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants