Skip to content

Repository files navigation

karyon

karyon

Genomic track plots for Rust. Composable tracks over a shared coordinate axis, rendered to standalone SVG.

CI License: MIT Rust 1.74+ Zero dependencies PathoGenOmics Lab

Paula Ruiz-Rodriguez1 and Mireia Coscolla1
1. I2SysBio, University of Valencia-CSIC, FISABIO Joint Research Unit Infection and Public Health, Valencia, Spain

General plotting libraries know about points and lines. They do not know that a position is a base, that a gene has a strand, that a pixel at genome scale covers two thousand bases, or that a figure is worthless if its tracks do not line up. karyon is the small amount of code that does know those things.

It draws what a genome browser draws: a stack of tracks over one shared coordinate axis, so read depth, the reference bases, the gene models and the variant calls all agree on where position 761,410 is.

A coverage profile with a dropout, the reference sequence, two gene models and variants coloured by consequence, all over one coordinate axis

Zoom in and the same tracks show individual bases. Nothing about the tracks changes, only the region:

The same locus at base resolution, with the reference sequence drawn as coloured letters

That figure is this much code:

use karyon::{plot, Feature, Strand, Variant};

let svg = plot("NC_000962.3:761000-761200")?
    .title("rpoB resistance determining region")
    .add_coverage(depth).label("depth")
    .add_sequence(bases).label("reference")
    .add_features(genes).label("genes")
    .add_variants(calls).label("variants")
    .to_svg();

Thirty-three track types compose that way, over one region, in the order you write them. No runtime dependencies, no I/O beyond an optional save_svg, and plain SVG 1.1 that opens unchanged in a browser, in Inkscape and in Illustrator.

Every kind of plot it draws, on one sheet
Every kind of plot karyon draws, on one sheet of twenty-two panels in three columns: a genomic stack, a read pileup, sequence logos, association statistics with a genotype matrix, a dotplot and synteny ribbons, a multiple sequence alignment, variable sites with a phylogeny, a tree, windowed statistics read against a baseline, a circular chromosome, raw nanopore signal, one locus compared across three genomes, Dam methylation across the E. coli origin of replication, an association scan across a whole draft assembly, structural variants as arcs between their breakpoints, the six reading frames, two trees face to face, a human imprinting control region read one molecule at a time, a coding sequence ruled in codons, one molecule aligned in three pieces, SARS-CoV-2 lineage deletions painted onto a phylogeny, and transcription units from start site to terminator

Where to go

The documentation is the manual; this page is the front door.

If you want to Go to
draw something in the next five minutes Quick start
find the plot that fits your data Plot catalogue, which sorts all thirty-three tracks by biological question rather than by type name
look up one track's exact API Track reference
read files instead of building vectors File formats: BED, bedGraph, GFF3, VCF, SAM, cytoBand, samtools depth, FASTA and Newick
draw trees, traits, support or dN/dS Phylogenetics
put samples on a map Geographic genomics
make it match the rest of your figures Theming and the visual system
use it from a shell instead of Rust Command line
know why a base lands where it does Coordinates, which is the one thing worth reading before trusting a figure
add a track type it lacks Extending, which is about thirty lines
copy a whole worked figure Recipes

Coordinates, in one paragraph

Positions are 0-based and half-open everywhere, the BED convention. The two exceptions are the ones a reader sees: locus strings such as NC_000962.3:761,000-763,000 are 1-based and inclusive, as samtools and IGV write them, and tick labels are printed the same way. karyon::read does that subtraction for you, and a property in the test suite checks that the same interval written as BED and as GFF3 comes back as the same two numbers. The coordinates page is the long version.

Installation

cargo install --git https://github.com/PathoGenOmics-Lab/karyon

Or as a library, until it is published to crates.io:

[dependencies]
karyon = { git = "https://github.com/PathoGenOmics-Lab/karyon" }

Building from source needs nothing but a Rust toolchain, 1.74 or newer:

git clone https://github.com/PathoGenOmics-Lab/karyon
cd karyon
cargo test

Roadmap

Not implemented yet, in the order they are likely to arrive:

  • A figure-level highlight and mask, one column running through every track, so a masked region is visible as a mask rather than as an absence of variants
  • PNG output, likely behind a feature flag so the default stays dependency-free
  • A release on crates.io

Contributing

Bug reports, questions and pull requests are all welcome. The contributing guide says what a change needs before it can be merged, and Q&A is the place for anything that is a question rather than a defect.

Citation

Please cite the tool and the formats it reads. The citation page has both.

License

MIT. See LICENSE.

A plotting library is meant to be a dependency, and a copyleft one cannot be used by a tool that is not itself copyleft. The formats it sits beside are permissive for the same reason: noodles and rust-bio are both MIT.


karyon is developed with ❤️ by:

Paula Ruiz-Rodriguez

💻 🔬 🤔 🔣 🎨 🔧

Mireia Coscolla

🔍 🤔 🧑‍🏫 🔬 📓

This project follows the all-contributors specification (emoji key).

About

Genomic track plots for Rust: composable tracks over a shared coordinate axis, rendered to standalone SVG with zero dependencies

Topics

Resources

Code of conduct

Contributing

Security policy

Stars

1 star

Watchers

0 watching

Forks

Releases

Packages

Used by

Contributors

Languages