@fishka/seqio 0.1.0
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/LICENSE +201 -0
- package/README.md +62 -0
- package/dist/abif/index.d.mts +370 -0
- package/dist/abif/index.d.ts +370 -0
- package/dist/abif/index.js +2 -0
- package/dist/abif/index.js.map +1 -0
- package/dist/abif/index.mjs +2 -0
- package/dist/abif/index.mjs.map +1 -0
- package/dist/index.d.mts +1 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.js +2 -0
- package/dist/index.js.map +1 -0
- package/dist/index.mjs +2 -0
- package/dist/index.mjs.map +1 -0
- package/index.ts +1 -0
- package/package.json +82 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,201 @@
|
|
|
1
|
+
Apache License
|
|
2
|
+
Version 2.0, January 2004
|
|
3
|
+
http://www.apache.org/licenses/
|
|
4
|
+
|
|
5
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
6
|
+
|
|
7
|
+
1. Definitions.
|
|
8
|
+
|
|
9
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
10
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
11
|
+
|
|
12
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
13
|
+
the copyright owner that is granting the License.
|
|
14
|
+
|
|
15
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
16
|
+
other entities that control, are controlled by, or are under common
|
|
17
|
+
control with that entity. For the purposes of this definition,
|
|
18
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
19
|
+
direction or management of such entity, whether by contract or
|
|
20
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
21
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
22
|
+
|
|
23
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
24
|
+
exercising permissions granted by this License.
|
|
25
|
+
|
|
26
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
27
|
+
including but not limited to software source code, documentation
|
|
28
|
+
source, and configuration files.
|
|
29
|
+
|
|
30
|
+
"Object" form shall mean any form resulting from mechanical
|
|
31
|
+
transformation or translation of a Source form, including but
|
|
32
|
+
not limited to compiled object code, generated documentation,
|
|
33
|
+
and conversions to other media types.
|
|
34
|
+
|
|
35
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
36
|
+
Object form, made available under the License, as indicated by a
|
|
37
|
+
copyright notice that is included in or attached to the work
|
|
38
|
+
(an example is provided in the Appendix below).
|
|
39
|
+
|
|
40
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
41
|
+
form, that is based on (or derived from) the Work and for which the
|
|
42
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
43
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
44
|
+
of this License, Derivative Works shall not include works that remain
|
|
45
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
46
|
+
the Work and Derivative Works thereof.
|
|
47
|
+
|
|
48
|
+
"Contribution" shall mean any work of authorship, including
|
|
49
|
+
the original version of the Work and any modifications or additions
|
|
50
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
51
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
52
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
53
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
54
|
+
means any form of electronic, verbal, or written communication sent
|
|
55
|
+
to the Licensor or its representatives, including but not limited to
|
|
56
|
+
communication on electronic mailing lists, source code control systems,
|
|
57
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
58
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
59
|
+
excluding communication that is conspicuously marked or otherwise
|
|
60
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
61
|
+
|
|
62
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
63
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
64
|
+
subsequently incorporated within the Work.
|
|
65
|
+
|
|
66
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
67
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
68
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
69
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
70
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
71
|
+
Work and such Derivative Works in Source or Object form.
|
|
72
|
+
|
|
73
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
74
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
75
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
76
|
+
(except as stated in this section) patent license to make, have made,
|
|
77
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
78
|
+
where such license applies only to those patent claims licensable
|
|
79
|
+
by such Contributor that are necessarily infringed by their
|
|
80
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
81
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
82
|
+
institute patent litigation against any entity (including a
|
|
83
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
84
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
85
|
+
or contributory patent infringement, then any patent licenses
|
|
86
|
+
granted to You under this License for that Work shall terminate
|
|
87
|
+
as of the date such litigation is filed.
|
|
88
|
+
|
|
89
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
90
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
91
|
+
modifications, and in Source or Object form, provided that You
|
|
92
|
+
meet the following conditions:
|
|
93
|
+
|
|
94
|
+
(a) You must give any other recipients of the Work or
|
|
95
|
+
Derivative Works a copy of this License; and
|
|
96
|
+
|
|
97
|
+
(b) You must cause any modified files to carry prominent notices
|
|
98
|
+
stating that You changed the files; and
|
|
99
|
+
|
|
100
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
101
|
+
that You distribute, all copyright, patent, trademark, and
|
|
102
|
+
attribution notices from the Source form of the Work,
|
|
103
|
+
excluding those notices that do not pertain to any part of
|
|
104
|
+
the Derivative Works; and
|
|
105
|
+
|
|
106
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
107
|
+
distribution, then any Derivative Works that You distribute must
|
|
108
|
+
include a readable copy of the attribution notices contained
|
|
109
|
+
within such NOTICE file, excluding those notices that do not
|
|
110
|
+
pertain to any part of the Derivative Works, in at least one
|
|
111
|
+
of the following places: within a NOTICE text file distributed
|
|
112
|
+
as part of the Derivative Works; within the Source form or
|
|
113
|
+
documentation, if provided along with the Derivative Works; or,
|
|
114
|
+
within a display generated by the Derivative Works, if and
|
|
115
|
+
wherever such third-party notices normally appear. The contents
|
|
116
|
+
of the NOTICE file are for informational purposes only and
|
|
117
|
+
do not modify the License. You may add Your own attribution
|
|
118
|
+
notices within Derivative Works that You distribute, alongside
|
|
119
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
120
|
+
that such additional attribution notices cannot be construed
|
|
121
|
+
as modifying the License.
|
|
122
|
+
|
|
123
|
+
You may add Your own copyright statement to Your modifications and
|
|
124
|
+
may provide additional or different license terms and conditions
|
|
125
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
126
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
127
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
128
|
+
the conditions stated in this License.
|
|
129
|
+
|
|
130
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
131
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
132
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
133
|
+
this License, without any additional terms or conditions.
|
|
134
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
135
|
+
the terms of any separate license agreement you may have executed
|
|
136
|
+
with Licensor regarding such Contributions.
|
|
137
|
+
|
|
138
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
139
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
140
|
+
except as required for reasonable and customary use in describing the
|
|
141
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
142
|
+
|
|
143
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
144
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
145
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
146
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
147
|
+
implied, including, without limitation, any warranties or conditions
|
|
148
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
149
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
150
|
+
appropriateness of using or redistributing the Work and assume any
|
|
151
|
+
risks associated with Your exercise of permissions under this License.
|
|
152
|
+
|
|
153
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
154
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
155
|
+
unless required by applicable law (such as deliberate and grossly
|
|
156
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
157
|
+
liable to You for damages, including any direct, indirect, special,
|
|
158
|
+
incidental, or consequential damages of any character arising as a
|
|
159
|
+
result of this License or out of the use or inability to use the
|
|
160
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
161
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
162
|
+
other commercial damages or losses), even if such Contributor
|
|
163
|
+
has been advised of the possibility of such damages.
|
|
164
|
+
|
|
165
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
166
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
167
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
168
|
+
or other liability obligations and/or rights consistent with this
|
|
169
|
+
License. However, in accepting such obligations, You may act only
|
|
170
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
171
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
172
|
+
defend, and hold each Contributor harmless for any liability
|
|
173
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
174
|
+
of your accepting any such warranty or additional liability.
|
|
175
|
+
|
|
176
|
+
END OF TERMS AND CONDITIONS
|
|
177
|
+
|
|
178
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
179
|
+
|
|
180
|
+
To apply the Apache License to your work, attach the following
|
|
181
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
182
|
+
replaced with your own identifying information. (Don't include
|
|
183
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
184
|
+
comment syntax for the file format. We also recommend that a
|
|
185
|
+
file or class name and description of purpose be included on the
|
|
186
|
+
same "printed page" as the copyright notice for easier
|
|
187
|
+
identification within third-party archives.
|
|
188
|
+
|
|
189
|
+
Copyright [yyyy] [name of copyright owner]
|
|
190
|
+
|
|
191
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
192
|
+
you may not use this file except in compliance with the License.
|
|
193
|
+
You may obtain a copy of the License at
|
|
194
|
+
|
|
195
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
196
|
+
|
|
197
|
+
Unless required by applicable law or agreed to in writing, software
|
|
198
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
199
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
200
|
+
See the License for the specific language governing permissions and
|
|
201
|
+
limitations under the License.
|
package/README.md
ADDED
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
# @fishka/seqio
|
|
2
|
+
|
|
3
|
+
Sequencing I/O — parsers and writers for bioinformatics file formats.
|
|
4
|
+
|
|
5
|
+
Currently supports:
|
|
6
|
+
|
|
7
|
+
- **ABIF** (`.ab1` / `.abi`) — chromatogram traces produced by ABI Sanger / fragment analysis instruments. Lossless round-trip, browser- and Node-compatible.
|
|
8
|
+
|
|
9
|
+
Planned: SCF, FASTA, FASTQ.
|
|
10
|
+
|
|
11
|
+
## Install
|
|
12
|
+
|
|
13
|
+
```sh
|
|
14
|
+
npm install @fishka/seqio
|
|
15
|
+
```
|
|
16
|
+
|
|
17
|
+
## Use
|
|
18
|
+
|
|
19
|
+
### Quick parse (typed view + metadata)
|
|
20
|
+
|
|
21
|
+
```ts
|
|
22
|
+
import { parseAbif } from '@fishka/seqio/abif';
|
|
23
|
+
// or: import { parseAbif } from '@fishka/seqio';
|
|
24
|
+
|
|
25
|
+
const result = parseAbif(uint8ArrayOrArrayBuffer, 'sample.ab1');
|
|
26
|
+
|
|
27
|
+
result.baseCalls?.sequence; // "ACGT..."
|
|
28
|
+
result.baseCalls?.confidences; // [40, 38, 41, ...]
|
|
29
|
+
result.baseCalls?.positions; // [13, 25, 38, ...] sample-point peaks
|
|
30
|
+
result.chromatogram.basecalled.A; // raw int16 trace for the A channel
|
|
31
|
+
result.metadata.sampleName; // SMPL tag
|
|
32
|
+
result.metadata.samplingRate; // SPAC tag (falls back to PLOC-derived spacing)
|
|
33
|
+
```
|
|
34
|
+
|
|
35
|
+
### Low-level (entry-by-entry, round-trip)
|
|
36
|
+
|
|
37
|
+
```ts
|
|
38
|
+
import { readAbif, writeAbif, findEntry, upsertEntry } from '@fishka/seqio/abif';
|
|
39
|
+
import { setSequence, setConfidences, setPositions, setAveragePeakSpacing } from '@fishka/seqio/abif';
|
|
40
|
+
|
|
41
|
+
const file = readAbif(bytes);
|
|
42
|
+
setSequence(file, 'ACGT...');
|
|
43
|
+
setConfidences(file, [40, 38, 41, ...]);
|
|
44
|
+
setPositions(file, [13, 25, 38, ...]);
|
|
45
|
+
setAveragePeakSpacing(file, 12.5, 'my-basecaller');
|
|
46
|
+
const out = writeAbif(file);
|
|
47
|
+
```
|
|
48
|
+
|
|
49
|
+
## Features
|
|
50
|
+
|
|
51
|
+
- Browser- and Node-compatible (Uint8Array + DataView, no Node Buffer dependency).
|
|
52
|
+
- Lossless round-trip: every directory entry preserved as raw payload.
|
|
53
|
+
- MacBinary preamble support.
|
|
54
|
+
- BioPython-compatible declared-vs-computed dataSize clamp.
|
|
55
|
+
- PLOC read/written as unsigned int16 (preserves traces > 32k scans).
|
|
56
|
+
- SPAC accepts both float32 (spec) and long (legacy) element types.
|
|
57
|
+
- PCON/PLOC version fallback when PBAS2 ships without matching PCON2/PLOC2.
|
|
58
|
+
- `ensureRawDataChannels()` helper for older DATA1..8-only files.
|
|
59
|
+
|
|
60
|
+
## License
|
|
61
|
+
|
|
62
|
+
MIT
|
|
@@ -0,0 +1,370 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Low-level ABIF file model: a flat list of directory entries with raw
|
|
3
|
+
* payloads. Lossless round-trip is preserved: every entry (including unknown
|
|
4
|
+
* vendor tags) is kept as a raw payload, so a subsequent writeAbif() reproduces
|
|
5
|
+
* the same meaning.
|
|
6
|
+
*/
|
|
7
|
+
interface AbifFile {
|
|
8
|
+
/** ABIF version, e.g. 101 for v1.01. */
|
|
9
|
+
version: number;
|
|
10
|
+
/** Directory entries in the original on-disk order. */
|
|
11
|
+
entries: AbifEntry[];
|
|
12
|
+
/** MacBinary preamble offset (128 if present, 0 otherwise). Preserved for diagnostics. */
|
|
13
|
+
macBinaryOffset: number;
|
|
14
|
+
}
|
|
15
|
+
interface AbifEntry {
|
|
16
|
+
/** 4-character tag name, e.g. "DATA", "PBAS". */
|
|
17
|
+
tagName: string;
|
|
18
|
+
/** Tag number, e.g. 1 or 2 for PBAS1 / PBAS2. */
|
|
19
|
+
tagNumber: number;
|
|
20
|
+
/** ABIF element type code (1=byte, 2=char, 3=word, 4=short, 5=long, 7=float,
|
|
21
|
+
* 8=double, 10=date, 11=time, 13=bool, 18=pString, 19=cString,
|
|
22
|
+
* 1023=tdir, ≥1024=user-defined). */
|
|
23
|
+
elementType: number;
|
|
24
|
+
/** Bytes per element. */
|
|
25
|
+
elementSize: number;
|
|
26
|
+
/** Number of elements. */
|
|
27
|
+
elementCount: number;
|
|
28
|
+
/** Raw payload bytes (length === elementCount * elementSize). */
|
|
29
|
+
payload: Uint8Array;
|
|
30
|
+
/** Opaque dataHandle field, usually 0. Preserved for round-trip. */
|
|
31
|
+
dataHandle: number;
|
|
32
|
+
}
|
|
33
|
+
interface ChannelSignals {
|
|
34
|
+
A: number[];
|
|
35
|
+
C: number[];
|
|
36
|
+
G: number[];
|
|
37
|
+
T: number[];
|
|
38
|
+
}
|
|
39
|
+
/** Per-base chromatogram view. */
|
|
40
|
+
interface Chromatogram {
|
|
41
|
+
/** Per-base peak position in sample points (from PLOC). */
|
|
42
|
+
positions: number[];
|
|
43
|
+
/** Four channels of signal values, aligned with sample points. */
|
|
44
|
+
signals: ChannelSignals;
|
|
45
|
+
/** Per-base Phred-like quality scores (0..100), from PCON. */
|
|
46
|
+
confidences?: number[];
|
|
47
|
+
/** Average peak spacing (samples per base), from SPAC. */
|
|
48
|
+
samplingRate?: number;
|
|
49
|
+
}
|
|
50
|
+
/** Basecalls extracted from PBAS/PCON/PLOC under the chosen version. */
|
|
51
|
+
interface AbifBaseCalls {
|
|
52
|
+
/** Called bases (uppercase). */
|
|
53
|
+
sequence: string;
|
|
54
|
+
/** Per-base Q-score / confidence (PCON). */
|
|
55
|
+
confidences: number[];
|
|
56
|
+
/** Per-base peak positions in sample points (PLOC). */
|
|
57
|
+
positions: number[];
|
|
58
|
+
/** Which PBAS version was selected (1 or 2). */
|
|
59
|
+
pbasVersion: number;
|
|
60
|
+
}
|
|
61
|
+
/** Optional metadata extracted from well-known tags. */
|
|
62
|
+
interface AbifMetadata {
|
|
63
|
+
sampleName?: string;
|
|
64
|
+
laneNumber?: number;
|
|
65
|
+
tube?: string;
|
|
66
|
+
machineName?: string;
|
|
67
|
+
machineModel?: string;
|
|
68
|
+
runDate?: string;
|
|
69
|
+
runTime?: string;
|
|
70
|
+
samplingRate?: number;
|
|
71
|
+
comments: string[];
|
|
72
|
+
}
|
|
73
|
+
/** Full chromatogram bundle: all DATA channels, plus FWO_-aware A/C/G/T views. */
|
|
74
|
+
interface AbifChromatogramBundle {
|
|
75
|
+
/** FWO_ value (e.g. "GATC"). */
|
|
76
|
+
baseOrder: string;
|
|
77
|
+
/** All DATA tags by tagNumber → trace. */
|
|
78
|
+
dataChannels: Record<number, number[]>;
|
|
79
|
+
/** Basecalled traces (DATA9..12) mapped to A/C/G/T by FWO_. */
|
|
80
|
+
basecalled: ChannelSignals;
|
|
81
|
+
/** Raw traces (DATA1..4) mapped to A/C/G/T by FWO_. */
|
|
82
|
+
raw: ChannelSignals;
|
|
83
|
+
}
|
|
84
|
+
/** Rich result from {@link parseAbif} — everything the typical viewer needs. */
|
|
85
|
+
interface ParsedAbif {
|
|
86
|
+
fileName: string;
|
|
87
|
+
fileSize: number;
|
|
88
|
+
abifVersion: number;
|
|
89
|
+
macBinaryOffset: number;
|
|
90
|
+
dirEntryCount: number;
|
|
91
|
+
metadata: AbifMetadata;
|
|
92
|
+
chromatogram: AbifChromatogramBundle;
|
|
93
|
+
baseCalls?: AbifBaseCalls;
|
|
94
|
+
/** All directory entries with their decoded payloads (best-effort by type). */
|
|
95
|
+
entries: AbifDirEntry[];
|
|
96
|
+
}
|
|
97
|
+
/** A directory entry with a typed decoded value alongside the raw payload. */
|
|
98
|
+
interface AbifDirEntry {
|
|
99
|
+
/** 4-character tag name, e.g. "DATA". */
|
|
100
|
+
tag: string;
|
|
101
|
+
tagNumber: number;
|
|
102
|
+
elementType: number;
|
|
103
|
+
elementTypeName: string;
|
|
104
|
+
elementSize: number;
|
|
105
|
+
elementCount: number;
|
|
106
|
+
dataSize: number;
|
|
107
|
+
dataOffset: number;
|
|
108
|
+
inline: boolean;
|
|
109
|
+
decoded: AbifDecodedValue;
|
|
110
|
+
preview: string;
|
|
111
|
+
}
|
|
112
|
+
type AbifDecodedValue = {
|
|
113
|
+
kind: 'number';
|
|
114
|
+
value: number;
|
|
115
|
+
} | {
|
|
116
|
+
kind: 'numbers';
|
|
117
|
+
value: number[];
|
|
118
|
+
} | {
|
|
119
|
+
kind: 'string';
|
|
120
|
+
value: string;
|
|
121
|
+
} | {
|
|
122
|
+
kind: 'bools';
|
|
123
|
+
value: boolean[];
|
|
124
|
+
} | {
|
|
125
|
+
kind: 'date';
|
|
126
|
+
value: {
|
|
127
|
+
year: number;
|
|
128
|
+
month: number;
|
|
129
|
+
day: number;
|
|
130
|
+
};
|
|
131
|
+
} | {
|
|
132
|
+
kind: 'time';
|
|
133
|
+
value: {
|
|
134
|
+
hour: number;
|
|
135
|
+
minute: number;
|
|
136
|
+
second: number;
|
|
137
|
+
hsec: number;
|
|
138
|
+
};
|
|
139
|
+
} | {
|
|
140
|
+
kind: 'bytes';
|
|
141
|
+
value: Uint8Array;
|
|
142
|
+
} | {
|
|
143
|
+
kind: 'unknown';
|
|
144
|
+
value: Uint8Array;
|
|
145
|
+
};
|
|
146
|
+
|
|
147
|
+
declare function tagNameFromInt32(n: number): string;
|
|
148
|
+
|
|
149
|
+
/**
|
|
150
|
+
* Low-level ABIF reader/writer.
|
|
151
|
+
*
|
|
152
|
+
* Round-trip without loss: every directory entry (including unknown vendor
|
|
153
|
+
* tags) is preserved as a raw payload (Uint8Array). The high-level layer
|
|
154
|
+
* (view.ts, parser.ts) provides typed access on top of this.
|
|
155
|
+
*
|
|
156
|
+
* ABIF file layout:
|
|
157
|
+
* [0..3] "ABIF" magic
|
|
158
|
+
* [4..5] version (int16 BE; 101 = v1.01)
|
|
159
|
+
* [6..33] TdirEntry describing the directory itself
|
|
160
|
+
* [34..127] reserved (94 bytes, zero-filled)
|
|
161
|
+
* [...] directory block (N * 28-byte entries) and payload blocks
|
|
162
|
+
*
|
|
163
|
+
* TdirEntry (28 bytes, big-endian):
|
|
164
|
+
* off size field
|
|
165
|
+
* 0 4 tagName (ASCII)
|
|
166
|
+
* 4 4 tagNumber (int32)
|
|
167
|
+
* 8 2 elementType (int16)
|
|
168
|
+
* 10 2 elementSize (int16)
|
|
169
|
+
* 12 4 elementCount (int32)
|
|
170
|
+
* 16 4 dataSize (int32; total payload bytes; spec says count*size)
|
|
171
|
+
* 20 4 dataOffset (int32) OR inline data if dataSize <= 4
|
|
172
|
+
* 24 4 dataHandle (int32; usually 0)
|
|
173
|
+
*
|
|
174
|
+
* Inline rule (per ABIF spec): when count*size <= 4 the payload bytes are
|
|
175
|
+
* stored directly in the dataOffset field (left-aligned, padded to 4 bytes).
|
|
176
|
+
*
|
|
177
|
+
* MacBinary preamble: some ABIF files (older Mac-origin) start with a 128-byte
|
|
178
|
+
* MacBinary header before the actual ABIF magic. We detect and skip it.
|
|
179
|
+
*/
|
|
180
|
+
|
|
181
|
+
declare const HEADER_SIZE = 128;
|
|
182
|
+
declare const ENTRY_SIZE = 28;
|
|
183
|
+
/**
|
|
184
|
+
* Parse an ABIF file from raw bytes.
|
|
185
|
+
*
|
|
186
|
+
* Accepts Uint8Array (works in Node and the browser). Node's Buffer extends
|
|
187
|
+
* Uint8Array, so `readAbif(buffer)` and `readAbif(new Uint8Array(arrayBuffer))`
|
|
188
|
+
* both work.
|
|
189
|
+
*
|
|
190
|
+
* Throws if the magic header is missing. Does NOT require any specific tags
|
|
191
|
+
* (PBAS, DATA, ...) to be present — raw pre-basecalled files are supported.
|
|
192
|
+
*/
|
|
193
|
+
declare function readAbif(bytes: Uint8Array): AbifFile;
|
|
194
|
+
/**
|
|
195
|
+
* Serialize an AbifFile back to a Uint8Array.
|
|
196
|
+
*
|
|
197
|
+
* Layout produced: header (128 B) + directory (N*28 B) + payload block.
|
|
198
|
+
* External payloads are packed tightly in entry order. Inline payloads
|
|
199
|
+
* (count*size <= 4) live entirely inside their directory entry.
|
|
200
|
+
*
|
|
201
|
+
* The output is not bit-identical to the input if the original had a different
|
|
202
|
+
* physical layout (e.g. payloads before directory), but the *meaning*
|
|
203
|
+
* round-trips: readAbif(writeAbif(f)) reproduces the same entries structurally.
|
|
204
|
+
*
|
|
205
|
+
* MacBinary preamble is not preserved by writeAbif.
|
|
206
|
+
*/
|
|
207
|
+
declare function writeAbif(file: AbifFile): Uint8Array;
|
|
208
|
+
/** Find an entry by name+number, or undefined. */
|
|
209
|
+
declare function findEntry(file: AbifFile, name: string, number: number): AbifEntry | undefined;
|
|
210
|
+
/** Find all entries with the given tag name. */
|
|
211
|
+
declare function findEntries(file: AbifFile, name: string): AbifEntry[];
|
|
212
|
+
/**
|
|
213
|
+
* Replace the payload of an existing entry, or append a new one.
|
|
214
|
+
* elementType/elementSize/elementCount must be supplied for new entries.
|
|
215
|
+
*/
|
|
216
|
+
declare function upsertEntry(file: AbifFile, name: string, number: number, payload: Uint8Array, defaults: {
|
|
217
|
+
elementType: number;
|
|
218
|
+
elementSize: number;
|
|
219
|
+
elementCount: number;
|
|
220
|
+
}): void;
|
|
221
|
+
|
|
222
|
+
/**
|
|
223
|
+
* High-level typed view over an AbifFile.
|
|
224
|
+
*
|
|
225
|
+
* Reading helpers that interpret the raw payloads of well-known tags. For
|
|
226
|
+
* mutation helpers (setSequence, setConfidences, ...) see ./setters.
|
|
227
|
+
*/
|
|
228
|
+
|
|
229
|
+
/** Get DATA<n> as a signed-int16 array, or undefined. */
|
|
230
|
+
declare function getDataChannel(file: AbifFile, n: number): Int16Array | undefined;
|
|
231
|
+
/**
|
|
232
|
+
* Dye order, 4 ASCII chars (e.g. "GATC"). Defaults to "GATC" if FWO_ absent.
|
|
233
|
+
*
|
|
234
|
+
* GATC is the dye order produced by modern ABI 3730/3500 instruments and the
|
|
235
|
+
* dominant default in the wild. Older "ACGT" defaults caused channel
|
|
236
|
+
* mis-mapping on files where FWO_ is missing or malformed.
|
|
237
|
+
*/
|
|
238
|
+
declare function getFwo(file: AbifFile): string;
|
|
239
|
+
/**
|
|
240
|
+
* True when the file carries BOTH DATA1..4 and DATA9..12. Newer ABI-style
|
|
241
|
+
* instruments produce both: DATA1..4 is post-processed (mobility-corrected,
|
|
242
|
+
* baseline-subtracted, color-separated) and DATA9..12 is raw fluorescence.
|
|
243
|
+
* Older instruments produce only DATA1..4 (which IS the raw signal).
|
|
244
|
+
*
|
|
245
|
+
* Callers that re-process traces (basecallers) should detect this and bypass
|
|
246
|
+
* their own baseline-subtraction / color-matrix steps when DATA1..4 is
|
|
247
|
+
* already cleaned.
|
|
248
|
+
*/
|
|
249
|
+
declare function hasProcessedTraces(file: AbifFile): boolean;
|
|
250
|
+
/**
|
|
251
|
+
* Map from base letter ("A"|"C"|"G"|"T") to the DATA tag number that holds
|
|
252
|
+
* its RAW fluorescence channel.
|
|
253
|
+
*
|
|
254
|
+
* ABIF stores up to 12 DATA tags. KB-basecaller-aware instruments (3130, 3500,
|
|
255
|
+
* ...) use DATA1..4 for processed traces and DATA9..12 for raw. Older / simpler
|
|
256
|
+
* instruments produce only DATA1..8 where DATA1..4 ARE the raw traces.
|
|
257
|
+
*
|
|
258
|
+
* This helper always returns the DATA1..4 mapping (the convention used by
|
|
259
|
+
* basecallers operating on raw signal). Use {@link hasProcessedTraces} to
|
|
260
|
+
* detect whether DATA1..4 has been pre-processed and bypass baseline/color
|
|
261
|
+
* steps accordingly.
|
|
262
|
+
*
|
|
263
|
+
* The dye-to-channel order within each block is given by FWO_. If
|
|
264
|
+
* FWO_="GATC" then G→1, A→2, T→3, C→4.
|
|
265
|
+
*/
|
|
266
|
+
declare function getRawChannelMap(file: AbifFile): Record<'A' | 'C' | 'G' | 'T', number>;
|
|
267
|
+
/** Get PBAS sequence (prefer PBAS2 over PBAS1). undefined if neither present. */
|
|
268
|
+
declare function getSequence(file: AbifFile): string | undefined;
|
|
269
|
+
/**
|
|
270
|
+
* Get per-base Phred-like quality scores (0..255 byte values, typically 0..60
|
|
271
|
+
* for Sanger). Prefers PCON2 over PCON1.
|
|
272
|
+
*
|
|
273
|
+
* PCON is declared in the ABIF spec as elementType=2 (char) but the byte
|
|
274
|
+
* values ARE the Q-scores — we read raw bytes regardless of declared type.
|
|
275
|
+
*/
|
|
276
|
+
declare function getConfidences(file: AbifFile): number[] | undefined;
|
|
277
|
+
/**
|
|
278
|
+
* Get peak scan positions (one per base). Prefers PLOC2 over PLOC1.
|
|
279
|
+
*
|
|
280
|
+
* Read as UNSIGNED int16: PLOC indexes into the sample trace and is always
|
|
281
|
+
* non-negative, but values > 32767 (long traces) would wrap to negative
|
|
282
|
+
* if interpreted as signed.
|
|
283
|
+
*/
|
|
284
|
+
declare function getPositions(file: AbifFile): number[] | undefined;
|
|
285
|
+
/**
|
|
286
|
+
* Get average peak spacing (samples per base), from SPAC/1.
|
|
287
|
+
*
|
|
288
|
+
* ABIF spec defines SPAC as float32 (elementType=7); some legacy files
|
|
289
|
+
* mislabel it as long (type=5). Both are 4 bytes and on disk the payload
|
|
290
|
+
* is always a 32-bit float, so we read as float regardless of declared type.
|
|
291
|
+
*
|
|
292
|
+
* Returns undefined if SPAC is absent or non-positive.
|
|
293
|
+
*/
|
|
294
|
+
declare function getSamplingRate(file: AbifFile): number | undefined;
|
|
295
|
+
|
|
296
|
+
/**
|
|
297
|
+
* Mutation helpers for AbifFile: write PBAS/PCON/PLOC/SPAC and ensure DATA9..12
|
|
298
|
+
* are present. Used by basecallers to author ABIF output.
|
|
299
|
+
*/
|
|
300
|
+
|
|
301
|
+
/** Set PBAS2 (replaces if present). */
|
|
302
|
+
declare function setSequence(file: AbifFile, sequence: string): void;
|
|
303
|
+
/** Set PCON2 (replaces if present). Values clamped to [0, 255]. */
|
|
304
|
+
declare function setConfidences(file: AbifFile, q: ArrayLike<number>): void;
|
|
305
|
+
/**
|
|
306
|
+
* Set PLOC2 (replaces if present).
|
|
307
|
+
*
|
|
308
|
+
* Written as UNSIGNED int16 so positions up to 65535 are preserved on disk
|
|
309
|
+
* (signed int16 would wrap on traces with > 32k scans).
|
|
310
|
+
*/
|
|
311
|
+
declare function setPositions(file: AbifFile, positions: ArrayLike<number>): void;
|
|
312
|
+
/**
|
|
313
|
+
* Set SPAC/1, SPAC/2, SPAC/3 — the standard ABIF "average peak spacing" trio
|
|
314
|
+
* that KB-basecaller writes and downstream tools (BioPython, Sequencher,
|
|
315
|
+
* KB-aware viewers) expect:
|
|
316
|
+
*
|
|
317
|
+
* - SPAC/1 (float32) — average peak spacing used in last analysis.
|
|
318
|
+
* - SPAC/2 (pString) — basecaller name / identifier.
|
|
319
|
+
* - SPAC/3 (float32) — average peak spacing computed by the basecaller.
|
|
320
|
+
*
|
|
321
|
+
* Both float fields are written with the same value.
|
|
322
|
+
*/
|
|
323
|
+
declare function setAveragePeakSpacing(file: AbifFile, spacing: number, basecallerName: string): void;
|
|
324
|
+
/**
|
|
325
|
+
* Mean consecutive peak-to-peak distance in scans, from a positions array.
|
|
326
|
+
* Returns 0 when fewer than 2 positions are present.
|
|
327
|
+
*/
|
|
328
|
+
declare function averagePeakSpacing(positions: ArrayLike<number>): number;
|
|
329
|
+
/**
|
|
330
|
+
* Ensure DATA9..12 are present in the file. Many downstream consumers
|
|
331
|
+
* (BioPython-style readers, viewers) read the chromatogram signal from
|
|
332
|
+
* DATA9..12 by convention — these tags are the raw fluorescence on newer
|
|
333
|
+
* instruments. Older files that only carry DATA1..8 break those consumers
|
|
334
|
+
* with a "no signal" error after re-basecalling.
|
|
335
|
+
*
|
|
336
|
+
* We populate DATA9..12 by copying DATA1..4 (which on DATA1..8-only files IS
|
|
337
|
+
* the raw signal). The DATA1..4 tags are left untouched so any tool that
|
|
338
|
+
* reads them keeps working.
|
|
339
|
+
*
|
|
340
|
+
* No-op when DATA9..12 already exist.
|
|
341
|
+
*/
|
|
342
|
+
declare function ensureRawDataChannels(file: AbifFile): void;
|
|
343
|
+
|
|
344
|
+
/**
|
|
345
|
+
* High-level "parse everything" wrapper around the raw + view layers.
|
|
346
|
+
*
|
|
347
|
+
* Returns a single ParsedAbif object with metadata, the FWO_-aware
|
|
348
|
+
* basecalled / raw channel split, basecalls, and decoded directory entries
|
|
349
|
+
* for diagnostics. Mirrors what typical viewers (chromatogram UIs, sample
|
|
350
|
+
* inspectors) need from a single file.
|
|
351
|
+
*
|
|
352
|
+
* For round-trip authoring (basecallers), prefer {@link readAbif} +
|
|
353
|
+
* setters from ./setters which operate directly on the raw AbifFile.
|
|
354
|
+
*/
|
|
355
|
+
|
|
356
|
+
/**
|
|
357
|
+
* Parse an ABIF file into a high-level view: metadata, channels, basecalls,
|
|
358
|
+
* and decoded directory entries.
|
|
359
|
+
*
|
|
360
|
+
* Accepts ArrayBuffer or Uint8Array (Buffer in Node works too — it extends
|
|
361
|
+
* Uint8Array). The `fileName` argument is informational only; it's preserved
|
|
362
|
+
* in the result.
|
|
363
|
+
*/
|
|
364
|
+
declare function parseAbif(input: ArrayBuffer | Uint8Array, fileName?: string): ParsedAbif;
|
|
365
|
+
/** True when any channel has at least one signal value. */
|
|
366
|
+
declare function hasSignals(s: ChannelSignals): boolean;
|
|
367
|
+
/** Length of the longest channel in a ChannelSignals bundle. */
|
|
368
|
+
declare function channelMaxLength(s: ChannelSignals): number;
|
|
369
|
+
|
|
370
|
+
export { type AbifBaseCalls, type AbifChromatogramBundle, type AbifDecodedValue, type AbifDirEntry, type AbifEntry, type AbifFile, type AbifMetadata, type ChannelSignals, type Chromatogram, ENTRY_SIZE, HEADER_SIZE, type ParsedAbif, averagePeakSpacing, channelMaxLength, ensureRawDataChannels, findEntries, findEntry, getConfidences, getDataChannel, getFwo, getPositions, getRawChannelMap, getSamplingRate, getSequence, hasProcessedTraces, hasSignals, parseAbif, readAbif, setAveragePeakSpacing, setConfidences, setPositions, setSequence, tagNameFromInt32, upsertEntry, writeAbif };
|