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

Bump to v1.7.2 #79

Merged
merged 8 commits into from
Dec 21, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Fix chord diagram code a little
- Change `initialize_from_matrix()` to `chord_diagram()`
- Leave `initialize_from_matrix()` for backward compatibility
  • Loading branch information
moshi4 committed Dec 21, 2024
commit 542e87e0be317998b255853c2e28deb667e738ef
14 changes: 7 additions & 7 deletions src/pycirclize/circos.py
Original file line number Diff line number Diff line change
Expand Up @@ -337,7 +337,7 @@ def radar_chart(
return circos

@staticmethod
def initialize_from_matrix(
def chord_diagram(
matrix: str | Path | pd.DataFrame | Matrix,
*,
start: float = 0,
Expand All @@ -354,9 +354,9 @@ def initialize_from_matrix(
link_kws: dict[str, Any] | None = None,
link_kws_handler: Callable[[str, str], dict[str, Any] | None] | None = None,
) -> Circos:
"""Initialize Circos instance from Matrix
"""Plot chord diagram

Circos tracks and links are auto-defined by Matrix (For plotting Chord Diagram)
Circos tracks and links are auto-defined from Matrix

Parameters
----------
Expand All @@ -379,7 +379,7 @@ def initialize_from_matrix(
link_cmap : list[tuple[str, str, str]] | None, optional
Link colormap to overwrite link colors automatically set by cmap.
User can set list of `from_label`, `to_label`, `color` tuple
(e.g. `[("A", "B", "red"), ("A", "C", "#ffff00), ...]`)
(e.g. `[("A", "B", "red"), ("A", "C", "#ffff00"), ...]`)
ticks_interval : int | None, optional
Ticks interval. If None, ticks are not plotted.
order : str | list[str] | None, optional
Expand Down Expand Up @@ -444,10 +444,10 @@ def initialize_from_matrix(
outer_track.xticks_by_interval(ticks_interval, **ticks_kws)

# Plot links
fromto_label2color = {f"{t[0]}--->{t[1]}": t[2] for t in link_cmap}
fromto_label2color = {f"{t[0]}-->{t[1]}": t[2] for t in link_cmap}
for link in matrix.to_links():
from_label, to_label = link[0][0], link[1][0]
fromto_label = f"{from_label}--->{to_label}"
fromto_label = f"{from_label}-->{to_label}"
# Set link color
if fromto_label in fromto_label2color:
color = fromto_label2color[fromto_label]
Expand All @@ -464,7 +464,7 @@ def initialize_from_matrix(

return circos

chord_diagram = initialize_from_matrix
initialize_from_matrix = chord_diagram # For backward compatibility

@staticmethod
def initialize_from_tree(
Expand Down
5 changes: 5 additions & 0 deletions tests/test_plot.py
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,11 @@ def test_radar_chart_plot(fig_outfile: Path, tsv_radar_table_file: Path):

def test_chord_diagram_plot(fig_outfile: Path, tsv_matrix_file: pd.DataFrame):
"""Test chord diagram plot"""
circos = Circos.chord_diagram(tsv_matrix_file)
circos.savefig(fig_outfile)
assert fig_outfile.exists()

# For backward compatibility method
circos = Circos.initialize_from_matrix(tsv_matrix_file)
circos.savefig(fig_outfile)
assert fig_outfile.exists()
Expand Down