gff-nostream 3.0.2 → 3.0.4
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 +16 -75
- package/dist/api.js +14 -21
- package/dist/api.js.map +1 -1
- package/dist/util.js +108 -214
- package/dist/util.js.map +1 -1
- package/esm/api.js +14 -21
- package/esm/api.js.map +1 -1
- package/esm/util.js +108 -214
- package/esm/util.js.map +1 -1
- package/package.json +15 -22
- package/src/api.ts +15 -22
- package/src/util.ts +157 -252
package/README.md
CHANGED
|
@@ -1,38 +1,29 @@
|
|
|
1
1
|
# gff-nostream
|
|
2
2
|
|
|
3
|
-
[](https://npmjs.org/package/gff-nostream)
|
|
4
|
+
[](https://github.com/GMOD/gff-nostream/actions?query=branch%3Amain+workflow%3APush+)
|
|
4
5
|
|
|
5
|
-
Parse GFF3 data.
|
|
6
|
-
[@gmod/gff](https://github.com/GMOD/gff-js) with just basic parsing and no
|
|
7
|
-
node.js stream module usage
|
|
6
|
+
Parse GFF3 data. A simplified version of [@gmod/gff](https://github.com/GMOD/gff-js) with no Node.js stream dependency.
|
|
8
7
|
|
|
9
8
|
## Install
|
|
10
9
|
|
|
11
|
-
$ npm install
|
|
10
|
+
$ npm install gff-nostream
|
|
12
11
|
|
|
13
12
|
## Usage
|
|
14
13
|
|
|
15
14
|
```js
|
|
16
|
-
const { parseStringSync } = require('gff-nostream')
|
|
17
|
-
// or in ES6 (recommended)
|
|
18
15
|
import { parseStringSync } from 'gff-nostream'
|
|
16
|
+
import fs from 'fs'
|
|
19
17
|
|
|
20
|
-
const fs = require('fs')
|
|
21
|
-
|
|
22
|
-
// parse a string of gff3 synchronously
|
|
23
18
|
const stringOfGFF3 = fs.readFileSync('my_annotations.gff3', 'utf8')
|
|
24
|
-
const
|
|
19
|
+
const features = parseStringSync(stringOfGFF3)
|
|
25
20
|
```
|
|
26
21
|
|
|
27
22
|
## Object format
|
|
28
23
|
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
In GFF3, features can have more than one location. We parse features as
|
|
32
|
-
arrayrefs of all the lines that share that feature's ID. Values that are `.` in
|
|
33
|
-
the GFF3 are `null` in the output.
|
|
24
|
+
In GFF3, features can have more than one location. Features are returned as arrays of all lines sharing the same ID. Values that are `.` in GFF3 are `null` in the output.
|
|
34
25
|
|
|
35
|
-
A simple feature
|
|
26
|
+
A simple feature located in one place:
|
|
36
27
|
|
|
37
28
|
```json
|
|
38
29
|
[
|
|
@@ -96,68 +87,18 @@ A CDS called `cds00001` located in two places:
|
|
|
96
87
|
|
|
97
88
|
## API
|
|
98
89
|
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
#### Table of Contents
|
|
102
|
-
|
|
103
|
-
- [ParseOptions](#parseoptions)
|
|
104
|
-
- [disableDerivesFromReferences](#disablederivesfromreferences)
|
|
105
|
-
- [encoding](#encoding)
|
|
106
|
-
- [parseFeatures](#parsefeatures)
|
|
107
|
-
- [parseDirectives](#parsedirectives)
|
|
108
|
-
- [parseComments](#parsecomments)
|
|
109
|
-
- [parseSequences](#parsesequences)
|
|
110
|
-
- [parseAll](#parseall)
|
|
111
|
-
|
|
112
|
-
### ParseOptions
|
|
113
|
-
|
|
114
|
-
Parser options
|
|
115
|
-
|
|
116
|
-
#### disableDerivesFromReferences
|
|
117
|
-
|
|
118
|
-
Whether to resolve references to derives from features
|
|
119
|
-
|
|
120
|
-
Type:
|
|
121
|
-
[boolean](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Boolean)
|
|
122
|
-
|
|
123
|
-
#### encoding
|
|
124
|
-
|
|
125
|
-
Text encoding of the input GFF3. default 'utf8'
|
|
126
|
-
|
|
127
|
-
Type: BufferEncoding
|
|
128
|
-
|
|
129
|
-
#### parseFeatures
|
|
130
|
-
|
|
131
|
-
Whether to parse features, default true
|
|
132
|
-
|
|
133
|
-
Type:
|
|
134
|
-
[boolean](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Boolean)
|
|
135
|
-
|
|
136
|
-
#### parseDirectives
|
|
137
|
-
|
|
138
|
-
Whether to parse directives, default false
|
|
139
|
-
|
|
140
|
-
Type:
|
|
141
|
-
[boolean](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Boolean)
|
|
142
|
-
|
|
143
|
-
#### parseComments
|
|
144
|
-
|
|
145
|
-
Whether to parse comments, default false
|
|
90
|
+
### `parseStringSync(str: string): GFF3Feature[]`
|
|
146
91
|
|
|
147
|
-
|
|
148
|
-
[boolean](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Boolean)
|
|
92
|
+
Synchronously parse a GFF3 string and return an array of features.
|
|
149
93
|
|
|
150
|
-
|
|
94
|
+
### `parseStringSyncJBrowse(str: string): JBrowseFeature[]`
|
|
151
95
|
|
|
152
|
-
|
|
96
|
+
Synchronously parse a GFF3 string and return features in JBrowse format (flat objects with `subfeatures` instead of `child_features`).
|
|
153
97
|
|
|
154
|
-
|
|
155
|
-
[boolean](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Boolean)
|
|
98
|
+
### `parseRecords(records: LineRecord[]): GFF3Feature[]`
|
|
156
99
|
|
|
157
|
-
|
|
100
|
+
Parse an array of `LineRecord` objects. Useful when managing raw line data directly (e.g. from an indexed file with byte offsets).
|
|
158
101
|
|
|
159
|
-
|
|
160
|
-
options. Default false.
|
|
102
|
+
### `parseRecordsJBrowse(records: LineRecord[]): JBrowseFeature[]`
|
|
161
103
|
|
|
162
|
-
|
|
163
|
-
[boolean](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Boolean)
|
|
104
|
+
Same as `parseRecords` but returns JBrowse-format features.
|
package/dist/api.js
CHANGED
|
@@ -27,15 +27,14 @@ function parseStringSyncJBrowse(str) {
|
|
|
27
27
|
function stringToRecords(str) {
|
|
28
28
|
const lines = str.split(/\r?\n/);
|
|
29
29
|
const records = [];
|
|
30
|
-
for (
|
|
31
|
-
|
|
32
|
-
if (line.length === 0 || line[0] === '#') {
|
|
30
|
+
for (const line of lines) {
|
|
31
|
+
if (line.length === 0 || line.startsWith('#')) {
|
|
33
32
|
if (line.startsWith('##FASTA')) {
|
|
34
33
|
break;
|
|
35
34
|
}
|
|
36
35
|
continue;
|
|
37
36
|
}
|
|
38
|
-
if (line
|
|
37
|
+
if (line.startsWith('>')) {
|
|
39
38
|
break;
|
|
40
39
|
}
|
|
41
40
|
records.push({
|
|
@@ -58,17 +57,14 @@ function parseRecords(records) {
|
|
|
58
57
|
const items = [];
|
|
59
58
|
const byId = new Map();
|
|
60
59
|
const orphans = new Map();
|
|
61
|
-
for (
|
|
62
|
-
const record = records[i];
|
|
60
|
+
for (const record of records) {
|
|
63
61
|
const featureLine = (record.hasEscapes
|
|
64
62
|
? (0, util_ts_1.parseFeature)(record.line)
|
|
65
63
|
: (0, util_ts_1.parseFeatureNoUnescape)(record.line));
|
|
66
64
|
featureLine.child_features = [];
|
|
67
65
|
featureLine.derived_features = [];
|
|
68
66
|
if (record.lineHash !== undefined) {
|
|
69
|
-
|
|
70
|
-
featureLine.attributes = {};
|
|
71
|
-
}
|
|
67
|
+
featureLine.attributes ?? (featureLine.attributes = {});
|
|
72
68
|
featureLine.attributes._lineHash = [String(record.lineHash)];
|
|
73
69
|
}
|
|
74
70
|
const attrs = featureLine.attributes;
|
|
@@ -94,8 +90,8 @@ function parseRecords(records) {
|
|
|
94
90
|
byId.set(id, feature);
|
|
95
91
|
const waiting = orphans.get(id);
|
|
96
92
|
if (waiting) {
|
|
97
|
-
for (
|
|
98
|
-
featureLine.child_features.push(
|
|
93
|
+
for (const w of waiting) {
|
|
94
|
+
featureLine.child_features.push(w);
|
|
99
95
|
}
|
|
100
96
|
orphans.delete(id);
|
|
101
97
|
}
|
|
@@ -105,12 +101,11 @@ function parseRecords(records) {
|
|
|
105
101
|
feature = [featureLine];
|
|
106
102
|
}
|
|
107
103
|
if (parents) {
|
|
108
|
-
for (
|
|
109
|
-
const parentId = parents[j];
|
|
104
|
+
for (const parentId of parents) {
|
|
110
105
|
const parent = byId.get(parentId);
|
|
111
106
|
if (parent) {
|
|
112
|
-
for (
|
|
113
|
-
|
|
107
|
+
for (const p of parent) {
|
|
108
|
+
p.child_features.push(feature);
|
|
114
109
|
}
|
|
115
110
|
}
|
|
116
111
|
else {
|
|
@@ -137,8 +132,7 @@ function parseRecordsJBrowse(records) {
|
|
|
137
132
|
const items = [];
|
|
138
133
|
const byId = new Map();
|
|
139
134
|
const orphans = new Map();
|
|
140
|
-
for (
|
|
141
|
-
const record = records[i];
|
|
135
|
+
for (const record of records) {
|
|
142
136
|
const feature = record.hasEscapes
|
|
143
137
|
? (0, util_ts_1.parseFeatureJBrowse)(record.line)
|
|
144
138
|
: (0, util_ts_1.parseFeatureJBrowseNoUnescape)(record.line);
|
|
@@ -160,8 +154,8 @@ function parseRecordsJBrowse(records) {
|
|
|
160
154
|
byId.set(id, feature);
|
|
161
155
|
const waiting = orphans.get(id);
|
|
162
156
|
if (waiting) {
|
|
163
|
-
for (
|
|
164
|
-
feature.subfeatures.push(
|
|
157
|
+
for (const w of waiting) {
|
|
158
|
+
feature.subfeatures.push(w);
|
|
165
159
|
}
|
|
166
160
|
orphans.delete(id);
|
|
167
161
|
}
|
|
@@ -169,8 +163,7 @@ function parseRecordsJBrowse(records) {
|
|
|
169
163
|
}
|
|
170
164
|
if (parent) {
|
|
171
165
|
const parents = Array.isArray(parent) ? parent : [parent];
|
|
172
|
-
for (
|
|
173
|
-
const parentId = parents[j];
|
|
166
|
+
for (const parentId of parents) {
|
|
174
167
|
const parentFeature = byId.get(parentId);
|
|
175
168
|
if (parentFeature) {
|
|
176
169
|
parentFeature.subfeatures.push(feature);
|
package/dist/api.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"api.js","sourceRoot":"","sources":["../src/api.ts"],"names":[],"mappings":";;AA4BA,0CAEC;AAQD,wDAEC;
|
|
1
|
+
{"version":3,"file":"api.js","sourceRoot":"","sources":["../src/api.ts"],"names":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