Add --chinese (CJK) figure-label rendering, plus related fixes#849
Merged
Conversation
Add a global --chinese option (in set_image_options) that renders figure
labels in Chinese: it implies --notex and selects a CJK-capable font
(set_chinese_font / CJK_FONTS, cross-platform). markup() now degrades LaTeX
markup when usetex is off (\textit{} -> mathtext italic, strips *..*, \\,
\noindent) so labels stay readable without LaTeX.
Per-figure Chinese variants are wired through where the textbook figures are
generated: graphics.tree (geoscale era/axis names), graphics.dotplot (title),
graphics.karyotype, graphics.align demo, projects.misc waterlilyGOM,
projects.jcvi synteny, projects.napus fig3.
Also fixes several rendering issues found along the way:
- karyotype: restrict provided `sizes` to each track's seqids, otherwise every
track inherits the genome-wide total and the per-chromosome gauge/coverage
axes collapse (e.g. napus fig3 panel A).
- tree: align leaf tips at max_dist on geoscale trees so a rerooted outgroup
is drawn at the present instead of in the past.
- compara.ks: tolerate Biopython>=1.78 (Bio.Align.Applications removed) and
resolve PAML/PAL2NAL paths lazily so importing the module no longer prompts.
- graphics.align: integer slice indices in OpticalMapTrack.duplicate.
- projects.napus: modernize annotate() arrowprops (drop removed `frac` kwarg).
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01QEaqko1qcY3wLLB93giokq
Contributor
There was a problem hiding this comment.
Pull request overview
This PR adds an opt-in --chinese rendering mode for figure labels (disabling LaTeX and selecting CJK-capable fonts), and applies several rendering and correctness fixes discovered while producing Chinese versions of figures across the projects and graphics modules.
Changes:
- Introduces
--chineseas a global image option, selects CJK fonts, and improvesmarkup()behavior when LaTeX is disabled. - Wires Chinese label variants through multiple figure generators (tree geoscale labels, dotplot titles, several project figures).
- Fixes several independent issues (karyotype per-track sizing, geoscale tree tip alignment, Biopython compatibility scaffolding, align slice indices, arrowprops modernization).
Reviewed changes
Copilot reviewed 11 out of 11 changed files in this pull request and generated 3 comments.
Show a summary per file
| File | Description |
|---|---|
| src/jcvi/projects/napus.py | Adds Chinese template/labels for fig3 and adjusts label rendering to work without LaTeX. |
| src/jcvi/projects/misc.py | Adds Chinese label/file selection to waterlilyGOM() and passes Chinese flag into tree rendering. |
| src/jcvi/projects/jcvi.py | Updates synteny() theme setup to respect usetex, re-applies CJK font, and outputs in requested format. |
| src/jcvi/graphics/tree.py | Adds chinese flag support for geoscale labels and aligns geoscale leaf tips to present. |
| src/jcvi/graphics/karyotype.py | Fixes per-track sizes handling so tracks don’t inherit genome-wide totals. |
| src/jcvi/graphics/dotplot.py | Adds chinese flag and localizes default title text. |
| src/jcvi/graphics/coverage.py | Routes labels through markup() to render without LaTeX. |
| src/jcvi/graphics/base.py | Enhances markup() for non-LaTeX rendering and adds CJK font selection helpers. |
| src/jcvi/graphics/align.py | Fixes OpticalMapTrack.duplicate() to use integer slice indices; localizes demo headers. |
| src/jcvi/compara/ks.py | Attempts Biopython >= 1.78 import tolerance and makes PAML/PAL2NAL resolution lazy. |
| src/jcvi/apps/base.py | Adds global --chinese CLI option, implies --notex, and applies CJK font selection. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Comment on lines
197
to
200
| if plot_label: | ||
| label = labels_dict.get(label, label.capitalize()) | ||
| label = r"\textit{{{0}}}".format(label) | ||
| label = markup(r"\textit{{{0}}}".format(label)) | ||
| root.text(x - 0.015, yy + yinterval / 2, label, ha="right", va="center") |
Comment on lines
+19
to
+22
| try: | ||
| from Bio.Align.Applications import ClustalwCommandline, MuscleCommandline | ||
| except ImportError: # Biopython >= 1.78 removed the Applications command wrappers | ||
| ClustalwCommandline = MuscleCommandline = None |
Comment on lines
+386
to
+395
| if sizes: | ||
| # Restrict the provided sizes to this track's seqids; otherwise | ||
| # every track inherits the genome-wide total and the per-chr | ||
| # gauge/coverage axes collapse. | ||
| sz = dict((x, sizes[x]) for x in seqids if x in sizes) | ||
| else: | ||
| sz = dict( | ||
| (x, max(z.end for z in list(bed.sub_bed(x)))) for x in seqids | ||
| ) | ||
| assert sz, "sizes not available and cannot be inferred" |
…validation
- coverage: format track labels via the *..* convention so markup() produces
valid output under both latex (-> \textit) and --notex (-> mathtext italic);
previously a pre-formatted \textit{} string was latex-escaped and broke.
- markup: render *..* like \textit{} when usetex is off (mathtext italic for
ASCII, plain for CJK).
- compara.ks: replace the None fallback with minimal Clustalw/Muscle command
shims (build the command and run the binary) so call sites keep working on
Biopython >= 1.78 instead of failing with a NoneType TypeError.
- karyotype: when sizes is provided, validate every seqid has a size and fail
early with a clear message instead of a later KeyError in Track.draw.
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01QEaqko1qcY3wLLB93giokq
Owner
Author
|
Addressed all three review comments in c1e9c4b:
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Adds opt-in Chinese (CJK) label rendering for figures, plus several
rendering fixes uncovered while producing Chinese versions of the textbook
figures.
Feature:
--chinese--chineseoption inset_image_options. It implies--notex(LaTeX can't render CJK) and selects a CJK-capable font via the new
set_chinese_font()/CJK_FONTS(cross-platform: macOS / Windows / Linux).markup()now degrades LaTeX-only markup whenusetexis off:\textit{...}→ mathtext italic (ASCII) or plain (CJK), strips*..*,\noindent, and turns\\into a newline — so labels render without LaTeX.graphics.tree(geoscale era/axis names),
graphics.dotplot(title),graphics.karyotype,graphics.align demo, and the project figuresprojects.misc waterlilyGOM,projects.jcvi synteny,projects.napus fig3.Usage: add
--chineseto any of these commands (no separate--notexneeded).Fixes (independent of i18n)
sizesmapping to each track'sseqids.Previously every track inherited the genome-wide total, so per-chromosome
gauge/coverage axes collapsed (e.g. napus
fig3panel A).geoscaletrees, align leaf tips atmax_distso a rerootedoutgroup is drawn at the present rather than in the past.
Bio.Align.Applicationsremoved)and resolve PAML/PAL2NAL paths lazily so importing the module no longer
prompts for binaries that only
calcneeds.OpticalMapTrack.duplicate.annotate()arrowprops (drop the removedfrackwarg).Notes
already paper-specific;
waterlilyGOM/synteny/fig3read*.cnlabelfiles or use Chinese label dicts only under
--chinese.--chinese) is unchanged; thefixes apply regardless of language.
🤖 Generated with Claude Code
https://claude.ai/code/session_01QEaqko1qcY3wLLB93giokq