ComplexHeatmap-py 0.1.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (64) hide show
  1. complexheatmap_py-0.1.0/LICENSE +24 -0
  2. complexheatmap_py-0.1.0/MANIFEST.in +7 -0
  3. complexheatmap_py-0.1.0/PKG-INFO +96 -0
  4. complexheatmap_py-0.1.0/README.md +63 -0
  5. complexheatmap_py-0.1.0/pyproject.toml +66 -0
  6. complexheatmap_py-0.1.0/setup.cfg +4 -0
  7. complexheatmap_py-0.1.0/src/ComplexHeatmap.py +7 -0
  8. complexheatmap_py-0.1.0/src/ComplexHeatmap_py.egg-info/PKG-INFO +96 -0
  9. complexheatmap_py-0.1.0/src/ComplexHeatmap_py.egg-info/SOURCES.txt +62 -0
  10. complexheatmap_py-0.1.0/src/ComplexHeatmap_py.egg-info/dependency_links.txt +1 -0
  11. complexheatmap_py-0.1.0/src/ComplexHeatmap_py.egg-info/requires.txt +8 -0
  12. complexheatmap_py-0.1.0/src/ComplexHeatmap_py.egg-info/top_level.txt +2 -0
  13. complexheatmap_py-0.1.0/src/complexheatmap/__init__.py +221 -0
  14. complexheatmap_py-0.1.0/src/complexheatmap/_base.py +56 -0
  15. complexheatmap_py-0.1.0/src/complexheatmap/_options.py +165 -0
  16. complexheatmap_py-0.1.0/src/complexheatmap/anno_funcs.py +2781 -0
  17. complexheatmap_py-0.1.0/src/complexheatmap/annotations.py +1611 -0
  18. complexheatmap_py-0.1.0/src/complexheatmap/colors.py +848 -0
  19. complexheatmap_py-0.1.0/src/complexheatmap/data/dmr_summary/cgi_anno.csv +9 -0
  20. complexheatmap_py-0.1.0/src/complexheatmap/data/dmr_summary/dist_tss.csv +9 -0
  21. complexheatmap_py-0.1.0/src/complexheatmap/data/dmr_summary/gene_anno.csv +9 -0
  22. complexheatmap_py-0.1.0/src/complexheatmap/data/dmr_summary/label.csv +9 -0
  23. complexheatmap_py-0.1.0/src/complexheatmap/data/dmr_summary/mat_enrich_gf.csv +9 -0
  24. complexheatmap_py-0.1.0/src/complexheatmap/data/dmr_summary/mat_enrich_st.csv +9 -0
  25. complexheatmap_py-0.1.0/src/complexheatmap/data/dmr_summary/mat_pct_st.csv +9 -0
  26. complexheatmap_py-0.1.0/src/complexheatmap/data/dmr_summary/mean_meth.csv +9 -0
  27. complexheatmap_py-0.1.0/src/complexheatmap/data/dmr_summary/n_corr.csv +9 -0
  28. complexheatmap_py-0.1.0/src/complexheatmap/data/dmr_summary/n_gr.csv +9 -0
  29. complexheatmap_py-0.1.0/src/complexheatmap/data/gene_expression.csv +156 -0
  30. complexheatmap_py-0.1.0/src/complexheatmap/data/gr.csv +2416 -0
  31. complexheatmap_py-0.1.0/src/complexheatmap/data/measles.csv +60 -0
  32. complexheatmap_py-0.1.0/src/complexheatmap/data/meth/enhancer.csv +1001 -0
  33. complexheatmap_py-0.1.0/src/complexheatmap/data/meth/expr.csv +1001 -0
  34. complexheatmap_py-0.1.0/src/complexheatmap/data/meth/meth.csv +1001 -0
  35. complexheatmap_py-0.1.0/src/complexheatmap/data/meth/row_meta.csv +1001 -0
  36. complexheatmap_py-0.1.0/src/complexheatmap/data/rand_mat.csv +19 -0
  37. complexheatmap_py-0.1.0/src/complexheatmap/data/random_meth_expr_data/anno.csv +21 -0
  38. complexheatmap_py-0.1.0/src/complexheatmap/data/random_meth_expr_data/anno_states.csv +1001 -0
  39. complexheatmap_py-0.1.0/src/complexheatmap/data/random_meth_expr_data/mat_expr.csv +1001 -0
  40. complexheatmap_py-0.1.0/src/complexheatmap/data/random_meth_expr_data/mat_meth.csv +1001 -0
  41. complexheatmap_py-0.1.0/src/complexheatmap/data/random_meth_expr_data/row_meta.csv +1001 -0
  42. complexheatmap_py-0.1.0/src/complexheatmap/data/sample_order.txt +172 -0
  43. complexheatmap_py-0.1.0/src/complexheatmap/data/tcga_lung_adenocarcinoma.csv +27 -0
  44. complexheatmap_py-0.1.0/src/complexheatmap/decorate.py +159 -0
  45. complexheatmap_py-0.1.0/src/complexheatmap/dendrogram.py +937 -0
  46. complexheatmap_py-0.1.0/src/complexheatmap/density.py +276 -0
  47. complexheatmap_py-0.1.0/src/complexheatmap/genomic.py +348 -0
  48. complexheatmap_py-0.1.0/src/complexheatmap/grid.py +1580 -0
  49. complexheatmap_py-0.1.0/src/complexheatmap/heatmap.py +2244 -0
  50. complexheatmap_py-0.1.0/src/complexheatmap/heatmap_list.py +1569 -0
  51. complexheatmap_py-0.1.0/src/complexheatmap/legend.py +992 -0
  52. complexheatmap_py-0.1.0/src/complexheatmap/oncoprint.py +488 -0
  53. complexheatmap_py-0.1.0/src/complexheatmap/text.py +655 -0
  54. complexheatmap_py-0.1.0/src/complexheatmap/three_d.py +188 -0
  55. complexheatmap_py-0.1.0/src/complexheatmap/translate.py +338 -0
  56. complexheatmap_py-0.1.0/src/complexheatmap/units.py +718 -0
  57. complexheatmap_py-0.1.0/src/complexheatmap/upset.py +886 -0
  58. complexheatmap_py-0.1.0/src/complexheatmap/utils.py +183 -0
  59. complexheatmap_py-0.1.0/tests/test_all_rd_examples.py +58 -0
  60. complexheatmap_py-0.1.0/tests/test_annotations_and_legends.py +149 -0
  61. complexheatmap_py-0.1.0/tests/test_clustering_and_alignment.py +172 -0
  62. complexheatmap_py-0.1.0/tests/test_core_and_colors.py +168 -0
  63. complexheatmap_py-0.1.0/tests/test_highlevel_and_translate.py +108 -0
  64. complexheatmap_py-0.1.0/tests/test_upset_and_oncoprint.py +112 -0
