@rtemis/a3 0.1.0 → 0.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +149 -0
- package/package.json +2 -2
package/README.md
ADDED
|
@@ -0,0 +1,149 @@
|
|
|
1
|
+
# @rtemis/a3
|
|
2
|
+
|
|
3
|
+
TypeScript implementation of the **Amino Acid Annotation (A3)** format —
|
|
4
|
+
a structured JSON format for amino acid sequences with site, region, PTM,
|
|
5
|
+
processing, and variant annotations.
|
|
6
|
+
|
|
7
|
+
Part of the [rtemis-org/a3](https://github.com/rtemis-org/a3) monorepo.
|
|
8
|
+
|
|
9
|
+
## Installation
|
|
10
|
+
|
|
11
|
+
```bash
|
|
12
|
+
npm install @rtemis/a3
|
|
13
|
+
# or
|
|
14
|
+
pnpm add @rtemis/a3
|
|
15
|
+
```
|
|
16
|
+
|
|
17
|
+
## Quick Start
|
|
18
|
+
|
|
19
|
+
```ts
|
|
20
|
+
import { A3 } from "@rtemis/a3"
|
|
21
|
+
|
|
22
|
+
const a3 = new A3({
|
|
23
|
+
sequence: "MKTAYIAKQR",
|
|
24
|
+
annotations: {
|
|
25
|
+
site: {
|
|
26
|
+
"Active site": { index: [3, 5], type: "activeSite" },
|
|
27
|
+
},
|
|
28
|
+
region: {
|
|
29
|
+
"Repeat 1": { index: [[1, 4]], type: "" },
|
|
30
|
+
},
|
|
31
|
+
ptm: {
|
|
32
|
+
Phosphorylation: { index: [7], type: "" },
|
|
33
|
+
},
|
|
34
|
+
processing: {},
|
|
35
|
+
variant: [{ position: 3, from: "K", to: "R" }],
|
|
36
|
+
},
|
|
37
|
+
metadata: {
|
|
38
|
+
uniprot_id: "P12345",
|
|
39
|
+
description: "Example protein",
|
|
40
|
+
reference: "",
|
|
41
|
+
organism: "Homo sapiens",
|
|
42
|
+
},
|
|
43
|
+
})
|
|
44
|
+
|
|
45
|
+
a3.length // 10
|
|
46
|
+
a3.residueAt(1) // "M"
|
|
47
|
+
a3.toJSONString() // canonical JSON string
|
|
48
|
+
```
|
|
49
|
+
|
|
50
|
+
## Parsing JSON
|
|
51
|
+
|
|
52
|
+
```ts
|
|
53
|
+
import { A3, A3ValidationError } from "@rtemis/a3"
|
|
54
|
+
|
|
55
|
+
try {
|
|
56
|
+
const a3 = A3.fromJSONText(jsonString)
|
|
57
|
+
} catch (e) {
|
|
58
|
+
if (e instanceof A3ValidationError) {
|
|
59
|
+
console.error(e.issues) // Zod issue array with field paths
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
```
|
|
63
|
+
|
|
64
|
+
## File I/O (Node.js)
|
|
65
|
+
|
|
66
|
+
```ts
|
|
67
|
+
import { readJSON, writeJSON } from "@rtemis/a3"
|
|
68
|
+
|
|
69
|
+
const a3 = await readJSON("./protein.json")
|
|
70
|
+
await writeJSON(a3, "./output.json")
|
|
71
|
+
```
|
|
72
|
+
|
|
73
|
+
## Wire Format
|
|
74
|
+
|
|
75
|
+
```json
|
|
76
|
+
{
|
|
77
|
+
"sequence": "MKTAYIAKQR",
|
|
78
|
+
"annotations": {
|
|
79
|
+
"site": { "Active site": { "index": [3, 5], "type": "activeSite" } },
|
|
80
|
+
"region": { "Repeat 1": { "index": [[1, 4]], "type": "" } },
|
|
81
|
+
"ptm": { "Phospho": { "index": [7], "type": "" } },
|
|
82
|
+
"processing": {},
|
|
83
|
+
"variant": [{ "position": 3, "from": "K", "to": "R" }]
|
|
84
|
+
},
|
|
85
|
+
"metadata": {
|
|
86
|
+
"uniprot_id": "P12345",
|
|
87
|
+
"description": "Example protein",
|
|
88
|
+
"reference": "",
|
|
89
|
+
"organism": "Homo sapiens"
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
```
|
|
93
|
+
|
|
94
|
+
All five annotation families are always present in output. Each annotation
|
|
95
|
+
entry is `{ index, type }` — bare arrays are rejected. Positions are
|
|
96
|
+
1-based, sorted, and deduplicated. Ranges are `[start, end]` pairs
|
|
97
|
+
(`start < end`), sorted by start; overlapping ranges are rejected.
|
|
98
|
+
|
|
99
|
+
## API
|
|
100
|
+
|
|
101
|
+
### `new A3(input)` / `A3.fromData(input)`
|
|
102
|
+
|
|
103
|
+
Construct and validate. Throws `A3ValidationError` if input is invalid.
|
|
104
|
+
|
|
105
|
+
### `A3.fromJSONText(text)`
|
|
106
|
+
|
|
107
|
+
Parse a JSON string and validate. Throws `A3ParseError` on invalid JSON,
|
|
108
|
+
`A3ValidationError` on schema violations.
|
|
109
|
+
|
|
110
|
+
### `a3.length`
|
|
111
|
+
|
|
112
|
+
Number of residues in the sequence.
|
|
113
|
+
|
|
114
|
+
### `a3.residueAt(position)`
|
|
115
|
+
|
|
116
|
+
Return the residue at a 1-based position. Throws `RangeError` if out of bounds.
|
|
117
|
+
|
|
118
|
+
### `a3.variantsAt(position)`
|
|
119
|
+
|
|
120
|
+
Return all variant records at a given 1-based position.
|
|
121
|
+
|
|
122
|
+
### `a3.toData()`
|
|
123
|
+
|
|
124
|
+
Return the validated data object (frozen).
|
|
125
|
+
|
|
126
|
+
### `a3.toJSONString(indent?)`
|
|
127
|
+
|
|
128
|
+
Serialize to a JSON string. Default indent is 2; pass 0 for compact output.
|
|
129
|
+
|
|
130
|
+
### `JSON.stringify(a3)`
|
|
131
|
+
|
|
132
|
+
Works directly — `toJSON()` is implemented.
|
|
133
|
+
|
|
134
|
+
## Exported Types
|
|
135
|
+
|
|
136
|
+
```ts
|
|
137
|
+
import type {
|
|
138
|
+
A3Data,
|
|
139
|
+
MetadataData,
|
|
140
|
+
VariantData,
|
|
141
|
+
SiteEntryData,
|
|
142
|
+
RegionEntryData,
|
|
143
|
+
FlexEntryData,
|
|
144
|
+
} from "@rtemis/a3"
|
|
145
|
+
```
|
|
146
|
+
|
|
147
|
+
## License
|
|
148
|
+
|
|
149
|
+
[MPL-2.0](https://www.mozilla.org/en-US/MPL/2.0/)
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@rtemis/a3",
|
|
3
|
-
"version": "0.1.
|
|
4
|
-
"description": "
|
|
3
|
+
"version": "0.1.1",
|
|
4
|
+
"description": "Amino Acid Annotation (A3) format — TypeScript implementation",
|
|
5
5
|
"license": "MPL-2.0",
|
|
6
6
|
"repository": {
|
|
7
7
|
"type": "git",
|