Skip to main content

csdb2snfg

PyPI Version PyPI Downloads Bioconda Version Bioconda Downloads

Convert CSDB linear notation to SNFG (Symbol Nomenclature for Glycans) diagrams.

Features

  • Parse CSDB linear strings into structured AST (JSON output)
  • Render SNFG diagrams as PNG/SVG images
  • Export PowerPoint (PPTX) with vector shapes
  • Supports branching, repeating units (/n=N/, expanded or compact [unit]n display), modifiers (Me, Ac)

Current Limitations

  • Only standard CSDB syntax and repeating units (/n=N/) are supported. Fuzzy/XOR alternatives (<...|...>, <<...|...>>) are not yet supported.
  • Only orthogonal (horizontal/vertical) chain layout is supported. Diagonal or angled linkages are not available.

Installation

From PyPI (stable):

pip install glyco-csdb2snfg

With uv:

# Install as a global CLI tool
uv tool install glyco-csdb2snfg

# Or run directly without installing
uvx --from glyco-csdb2snfg csdb2snfg parse -c="-4)βDGlcp(1-4)αDGlcp(1-"

From source:

pip install git+https://github.com/sosyphe/glyco-csdb2snfg.git

Development (uv)

This project uses uv for dependency management (pyproject.toml + uv.lock).

git clone https://github.com/sosyphe/glyco-csdb2snfg.git
cd glyco-csdb2snfg

# Create .venv and install all dependencies (including dev extras)
uv sync --extra dev

# Run the CLI inside the project environment
uv run csdb2snfg --version

Quick Start

# Render to PNG
csdb2snfg image -c="-4)βDGlcp(1-4)βDGlcp(1-4)αDGlcp(1-" --format png -o output/

# Export to PowerPoint
csdb2snfg pptx -c="-4)βDGalp(1-4)βDGalp(1-3)αDGalp(1-" -o output/

# Parse to JSON AST
csdb2snfg parse -c="-4)βDGlcp(1-4)αDGlcp(1-"

# Repeating unit in compact mode ([unit]n instead of expanding)
csdb2snfg image -c="-4)βDGalp(1-4)/βDGalp(1-4)/n=3/βDGalp(1-4)αDGlcp(1-" --compact-repeat -o output/

# Batch processing (one CSDB string per line, # for comments)
csdb2snfg image -f glycans.txt --format png -o output/

Note: Use -c="..." (with =) to prevent argparse from treating the leading - as a flag.

Python API

from csdb2snfg import parse_csdb_linear, draw_snfg, generate_snfg_pptx

tree = parse_csdb_linear("-4)βDGlcp(1-4)αDGlcp(1-")

# Render to matplotlib figure
fig, ax = draw_snfg(tree)
fig.savefig("glycan.png", dpi=300, bbox_inches="tight")

# Save SVG directly
draw_snfg(tree, save_svg="glycan.svg")

# Export to PowerPoint
buf = generate_snfg_pptx(["-4)βDGlcp(1-4)αDGlcp(1-"])
with open("glycans.pptx", "wb") as f:
    f.write(buf.read())

Examples

Simple linear chain

-4)βDGlcp(1-4)βDGlcp(1-4)βDGlcp(1-4)αDGlcp(1-

Branched unit

-4)[βDGalp(1-6)]αDManp(1-4)[βDGalp(1-3)]αDManp(1-4)βDGlcNAcp(1-4)βDGlcNAcp(1-

Repeating unit (/n=3/)

-4)βDGalp(1-4)/βDGalp(1-4)/n=3/βDGalp(1-4)αDGlcp(1-

The image above shows the compact display: the repeat unit is drawn once with an n= annotation. The CLI expands the unit N times by default — pass --compact-repeat for the compact display (which is the default in the Python API: draw_snfg(tree, compact_repeat=True)).

With modifiers (Me, Ac)

-4)[Me(1-3)]αDGalp(1-6)[Ac(1-3)]αDGalp(1-6)αDGalp(1-

Complex multi-branched

-3)[[αDGalp(1-6)]αLArap(1-3)αLAraf(1-6)]βDGalp(1-3)[Me(1-4)βDGalp(1-4)βDGalp(1-6)]βDGalp(1-3)[αLAraf(1-4)βDXylp(1-6)]βDGalp(1-3)[αLAraf(1-4)βDManp(1-6)]βDGalp(1-3)βDGalp(1-3)βDGlcp(1-

License

MIT License - see LICENSE for details.

Metadata

Release files for glyco-csdb2snfg 0.2.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for glyco-csdb2snfg 0.2.0
File Size Uploaded
glyco_csdb2snfg-0.2.0.tar.gz 35.9 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for glyco-csdb2snfg 0.2.0
File Interpreter ABI Platform
glyco_csdb2snfg-0.2.0-py3-none-any.whl Python 3 none any Details

Total release size: 77.7 kB

Release files / glyco_csdb2snfg-0.2.0.tar.gz

Download URL glyco_csdb2snfg-0.2.0.tar.gz
Size 35.9 kB
Tags Source
SHA-256 checksum
How to use checksums
d509fbd0d7ba227879437aa03728c4cd827a15f9cc2ee6a9b9e98b5c78656b13
BLAKE2b-256 checksum
How to use checksums
433229d2606a30ae0fb103544da3e9a99e83a67049a997d258b73cce6efc4ca3
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Oct 8, 2026.

Transparency log

Release files / glyco_csdb2snfg-0.2.0-py3-none-any.whl

Download URL glyco_csdb2snfg-0.2.0-py3-none-any.whl
Size 41.8 kB
Tags Python 3
SHA-256 checksum
How to use checksums
e26c72b51e1d66ce298b563276b9cf3c054a581c6c84e639f4912d5e1a2da4bf
BLAKE2b-256 checksum
How to use checksums
eaaf8f12b390776ac6c0076f2138f3432a02df56e8a3e6fa750119f20805164c
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Oct 8, 2026.

Transparency log

Release history Release notifications | RSS feed

This release

0.2.0 This release

2 release files

0.1.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page