Skip to main content

rtemis-a3

Python implementation of the Amino Acid Annotation (A3) format — a structured JSON format for amino acid sequences with site, region, PTM, processing, and variant annotations.

Part of the rtemis-org/a3 monorepo, which provides A3 implementations in Python, TypeScript, R, Julia, and Rust.

Installation

pip install rtemis-a3
# or with uv
uv add rtemis-a3

Quick Start

from rtemis.a3 import create_a3

a3 = create_a3(
    "MKTAYIAKQR",
    site={
        "Active site": {"index": [3, 5], "type": "activeSite"},
    },
    region={
        "Repeat 1": {"index": [[1, 4]], "type": ""},
    },
    ptm={
        "Phosphorylation": {"index": [7], "type": ""},
    },
    variant=[{"position": 3, "from": "K", "to": "R"}],
    metadata={
        "uniprot_id":  "P12345",
        "description": "Example protein",
        "organism":    "Homo sapiens",
    },
)

len(a3.sequence)   # 10

Parsing JSON

from rtemis.a3 import a3_from_json, A3ValidationError, A3ParseError

try:
    a3 = a3_from_json(json_string)
except A3ValidationError as e:
    print(e.errors)  # list of Pydantic error dicts with field paths
except A3ParseError as e:
    print(e)         # malformed JSON

File I/O

from rtemis.a3 import read_a3json, write_a3json

a3 = read_a3json("protein.json")
write_a3json(a3, "output.json", indent=2)

Serialization

from rtemis.a3 import a3_to_json

json_string = a3_to_json(a3)           # compact
json_string = a3_to_json(a3, indent=2) # pretty-printed

Wire Format

{
  "$schema":    "https://schema.rtemis.org/a3/v1/schema.json",
  "a3_version": "1.0.0",
  "sequence":   "MKTAYIAKQR",
  "annotations": {
    "site":       { "Active site": { "index": [3, 5],   "type": "activeSite" } },
    "region":     { "Repeat 1":    { "index": [[1, 4]], "type": "" } },
    "ptm":        { "Phospho":     { "index": [7],      "type": "" } },
    "processing": {},
    "variant":    [{ "position": 3, "from": "K", "to": "R" }]
  },
  "metadata": {
    "uniprot_id":  "P12345",
    "description": "Example protein",
    "reference":   "",
    "organism":    "Homo sapiens"
  }
}

All five annotation families are always present in output. Each annotation entry is { index, type } — bare arrays are rejected. Positions are 1-based, sorted, and deduplicated. Ranges are [start, end] pairs (start < end), sorted by start; overlapping ranges are rejected.

API

Construction

Function Description
create_a3(sequence, *, site, region, ptm, processing, variant, metadata) Build and validate an A3 object

Queries

Function Description
residue_at(a3, position) Residue at a 1-based position; raises ValueError if out of bounds
variants_at(a3, position) All variant records at a 1-based position

Serialization / I/O

Function Description
a3_from_json(text) Parse a JSON string into an A3 object
a3_to_json(a3, *, indent) Serialize an A3 object to a JSON string
read_a3json(path) Read an A3 JSON file from disk
write_a3json(a3, path, *, indent) Write an A3 object to a JSON file

Pydantic Model Hierarchy

A3
 ├── sequence:    str
 ├── annotations: A3Annotations
 │   ├── site:        dict[str, SiteEntry]    (position index)
 │   ├── region:      dict[str, RegionEntry]  (range index)
 │   ├── ptm:         dict[str, FlexEntry]    (position or range index)
 │   ├── processing:  dict[str, FlexEntry]    (position or range index)
 │   └── variant:     list[VariantRecord]
 └── metadata:    A3Metadata
     ├── uniprot_id, description, reference, organism

All models are immutable (frozen=True). Users never construct them directly — use create_a3 or a3_from_json instead.

Canonical Schema

See specs/a3.md for the language-agnostic specification and specs/A3_Pydantic.md for Pydantic-specific design notes.

License

MPL-2.0

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

rtemis_a3-0.2.0.tar.gz (23.0 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

rtemis_a3-0.2.0-py3-none-any.whl (27.3 kB view details)

Uploaded Python 3

File details

Details for the file rtemis_a3-0.2.0.tar.gz.

File metadata

  • Download URL: rtemis_a3-0.2.0.tar.gz
  • Upload date:
  • Size: 23.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.12.2 {"installer":{"name":"uv","version":"0.12.2","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"macOS","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

File hashes

Hashes for rtemis_a3-0.2.0.tar.gz
Algorithm Hash digest
SHA256 6c601c60e5ffa53f51f7b563d1a50815b4560b58897308609a460cea81a1ab7c
MD5 75024334c3cd0bf567254f4ab353495f
BLAKE2b-256 2e2ecd29850e82fdf7784b1d6201e0d57502ac1ecd8e84d66f0fc26bb2919128

See more details on using hashes here.

File details

Details for the file rtemis_a3-0.2.0-py3-none-any.whl.

File metadata

  • Download URL: rtemis_a3-0.2.0-py3-none-any.whl
  • Upload date:
  • Size: 27.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.12.2 {"installer":{"name":"uv","version":"0.12.2","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"macOS","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

File hashes

Hashes for rtemis_a3-0.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 e4574ed604ecc3ec7fe37226437abe7d498cdbae9c11a67962040a7f843ad578
MD5 6b3dd6d53b93f93ec1af29abaaae0c3a
BLAKE2b-256 1cf5e23aebdeb9051f551d5bc6535b6c117bb3c4fb1d0c13585959be2d2aa9a1

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page