Skip to main content

A python package to plot complex heatmap

Project description

PyComplexHeatmap Downloads Downloads Downloads

PyComplexHeatmap is a Python package to plot complex heatmap (clustermap). Please click here for documentation.

Documentation:


https://dingwb.github.io/PyComplexHeatmap

PYPI

Wiki

wiki/layout
wiki/Parameters
wiki/Features

Dependencies:


  • matplotlib>=3.3.1
  • numpy
  • pandas
  • scipy
  • fastcluster
pip install --ignore-install matplotlib numpy pandas
pip install seaborn #only needed when call functions in tools.py

Citation

Ding, W., Goldberg, D. and Zhou, W. (2023), PyComplexHeatmap: A Python package to visualize multimodal genomics data. iMeta e115. https://doi.org/10.1002/imt2.115
DOI: 10.1002/imt2.115

Installation


  1. Install using pip:
pip install PyComplexHeatmap

#upgrade from older version
pip install --upgrade PyComplexHeatmap
  1. Install the developmental version directly from github:
pip install git+https://github.com/DingWB/PyComplexHeatmap

if you have installed it previously and want to update it, please run pip uninstall PyComplexHeatmap and install from github again OR

git clone https://github.com/DingWB/PyComplexHeatmap
cd PyComplexHeatmap
python setup.py install

Usage


1. Simple Guide To Get started.

from PyComplexHeatmap import *

#Generate example dataset (random)
df = pd.DataFrame(['GroupA'] * 5 + ['GroupB'] * 5, columns=['AB'])
df['CD'] = ['C'] * 3 + ['D'] * 3 + ['G'] * 4
df['EF'] = ['E'] * 6 + ['F'] * 2 + ['H'] * 2
df['F'] = np.random.normal(0, 1, 10)
df.index = ['sample' + str(i) for i in range(1, df.shape[0] + 1)]
df_box = pd.DataFrame(np.random.randn(10, 4), columns=['Gene' + str(i) for i in range(1, 5)])
df_box.index = ['sample' + str(i) for i in range(1, df_box.shape[0] + 1)]
df_bar = pd.DataFrame(np.random.uniform(0, 10, (10, 2)), columns=['TMB1', 'TMB2'])
df_bar.index = ['sample' + str(i) for i in range(1, df_box.shape[0] + 1)]
df_scatter = pd.DataFrame(np.random.uniform(0, 10, 10), columns=['Scatter'])
df_scatter.index = ['sample' + str(i) for i in range(1, df_box.shape[0] + 1)]
df_heatmap = pd.DataFrame(np.random.randn(30, 10), columns=['sample' + str(i) for i in range(1, 11)])
df_heatmap.index = ["Fea" + str(i) for i in range(1, df_heatmap.shape[0] + 1)]
df_heatmap.iloc[1, 2] = np.nan

#Annotate the rows with sample4 > 0.5
df_rows = df_heatmap.apply(lambda x:x.name if x.sample4 > 0.5 else None,axis=1)
df_rows=df_rows.to_frame(name='Selected')
df_rows['XY']=df_rows.index.to_series().apply(lambda x:'A' if int(x.replace('Fea',''))>=15 else 'B')

#Create row annotations
row_ha = HeatmapAnnotation(
                           Scatter=anno_scatterplot(df_heatmap.sample4.apply(lambda x:round(x,2)),
                                            height=12,cmap='jet',legend=False),
                           Bar=anno_barplot(df_heatmap.sample4.apply(lambda x:round(x,2)),
                                            height=16,cmap='rainbow',legend=False),
                           selected=anno_label(df_rows,colors='red',relpos=(-0.05,0.4)),
                           label_kws={'rotation':30,'horizontalalignment':'left','verticalalignment':'bottom'},
                            axis=0,verbose=0)

#Create column annotations
col_ha = HeatmapAnnotation(label=anno_label(df.AB, merge=True,rotation=10),
                           AB=anno_simple(df.AB,add_text=True),axis=1,
                           CD=anno_simple(df.CD,add_text=True),
                           EF=anno_simple(df.EF,add_text=True,
                                            legend_kws={'frameon':True}),
                           G=anno_boxplot(df_box, cmap='jet',legend=False),
                           verbose=0)

plt.figure(figsize=(5.5, 6.5))
cm = ClusterMapPlotter(data=df_heatmap, top_annotation=col_ha,right_annotation=row_ha,
                       col_cluster=True,row_cluster=True,
                       col_split=df.AB,row_split=2, 
                       col_split_gap=0.5,row_split_gap=0.8,
                       label='values',row_dendrogram=True,
                       show_rownames=False,show_colnames=True,
                       tree_kws={'row_cmap': 'Set1'},verbose=0,legend_gap=5,
                       cmap='RdYlBu_r',xticklabels_kws={'labelrotation':-45,'labelcolor':'blue'})
#plt.savefig("example0.pdf", bbox_inches='tight')
plt.show()

Example output

Click picture to view the source code

More Examples

https://dingwb.github.io/PyComplexHeatmap/build/html/more_examples.html

Call for Contributions


The PyComplexHeatmap project welcomes your expertise and enthusiasm!

Small improvements or fixes are always appreciated. If you are considering larger contributions to the source code, please contact us (ding.wu.bin.gm@gmail.com).

Writing code isn’t the only way to contribute to PyComplexHeatmap. You can also:

  • review pull requests
  • help us stay on top of new and old issues
  • develop tutorials, presentations, and other educational materials
  • maintain and improve our website
  • develop graphic design for our brand assets and promotional materials
  • translate website content
  • help with outreach and onboard new contributors
  • put forward some new ideas about update.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

PyComplexHeatmap-1.6.tar.gz (60.7 kB view details)

Uploaded Source

Built Distribution

PyComplexHeatmap-1.6-py3-none-any.whl (61.9 kB view details)

Uploaded Python 3

File details

Details for the file PyComplexHeatmap-1.6.tar.gz.

File metadata

  • Download URL: PyComplexHeatmap-1.6.tar.gz
  • Upload date:
  • Size: 60.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.9.18

File hashes

Hashes for PyComplexHeatmap-1.6.tar.gz
Algorithm Hash digest
SHA256 bef82c4d18aa5ab266c44f4df76dc290bcf1a045c93b11afd60e0b5407b47071
MD5 a9215c6ae562b21c3629484b0f564d21
BLAKE2b-256 15cda59476d9b3f6e76b023fba11a443d98027707c9c75bf44b2629f20df8d43

See more details on using hashes here.

File details

Details for the file PyComplexHeatmap-1.6-py3-none-any.whl.

File metadata

File hashes

Hashes for PyComplexHeatmap-1.6-py3-none-any.whl
Algorithm Hash digest
SHA256 be3fa95386de9d7b34a1cb835d27bf2b15eb8d2d12a930f8a5fa8f640b76e060
MD5 391292e6dcec21a494b0f22a92b81514
BLAKE2b-256 6e4667c73f90220b3114d3a968ad4d5bfe9381ee1b3ddfc4740a1598de272fac

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page