Metadata-Version: 2.4
Name: coverdraw
Version: 0.1.0
Summary: Protein sequence peptide coverage visualizer with PTM and amino acid substitution highlighting (SVG, PNG/JPG, HTML).
License: MIT
License-File: LICENSE
Keywords: proteomics,mass-spectrometry,peptide-coverage,proforma,visualization,svg
Author: Kirill Nikolsky
Author-email: kirill.s.nikolsky@yandex.ru
Requires-Python: >=3.10
Classifier: Development Status :: 4 - Beta
Classifier: Intended Audience :: Science/Research
Classifier: License :: OSI Approved :: MIT License
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.10
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Classifier: Programming Language :: Python :: 3.13
Classifier: Topic :: Scientific/Engineering :: Bio-Informatics
Requires-Dist: cairosvg (>=2.9.1,<3.0.0)
Requires-Dist: lxml (>=6.1.3,<7.0.0)
Requires-Dist: numpy (>=2.0.0,<2.3.0) ; python_version < "3.11"
Requires-Dist: numpy (>=2.0.0,<2.5.0) ; python_version == "3.11"
Requires-Dist: numpy (>=2.0.0,<3.0.0) ; python_version >= "3.12"
Requires-Dist: pillow (>=11.0.0,<13.0.0) ; python_version < "3.11"
Requires-Dist: pillow (>=11.0.0,<14.0.0) ; python_version >= "3.11"
Requires-Dist: pyteomics (>=5.0.2,<6.0.0)
Description-Content-Type: text/markdown

# coverdraw

`coverdraw` is a Python library that visualizes peptide coverage of a protein sequence identified in mass-spectrometry experiments, highlighting post-translational modifications (PTMs, ProForma notation) and amino acid substitutions (including insertions and deletions).

## Features

- Peptide coverage grid with PTM and amino-acid substitutions highlighting
- ProForma input notation for modified peptide sequences
- SVG / PNG / JPG / HTML output
- Embedded Roboto Mono font in SVG
- PSMs intensity levels

## Installation

```bash
pip install coverdraw
```

## Quick start

```python
from coverdraw import SeqCoverageBuilder

protein = "MPSSVSWGILLLAGLCCLVPVSLAEDPQGDAAQKTDTSHHDQDHPTFNKITPNLAEFAFSLYRQLAHQSNSTNIFFSPVSIATAFAMLSLGTKADTHDEILEGLNFNLTEIPEAQIHEGFQELLRTLNQPDSQLQLTTGNGLFLSEGLKLVDKFLEDVKKLYHSEAFTVNFGDTEEAKKQINDYVEKGTQGKIVDLVKELDRDTVFALVNYIFFKGKWERPFEVKDTEEEDFHVDQVTTVKVPMMKRLGMFNIQHCKKLSSWVLLMKYLGNATAIFFLPDEGKLQHLENELTHDIITKFLENEDRRSASLHLPKLSITGTYDLKSVLGQLGITKVFSNGADLSGVTEEAPLKLSKAVHKAVLTIDEKGTEAAGAMFLEAIPMSIPPEVKFNKPFVFLMIEQNTKSPLFMGKVVNPTQK"
builder = SeqCoverageBuilder(
    protein,
    ["LASWVLLMK", ("DTEEEDFHVDQVTTVK", "DTEEEDFHVDQVT[Phospho]TVK")],
    allowed_ptms=["Phospho"],
)
svg = builder.get_vector(aa_in_row=50)
png = builder.get_image(aa_in_row=50, format="png", width=1200)
jpg = builder.get_image(format="jpg", width=1200)
html = builder.get_html(font_size=20, headless=True)
```

## API

### `SeqCoverageBuilder(sequence, peptides, allowed_ptms=None, on_wrong_peptides="skip")`

- `sequence` — protein sequence (canonical one-letter amino acid codes; non-standard characters are replaced with `X`).
- `peptides` — list of peptide records: either a plain canonical sequence string, or a `(canonical, modified)` tuple where `modified` uses ProForma notation for PTMs and observed substitutions.
- `allowed_ptms` — list of allowed PTM names (case-insensitive). Defaults to `["Phospho"]`; pass `None` to allow all PTMs without filtering.
- `on_wrong_peptides` — behavior for invalid peptide records: `"skip"` (default, silently skip), `"warn"` (emit a `UserWarning` and skip), or `"raise"` (raise a `ValueError`).

### Methods

- `get_vector(aa_in_row=50)` — render the coverage grid as an SVG string (`str`), with the Roboto Mono font embedded as base64.
- `get_image(aa_in_row=50, format="png", width=800)` — rasterize the SVG into `png` or `jpg` bytes (`bytes`), scaled to the requested width.
- `get_html(font_size=20, headless=False)` — render as HTML (`str`): a full page when `headless=False`, or an embeddable `<div>` fragment with native `title` tooltips when `headless=True`.

### Color scheme

Cell background colors follow a strict priority order:

1. PTM present → `#7979ff` (blue)
2. Substitution present → `#ff7979` (red)
3. Covered by more than 1 PSM → `#00a100` (dark green)
4. Covered by exactly 1 PSM → `#00ff00` (green)
5. Not covered → transparent background

## License

MIT — see [LICENSE](LICENSE).