@@ -0,0 +1,24 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Xiaowei Zhan and ComplexHeatmap-py Contributors
4
+
5
+ Ported from the R/Bioconductor ComplexHeatmap package, Copyright (c) 2020 Zuguang Gu
6
+ (MIT License, https://github.com/jokergoo/ComplexHeatmap).
7
+
8
+ Permission is hereby granted, free of charge, to any person obtaining a copy
9
+ of this software and associated documentation files (the "Software"), to deal
10
+ in the Software without restriction, including without limitation the rights
11
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
12
+ copies of the Software, and to permit persons to whom the Software is
13
+ furnished to do so, subject to the following conditions:
14
+
15
+ The above copyright notice and this permission notice shall be included in all
16
+ copies or substantial portions of the Software.
17
+
18
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
21
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
22
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
23
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
24
+ SOFTWARE.
@@ -0,0 +1,7 @@
1
+ include LICENSE
2
+ include README.md
3
+ include pyproject.toml
4
+ recursive-include src/complexheatmap/data *.csv *.txt
5
+ prune .venv
6
+ prune .pytest_cache
7
+ global-exclude __pycache__ *.py[cod] .DS_Store
@@ -0,0 +1,96 @@
1
+ Metadata-Version: 2.4
2
+ Name: ComplexHeatmap-py
3
+ Version: 0.1.0
4
+ Summary: Python port of the ComplexHeatmap R/Bioconductor package for making complex heatmaps, annotations, oncoPrints, UpSet plots, and density heatmaps.
5
+ Author-email: Xiaowei Zhan <zhanxw@gmail.com>
6
+ License: MIT
7
+ Project-URL: Homepage, https://github.com/zhanxw/ComplexHeatmap-py
8
+ Project-URL: Repository, https://github.com/zhanxw/ComplexHeatmap-py
9
+ Project-URL: Issues, https://github.com/zhanxw/ComplexHeatmap-py/issues
10
+ Keywords: heatmap,complexheatmap,bioinformatics,genomics,oncoprint,upset,matplotlib,visualization
11
+ Classifier: Development Status :: 4 - Beta
12
+ Classifier: Intended Audience :: Science/Research
13
+ Classifier: Operating System :: OS Independent
14
+ Classifier: Programming Language :: Python :: 3
15
+ Classifier: Programming Language :: Python :: 3.10
16
+ Classifier: Programming Language :: Python :: 3.11
17
+ Classifier: Programming Language :: Python :: 3.12
18
+ Classifier: Programming Language :: Python :: 3.13
19
+ Classifier: Programming Language :: Python :: 3.14
20
+ Classifier: Topic :: Scientific/Engineering :: Bio-Informatics
21
+ Classifier: Topic :: Scientific/Engineering :: Visualization
22
+ Requires-Python: >=3.10
23
+ Description-Content-Type: text/markdown
24
+ License-File: LICENSE
25
+ Requires-Dist: numpy>=1.24
26
+ Requires-Dist: scipy>=1.10
27
+ Requires-Dist: matplotlib>=3.7
28
+ Requires-Dist: pandas>=2.0
29
+ Requires-Dist: pillow>=10.0
30
+ Provides-Extra: dev
31
+ Requires-Dist: pytest>=7.0; extra == "dev"
32
+ Dynamic: license-file
33
+
34
+ # ComplexHeatmap-py
35
+
36
+ Complete standalone Python port of the R/Bioconductor **ComplexHeatmap** (v2.25.3) package, powered by NumPy, SciPy, Pandas, Pillow, and Matplotlib.
37
+
38
+ ## Installation
39
+
40
+ ```bash
41
+ pip install ComplexHeatmap-py
42
+ ```
43
+
44
+ Or install from source:
45
+
46
+ ```bash
47
+ git clone https://github.com/zhanxw/ComplexHeatmap-py.git
48
+ cd ComplexHeatmap-py
49
+ pip install -e .
50
+ ```
51
+
52
+ Both `import complexheatmap as ch` and `import ComplexHeatmap as ch` are supported.
53
+
54
+ ## Quick Example
55
+
56
+ ```python
57
+ import matplotlib
58
+ matplotlib.use("Agg")
59
+ import numpy as np
60
+ import pandas as pd
61
+ import complexheatmap as ch
62
+
63
+ rng = np.random.default_rng(123)
64
+ mat = pd.DataFrame(
65
+ rng.standard_normal((12, 10)),
66
+ index=[f"gene_{i}" for i in range(12)],
67
+ columns=[f"sample_{j}" for j in range(10)],
68
+ )
69
+
70
+ ha_top = ch.HeatmapAnnotation(
71
+ Group=["Ctrl"] * 5 + ["Treat"] * 5,
72
+ Score=ch.anno_barplot(rng.uniform(0, 1, 10)),
73
+ col={"Group": {"Ctrl": "#4DAF4A", "Treat": "#E41A1C"}},
74
+ )
75
+
76
+ ht1 = ch.Heatmap(mat, name="Expr", row_km=2, top_annotation=ha_top, border=True)
77
+ ht2 = ch.Heatmap(mat.iloc[:, :4] * 2, name="Delta")
78
+ ch.draw(ht1 + ht2, save="heatmap.png", width=9, height=6.5, dpi=150)
79
+
80
+ # Post-draw decoration (just like R's decorate_heatmap_body)
81
+ with ch.decorate_heatmap_body("Expr", row_slice=1, column_slice=1):
82
+ ch.grid.rect(gp=ch.gpar(fill="transparent", col="gold", lwd=2))
83
+ ```
84
+
85
+ ## Implemented Modules & Features
86
+
87
+ - **Core Graphics & Units (`units.py`, `grid.py`, `text.py`, `colors.py`)**: Vectorized `Unit` arithmetic (`mm`, `cm`, `inches`, `pt`, `npc`, `snpc`, `native`, `lines`, `char`, `grobwidth`/`grobheight`), `gpar`, nested Matplotlib viewports (`Viewport`, `pushViewport`, `popViewport`, `seekViewport`, `grid.*`), `GridText` (`gt_render` rich markup), `textbox_grob`, `smartAlign2`, and `colorRamp2` (LAB/XYZ/sRGB/HSV) + `ColorMapping`.
88
+ - **Clustering & Dendrograms (`dendrogram.py`)**: `dist`, `dist2`, `hclust`, `Dendrogram`, `cut_dendrogram`, `adjust_dend_by_x`, `merge_dendrogram`, `color_branches`, `cluster_within_group`, `cluster_between_groups`, `grid_dendrogram`, Path A cutree & Path B slice-first + consensus k-means clustering.
89
+ - **Annotations (`annotations.py`, `anno_funcs.py`)**: All 21 `anno_*` (`anno_simple`, `anno_empty`, `anno_points`, `anno_lines`, `anno_barplot`, `anno_boxplot`, `anno_histogram`, `anno_density`, `anno_joyplot`, `anno_horizon`, `anno_text`, `anno_numeric`, `anno_mark`, `anno_zoom`, `anno_link`, `anno_block`, `anno_summary`, `anno_image`, `anno_customize`, `anno_textbox`, `anno_oncoprint_barplot`) + 6 `row_anno_*` aliases, `HeatmapAnnotation`, `rowAnnotation`, `columnAnnotation`, `SingleAnnotation`, `AnnotationFunction`, `attach_annotation`.
90
+ - **Multi-Heatmap Lists & Legends (`heatmap.py`, `heatmap_list.py`, `legend.py`, `decorate.py`)**: Horizontal (`+`) and vertical (`%v%` / `/`) concatenation, `auto_adjust`, `main_heatmap` alignment, `Legend`/`packLegend` discrete + continuous + unequal-break legends, legend deduplication/`c_ColorMapping`, all 11 `decorate_*` viewport decorators, and slice/subsetting indexing (`ht[i, j]`, `ht_list[i, j]`).
91
+ - **High-Level Genomics & Plots (`oncoprint.py`, `upset.py`, `density.py`, `three_d.py`, `genomic.py`, `translate.py`)**: `oncoPrint` (with memoSort & alteration polygons), `make_comb_mat` / `UpSet` (`distinct`, `intersect`, `union`, genomic intervals, `t(m)`), `densityHeatmap`, `frequencyHeatmap`, `ks_dist`, `bar3D`, `Heatmap3D`, `IRanges`/`GRanges`/`bin_genome`/`normalize_genomic_signals_to_bins`, and drop-in translations `pheatmap`, `heatmap`, `heatmap_2`, `compare_*`.
92
+ - **Examples & Verification**: Complete ports of all **102 executable `.Rd` examples** ([examples/run_all_rd_examples.py](https://github.com/zhanxw/ComplexHeatmap-py/blob/main/examples/run_all_rd_examples.py)), publication gallery ([examples/showcase_gallery.py](https://github.com/zhanxw/ComplexHeatmap-py/blob/main/examples/showcase_gallery.py)), R-to-Python guide ([examples/r_to_python_guide.md](https://github.com/zhanxw/ComplexHeatmap-py/blob/main/examples/r_to_python_guide.md)), and `pytest` suite.
93
+
94
+ ## License & Attribution
95
+
96
+ Released under the [MIT License](https://github.com/zhanxw/ComplexHeatmap-py/blob/main/LICENSE). Ported from the R/Bioconductor [ComplexHeatmap](https://github.com/jokergoo/ComplexHeatmap) package (v2.25.3), Copyright (c) 2020 Zuguang Gu (MIT License).
@@ -0,0 +1,63 @@
1
+ # ComplexHeatmap-py
2
+
3
+ Complete standalone Python port of the R/Bioconductor **ComplexHeatmap** (v2.25.3) package, powered by NumPy, SciPy, Pandas, Pillow, and Matplotlib.
4
+
5
+ ## Installation
6
+
7
+ ```bash
8
+ pip install ComplexHeatmap-py
9
+ ```
10
+
11
+ Or install from source:
12
+
13
+ ```bash
14
+ git clone https://github.com/zhanxw/ComplexHeatmap-py.git
15
+ cd ComplexHeatmap-py
16
+ pip install -e .
17
+ ```
18
+
19
+ Both `import complexheatmap as ch` and `import ComplexHeatmap as ch` are supported.
20
+
21
+ ## Quick Example
22
+
23
+ ```python
24
+ import matplotlib
25
+ matplotlib.use("Agg")
26
+ import numpy as np
27
+ import pandas as pd
28
+ import complexheatmap as ch
29
+
30
+ rng = np.random.default_rng(123)
31
+ mat = pd.DataFrame(
32
+ rng.standard_normal((12, 10)),
33
+ index=[f"gene_{i}" for i in range(12)],
34
+ columns=[f"sample_{j}" for j in range(10)],
35
+ )
36
+
37
+ ha_top = ch.HeatmapAnnotation(
38
+ Group=["Ctrl"] * 5 + ["Treat"] * 5,
39
+ Score=ch.anno_barplot(rng.uniform(0, 1, 10)),
40
+ col={"Group": {"Ctrl": "#4DAF4A", "Treat": "#E41A1C"}},
41
+ )
42
+
43
+ ht1 = ch.Heatmap(mat, name="Expr", row_km=2, top_annotation=ha_top, border=True)
44
+ ht2 = ch.Heatmap(mat.iloc[:, :4] * 2, name="Delta")
45
+ ch.draw(ht1 + ht2, save="heatmap.png", width=9, height=6.5, dpi=150)
46
+
47
+ # Post-draw decoration (just like R's decorate_heatmap_body)
48
+ with ch.decorate_heatmap_body("Expr", row_slice=1, column_slice=1):
49
+ ch.grid.rect(gp=ch.gpar(fill="transparent", col="gold", lwd=2))
50
+ ```
51
+
52
+ ## Implemented Modules & Features
53
+
54
+ - **Core Graphics & Units (`units.py`, `grid.py`, `text.py`, `colors.py`)**: Vectorized `Unit` arithmetic (`mm`, `cm`, `inches`, `pt`, `npc`, `snpc`, `native`, `lines`, `char`, `grobwidth`/`grobheight`), `gpar`, nested Matplotlib viewports (`Viewport`, `pushViewport`, `popViewport`, `seekViewport`, `grid.*`), `GridText` (`gt_render` rich markup), `textbox_grob`, `smartAlign2`, and `colorRamp2` (LAB/XYZ/sRGB/HSV) + `ColorMapping`.
55
+ - **Clustering & Dendrograms (`dendrogram.py`)**: `dist`, `dist2`, `hclust`, `Dendrogram`, `cut_dendrogram`, `adjust_dend_by_x`, `merge_dendrogram`, `color_branches`, `cluster_within_group`, `cluster_between_groups`, `grid_dendrogram`, Path A cutree & Path B slice-first + consensus k-means clustering.
56
+ - **Annotations (`annotations.py`, `anno_funcs.py`)**: All 21 `anno_*` (`anno_simple`, `anno_empty`, `anno_points`, `anno_lines`, `anno_barplot`, `anno_boxplot`, `anno_histogram`, `anno_density`, `anno_joyplot`, `anno_horizon`, `anno_text`, `anno_numeric`, `anno_mark`, `anno_zoom`, `anno_link`, `anno_block`, `anno_summary`, `anno_image`, `anno_customize`, `anno_textbox`, `anno_oncoprint_barplot`) + 6 `row_anno_*` aliases, `HeatmapAnnotation`, `rowAnnotation`, `columnAnnotation`, `SingleAnnotation`, `AnnotationFunction`, `attach_annotation`.
57
+ - **Multi-Heatmap Lists & Legends (`heatmap.py`, `heatmap_list.py`, `legend.py`, `decorate.py`)**: Horizontal (`+`) and vertical (`%v%` / `/`) concatenation, `auto_adjust`, `main_heatmap` alignment, `Legend`/`packLegend` discrete + continuous + unequal-break legends, legend deduplication/`c_ColorMapping`, all 11 `decorate_*` viewport decorators, and slice/subsetting indexing (`ht[i, j]`, `ht_list[i, j]`).
58
+ - **High-Level Genomics & Plots (`oncoprint.py`, `upset.py`, `density.py`, `three_d.py`, `genomic.py`, `translate.py`)**: `oncoPrint` (with memoSort & alteration polygons), `make_comb_mat` / `UpSet` (`distinct`, `intersect`, `union`, genomic intervals, `t(m)`), `densityHeatmap`, `frequencyHeatmap`, `ks_dist`, `bar3D`, `Heatmap3D`, `IRanges`/`GRanges`/`bin_genome`/`normalize_genomic_signals_to_bins`, and drop-in translations `pheatmap`, `heatmap`, `heatmap_2`, `compare_*`.
59
+ - **Examples & Verification**: Complete ports of all **102 executable `.Rd` examples** ([examples/run_all_rd_examples.py](https://github.com/zhanxw/ComplexHeatmap-py/blob/main/examples/run_all_rd_examples.py)), publication gallery ([examples/showcase_gallery.py](https://github.com/zhanxw/ComplexHeatmap-py/blob/main/examples/showcase_gallery.py)), R-to-Python guide ([examples/r_to_python_guide.md](https://github.com/zhanxw/ComplexHeatmap-py/blob/main/examples/r_to_python_guide.md)), and `pytest` suite.
60
+
61
+ ## License & Attribution
62
+
63
+ Released under the [MIT License](https://github.com/zhanxw/ComplexHeatmap-py/blob/main/LICENSE). Ported from the R/Bioconductor [ComplexHeatmap](https://github.com/jokergoo/ComplexHeatmap) package (v2.25.3), Copyright (c) 2020 Zuguang Gu (MIT License).
@@ -0,0 +1,66 @@
1
+ [build-system]
2
+ requires = ["setuptools>=68.0"]
3
+ build-backend = "setuptools.build_meta"
4
+
5
+ [project]
6
+ name = "ComplexHeatmap-py"
7
+ version = "0.1.0"
8
+ description = "Python port of the ComplexHeatmap R/Bioconductor package for making complex heatmaps, annotations, oncoPrints, UpSet plots, and density heatmaps."
9
+ readme = "README.md"
10
+ license = {text = "MIT"}
11
+ requires-python = ">=3.10"
12
+ authors = [
13
+ {name = "Xiaowei Zhan", email = "zhanxw@gmail.com"},
14
+ ]
15
+ keywords = [
16
+ "heatmap",
17
+ "complexheatmap",
18
+ "bioinformatics",
19
+ "genomics",
20
+ "oncoprint",
21
+ "upset",
22
+ "matplotlib",
23
+ "visualization",
24
+ ]
25
+ classifiers = [
26
+ "Development Status :: 4 - Beta",
27
+ "Intended Audience :: Science/Research",
28
+ "Operating System :: OS Independent",
29
+ "Programming Language :: Python :: 3",
30
+ "Programming Language :: Python :: 3.10",
31
+ "Programming Language :: Python :: 3.11",
32
+ "Programming Language :: Python :: 3.12",
33
+ "Programming Language :: Python :: 3.13",
34
+ "Programming Language :: Python :: 3.14",
35
+ "Topic :: Scientific/Engineering :: Bio-Informatics",
36
+ "Topic :: Scientific/Engineering :: Visualization",
37
+ ]
38
+ dependencies = [
39
+ "numpy>=1.24",
40
+ "scipy>=1.10",
41
+ "matplotlib>=3.7",
42
+ "pandas>=2.0",
43
+ "pillow>=10.0",
44
+ ]
45
+
46
+ [project.urls]
47
+ Homepage = "https://github.com/zhanxw/ComplexHeatmap-py"
48
+ Repository = "https://github.com/zhanxw/ComplexHeatmap-py"
49
+ Issues = "https://github.com/zhanxw/ComplexHeatmap-py/issues"
50
+
51
+ [project.optional-dependencies]
52
+ dev = ["pytest>=7.0"]
53
+
54
+ [tool.setuptools]
55
+ package-dir = {"" = "src"}
56
+ py-modules = ["ComplexHeatmap"]
57
+
58
+ [tool.setuptools.packages.find]
59
+ where = ["src"]
60
+
61
+ [tool.setuptools.package-data]
62
+ complexheatmap = ["data/*.csv", "data/*.txt", "data/**/*.csv"]
63
+
64
+ [tool.pytest.ini_options]
65
+ testpaths = ["tests"]
66
+ addopts = "-ra"
@@ -0,0 +1,4 @@
1
+ [egg_info]
2
+ tag_build =
3
+ tag_date = 0
4
+
@@ -0,0 +1,7 @@
1
+ """CamelCase alias module for R-identical `import ComplexHeatmap`."""
2
+
3
+ import complexheatmap as _ch
4
+ from complexheatmap import * # noqa: F401, F403
5
+ from complexheatmap import __all__, __version__ # noqa: F401
6
+
7
+ __path__ = _ch.__path__
@@ -0,0 +1,96 @@
1
+ Metadata-Version: 2.4
2
+ Name: ComplexHeatmap-py
3
+ Version: 0.1.0
4
+ Summary: Python port of the ComplexHeatmap R/Bioconductor package for making complex heatmaps, annotations, oncoPrints, UpSet plots, and density heatmaps.
5
+ Author-email: Xiaowei Zhan <zhanxw@gmail.com>
6
+ License: MIT
7
+ Project-URL: Homepage, https://github.com/zhanxw/ComplexHeatmap-py
8
+ Project-URL: Repository, https://github.com/zhanxw/ComplexHeatmap-py
9
+ Project-URL: Issues, https://github.com/zhanxw/ComplexHeatmap-py/issues
10
+ Keywords: heatmap,complexheatmap,bioinformatics,genomics,oncoprint,upset,matplotlib,visualization
11
+ Classifier: Development Status :: 4 - Beta
12
+ Classifier: Intended Audience :: Science/Research
13
+ Classifier: Operating System :: OS Independent
14
+ Classifier: Programming Language :: Python :: 3
15
+ Classifier: Programming Language :: Python :: 3.10
16
+ Classifier: Programming Language :: Python :: 3.11
17
+ Classifier: Programming Language :: Python :: 3.12
18
+ Classifier: Programming Language :: Python :: 3.13
19
+ Classifier: Programming Language :: Python :: 3.14
20
+ Classifier: Topic :: Scientific/Engineering :: Bio-Informatics
21
+ Classifier: Topic :: Scientific/Engineering :: Visualization
22
+ Requires-Python: >=3.10
23
+ Description-Content-Type: text/markdown
24
+ License-File: LICENSE
25
+ Requires-Dist: numpy>=1.24
26
+ Requires-Dist: scipy>=1.10
27
+ Requires-Dist: matplotlib>=3.7
28
+ Requires-Dist: pandas>=2.0
29
+ Requires-Dist: pillow>=10.0
30
+ Provides-Extra: dev
31
+ Requires-Dist: pytest>=7.0; extra == "dev"
32
+ Dynamic: license-file
33
+
34
+ # ComplexHeatmap-py
35
+
36
+ Complete standalone Python port of the R/Bioconductor **ComplexHeatmap** (v2.25.3) package, powered by NumPy, SciPy, Pandas, Pillow, and Matplotlib.
37
+
38
+ ## Installation
39
+
40
+ ```bash
41
+ pip install ComplexHeatmap-py
42
+ ```
43
+
44
+ Or install from source:
45
+
46
+ ```bash
47
+ git clone https://github.com/zhanxw/ComplexHeatmap-py.git
48
+ cd ComplexHeatmap-py
49
+ pip install -e .
50
+ ```
51
+
52
+ Both `import complexheatmap as ch` and `import ComplexHeatmap as ch` are supported.
53
+
54
+ ## Quick Example
55
+
56
+ ```python
57
+ import matplotlib
58
+ matplotlib.use("Agg")
59
+ import numpy as np
60
+ import pandas as pd
61
+ import complexheatmap as ch
62
+
63
+ rng = np.random.default_rng(123)
64
+ mat = pd.DataFrame(
65
+ rng.standard_normal((12, 10)),
66
+ index=[f"gene_{i}" for i in range(12)],
67
+ columns=[f"sample_{j}" for j in range(10)],
68
+ )
69
+
70
+ ha_top = ch.HeatmapAnnotation(
71
+ Group=["Ctrl"] * 5 + ["Treat"] * 5,
72
+ Score=ch.anno_barplot(rng.uniform(0, 1, 10)),
73
+ col={"Group": {"Ctrl": "#4DAF4A", "Treat": "#E41A1C"}},
74
+ )
75
+
76
+ ht1 = ch.Heatmap(mat, name="Expr", row_km=2, top_annotation=ha_top, border=True)
77
+ ht2 = ch.Heatmap(mat.iloc[:, :4] * 2, name="Delta")
78
+ ch.draw(ht1 + ht2, save="heatmap.png", width=9, height=6.5, dpi=150)
79
+
80
+ # Post-draw decoration (just like R's decorate_heatmap_body)
81
+ with ch.decorate_heatmap_body("Expr", row_slice=1, column_slice=1):
82
+ ch.grid.rect(gp=ch.gpar(fill="transparent", col="gold", lwd=2))
83
+ ```
84
+
85
+ ## Implemented Modules & Features
86
+
87
+ - **Core Graphics & Units (`units.py`, `grid.py`, `text.py`, `colors.py`)**: Vectorized `Unit` arithmetic (`mm`, `cm`, `inches`, `pt`, `npc`, `snpc`, `native`, `lines`, `char`, `grobwidth`/`grobheight`), `gpar`, nested Matplotlib viewports (`Viewport`, `pushViewport`, `popViewport`, `seekViewport`, `grid.*`), `GridText` (`gt_render` rich markup), `textbox_grob`, `smartAlign2`, and `colorRamp2` (LAB/XYZ/sRGB/HSV) + `ColorMapping`.
88
+ - **Clustering & Dendrograms (`dendrogram.py`)**: `dist`, `dist2`, `hclust`, `Dendrogram`, `cut_dendrogram`, `adjust_dend_by_x`, `merge_dendrogram`, `color_branches`, `cluster_within_group`, `cluster_between_groups`, `grid_dendrogram`, Path A cutree & Path B slice-first + consensus k-means clustering.
89
+ - **Annotations (`annotations.py`, `anno_funcs.py`)**: All 21 `anno_*` (`anno_simple`, `anno_empty`, `anno_points`, `anno_lines`, `anno_barplot`, `anno_boxplot`, `anno_histogram`, `anno_density`, `anno_joyplot`, `anno_horizon`, `anno_text`, `anno_numeric`, `anno_mark`, `anno_zoom`, `anno_link`, `anno_block`, `anno_summary`, `anno_image`, `anno_customize`, `anno_textbox`, `anno_oncoprint_barplot`) + 6 `row_anno_*` aliases, `HeatmapAnnotation`, `rowAnnotation`, `columnAnnotation`, `SingleAnnotation`, `AnnotationFunction`, `attach_annotation`.
90
+ - **Multi-Heatmap Lists & Legends (`heatmap.py`, `heatmap_list.py`, `legend.py`, `decorate.py`)**: Horizontal (`+`) and vertical (`%v%` / `/`) concatenation, `auto_adjust`, `main_heatmap` alignment, `Legend`/`packLegend` discrete + continuous + unequal-break legends, legend deduplication/`c_ColorMapping`, all 11 `decorate_*` viewport decorators, and slice/subsetting indexing (`ht[i, j]`, `ht_list[i, j]`).
91
+ - **High-Level Genomics & Plots (`oncoprint.py`, `upset.py`, `density.py`, `three_d.py`, `genomic.py`, `translate.py`)**: `oncoPrint` (with memoSort & alteration polygons), `make_comb_mat` / `UpSet` (`distinct`, `intersect`, `union`, genomic intervals, `t(m)`), `densityHeatmap`, `frequencyHeatmap`, `ks_dist`, `bar3D`, `Heatmap3D`, `IRanges`/`GRanges`/`bin_genome`/`normalize_genomic_signals_to_bins`, and drop-in translations `pheatmap`, `heatmap`, `heatmap_2`, `compare_*`.
92
+ - **Examples & Verification**: Complete ports of all **102 executable `.Rd` examples** ([examples/run_all_rd_examples.py](https://github.com/zhanxw/ComplexHeatmap-py/blob/main/examples/run_all_rd_examples.py)), publication gallery ([examples/showcase_gallery.py](https://github.com/zhanxw/ComplexHeatmap-py/blob/main/examples/showcase_gallery.py)), R-to-Python guide ([examples/r_to_python_guide.md](https://github.com/zhanxw/ComplexHeatmap-py/blob/main/examples/r_to_python_guide.md)), and `pytest` suite.
93
+
94
+ ## License & Attribution
95
+
96
+ Released under the [MIT License](https://github.com/zhanxw/ComplexHeatmap-py/blob/main/LICENSE). Ported from the R/Bioconductor [ComplexHeatmap](https://github.com/jokergoo/ComplexHeatmap) package (v2.25.3), Copyright (c) 2020 Zuguang Gu (MIT License).
@@ -0,0 +1,62 @@
1
+ LICENSE
2
+ MANIFEST.in
3
+ README.md
4
+ pyproject.toml
5
+ src/ComplexHeatmap.py
6
+ src/ComplexHeatmap_py.egg-info/PKG-INFO
7
+ src/ComplexHeatmap_py.egg-info/SOURCES.txt
8
+ src/ComplexHeatmap_py.egg-info/dependency_links.txt
9
+ src/ComplexHeatmap_py.egg-info/requires.txt
10
+ src/ComplexHeatmap_py.egg-info/top_level.txt
11
+ src/complexheatmap/__init__.py
12
+ src/complexheatmap/_base.py
13
+ src/complexheatmap/_options.py
14
+ src/complexheatmap/anno_funcs.py
15
+ src/complexheatmap/annotations.py
16
+ src/complexheatmap/colors.py
17
+ src/complexheatmap/decorate.py
18
+ src/complexheatmap/dendrogram.py
19
+ src/complexheatmap/density.py
20
+ src/complexheatmap/genomic.py
21
+ src/complexheatmap/grid.py
22
+ src/complexheatmap/heatmap.py
23
+ src/complexheatmap/heatmap_list.py
24
+ src/complexheatmap/legend.py
25
+ src/complexheatmap/oncoprint.py
26
+ src/complexheatmap/text.py
27
+ src/complexheatmap/three_d.py
28
+ src/complexheatmap/translate.py
29
+ src/complexheatmap/units.py
30
+ src/complexheatmap/upset.py
31
+ src/complexheatmap/utils.py
32
+ src/complexheatmap/data/gene_expression.csv
33
+ src/complexheatmap/data/gr.csv
34
+ src/complexheatmap/data/measles.csv
35
+ src/complexheatmap/data/rand_mat.csv
36
+ src/complexheatmap/data/sample_order.txt
37
+ src/complexheatmap/data/tcga_lung_adenocarcinoma.csv
38
+ src/complexheatmap/data/dmr_summary/cgi_anno.csv
39
+ src/complexheatmap/data/dmr_summary/dist_tss.csv
40
+ src/complexheatmap/data/dmr_summary/gene_anno.csv
41
+ src/complexheatmap/data/dmr_summary/label.csv
42
+ src/complexheatmap/data/dmr_summary/mat_enrich_gf.csv
43
+ src/complexheatmap/data/dmr_summary/mat_enrich_st.csv
44
+ src/complexheatmap/data/dmr_summary/mat_pct_st.csv
45
+ src/complexheatmap/data/dmr_summary/mean_meth.csv
46
+ src/complexheatmap/data/dmr_summary/n_corr.csv
47
+ src/complexheatmap/data/dmr_summary/n_gr.csv
48
+ src/complexheatmap/data/meth/enhancer.csv
49
+ src/complexheatmap/data/meth/expr.csv
50
+ src/complexheatmap/data/meth/meth.csv
51
+ src/complexheatmap/data/meth/row_meta.csv
52
+ src/complexheatmap/data/random_meth_expr_data/anno.csv
53
+ src/complexheatmap/data/random_meth_expr_data/anno_states.csv
54
+ src/complexheatmap/data/random_meth_expr_data/mat_expr.csv
55
+ src/complexheatmap/data/random_meth_expr_data/mat_meth.csv
56
+ src/complexheatmap/data/random_meth_expr_data/row_meta.csv
57
+ tests/test_all_rd_examples.py
58
+ tests/test_annotations_and_legends.py
59
+ tests/test_clustering_and_alignment.py
60
+ tests/test_core_and_colors.py
61
+ tests/test_highlevel_and_translate.py
62
+ tests/test_upset_and_oncoprint.py
@@ -0,0 +1,8 @@
1
+ numpy>=1.24
2
+ scipy>=1.10
3
+ matplotlib>=3.7
4
+ pandas>=2.0
5
+ pillow>=10.0
6
+
7
+ [dev]
8
+ pytest>=7.0
@@ -0,0 +1,2 @@
1
+ ComplexHeatmap
2
+ complexheatmap
@@ -0,0 +1,221 @@
1
+ """ComplexHeatmap-py: Python port of R/Bioconductor ComplexHeatmap (v2.25.3)."""
2
+
3
+ from __future__ import annotations
4
+
5
+ __version__ = "0.1.0"
6
+ __upstream_r_version__ = "2.25.3"
7
+
8
+ # Core options, base infix operators, units & graphics
9
+ from ._base import AdditiveUnit, v
10
+ from ._options import GLOBAL_PADDING, _ENV, get_last_ht, ht_global_opt, ht_opt
11
+ from .colors import (
12
+ ColorMapping,
13
+ add_luminance,
14
+ add_transparency,
15
+ brewer_pal,
16
+ c_ColorMapping,
17
+ colorRamp2,
18
+ color_mapping_legend,
19
+ default_col,
20
+ grid_pretty,
21
+ hcl_colors,
22
+ map_to_colors,
23
+ pretty_breaks,
24
+ rand_color,
25
+ to_hex_rgba,
26
+ to_hex_rgba_list,
27
+ to_rgba_tuple,
28
+ )
29
+ from .grid import (
30
+ GTree,
31
+ Grob,
32
+ Viewport,
33
+ current_device,
34
+ current_viewport,
35
+ getXY_in_parent_vp,
36
+ grid,
37
+ grid_boxplot,
38
+ grid_circle,
39
+ grid_draw,
40
+ grid_grabExpr,
41
+ grid_lines,
42
+ grid_newpage,
43
+ grid_points,
44
+ grid_polygon,
45
+ grid_raster,
46
+ grid_rect,
47
+ grid_roundrect,
48
+ grid_segments,
49
+ grid_text,
50
+ grid_xaxis,
51
+ grid_yaxis,
52
+ grobHeight,
53
+ grobWidth,
54
+ linesGrob,
55
+ list_components,
56
+ max_text_height,
57
+ max_text_width,
58
+ pointsGrob,
59
+ polygonGrob,
60
+ popViewport,
61
+ pushViewport,
62
+ rectGrob,
63
+ roundrectGrob,
64
+ seekViewport,
65
+ segmentsGrob,
66
+ textGrob,
67
+ upViewport,
68
+ viewport,
69
+ )
70
+ from .text import GridText, draw_richtext, grid_textbox, gt_render, smartAlign, smartAlign2, textbox_grob
71
+ from .units import (
72
+ Gpar,
73
+ Unit,
74
+ as_unit,
75
+ check_gp,
76
+ convertHeight,
77
+ convertWidth,
78
+ convertX,
79
+ convertY,
80
+ gpar,
81
+ is_abs_unit,
82
+ is_unit,
83
+ merge_gp,
84
+ recycle_gp,
85
+ subset_gp,
86
+ unit,
87
+ unit_c,
88
+ unit_max,
89
+ unit_min,
90
+ unit_pmax,
91
+ unit_pmin,
92
+ unit_rep,
93
+ unit_sum,
94
+ )
95
+
96
+ # Dendrogram & clustering
97
+ from .dendrogram import (
98
+ Dendrogram,
99
+ DistMatrix,
100
+ Hclust,
101
+ adjust_dend_by_x,
102
+ as_dendrogram,
103
+ as_dist,
104
+ cluster_between_groups,
105
+ cluster_within_group,
106
+ color_branches,
107
+ cut_dendrogram,
108
+ cutree,
109
+ dend_heights,
110
+ dend_xy,
111
+ dendrogramGrob,
112
+ dist,
113
+ dist2,
114
+ grid_dendrogram,
115
+ hclust,
116
+ merge_dendrogram,
117
+ nobs,
118
+ order_dendrogram,
119
+ reorder_dendrogram,
120
+ )
121
+
122
+ # Legends
123
+ from .legend import Legend, Legends, packLegend
124
+
125
+ # Annotations (always import annotations before anno_funcs)
126
+ from .annotations import (
127
+ AnnotationFunction,
128
+ HeatmapAnnotation,
129
+ SingleAnnotation,
130
+ anno_barplot,
131
+ anno_block,
132
+ anno_boxplot,
133
+ anno_customize,
134
+ anno_density,
135
+ anno_empty,
136
+ anno_histogram,
137
+ anno_horizon,
138
+ anno_image,
139
+ anno_joyplot,
140
+ anno_lines,
141
+ anno_link,
142
+ anno_mark,
143
+ anno_numeric,
144
+ anno_oncoprint_barplot,
145
+ anno_points,
146
+ anno_simple,
147
+ anno_summary,
148
+ anno_text,
149
+ anno_textbox,
150
+ anno_zoom,
151
+ annotation_axis_grob,
152
+ c_HeatmapAnnotation,
153
+ columnAnnotation,
154
+ construct_axis_grob,
155
+ default_axis_param,
156
+ grid_annotation_axis,
157
+ rowAnnotation,
158
+ row_anno_barplot,
159
+ row_anno_boxplot,
160
+ row_anno_density,
161
+ row_anno_histogram,
162
+ row_anno_points,
163
+ row_anno_text,
164
+ validate_axis_param,
165
+ )
166
+
167
+ # Heatmap, HeatmapList & Decorations
168
+ from .decorate import (
169
+ decorate_annotation,
170
+ decorate_column_dend,
171
+ decorate_column_names,
172
+ decorate_column_title,
173
+ decorate_dend,
174
+ decorate_dimnames,
175
+ decorate_heatmap_body,
176
+ decorate_row_dend,
177
+ decorate_row_names,
178
+ decorate_row_title,
179
+ decorate_title,
180
+ )
181
+ from .heatmap import Heatmap
182
+ from .heatmap_list import (
183
+ HeatmapList,
184
+ add_heatmap,
185
+ attach_annotation,
186
+ column_dend,
187
+ column_order,
188
+ draw,
189
+ ht_size,
190
+ row_dend,
191
+ row_order,
192
+ )
193
+
194
+ # High-level plots, genomic utilities, translations & helpers
195
+ from .density import densityHeatmap, frequencyHeatmap, ks_dist
196
+ from .genomic import GRanges, IRanges, bin_genome, findOverlaps, generateRandomBed, normalize_genomic_signals_to_bins
197
+ from .oncoprint import alter_graphic, default_get_type, oncoPrint, test_alter_fun, unify_mat_list
198
+ from .three_d import Heatmap3D, bar3D
199
+ from .translate import compare_heatmap, compare_heatmap_2, compare_pheatmap, heatmap, heatmap_2, pheatmap
200
+ from .upset import (
201
+ CombMat,
202
+ UpSet,
203
+ comb_degree,
204
+ comb_name,
205
+ comb_size,
206
+ complement_size,
207
+ extract_comb,
208
+ full_comb_code,
209
+ list_to_matrix,
210
+ make_comb_mat,
211
+ normalize_comb_mat,
212
+ order_comb_mat,
213
+ set_name,
214
+ set_size,
215
+ upset_left_annotation,
216
+ upset_right_annotation,
217
+ upset_top_annotation,
218
+ )
219
+ from .utils import c, dim, height, load_dataset, names, ncol, nrow, pindex, restore_matrix, set_names, size, summary, t, width
220
+
221
+ __all__ = [name for name in globals() if not name.startswith("_")]