From 3c8a000c5df0b5bd378499322578ad13bae3f5d2 Mon Sep 17 00:00:00 2001 From: moshi Date: Mon, 29 Jan 2024 20:28:15 +0900 Subject: [PATCH 1/7] Add confidence value to `alphabet.nwk` --- src/pycirclize/utils/example_data/trees/alphabet.nwk | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/pycirclize/utils/example_data/trees/alphabet.nwk b/src/pycirclize/utils/example_data/trees/alphabet.nwk index d5e8cbd..e3a852a 100644 --- a/src/pycirclize/utils/example_data/trees/alphabet.nwk +++ b/src/pycirclize/utils/example_data/trees/alphabet.nwk @@ -1 +1 @@ -(((A:1.90623,(B:0.77315,(C:0.78332,(D:2.24573,(E:1.25976,F:1.85780):0.00000):0.15046):1.04012):0.90160):0.72056,((((G:0.59616,H:1.70149):1.58325,I:1.00419):1.19115,(J:0.91877,K:1.31367):0.88856):1.55681,L:0.88143):0.74292):1.02610,((M:1.46117,((N:0.12272,(O:1.12953,P:0.58300):0.73047):0.70152,(Q:0.71106,((((R:0.53759,S:0.71617):1.49010,T:1.40058):1.09120,(U:0.80607,V:1.06576):0.73818):0.94044,W:1.90216):1.65416):1.75184):0.90540):1.56327,(X:0.59332,(Y:1.23427,Z:1.60350):0.98802):0.87582):0.47830):0.00000; +(((A:1.90623,(B:0.77315,(C:0.78332,(D:2.24573,(E:1.25976,F:1.85780)95:0.00000)99:0.15046)99:1.04012)100:0.90160)99:0.72056,((((G:0.59616,H:1.70149)91:1.58325,I:1.00419)98:1.19115,(J:0.91877,K:1.31367)91:0.88856)99:1.55681,L:0.88143)99:0.74292)95:1.02610,((M:1.46117,((N:0.12272,(O:1.12953,P:0.58300)99:0.73047)91:0.70152,(Q:0.71106,((((R:0.53759,S:0.71617)90:1.49010,T:1.40058)100:1.09120,(U:0.80607,V:1.06576)99:0.73818)100:0.94044,W:1.90216)91:1.65416)93:1.75184)90:0.90540)91:1.56327,(X:0.59332,(Y:1.23427,Z:1.60350)93:0.98802)90:0.87582)97:0.47830)100:0.00000; From 95471bba9723fff5b44cf352033c79a919276642 Mon Sep 17 00:00:00 2001 From: moshi Date: Mon, 29 Jan 2024 20:31:49 +0900 Subject: [PATCH 2/7] Add `show_confidence()` method --- src/pycirclize/tree.py | 43 ++++++++++++++++++++++++++++++++++++++++++ tests/test_plot.py | 2 ++ 2 files changed, 45 insertions(+) diff --git a/src/pycirclize/tree.py b/src/pycirclize/tree.py index 797acee..5a8d515 100644 --- a/src/pycirclize/tree.py +++ b/src/pycirclize/tree.py @@ -246,6 +246,49 @@ def get_target_xlim( ) return target_xlim + def show_confidence( + self, + *, + size: float = 8, + orientation: str = "vertical", + label_formatter: Callable[[float], str] | None = None, + **kwargs, + ) -> None: + """Show confidence value on each internal node of the phylogenetic tree + + Parameters + ---------- + size : float, optional + Text size + orientation : str, optional + Text orientation (`horizontal` or `vertical`) + label_formatter : Callable[[float], str] | None, optional + User-defined function for label format. + **kwargs : dict, optional + Text properties (e.g. `color="red", ...`) + + """ + node: Clade + for node in self.tree.get_nonterminals(): + # Ignore if confidence value is None + confidence = node.confidence + if confidence is None: + continue + + # Format confidence label + if label_formatter: + label = label_formatter(float(confidence)) + elif str(confidence).isdigit(): + label = str(confidence) + else: + label = f"{float(confidence):.2f}" + + # Get target node x, r coordinate + x, r = self.name2xr[str(node.name)] + + kwargs.update(size=size, orientation=orientation) + self.track.parent_sector.text(label, x, r + 1.0, **kwargs) + def highlight( self, query: str | list[str] | tuple[str], diff --git a/tests/test_plot.py b/tests/test_plot.py index e496af4..c1b152d 100644 --- a/tests/test_plot.py +++ b/tests/test_plot.py @@ -182,6 +182,8 @@ def test_phylogenetic_tree_plot(fig_outfile: Path): tv.set_node_line_props(["S", "R"], color="lime", descendent=False) tv.set_node_line_props(["X", "Y", "Z"], color="purple", apply_label_color=True) + tv.show_confidence() + circos.savefig(fig_outfile) assert fig_outfile.exists() From f84815d3dd5324e2ca74323b7543164eaaf91063 Mon Sep 17 00:00:00 2001 From: moshi Date: Mon, 29 Jan 2024 20:35:36 +0900 Subject: [PATCH 3/7] Fix `parse_fromto_table()` to ignore 0 value --- src/pycirclize/parser/matrix.py | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/pycirclize/parser/matrix.py b/src/pycirclize/parser/matrix.py index ace7985..8327f67 100644 --- a/src/pycirclize/parser/matrix.py +++ b/src/pycirclize/parser/matrix.py @@ -102,10 +102,11 @@ def parse_fromto_table( fromto2value = defaultdict(int) for row in fromto_table.itertuples(): from_label, to_label, value = str(row[1]), str(row[2]), row[3] - fromto = f"{from_label}{to_label}" - fromto2value[fromto] = value - label2value_sum[from_label] += value - label2value_sum[to_label] += value + if float(value) > 0: + fromto = f"{from_label}{to_label}" + fromto2value[fromto] = value + label2value_sum[from_label] += value + label2value_sum[to_label] += value all_labels = list(label2value_sum.keys()) # Set user specified label order From 526512f7f18ba357b5595af451f150196fc0bb09 Mon Sep 17 00:00:00 2001 From: moshi Date: Mon, 29 Jan 2024 20:36:30 +0900 Subject: [PATCH 4/7] Update CI workflow gh-actions version --- .github/workflows/ci.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index a592b6a..475a9e8 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -17,10 +17,10 @@ jobs: python-version: ["3.8", "3.9", "3.10", "3.11", "3.12"] steps: - name: Checkout - uses: actions/checkout@v3 + uses: actions/checkout@v4 - name: Setup Python ${{ matrix.python-version}} - uses: actions/setup-python@v4 + uses: actions/setup-python@v5 with: python-version: ${{ matrix.python-version }} From c5789cfd98174ebe7f18ff4bddad74c963c81794 Mon Sep 17 00:00:00 2001 From: moshi Date: Sun, 18 Feb 2024 20:31:48 +0900 Subject: [PATCH 5/7] Update gh workflow version --- .github/workflows/publish_mkdocs.yml | 4 ++-- .github/workflows/publish_to_pypi.yml | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/.github/workflows/publish_mkdocs.yml b/.github/workflows/publish_mkdocs.yml index f630294..8732bb1 100644 --- a/.github/workflows/publish_mkdocs.yml +++ b/.github/workflows/publish_mkdocs.yml @@ -10,10 +10,10 @@ jobs: runs-on: ubuntu-latest steps: - name: Checkout - uses: actions/checkout@v3 + uses: actions/checkout@v4 - name: Setup Python 3.11 - uses: actions/setup-python@v4 + uses: actions/setup-python@v5 with: python-version: "3.11" diff --git a/.github/workflows/publish_to_pypi.yml b/.github/workflows/publish_to_pypi.yml index 0992afe..2bb8587 100644 --- a/.github/workflows/publish_to_pypi.yml +++ b/.github/workflows/publish_to_pypi.yml @@ -13,10 +13,10 @@ jobs: PYPI_PASSWORD: ${{ secrets.PYPI_PASSWORD }} steps: - name: Checkout - uses: actions/checkout@v3 + uses: actions/checkout@v4 - name: Setup Python 3.11 - uses: actions/setup-python@v4 + uses: actions/setup-python@v5 with: python-version: "3.11" From c1bd67639bd6e21b66566db362242461e5a9e8d8 Mon Sep 17 00:00:00 2001 From: moshi Date: Sun, 18 Feb 2024 20:38:24 +0900 Subject: [PATCH 6/7] Fix too many points in vector curves (#56) --- src/pycirclize/config.py | 2 +- src/pycirclize/track.py | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/src/pycirclize/config.py b/src/pycirclize/config.py index 69167ac..cac1cc6 100644 --- a/src/pycirclize/config.py +++ b/src/pycirclize/config.py @@ -12,7 +12,7 @@ MIN_R = 0 MAX_R = 100 R_PLOT_MARGIN = 5 -ARC_RADIAN_STEP = 0.001 +ARC_RADIAN_STEP = 0.01 R_LIM = (MIN_R, MAX_R) AXIS_FACE_PARAM = dict(zorder=0.99, ec="none", edgecolor="none") AXIS_EDGE_PARAM = dict(zorder=1.01, fc="none", facecolor="none") diff --git a/src/pycirclize/track.py b/src/pycirclize/track.py index 8ffa958..1205481 100644 --- a/src/pycirclize/track.py +++ b/src/pycirclize/track.py @@ -1321,7 +1321,8 @@ def _to_arc_radr( all_arc_rad.extend([rad1, rad2]) all_arc_r.extend([r1, r2]) else: - step = config.ARC_RADIAN_STEP + # To obtain finely chopped coordinates, step is reduced by a tenth + step = config.ARC_RADIAN_STEP / 10 if rad1 > rad2: step *= -1 arc_rad = list(np.arange(rad1, rad2, step)) + [rad2] From 212b36f1bf2587bc15ed6d7045c0af5335de3475 Mon Sep 17 00:00:00 2001 From: moshi Date: Sun, 18 Feb 2024 20:54:54 +0900 Subject: [PATCH 7/7] Change v1.2.0 to v1.3.0 --- pyproject.toml | 2 +- src/pycirclize/__init__.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/pyproject.toml b/pyproject.toml index 1feb280..5b96460 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,6 +1,6 @@ [tool.poetry] name = "pyCirclize" -version = "1.2.0" +version = "1.3.0" description = "Circular visualization in Python" authors = ["moshi4"] license = "MIT" diff --git a/src/pycirclize/__init__.py b/src/pycirclize/__init__.py index eb8d383..88c3e3f 100644 --- a/src/pycirclize/__init__.py +++ b/src/pycirclize/__init__.py @@ -1,6 +1,6 @@ from pycirclize.circos import Circos -__version__ = "1.2.0" +__version__ = "1.3.0" __all__ = [ "Circos",