Skip to content

Commit 0e7ef2d

Browse files
authored
Merge pull request #79 from moshi4/develop
Bump to v1.7.2
2 parents d9e4756 + 219e629 commit 0e7ef2d

24 files changed

+778
-389
lines changed

.pre-commit-config.yaml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,12 @@
22
# See https://pre-commit.com/hooks.html for more hooks
33
repos:
44
- repo: https://github.com/astral-sh/ruff-pre-commit
5-
rev: v0.6.4
5+
rev: v0.8.4
66
hooks:
77
- id: ruff
88
name: ruff lint check
9+
types_or: [python, pyi]
910
args: [--fix]
1011
- id: ruff-format
1112
name: ruff format check
13+
types_or: [python, pyi]

README.md

Lines changed: 38 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ API usage is described in each of the following sections in the [document](https
4848
- [Chord Diagram](https://moshi4.github.io/pyCirclize/chord_diagram/)
4949
- [Radar Chart](https://moshi4.github.io/pyCirclize/radar_chart/)
5050
- [Circos Plot (Genomics)](https://moshi4.github.io/pyCirclize/circos_plot/)
51+
- [Comparative Genomics](https://moshi4.github.io/pyCirclize/comparative_genomics/)
5152
- [Phylogenetic Tree](https://moshi4.github.io/pyCirclize/phylogenetic_tree/)
5253
- [Plot Tips](https://moshi4.github.io/pyCirclize/plot_tips/)
5354

@@ -108,37 +109,42 @@ gbk_fetch_data = fetch_genbank_by_accid("NC_002483")
108109
gbk = Genbank(gbk_fetch_data)
109110

110111
# Initialize Circos instance with genome size
111-
circos = Circos(sectors={gbk.name: gbk.range_size})
112+
sectors = gbk.get_seqid2size()
113+
space = 0 if len(sectors) == 1 else 2
114+
circos = Circos(sectors, space=space)
112115
circos.text(f"Escherichia coli K-12 plasmid F\n\n{gbk.name}", size=14)
113-
circos.rect(r_lim=(90, 100), fc="lightgrey", ec="none", alpha=0.5)
114-
sector = circos.sectors[0]
115-
116-
# Plot forward strand CDS
117-
f_cds_track = sector.add_track((95, 100))
118-
f_cds_feats = gbk.extract_features("CDS", target_strand=1)
119-
f_cds_track.genomic_features(f_cds_feats, plotstyle="arrow", fc="salmon", lw=0.5)
120-
121-
# Plot reverse strand CDS
122-
r_cds_track = sector.add_track((90, 95))
123-
r_cds_feats = gbk.extract_features("CDS", target_strand=-1)
124-
r_cds_track.genomic_features(r_cds_feats, plotstyle="arrow", fc="skyblue", lw=0.5)
125-
126-
# Plot 'gene' qualifier label if exists
127-
labels, label_pos_list = [], []
128-
for feat in gbk.extract_features("CDS"):
129-
start = int(feat.location.start)
130-
end = int(feat.location.end)
131-
label_pos = (start + end) / 2
132-
gene_name = feat.qualifiers.get("gene", [None])[0]
133-
if gene_name is not None:
134-
labels.append(gene_name)
135-
label_pos_list.append(label_pos)
136-
f_cds_track.xticks(label_pos_list, labels, label_size=6, label_orientation="vertical")
137-
138-
# Plot xticks (interval = 10 Kb)
139-
r_cds_track.xticks_by_interval(
140-
10000, outer=False, label_formatter=lambda v: f"{v/1000:.1f} Kb"
141-
)
116+
117+
seqid2features = gbk.get_seqid2features(feature_type="CDS")
118+
for sector in circos.sectors:
119+
# Setup track for features plot
120+
f_cds_track = sector.add_track((95, 100))
121+
f_cds_track.axis(fc="lightgrey", ec="none", alpha=0.5)
122+
r_cds_track = sector.add_track((90, 95))
123+
r_cds_track.axis(fc="lightgrey", ec="none", alpha=0.5)
124+
# Plot forward/reverse strand CDS
125+
features = seqid2features[sector.name]
126+
for feature in features:
127+
if feature.location.strand == 1:
128+
f_cds_track.genomic_features(feature, plotstyle="arrow", fc="salmon", lw=0.5)
129+
else:
130+
r_cds_track.genomic_features(feature, plotstyle="arrow", fc="skyblue", lw=0.5)
131+
132+
# Plot 'gene' qualifier label if exists
133+
labels, label_pos_list = [], []
134+
for feature in features:
135+
start = int(feature.location.start)
136+
end = int(feature.location.end)
137+
label_pos = (start + end) / 2
138+
gene_name = feature.qualifiers.get("gene", [None])[0]
139+
if gene_name is not None:
140+
labels.append(gene_name)
141+
label_pos_list.append(label_pos)
142+
f_cds_track.xticks(label_pos_list, labels, label_size=6, label_orientation="vertical")
143+
144+
# Plot xticks (interval = 10 Kb)
145+
r_cds_track.xticks_by_interval(
146+
10000, outer=False, label_formatter=lambda v: f"{v/1000:.1f} Kb"
147+
)
142148

143149
circos.savefig("example02.png")
144150
```
@@ -161,8 +167,8 @@ matrix_data = [
161167
]
162168
matrix_df = pd.DataFrame(matrix_data, index=row_names, columns=col_names)
163169

164-
# Initialize Circos from matrix for plotting Chord Diagram
165-
circos = Circos.initialize_from_matrix(
170+
# Initialize Circos instance for chord diagram plot
171+
circos = Circos.chord_diagram(
166172
matrix_df,
167173
space=5,
168174
cmap="tab10",

docs/chord_diagram.ipynb

Lines changed: 32 additions & 16 deletions
Large diffs are not rendered by default.

docs/circos_plot.ipynb

Lines changed: 152 additions & 122 deletions
Large diffs are not rendered by default.

docs/comparative_genomics.ipynb

Lines changed: 292 additions & 0 deletions
Large diffs are not rendered by default.

docs/getting_started.ipynb

Lines changed: 24 additions & 9 deletions
Large diffs are not rendered by default.

docs/index.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,5 +39,6 @@ API usage is described in each of the following sections.
3939
- [Chord Diagram](./chord_diagram/)
4040
- [Radar Chart](./radar_chart/)
4141
- [Circos Plot (Genomics)](./circos_plot/)
42+
- [Comparative Genomics](./comparative_genomics)
4243
- [Phylogenetic Tree](./phylogenetic_tree/)
4344
- [Plot Tips](./plot_tips/)

docs/plot_api_example.ipynb

Lines changed: 97 additions & 87 deletions
Large diffs are not rendered by default.

docs/plot_tips.ipynb

Lines changed: 14 additions & 15 deletions
Large diffs are not rendered by default.

docs/radar_chart.ipynb

Lines changed: 19 additions & 17 deletions
Large diffs are not rendered by default.

0 commit comments

Comments
 (0)