gff-nostream 3.0.6 → 3.0.9
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 +59 -12
- package/dist/api.d.ts +13 -7
- package/dist/api.js +15 -4
- package/dist/api.js.map +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +2 -1
- package/dist/index.js.map +1 -1
- package/esm/api.d.ts +13 -7
- package/esm/api.js +14 -4
- package/esm/api.js.map +1 -1
- package/esm/index.d.ts +1 -1
- package/esm/index.js +1 -1
- package/esm/index.js.map +1 -1
- package/package.json +5 -5
- package/src/api.ts +29 -15
- package/src/index.ts +1 -0
package/README.md
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
# gff-nostream
|
|
2
2
|
|
|
3
3
|
[](https://npmjs.org/package/gff-nostream)
|
|
4
|
-
|
|
4
|
+

|
|
5
5
|
|
|
6
6
|
Parse GFF3 data. A simplified version of
|
|
7
7
|
[@gmod/gff](https://github.com/GMOD/gff-js) with no Node.js stream dependency.
|
|
8
8
|
|
|
9
9
|
## Install
|
|
10
10
|
|
|
11
|
-
$
|
|
11
|
+
$ pnpm add gff-nostream
|
|
12
12
|
|
|
13
13
|
## Usage
|
|
14
14
|
|
|
@@ -16,15 +16,25 @@ Parse GFF3 data. A simplified version of
|
|
|
16
16
|
import { parseStringSync } from 'gff-nostream'
|
|
17
17
|
import fs from 'fs'
|
|
18
18
|
|
|
19
|
-
const
|
|
20
|
-
|
|
19
|
+
const features = parseStringSync(fs.readFileSync('my_annotations.gff3', 'utf8'))
|
|
20
|
+
```
|
|
21
|
+
|
|
22
|
+
For browser or other non-Node environments, pass any GFF3 string directly — for
|
|
23
|
+
example from `fetch`:
|
|
24
|
+
|
|
25
|
+
```js
|
|
26
|
+
import { parseStringSyncJBrowse } from 'gff-nostream'
|
|
27
|
+
|
|
28
|
+
const text = await fetch('my_annotations.gff3').then(r => r.text())
|
|
29
|
+
const features = parseStringSyncJBrowse(text)
|
|
21
30
|
```
|
|
22
31
|
|
|
23
32
|
## Object format
|
|
24
33
|
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
34
|
+
### GFF3 format
|
|
35
|
+
|
|
36
|
+
Features are returned as arrays of all lines sharing the same ID (to represent
|
|
37
|
+
multi-location features). Values that are `.` in GFF3 are `null` in the output.
|
|
28
38
|
|
|
29
39
|
A simple feature located in one place:
|
|
30
40
|
|
|
@@ -88,31 +98,68 @@ A CDS called `cds00001` located in two places:
|
|
|
88
98
|
]
|
|
89
99
|
```
|
|
90
100
|
|
|
101
|
+
### JBrowse format
|
|
102
|
+
|
|
103
|
+
The `JBrowse` variants return flat objects with coordinates converted to 0-based
|
|
104
|
+
half-open, `strand` as a number (`1`/`-1`/`0`), attributes spread as lowercase
|
|
105
|
+
top-level keys, and `subfeatures` instead of `child_features`.
|
|
106
|
+
|
|
107
|
+
The same gene feature in JBrowse format:
|
|
108
|
+
|
|
109
|
+
```json
|
|
110
|
+
{
|
|
111
|
+
"refName": "ctg123",
|
|
112
|
+
"source": null,
|
|
113
|
+
"type": "gene",
|
|
114
|
+
"start": 999,
|
|
115
|
+
"end": 9000,
|
|
116
|
+
"strand": 1,
|
|
117
|
+
"subfeatures": [],
|
|
118
|
+
"id": "gene00001",
|
|
119
|
+
"name": "EDEN"
|
|
120
|
+
}
|
|
121
|
+
```
|
|
122
|
+
|
|
123
|
+
Note: multi-location features (same ID on multiple lines) are not merged in
|
|
124
|
+
JBrowse format — only the first occurrence is kept.
|
|
125
|
+
|
|
91
126
|
## API
|
|
92
127
|
|
|
93
128
|
### `parseStringSync(str: string): GFF3Feature[]`
|
|
94
129
|
|
|
95
|
-
Synchronously parse a GFF3 string and return an array of features.
|
|
130
|
+
Synchronously parse a GFF3 string and return an array of features. Comments,
|
|
131
|
+
directives, and `##FASTA` sections are ignored.
|
|
96
132
|
|
|
97
133
|
### `parseStringSyncJBrowse(str: string): JBrowseFeature[]`
|
|
98
134
|
|
|
99
|
-
Synchronously parse a GFF3 string and return features in JBrowse format
|
|
100
|
-
objects with `subfeatures` instead of `child_features`).
|
|
135
|
+
Synchronously parse a GFF3 string and return features in JBrowse format.
|
|
101
136
|
|
|
102
137
|
### `parseRecords(records: LineRecord[]): GFF3Feature[]`
|
|
103
138
|
|
|
104
139
|
Parse an array of `LineRecord` objects. Useful when managing raw line data
|
|
105
|
-
directly (e.g. from
|
|
140
|
+
directly (e.g. from a tabix-indexed file with byte offsets).
|
|
106
141
|
|
|
107
142
|
### `parseRecordsJBrowse(records: LineRecord[]): JBrowseFeature[]`
|
|
108
143
|
|
|
109
144
|
Same as `parseRecords` but returns JBrowse-format features.
|
|
110
145
|
|
|
146
|
+
### `LineRecord`
|
|
147
|
+
|
|
148
|
+
```ts
|
|
149
|
+
interface LineRecord {
|
|
150
|
+
line: string
|
|
151
|
+
hasEscapes: boolean // set true when line contains '%' to enable URL-decoding
|
|
152
|
+
lineHash?: string | number // propagated to attributes._lineHash on the parsed feature
|
|
153
|
+
start?: number // byte offset passthrough (not used by the parser)
|
|
154
|
+
end?: number // byte offset passthrough (not used by the parser)
|
|
155
|
+
}
|
|
156
|
+
```
|
|
157
|
+
|
|
111
158
|
## Publishing
|
|
112
159
|
|
|
113
160
|
[Trusted publishing](https://docs.npmjs.com/about-trusted-publishing) via GitHub
|
|
114
161
|
Actions.
|
|
115
162
|
|
|
116
163
|
```bash
|
|
117
|
-
|
|
164
|
+
pnpm version patch # or minor/major
|
|
118
165
|
```
|
package/dist/api.d.ts
CHANGED
|
@@ -1,13 +1,19 @@
|
|
|
1
1
|
import type { GFF3Feature, JBrowseFeature } from './util.ts';
|
|
2
|
-
|
|
2
|
+
interface ParseInput {
|
|
3
3
|
line: string;
|
|
4
4
|
lineHash?: string | number;
|
|
5
|
-
/** Optional passthrough byte offsets — not used by the parser */
|
|
6
|
-
start?: number;
|
|
7
|
-
/** Optional passthrough byte offsets — not used by the parser */
|
|
8
|
-
end?: number;
|
|
9
5
|
hasEscapes: boolean;
|
|
10
6
|
}
|
|
7
|
+
export interface LineRecord extends ParseInput {
|
|
8
|
+
/** Genomic start coordinate from the tabix index (1-based) */
|
|
9
|
+
start: number;
|
|
10
|
+
/** Genomic end coordinate from the tabix index */
|
|
11
|
+
end: number;
|
|
12
|
+
/** GFF3 feature type (column 3) */
|
|
13
|
+
type: string;
|
|
14
|
+
}
|
|
15
|
+
/** Extract the GFF3 feature type (column 3) from a raw line without a full split. */
|
|
16
|
+
export declare function extractType(line: string): string;
|
|
11
17
|
/**
|
|
12
18
|
* Synchronously parse a string containing GFF3 and return an array of the
|
|
13
19
|
* parsed items.
|
|
@@ -30,7 +36,7 @@ export declare function parseStringSyncJBrowse(str: string): JBrowseFeature[];
|
|
|
30
36
|
* @param records - Array of LineRecord objects with raw line and metadata
|
|
31
37
|
* @returns array of parsed features
|
|
32
38
|
*/
|
|
33
|
-
export declare function parseRecords(records:
|
|
39
|
+
export declare function parseRecords(records: ParseInput[]): GFF3Feature[];
|
|
34
40
|
/**
|
|
35
41
|
* Parse an array of LineRecord objects directly into JBrowse feature format.
|
|
36
42
|
* Supports parent/child relationships via subfeatures.
|
|
@@ -38,5 +44,5 @@ export declare function parseRecords(records: LineRecord[]): GFF3Feature[];
|
|
|
38
44
|
* @param records - Array of LineRecord objects with raw line and metadata
|
|
39
45
|
* @returns array of JBrowse-format features
|
|
40
46
|
*/
|
|
41
|
-
export declare function parseRecordsJBrowse(records:
|
|
47
|
+
export declare function parseRecordsJBrowse(records: ParseInput[]): JBrowseFeature[];
|
|
42
48
|
export type { GFF3Comment, GFF3Directive, GFF3Feature, GFF3FeatureLine, GFF3FeatureLineWithRefs, GFF3Item, GFF3Sequence, JBrowseFeature, } from './util.ts';
|
package/dist/api.js
CHANGED
|
@@ -1,10 +1,18 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.extractType = extractType;
|
|
3
4
|
exports.parseStringSync = parseStringSync;
|
|
4
5
|
exports.parseStringSyncJBrowse = parseStringSyncJBrowse;
|
|
5
6
|
exports.parseRecords = parseRecords;
|
|
6
7
|
exports.parseRecordsJBrowse = parseRecordsJBrowse;
|
|
7
8
|
const util_ts_1 = require("./util.js");
|
|
9
|
+
/** Extract the GFF3 feature type (column 3) from a raw line without a full split. */
|
|
10
|
+
function extractType(line) {
|
|
11
|
+
const t1 = line.indexOf('\t');
|
|
12
|
+
const t2 = line.indexOf('\t', t1 + 1);
|
|
13
|
+
const t3 = line.indexOf('\t', t2 + 1);
|
|
14
|
+
return line.slice(t2 + 1, t3);
|
|
15
|
+
}
|
|
8
16
|
/**
|
|
9
17
|
* Synchronously parse a string containing GFF3 and return an array of the
|
|
10
18
|
* parsed items.
|
|
@@ -53,11 +61,14 @@ function parseRecords(records) {
|
|
|
53
61
|
const byId = new Map();
|
|
54
62
|
const orphans = new Map();
|
|
55
63
|
for (const record of records) {
|
|
56
|
-
const
|
|
64
|
+
const parsed = record.hasEscapes
|
|
57
65
|
? (0, util_ts_1.parseFeature)(record.line)
|
|
58
|
-
: (0, util_ts_1.parseFeatureNoUnescape)(record.line)
|
|
59
|
-
featureLine
|
|
60
|
-
|
|
66
|
+
: (0, util_ts_1.parseFeatureNoUnescape)(record.line);
|
|
67
|
+
const featureLine = {
|
|
68
|
+
...parsed,
|
|
69
|
+
child_features: [],
|
|
70
|
+
derived_features: [],
|
|
71
|
+
};
|
|
61
72
|
if (record.lineHash !== undefined) {
|
|
62
73
|
featureLine.attributes ??= {};
|
|
63
74
|
featureLine.attributes._lineHash = [String(record.lineHash)];
|
package/dist/api.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"api.js","sourceRoot":"","sources":["../src/api.ts"],"names":[],"mappings":";;
|
|
1
|
+
{"version":3,"file":"api.js","sourceRoot":"","sources":["../src/api.ts"],"names":[],"mappings":";;AA6BA,kCAKC;AASD,0CAEC;AAQD,wDAEC;AA2BD,oCA8EC;AASD,kDAyDC;AAlOD,uCA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nB,CAAC;gBACH,CAAC;YACH,CAAC;QACH,CAAC;IACH,CAAC;IAED,OAAO,KAAK,CAAA;AACd,CAAC"}
|
package/dist/index.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export { parseRecords, parseRecordsJBrowse, parseStringSync, parseStringSyncJBrowse, } from './api.ts';
|
|
1
|
+
export { extractType, parseRecords, parseRecordsJBrowse, parseStringSync, parseStringSyncJBrowse, } from './api.ts';
|
|
2
2
|
export type { GFF3Comment, GFF3Directive, GFF3Feature, GFF3FeatureLine, GFF3FeatureLineWithRefs, GFF3Item, GFF3Sequence, JBrowseFeature, LineRecord, } from './api.ts';
|
package/dist/index.js
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.parseStringSyncJBrowse = exports.parseStringSync = exports.parseRecordsJBrowse = exports.parseRecords = void 0;
|
|
3
|
+
exports.parseStringSyncJBrowse = exports.parseStringSync = exports.parseRecordsJBrowse = exports.parseRecords = exports.extractType = void 0;
|
|
4
4
|
var api_ts_1 = require("./api.js");
|
|
5
|
+
Object.defineProperty(exports, "extractType", { enumerable: true, get: function () { return api_ts_1.extractType; } });
|
|
5
6
|
Object.defineProperty(exports, "parseRecords", { enumerable: true, get: function () { return api_ts_1.parseRecords; } });
|
|
6
7
|
Object.defineProperty(exports, "parseRecordsJBrowse", { enumerable: true, get: function () { return api_ts_1.parseRecordsJBrowse; } });
|
|
7
8
|
Object.defineProperty(exports, "parseStringSync", { enumerable: true, get: function () { return api_ts_1.parseStringSync; } });
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;AAAA,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;AAAA,mCAMiB;AALf,qGAAA,WAAW,OAAA;AACX,sGAAA,YAAY,OAAA;AACZ,6GAAA,mBAAmB,OAAA;AACnB,yGAAA,eAAe,OAAA;AACf,gHAAA,sBAAsB,OAAA"}
|
package/esm/api.d.ts
CHANGED
|
@@ -1,13 +1,19 @@
|
|
|
1
1
|
import type { GFF3Feature, JBrowseFeature } from './util.ts';
|
|
2
|
-
|
|
2
|
+
interface ParseInput {
|
|
3
3
|
line: string;
|
|
4
4
|
lineHash?: string | number;
|
|
5
|
-
/** Optional passthrough byte offsets — not used by the parser */
|
|
6
|
-
start?: number;
|
|
7
|
-
/** Optional passthrough byte offsets — not used by the parser */
|
|
8
|
-
end?: number;
|
|
9
5
|
hasEscapes: boolean;
|
|
10
6
|
}
|
|
7
|
+
export interface LineRecord extends ParseInput {
|
|
8
|
+
/** Genomic start coordinate from the tabix index (1-based) */
|
|
9
|
+
start: number;
|
|
10
|
+
/** Genomic end coordinate from the tabix index */
|
|
11
|
+
end: number;
|
|
12
|
+
/** GFF3 feature type (column 3) */
|
|
13
|
+
type: string;
|
|
14
|
+
}
|
|
15
|
+
/** Extract the GFF3 feature type (column 3) from a raw line without a full split. */
|
|
16
|
+
export declare function extractType(line: string): string;
|
|
11
17
|
/**
|
|
12
18
|
* Synchronously parse a string containing GFF3 and return an array of the
|
|
13
19
|
* parsed items.
|
|
@@ -30,7 +36,7 @@ export declare function parseStringSyncJBrowse(str: string): JBrowseFeature[];
|
|
|
30
36
|
* @param records - Array of LineRecord objects with raw line and metadata
|
|
31
37
|
* @returns array of parsed features
|
|
32
38
|
*/
|
|
33
|
-
export declare function parseRecords(records:
|
|
39
|
+
export declare function parseRecords(records: ParseInput[]): GFF3Feature[];
|
|
34
40
|
/**
|
|
35
41
|
* Parse an array of LineRecord objects directly into JBrowse feature format.
|
|
36
42
|
* Supports parent/child relationships via subfeatures.
|
|
@@ -38,5 +44,5 @@ export declare function parseRecords(records: LineRecord[]): GFF3Feature[];
|
|
|
38
44
|
* @param records - Array of LineRecord objects with raw line and metadata
|
|
39
45
|
* @returns array of JBrowse-format features
|
|
40
46
|
*/
|
|
41
|
-
export declare function parseRecordsJBrowse(records:
|
|
47
|
+
export declare function parseRecordsJBrowse(records: ParseInput[]): JBrowseFeature[];
|
|
42
48
|
export type { GFF3Comment, GFF3Directive, GFF3Feature, GFF3FeatureLine, GFF3FeatureLineWithRefs, GFF3Item, GFF3Sequence, JBrowseFeature, } from './util.ts';
|
package/esm/api.js
CHANGED
|
@@ -1,4 +1,11 @@
|
|
|
1
1
|
import { parseFeature, parseFeatureJBrowse, parseFeatureJBrowseNoUnescape, parseFeatureNoUnescape, } from "./util.js";
|
|
2
|
+
/** Extract the GFF3 feature type (column 3) from a raw line without a full split. */
|
|
3
|
+
export function extractType(line) {
|
|
4
|
+
const t1 = line.indexOf('\t');
|
|
5
|
+
const t2 = line.indexOf('\t', t1 + 1);
|
|
6
|
+
const t3 = line.indexOf('\t', t2 + 1);
|
|
7
|
+
return line.slice(t2 + 1, t3);
|
|
8
|
+
}
|
|
2
9
|
/**
|
|
3
10
|
* Synchronously parse a string containing GFF3 and return an array of the
|
|
4
11
|
* parsed items.
|
|
@@ -47,11 +54,14 @@ export function parseRecords(records) {
|
|
|
47
54
|
const byId = new Map();
|
|
48
55
|
const orphans = new Map();
|
|
49
56
|
for (const record of records) {
|
|
50
|
-
const
|
|
57
|
+
const parsed = record.hasEscapes
|
|
51
58
|
? parseFeature(record.line)
|
|
52
|
-
: parseFeatureNoUnescape(record.line)
|
|
53
|
-
featureLine
|
|
54
|
-
|
|
59
|
+
: parseFeatureNoUnescape(record.line);
|
|
60
|
+
const featureLine = {
|
|
61
|
+
...parsed,
|
|
62
|
+
child_features: [],
|
|
63
|
+
derived_features: [],
|
|
64
|
+
};
|
|
55
65
|
if (record.lineHash !== undefined) {
|
|
56
66
|
featureLine.attributes ??= {};
|
|
57
67
|
featureLine.attributes._lineHash = [String(record.lineHash)];
|
package/esm/api.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"api.js","sourceRoot":"","sources":["../src/api.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,YAAY,EACZ,mBAAmB,EACnB,6BAA6B,EAC7B,sBAAsB,GACvB,MAAM,WAAW,CAAA;
|
|
1
|
+
{"version":3,"file":"api.js","sourceRoot":"","sources":["../src/api.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,YAAY,EACZ,mBAAmB,EACnB,6BAA6B,EAC7B,sBAAsB,GACvB,MAAM,WAAW,CAAA;AAuBlB,qFAAqF;AACrF,MAAM,UAAU,WAAW,CAAC,IAAY;IACtC,MAAM,EAAE,GAAG,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,CAAA;IAC7B,MAAM,EAAE,GAAG,IAAI,CAAC,OAAO,CAAC,IAAI,EAAE,EAAE,GAAG,CAAC,CAAC,CAAA;IACrC,MAAM,EAAE,GAAG,IAAI,CAAC,OAAO,CAAC,IAAI,EAAE,EAAE,GAAG,CAAC,CAAC,CAAA;IACrC,OAAO,IAAI,CAAC,KAAK,CAAC,EAAE,GAAG,CAAC,EAAE,EAAE,CAAC,CAAA;AAC/B,CAAC;AAED;;;;;;GAMG;AACH,MAAM,UAAU,eAAe,CAAC,GAAW;IACzC,OAAO,YAAY,CAAC,eAAe,CAAC,GAAG,CAAC,CAAC,CAAA;AAC3C,CAAC;AAED;;;;;GAKG;AACH,MAAM,UAAU,sBAAsB,CAAC,GAAW;IAChD,OAAO,mBAAmB,CAAC,eAAe,CAAC,GAAG,CAAC,CAAC,CAAA;AAClD,CAAC;AAED,SAAS,eAAe,CAAC,GAAW;IAClC,MAAM,KAAK,GAAG,GAAG,CAAC,KAAK,CAAC,OAAO,CAAC,CAAA;IAChC,MAAM,OAAO,GAAiB,EAAE,CAAA;IAChC,KAAK,MAAM,IAAI,IAAI,KAAK,EAAE,CAAC;QACzB,IAAI,IAAI,CAAC,UAAU,CAAC,SAAS,CAAC,IAAI,IAAI,CAAC,UAAU,CAAC,GAAG,CAAC,EAAE,CAAC;YAC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CAAA;oBACzC,CAAC;yBAAM,CAAC;wBACN,IAAI,GAAG,GAAG,OAAO,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAA;wBAC/B,IAAI,CAAC,GAAG,EAAE,CAAC;4BACT,GAAG,GAAG,EAAE,CAAA;4BACR,OAAO,CAAC,GAAG,CAAC,QAAQ,EAAE,GAAG,CAAC,CAAA;wBAC5B,CAAC;wBACD,GAAG,CAAC,IAAI,CAAC,OAAO,CAAC,CAAA;oBACnB,CAAC;gBACH,CAAC;YACH,CAAC;QACH,CAAC;IACH,CAAC;IAED,OAAO,KAAK,CAAA;AACd,CAAC"}
|
package/esm/index.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export { parseRecords, parseRecordsJBrowse, parseStringSync, parseStringSyncJBrowse, } from './api.ts';
|
|
1
|
+
export { extractType, parseRecords, parseRecordsJBrowse, parseStringSync, parseStringSyncJBrowse, } from './api.ts';
|
|
2
2
|
export type { GFF3Comment, GFF3Directive, GFF3Feature, GFF3FeatureLine, GFF3FeatureLineWithRefs, GFF3Item, GFF3Sequence, JBrowseFeature, LineRecord, } from './api.ts';
|
package/esm/index.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export { parseRecords, parseRecordsJBrowse, parseStringSync, parseStringSyncJBrowse, } from "./api.js";
|
|
1
|
+
export { extractType, parseRecords, parseRecordsJBrowse, parseStringSync, parseStringSyncJBrowse, } from "./api.js";
|
|
2
2
|
//# sourceMappingURL=index.js.map
|
package/esm/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,YAAY,EACZ,mBAAmB,EACnB,eAAe,EACf,sBAAsB,GACvB,MAAM,UAAU,CAAA"}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,WAAW,EACX,YAAY,EACZ,mBAAmB,EACnB,eAAe,EACf,sBAAsB,GACvB,MAAM,UAAU,CAAA"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "gff-nostream",
|
|
3
|
-
"version": "3.0.
|
|
3
|
+
"version": "3.0.9",
|
|
4
4
|
"description": "utilities to read GFF3 data",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"repository": {
|
|
@@ -48,13 +48,13 @@
|
|
|
48
48
|
],
|
|
49
49
|
"devDependencies": {
|
|
50
50
|
"@eslint/js": "^10.0.1",
|
|
51
|
-
"@types/node": "^25.
|
|
52
|
-
"eslint": "^10.
|
|
51
|
+
"@types/node": "^25.8.0",
|
|
52
|
+
"eslint": "^10.4.0",
|
|
53
53
|
"eslint-plugin-import-x": "^4.16.2",
|
|
54
54
|
"prettier": "^3.8.3",
|
|
55
55
|
"rimraf": "^6.1.3",
|
|
56
56
|
"typescript": "^6.0.3",
|
|
57
|
-
"typescript-eslint": "^8.59.
|
|
58
|
-
"vitest": "^4.1.
|
|
57
|
+
"typescript-eslint": "^8.59.3",
|
|
58
|
+
"vitest": "^4.1.6"
|
|
59
59
|
}
|
|
60
60
|
}
|
package/src/api.ts
CHANGED
|
@@ -11,16 +11,29 @@ import type {
|
|
|
11
11
|
JBrowseFeature,
|
|
12
12
|
} from './util.ts'
|
|
13
13
|
|
|
14
|
-
|
|
14
|
+
interface ParseInput {
|
|
15
15
|
line: string
|
|
16
16
|
lineHash?: string | number
|
|
17
|
-
/** Optional passthrough byte offsets — not used by the parser */
|
|
18
|
-
start?: number
|
|
19
|
-
/** Optional passthrough byte offsets — not used by the parser */
|
|
20
|
-
end?: number
|
|
21
17
|
hasEscapes: boolean
|
|
22
18
|
}
|
|
23
19
|
|
|
20
|
+
export interface LineRecord extends ParseInput {
|
|
21
|
+
/** Genomic start coordinate from the tabix index (1-based) */
|
|
22
|
+
start: number
|
|
23
|
+
/** Genomic end coordinate from the tabix index */
|
|
24
|
+
end: number
|
|
25
|
+
/** GFF3 feature type (column 3) */
|
|
26
|
+
type: string
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
/** Extract the GFF3 feature type (column 3) from a raw line without a full split. */
|
|
30
|
+
export function extractType(line: string): string {
|
|
31
|
+
const t1 = line.indexOf('\t')
|
|
32
|
+
const t2 = line.indexOf('\t', t1 + 1)
|
|
33
|
+
const t3 = line.indexOf('\t', t2 + 1)
|
|
34
|
+
return line.slice(t2 + 1, t3)
|
|
35
|
+
}
|
|
36
|
+
|
|
24
37
|
/**
|
|
25
38
|
* Synchronously parse a string containing GFF3 and return an array of the
|
|
26
39
|
* parsed items.
|
|
@@ -44,7 +57,7 @@ export function parseStringSyncJBrowse(str: string): JBrowseFeature[] {
|
|
|
44
57
|
|
|
45
58
|
function stringToRecords(str: string) {
|
|
46
59
|
const lines = str.split(/\r?\n/)
|
|
47
|
-
const records:
|
|
60
|
+
const records: ParseInput[] = []
|
|
48
61
|
for (const line of lines) {
|
|
49
62
|
if (line.startsWith('##FASTA') || line.startsWith('>')) {
|
|
50
63
|
break
|
|
@@ -67,19 +80,20 @@ function stringToRecords(str: string) {
|
|
|
67
80
|
* @param records - Array of LineRecord objects with raw line and metadata
|
|
68
81
|
* @returns array of parsed features
|
|
69
82
|
*/
|
|
70
|
-
export function parseRecords(records:
|
|
83
|
+
export function parseRecords(records: ParseInput[]): GFF3Feature[] {
|
|
71
84
|
const items: GFF3Feature[] = []
|
|
72
85
|
const byId = new Map<string, GFF3Feature>()
|
|
73
86
|
const orphans = new Map<string, GFF3Feature[]>()
|
|
74
87
|
|
|
75
88
|
for (const record of records) {
|
|
76
|
-
const
|
|
77
|
-
record.
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
89
|
+
const parsed = record.hasEscapes
|
|
90
|
+
? parseFeature(record.line)
|
|
91
|
+
: parseFeatureNoUnescape(record.line)
|
|
92
|
+
const featureLine: GFF3FeatureLineWithRefs = {
|
|
93
|
+
...parsed,
|
|
94
|
+
child_features: [],
|
|
95
|
+
derived_features: [],
|
|
96
|
+
}
|
|
83
97
|
|
|
84
98
|
if (record.lineHash !== undefined) {
|
|
85
99
|
featureLine.attributes ??= {}
|
|
@@ -153,7 +167,7 @@ export function parseRecords(records: LineRecord[]): GFF3Feature[] {
|
|
|
153
167
|
* @param records - Array of LineRecord objects with raw line and metadata
|
|
154
168
|
* @returns array of JBrowse-format features
|
|
155
169
|
*/
|
|
156
|
-
export function parseRecordsJBrowse(records:
|
|
170
|
+
export function parseRecordsJBrowse(records: ParseInput[]): JBrowseFeature[] {
|
|
157
171
|
const items: JBrowseFeature[] = []
|
|
158
172
|
const byId = new Map<string, JBrowseFeature>()
|
|
159
173
|
const orphans = new Map<string, JBrowseFeature[]>()
|