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

tso.plot_heatmap blank plot #15

Open
bijendrabio opened this issue Jun 22, 2023 · 7 comments
Open

tso.plot_heatmap blank plot #15

bijendrabio opened this issue Jun 22, 2023 · 7 comments

Comments

@bijendrabio
Copy link

bijendrabio commented Jun 22, 2023

Hello,
Curious if its possible to reorder the tissue samples in the heatmap? For example, if I change the order of tissues in the sample input, the heat map doesn't generate logical order. Kindly suggest

tso.plot_heatmap(threshold=0.8, sort_genes=True, use_zscore=True, gene_names=False)

Eg.
image

@apcamargo

Regards,
B

@apcamargo
Copy link
Owner

Hi @bijendrabio

Sorry for taking so long to answer you. What is your pandas version?

import pandas as pd
pd.__version__

I couldn't reproduce your issue. It seems that your x-axis is also wrong. See the result I got below.

output

To answer your question. Genes are ordered so that the genes that are specific to the first tissue in the x-axis (in this case, bladder) are shown first, then genes that are specific to the second tissue, and so on. The code to sort the genes can be found here.

@bijendrabio
Copy link
Author

@apcamargo Thank you for your response. My pandas version is 1.5.3. Could it be due to different pandas version?. For X-axis, I reordered the tissues on purpose while extracting the expression data from gtex_link. Also, curious why the edges of heatmaps are blurred.?

@apcamargo
Copy link
Owner

The blur effect is due to a change in the default parameters in Matplotlib. I'll update tspex to disable it.

If you try to follow the tutorial step-by-step (without reordering anything) do you still get that plot? If so, try to update pandas to a newer release.

@apcamargo
Copy link
Owner

I just pushed a new release to PyPI that disables the blur effect. If you want, you can also take a look at how the heatmap is constructed here.

@bijendrabio
Copy link
Author

The blur effect is due to a change in the default parameters in Matplotlib. I'll update tspex to disable it.

If you try to follow the tutorial step-by-step (without reordering anything) do you still get that plot? If so, try to update pandas to a newer release.

@apcamargo The blur effect is fixed now, thank you for pushing the updates., but curious why the reordering or sorted genes in the plot.

@apcamargo
Copy link
Owner

I suspect it is because you manually reordered the tissues. Did you try to follow the tutorial without any modifications to check if if works as expected? If you are still having this issue, try to update pandas.

@daniel-spies
Copy link

daniel-spies commented Jan 8, 2024

I observe the same behaviour, though this is due to the fact that pandas is performing an alphabetical sort of the tissues.

One solution would be to create a category variable with the desired order and adjust the sorting call by assigning the category before sorting to use instead of the alphabetic order

#get category order from data
cat_type = pd.api.types.CategoricalDtype(categories=expr_data.columns.tolist(),ordered=True)

# sort genes by max column respecting the category order
sorted_index = expr_data.idxmax(axis=1).astype(cat_type).sort_values().index
expr_data = expr_data.reindex(idx)

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

No branches or pull requests

3 participants