Skip to content

Commit

Permalink
Merge pull request #44 from moshi4/develop
Browse files Browse the repository at this point in the history
Bump to v1.1.0
  • Loading branch information
moshi4 authored Dec 9, 2023
2 parents a01285f + 5eaf7ed commit 2e186d3
Show file tree
Hide file tree
Showing 16 changed files with 93 additions and 26 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/publish_mkdocs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,10 @@ jobs:
- name: Checkout
uses: actions/checkout@v3

- name: Setup Python 3.9
- name: Setup Python 3.11
uses: actions/setup-python@v4
with:
python-version: 3.9
python-version: "3.11"

- name: Install MkDocs & Plugins
run: |
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/publish_to_pypi.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,10 @@ jobs:
- name: Checkout
uses: actions/checkout@v3

- name: Setup Python 3.9
- name: Setup Python 3.11
uses: actions/setup-python@v4
with:
python-version: 3.9
python-version: "3.11"

- name: Install Poetry
run: |
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ group_name2species_list = dict(
Monotremata=["Tachyglossus_aculeatus", "Ornithorhynchus_anatinus"],
Marsupialia=["Monodelphis_domestica", "Vombatus_ursinus"],
Xenarthra=["Choloepus_didactylus", "Dasypus_novemcinctus"],
Afrotheria=["Trichechus_manatus_latirostris", "Chrysochloris_asiatica"],
Afrotheria=["Trichechus_manatus", "Chrysochloris_asiatica"],
Euarchontes=["Galeopterus_variegatus", "Theropithecus_gelada"],
Glires=["Oryctolagus_cuniculus", "Microtus_oregoni"],
Laurasiatheria=["Talpa_occidentalis", "Mirounga_leonina"],
Expand Down
Binary file modified docs/images/example04.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
27 changes: 21 additions & 6 deletions docs/phylogenetic_tree.ipynb

Large diffs are not rendered by default.

29 changes: 23 additions & 6 deletions docs/plot_api_example.ipynb

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "pyCirclize"
version = "1.0.0"
version = "1.1.0"
description = "Circular visualization in Python"
authors = ["moshi4"]
license = "MIT"
Expand Down
2 changes: 1 addition & 1 deletion src/pycirclize/__init__.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from pycirclize.circos import Circos

__version__ = "1.0.0"
__version__ = "1.1.0"

__all__ = [
"Circos",
Expand Down
6 changes: 6 additions & 0 deletions src/pycirclize/circos.py
Original file line number Diff line number Diff line change
Expand Up @@ -311,6 +311,7 @@ def initialize_from_tree(
reverse: bool = False,
ladderize: bool = False,
line_kws: dict[str, Any] | None = None,
label_formatter: Callable[[str], str] | None = None,
align_line_kws: dict[str, Any] | None = None,
) -> tuple[Circos, TreeViz]:
"""Initialize Circos instance from phylogenetic tree
Expand Down Expand Up @@ -349,6 +350,10 @@ def initialize_from_tree(
align_line_kws : dict[str, Any] | None, optional
Patch properties (e.g. `dict(lw=1, ls="dotted", alpha=1.0, ...)`)
<https://matplotlib.org/stable/api/_as_gen/matplotlib.patches.Patch.html>
label_formatter : Callable[[str], str] | None, optional
User-defined label text format function to change plot label text content.
For example, if you want to change underscore of the label to space,
set `lambda t: t.replace("_", " ")`.
Returns
-------
Expand All @@ -374,6 +379,7 @@ def initialize_from_tree(
reverse=reverse,
ladderize=ladderize,
line_kws=line_kws,
label_formatter=label_formatter,
align_line_kws=align_line_kws,
)
return circos, tv
Expand Down
4 changes: 4 additions & 0 deletions src/pycirclize/parser/genbank.py
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,8 @@ def calc_gc_skew(
window_size = int(len(seq) / 500)
if step_size is None:
step_size = int(len(seq) / 1000)
if window_size == 0 or step_size == 0:
window_size, step_size = len(seq), int(len(seq) / 2)
pos_list = list(range(0, len(seq), step_size)) + [len(seq)]
for pos in pos_list:
window_start_pos = pos - int(window_size / 2)
Expand Down Expand Up @@ -218,6 +220,8 @@ def calc_gc_content(
window_size = int(len(seq) / 500)
if step_size is None:
step_size = int(len(seq) / 1000)
if window_size == 0 or step_size == 0:
window_size, step_size = len(seq), int(len(seq) / 2)
pos_list = list(range(0, len(seq), step_size)) + [len(seq)]
for pos in pos_list:
window_start_pos = pos - int(window_size / 2)
Expand Down
15 changes: 12 additions & 3 deletions src/pycirclize/track.py
Original file line number Diff line number Diff line change
Expand Up @@ -1149,6 +1149,7 @@ def tree(
ladderize: bool = False,
line_kws: dict[str, Any] | None = None,
align_line_kws: dict[str, Any] | None = None,
label_formatter: Callable[[str], str] | None = None,
) -> TreeViz:
"""Plot tree
Expand Down Expand Up @@ -1181,6 +1182,10 @@ def tree(
align_line_kws : dict[str, Any] | None, optional
Patch properties (e.g. `dict(lw=1, ls="dotted", alpha=1.0, ...)`)
<https://matplotlib.org/stable/api/_as_gen/matplotlib.patches.Patch.html>
label_formatter : Callable[[str], str] | None, optional
User-defined label text format function to change plot label text content.
For example, if you want to change underscore of the label to space,
set `lambda t: t.replace("_", " ")`.
Returns
-------
Expand All @@ -1199,6 +1204,7 @@ def tree(
ladderize=ladderize,
line_kws=line_kws,
align_line_kws=align_line_kws,
label_formatter=label_formatter,
track=self,
)
self._trees.append(tv)
Expand All @@ -1207,7 +1213,7 @@ def tree(

def genomic_features(
self,
features: list[SeqFeature],
features: SeqFeature | list[SeqFeature],
*,
plotstyle: str = "box",
r_lim: tuple[float, float] | None = None,
Expand All @@ -1218,8 +1224,8 @@ def genomic_features(
Parameters
----------
features : list[SeqFeature]
Biopython's SeqFeature list
features : SeqFeature | list[SeqFeature]
Biopython's SeqFeature or SeqFeature list
plotstyle : str, optional
Plot style (`box` or `arrow`)
r_lim : tuple[float, float] | None, optional
Expand All @@ -1230,6 +1236,9 @@ def genomic_features(
Patch properties (e.g. `fc="red", ec="blue", lw=1.0, ...`)
<https://matplotlib.org/stable/api/_as_gen/matplotlib.patches.Patch.html>
"""
if isinstance(features, SeqFeature):
features = [features]

if r_lim is None:
r_lim = self.r_plot_lim
else:
Expand Down
12 changes: 11 additions & 1 deletion src/pycirclize/tree.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
from copy import deepcopy
from functools import cached_property
from pathlib import Path
from typing import TYPE_CHECKING, Any
from typing import TYPE_CHECKING, Any, Callable
from urllib.parse import urlparse
from urllib.request import urlopen

Expand Down Expand Up @@ -40,6 +40,7 @@ def __init__(
ladderize: bool = False,
line_kws: dict[str, Any] | None = None,
align_line_kws: dict[str, Any] | None = None,
label_formatter: Callable[[str], str] | None = None,
track: Track,
):
"""
Expand Down Expand Up @@ -69,6 +70,10 @@ def __init__(
align_line_kws : dict[str, Any] | None, optional
Patch properties (e.g. `dict(lw=1, ls="dotted", alpha=1.0, ...)`)
<https://matplotlib.org/stable/api/_as_gen/matplotlib.patches.Patch.html>
label_formatter : Callable[[str], str] | None, optional
User-defined label text format function to change plot label text content.
For example, if you want to change underscore of the label to space,
set `lambda t: t.replace("_", " ")`.
track : Track
Track for tree visualization
"""
Expand Down Expand Up @@ -106,6 +111,8 @@ def __init__(
self._node2label_props: dict[str, dict[str, Any]] = defaultdict(lambda: {})
self._node2line_props: dict[str, dict[str, Any]] = defaultdict(lambda: {})

self._label_formatter: Callable[[str], str] | None = label_formatter

############################################################
# Properties
############################################################
Expand Down Expand Up @@ -617,6 +624,9 @@ def _plot_tree_label(self) -> None:
_text_kws.update(params)
_text_kws.update(self._node2label_props[label])

# Apply label text format function if defined
if self._label_formatter is not None:
label = self._label_formatter(label)
# Plot label if text size > 0
if float(_text_kws["size"]) > 0:
self.track.text(label, x, r, **_text_kws) # type: ignore
Loading

0 comments on commit 2e186d3

Please sign in to comment.