Skip to content

Commit

Permalink
Merge pull request #79 from moshi4/develop
Browse files Browse the repository at this point in the history
Bump to v1.7.2
  • Loading branch information
moshi4 authored Dec 21, 2024
2 parents d9e4756 + 219e629 commit 0e7ef2d
Show file tree
Hide file tree
Showing 24 changed files with 778 additions and 389 deletions.
4 changes: 3 additions & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,12 @@
# See https://pre-commit.com/hooks.html for more hooks
repos:
- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.6.4
rev: v0.8.4
hooks:
- id: ruff
name: ruff lint check
types_or: [python, pyi]
args: [--fix]
- id: ruff-format
name: ruff format check
types_or: [python, pyi]
70 changes: 38 additions & 32 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ API usage is described in each of the following sections in the [document](https
- [Chord Diagram](https://moshi4.github.io/pyCirclize/chord_diagram/)
- [Radar Chart](https://moshi4.github.io/pyCirclize/radar_chart/)
- [Circos Plot (Genomics)](https://moshi4.github.io/pyCirclize/circos_plot/)
- [Comparative Genomics](https://moshi4.github.io/pyCirclize/comparative_genomics/)
- [Phylogenetic Tree](https://moshi4.github.io/pyCirclize/phylogenetic_tree/)
- [Plot Tips](https://moshi4.github.io/pyCirclize/plot_tips/)

Expand Down Expand Up @@ -108,37 +109,42 @@ gbk_fetch_data = fetch_genbank_by_accid("NC_002483")
gbk = Genbank(gbk_fetch_data)

# Initialize Circos instance with genome size
circos = Circos(sectors={gbk.name: gbk.range_size})
sectors = gbk.get_seqid2size()
space = 0 if len(sectors) == 1 else 2
circos = Circos(sectors, space=space)
circos.text(f"Escherichia coli K-12 plasmid F\n\n{gbk.name}", size=14)
circos.rect(r_lim=(90, 100), fc="lightgrey", ec="none", alpha=0.5)
sector = circos.sectors[0]

# Plot forward strand CDS
f_cds_track = sector.add_track((95, 100))
f_cds_feats = gbk.extract_features("CDS", target_strand=1)
f_cds_track.genomic_features(f_cds_feats, plotstyle="arrow", fc="salmon", lw=0.5)

# Plot reverse strand CDS
r_cds_track = sector.add_track((90, 95))
r_cds_feats = gbk.extract_features("CDS", target_strand=-1)
r_cds_track.genomic_features(r_cds_feats, plotstyle="arrow", fc="skyblue", lw=0.5)

# Plot 'gene' qualifier label if exists
labels, label_pos_list = [], []
for feat in gbk.extract_features("CDS"):
start = int(feat.location.start)
end = int(feat.location.end)
label_pos = (start + end) / 2
gene_name = feat.qualifiers.get("gene", [None])[0]
if gene_name is not None:
labels.append(gene_name)
label_pos_list.append(label_pos)
f_cds_track.xticks(label_pos_list, labels, label_size=6, label_orientation="vertical")

# Plot xticks (interval = 10 Kb)
r_cds_track.xticks_by_interval(
10000, outer=False, label_formatter=lambda v: f"{v/1000:.1f} Kb"
)

seqid2features = gbk.get_seqid2features(feature_type="CDS")
for sector in circos.sectors:
# Setup track for features plot
f_cds_track = sector.add_track((95, 100))
f_cds_track.axis(fc="lightgrey", ec="none", alpha=0.5)
r_cds_track = sector.add_track((90, 95))
r_cds_track.axis(fc="lightgrey", ec="none", alpha=0.5)
# Plot forward/reverse strand CDS
features = seqid2features[sector.name]
for feature in features:
if feature.location.strand == 1:
f_cds_track.genomic_features(feature, plotstyle="arrow", fc="salmon", lw=0.5)
else:
r_cds_track.genomic_features(feature, plotstyle="arrow", fc="skyblue", lw=0.5)

# Plot 'gene' qualifier label if exists
labels, label_pos_list = [], []
for feature in features:
start = int(feature.location.start)
end = int(feature.location.end)
label_pos = (start + end) / 2
gene_name = feature.qualifiers.get("gene", [None])[0]
if gene_name is not None:
labels.append(gene_name)
label_pos_list.append(label_pos)
f_cds_track.xticks(label_pos_list, labels, label_size=6, label_orientation="vertical")

# Plot xticks (interval = 10 Kb)
r_cds_track.xticks_by_interval(
10000, outer=False, label_formatter=lambda v: f"{v/1000:.1f} Kb"
)

circos.savefig("example02.png")
```
Expand All @@ -161,8 +167,8 @@ matrix_data = [
]
matrix_df = pd.DataFrame(matrix_data, index=row_names, columns=col_names)

# Initialize Circos from matrix for plotting Chord Diagram
circos = Circos.initialize_from_matrix(
# Initialize Circos instance for chord diagram plot
circos = Circos.chord_diagram(
matrix_df,
space=5,
cmap="tab10",
Expand Down
48 changes: 32 additions & 16 deletions docs/chord_diagram.ipynb

Large diffs are not rendered by default.

274 changes: 152 additions & 122 deletions docs/circos_plot.ipynb

Large diffs are not rendered by default.

292 changes: 292 additions & 0 deletions docs/comparative_genomics.ipynb

Large diffs are not rendered by default.

33 changes: 24 additions & 9 deletions docs/getting_started.ipynb

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions docs/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,5 +39,6 @@ API usage is described in each of the following sections.
- [Chord Diagram](./chord_diagram/)
- [Radar Chart](./radar_chart/)
- [Circos Plot (Genomics)](./circos_plot/)
- [Comparative Genomics](./comparative_genomics)
- [Phylogenetic Tree](./phylogenetic_tree/)
- [Plot Tips](./plot_tips/)
184 changes: 97 additions & 87 deletions docs/plot_api_example.ipynb

Large diffs are not rendered by default.

29 changes: 14 additions & 15 deletions docs/plot_tips.ipynb

Large diffs are not rendered by default.

36 changes: 19 additions & 17 deletions docs/radar_chart.ipynb

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions mkdocs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ nav:
- Chord Diagram: chord_diagram.ipynb
- Radar Chart: radar_chart.ipynb
- Circos Plot (Genomics): circos_plot.ipynb
- Comparative Genomics: comparative_genomics.ipynb
- Phylogenetic Tree: phylogenetic_tree.ipynb
- Plot Tips: plot_tips.ipynb
- API Docs:
Expand Down
2 changes: 2 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,8 @@ dev-dependencies = [
"mkdocs-jupyter>=0.21.0",
"mkdocs-material>=8.2",
"black>=22.3.0",
# additional
"pygenomeviz>=1.5.0",
]

[tool.pytest.ini_options]
Expand Down
Loading

0 comments on commit 0e7ef2d

Please sign in to comment.