|
| 1 | +# Typshade |
| 2 | + |
| 3 | + |
| 4 | + |
| 5 | +Typshade is a Typst package for visualizing multiple sequence alignments in bioinformatics. |
| 6 | + |
| 7 | +It provides a Typst-native interface centered on `shade(...)`, offering a readable and composable way to render alignments, add annotations, and incorporate logos, structure tracks, and graph tracks. |
| 8 | + |
| 9 | +Inspired by [TeXshade](https://ctan.org/pkg/texshade), Typshade rethinks alignment visualization with a focus on clarity, composability, and a Typst-native user experience. |
| 10 | + |
| 11 | +## Why Typshade? |
| 12 | + |
| 13 | +TeXshade is powerful, but its UI reflects TeX: many global commands, implicit state, and order-sensitive setup before the alignment is rendered. Typshade keeps the feature set while making the source read like a figure specification. |
| 14 | + |
| 15 | +TeXshade style: |
| 16 | + |
| 17 | +```latex |
| 18 | +\begin{texshade}{alignment.msf} |
| 19 | + \shadingmode[similar]{identical} |
| 20 | + \shadingcolors{blues} |
| 21 | + \residuesperline{45} |
| 22 | + \setends{1}{80..125} |
| 23 | + \showruler{top}{1} |
| 24 | + \rulersteps{10} |
| 25 | + \showconsensus{bottom} |
| 26 | + \showsequencelogo{top} |
| 27 | + \shaderegion{1}{NPA}{White}{BrickRed} |
| 28 | + \feature{top}{1}{NXX[ST]N}{box[Yellow]}{motif} |
| 29 | +\end{texshade} |
| 30 | +``` |
| 31 | + |
| 32 | +Typshade style: |
| 33 | + |
| 34 | +```typst |
| 35 | +#let alignment = read("alignment.msf", encoding: none) |
| 36 | +
|
| 37 | +#shade( |
| 38 | + alignment, |
| 39 | + format: "msf", |
| 40 | + figure: publication( |
| 41 | + similarity: "blues", |
| 42 | + region: "80..125", |
| 43 | + logo: "charge", |
| 44 | + motifs: ( |
| 45 | + "NPA": (bg: "BrickRed", text: "active site"), |
| 46 | + "NXX[ST]N": "motif", |
| 47 | + ), |
| 48 | + ), |
| 49 | +) |
| 50 | +``` |
| 51 | + |
| 52 | +The lower-level helpers are still available through `commands:` when you need precise control, but new documents can usually start from the kind of figure you want: publication figure, motif map, structure map, or logo analysis. |
| 53 | + |
| 54 | +## Quick Start |
| 55 | + |
| 56 | +```typst |
| 57 | +#import "@preview/typshade:0.1.2": * |
| 58 | +
|
| 59 | +#let alignment = read("alignment.msf", encoding: none) |
| 60 | +
|
| 61 | +#shade( |
| 62 | + alignment, |
| 63 | + format: "msf", |
| 64 | + theme: "screen", |
| 65 | + figure: motif-map(auto), |
| 66 | +) |
| 67 | +``` |
| 68 | + |
| 69 | +`read(..., encoding: none)` remains supported on Typst 0.15 and later. On Typst 0.15 or later, you can additionally pass a resolved project path and let Typshade read the source inside the package: |
| 70 | + |
| 71 | +```typst |
| 72 | +#shade(path("alignment.msf"), format: "msf", figure: motif-map(auto)) |
| 73 | +``` |
| 74 | + |
| 75 | +## Preview |
| 76 | + |
| 77 | +Protein alignment with similarity shading, motif annotations, a ruler, |
| 78 | +a conservation track, and a legend: |
| 79 | + |
| 80 | + |
| 81 | + |
| 82 | +Protein alignment with hydropathy-based functional coloring: |
| 83 | + |
| 84 | + |
| 85 | + |
| 86 | +Nucleotide alignment with DNA coloring, a sequence logo, a conservation track, |
| 87 | +and a ruler: |
| 88 | + |
| 89 | + |
| 90 | + |
| 91 | +## Typst-Native Helpers |
| 92 | + |
| 93 | +- `shade(...)`: Named-option alignment renderer for new documents. |
| 94 | +- `figure:`: Purpose-level recipe slot for complete figure designs. |
| 95 | +- `publication`, `motif-map`, `structure-map`, `logo-analysis`, `overview`: High-level recipes. |
| 96 | +- `similar`, `identical`, `diverse`, `functional`, `lines`, `window`, `ruler`, `consensus`, `logo`, `legend`: Compact command helpers. |
| 97 | +- `color-scheme`, `scoring-mode`, `sequence-window`: Small, readable option helpers. |
| 98 | +- `ruler-track`, `consensus-track`, `sequence-logo`, `subfamily-logo`, `legend-track`: Track helpers. |
| 99 | +- `structure-tracks(...)`: Adds topology/secondary-structure tracks from sidecar files. |
| 100 | +- `shade-preset("publication" | "overview" | "logo" | "functional" | "structure")`: Reusable command bundles. |
| 101 | +- `shade-theme("classic" | "print" | "screen" | "warm" | "nature")` and `visual-theme(...)`: Color/style bundles. |
| 102 | +- `highlight`, `tint`, `emphasize`, `mark`, `motif`, `graph`: Readable command builders for common annotations. |
| 103 | +- `pdb-point`, `pdb-line`, `pdb-plane`: Safer constructors for PDB selections. |
| 104 | +- `alignment-position("left" | "center" | "right")`: Overrides the default left-aligned block placement. |
| 105 | +- `alignment-summary(...)` and `selection-preview(...)`: In-document inspection helpers. |
| 106 | +- `sequence-list(...)` and `selection-table(...)`: Typst tables for data-aware reports. |
| 107 | +- `percent-identity(...)`, `percent-similarity(...)`, and `similarity-table(...)`: Pairwise identity/similarity analysis. |
| 108 | +- `alignment-data(...)` and `parse-alignment(...)`: Data access helpers for custom Typst logic. |
| 109 | + |
| 110 | +## TeXshade To Typshade |
| 111 | + |
| 112 | +| TeXshade idea | Typshade API | |
| 113 | +|---|---| |
| 114 | +| `texshade` environment | `shade(read("alignment.msf", encoding: none), format: "msf", figure: publication(...))`, or `shade(path("alignment.msf"), format: "msf", ...)` on Typst 0.15+ | |
| 115 | +| `shadingmode`, `shadingcolors`, `threshold` | `similar`, `identical`, `diverse`, `functional`, or `scoring-mode`, `color-scheme`, `threshold` | |
| 116 | +| `residuesperline`, `setends` | `lines`, `window`, or `residues-per-line`, `sequence-window` | |
| 117 | +| `shownames`, `shownumbering`, `showconsensus`, `showruler` | `names`, `numbers`, `consensus`, `ruler`, or the fine-grained track helpers | |
| 118 | +| `showsequencelogo`, `showsubfamilylogo`, `showlegend` | `logo`, `subfamily-logo`, `legend` | |
| 119 | +| `shaderegion`, `tintregion`, `emphregion`, `feature` | `highlight`, `tint`, `emphasize`, `mark`, `motif`, `graph` | |
| 120 | +| `includeDSSP`, `includeSTRIDE`, `includeHMMTOP`, `includePHD*` | `structure-tracks`, `dssp-track`, `stride-track`, `hmmtop-track`, `phd-topology-track`, `phd-secondary-track` | |
| 121 | +| font and spacing macros | `text-family`, `text-weight`, `text-posture`, `text-size`, `block-gap`, `feature-slot-space` | |
| 122 | + |
| 123 | +See [documentation](https://github.com/rice8y/typshade/blob/v0.1.2/docs/documentation.pdf) for the full guide and a larger correspondence table. |
| 124 | + |
| 125 | +## Smart Recipes |
| 126 | + |
| 127 | +Recipes inspect the alignment before rendering. For example, `motif-map(auto)` detects common motifs for the sequence type, focuses the region around them, chooses a readable line length, adds conservation when useful, and enables a logo only when the figure stays readable. Override any option when you need exact control. |
| 128 | + |
| 129 | +## Fine-Grained Control |
| 130 | + |
| 131 | +Macro-style command names are intentionally not part of the public API. Use Typst-shaped command helpers when you need detailed control: |
| 132 | + |
| 133 | +- Scoring: `threshold`, `weight-table`, `set-weight`, `gap-penalty`, `residue-style`, `functional-group`. |
| 134 | +- Tracks: `names-track`, `numbering-track`, `consensus-name`, `consensus-symbols`, `ruler-name`, `ruler-marker`, `logo-color`. |
| 135 | +- Sequence layout: `start-number`, `sequence-length`, `domain`, `hide-sequence`, `sequence-order`, `separation-line`. |
| 136 | +- Features and structure: `feature-rule`, `feature-text-label`, `backtranslation-label`, `show-structure-types`, `structure-appearance`, `stride-track`, `dssp-track`, `hmmtop-track`, `phd-topology-track`, `phd-secondary-track`. |
| 137 | +- Typography and spacing: `text-family`, `text-weight`, `text-posture`, `text-size`, `character-stretch`, `line-stretch`, `block-gap`, `feature-slot-space`. |
| 138 | + |
| 139 | +## Custom Control |
| 140 | + |
| 141 | +Use recipes when you know the purpose of the figure: |
| 142 | + |
| 143 | +```typst |
| 144 | +#let alignment = read("alignment.msf", encoding: none) |
| 145 | +
|
| 146 | +#shade( |
| 147 | + alignment, |
| 148 | + format: "msf", |
| 149 | + figure: publication( |
| 150 | + region: "80..125", |
| 151 | + logo: "charge", |
| 152 | + motifs: ( |
| 153 | + "NPA": (bg: "BrickRed", text: "active site"), |
| 154 | + "NXX[ST]N": "glycosylation", |
| 155 | + ), |
| 156 | + ), |
| 157 | +) |
| 158 | +``` |
| 159 | + |
| 160 | +Use `commands:` when you want to assemble visible parts yourself: |
| 161 | + |
| 162 | +```typst |
| 163 | +#let alignment = read("alignment.msf", encoding: none) |
| 164 | +
|
| 165 | +#shade( |
| 166 | + alignment, |
| 167 | + format: "msf", |
| 168 | + preset: "publication", |
| 169 | + theme: "screen", |
| 170 | + commands: ( |
| 171 | + similar(colors: "blues", threshold: 45), |
| 172 | + lines(45), |
| 173 | + window(1, "80..125"), |
| 174 | + ruler("top", sequence: 1, every: 10), |
| 175 | + consensus("bottom", name: "conservation"), |
| 176 | + logo("top", colors: "charge"), |
| 177 | + legend(), |
| 178 | + highlight(1, "NPA", bg: "BrickRed"), |
| 179 | + motif(1, "NXX[ST]N", text: "motif"), |
| 180 | + graph("bottom", 1, "all", "conservation", kind: "color", options: ("ColdHot",)), |
| 181 | + ), |
| 182 | +) |
| 183 | +``` |
| 184 | + |
| 185 | +You can also mix recipe output with explicit, reproducible helper lists: |
| 186 | + |
| 187 | +```typst |
| 188 | +#let alignment = read("alignment.msf", encoding: none) |
| 189 | +
|
| 190 | +#shade( |
| 191 | + alignment, |
| 192 | + format: "msf", |
| 193 | + figure: publication(region: "80..125"), |
| 194 | + commands: ( |
| 195 | + highlight(1, "NXX[DE][KR]XXQ", fg: "White", bg: "BrickRed"), |
| 196 | + sequence-logo(position: "top"), |
| 197 | + ), |
| 198 | +) |
| 199 | +``` |
| 200 | + |
| 201 | +# License |
| 202 | + |
| 203 | +This project is distributed under the GPL v2 License. See [LICENSE](LICENSE) for details. |
0 commit comments