gff-nostream 3.0.11 → 5.0.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/esm/api.js CHANGED
@@ -1,4 +1,4 @@
1
- import { parseFeature, parseFeatureJBrowse, parseFeatureJBrowseNoUnescape, parseFeatureNoUnescape, } from "./util.js";
1
+ import { parseFeature } from "./util.js";
2
2
  /** Extract the GFF3 feature type (column 3) from a raw line without a full split. */
3
3
  export function extractType(line) {
4
4
  const t1 = line.indexOf('\t');
@@ -17,8 +17,8 @@ function appendOrphan(orphans, key, value) {
17
17
  }
18
18
  }
19
19
  /**
20
- * The JBrowse parser collapses single-element attribute arrays to scalars, so a
21
- * raw ID/Parent value can be a string, a string array, or absent. These coerce
20
+ * The parser collapses single-element attribute arrays to scalars, so a raw
21
+ * ID/Parent value can be a string, a string array, or absent. These coerce
22
22
  * those `unknown` values without typecasts.
23
23
  */
24
24
  function firstString(value) {
@@ -32,174 +32,82 @@ function toStringArray(value) {
32
32
  return typeof value === 'string' ? [value] : [];
33
33
  }
34
34
  /**
35
- * Synchronously parse a string containing GFF3 and return an array of the
36
- * parsed items.
37
- *
38
- * @param str - GFF3 string
39
- * @returns array of parsed features
40
- */
41
- export function parseStringSync(str) {
42
- return parseRecords(stringToRecords(str));
43
- }
44
- /**
45
- * Synchronously parse a string containing GFF3 directly into JBrowse format.
46
- *
47
- * @param str - GFF3 string
48
- * @returns array of JBrowse-format features
35
+ * Register a feature's ID and attach it to its parent(s), building the
36
+ * subfeature tree in `byId`/`orphans`. Returns true when the feature is
37
+ * top-level (has no Parent) and the caller should collect it.
49
38
  */
50
- export function parseStringSyncJBrowse(str) {
51
- return parseRecordsJBrowse(stringToRecords(str));
52
- }
53
- function stringToRecords(str) {
54
- const lines = str.split(/\r?\n/);
55
- const records = [];
56
- for (const line of lines) {
57
- if (line.startsWith('##FASTA') || line.startsWith('>')) {
58
- break;
39
+ function linkFeature(feature, byId, orphans) {
40
+ const id = firstString(feature.id);
41
+ const parents = toStringArray(feature.parent);
42
+ // Register the id only the first time it is seen. Continuation lines
43
+ // (multi-location features such as a CDS spanning several segments share one
44
+ // ID across lines) skip registration but must still be attached to their
45
+ // parent below, so this is independent of the parent handling.
46
+ if (id && !byId.has(id)) {
47
+ byId.set(id, feature);
48
+ const waiting = orphans.get(id);
49
+ if (waiting) {
50
+ for (const w of waiting) {
51
+ feature.subfeatures.push(w);
52
+ }
53
+ orphans.delete(id);
59
54
  }
60
- if (line.length === 0 || line.startsWith('#')) {
61
- continue;
55
+ }
56
+ for (const parentId of parents) {
57
+ const parentFeature = byId.get(parentId);
58
+ if (parentFeature) {
59
+ parentFeature.subfeatures.push(feature);
60
+ }
61
+ else {
62
+ appendOrphan(orphans, parentId, feature);
62
63
  }
63
- records.push({
64
- line,
65
- hasEscapes: line.includes('%'),
66
- });
67
64
  }
68
- return records;
65
+ // Every line of a top-level discontinuous feature (e.g. cDNA_match spanning
66
+ // several segments under one shared ID, with no Parent) is its own top-level
67
+ // item, so this is independent of whether the id was just registered.
68
+ return parents.length === 0;
69
69
  }
70
70
  /**
71
- * Parse an array of LineRecord objects containing raw GFF3 lines.
72
- * Supports parent/child relationships.
71
+ * Synchronously parse a string containing GFF3 and return an array of the
72
+ * parsed features. Comments, directives, and `##FASTA` sections are ignored.
73
73
  *
74
- * @param records - Array of LineRecord objects with raw line and metadata
74
+ * @param str - GFF3 string
75
75
  * @returns array of parsed features
76
76
  */
77
- export function parseRecords(records) {
77
+ export function parseStringSync(str) {
78
78
  const items = [];
79
79
  const byId = new Map();
80
80
  const orphans = new Map();
81
- for (const record of records) {
82
- const parsed = record.hasEscapes
83
- ? parseFeature(record.line)
84
- : parseFeatureNoUnescape(record.line);
85
- const featureLine = {
86
- ...parsed,
87
- child_features: [],
88
- derived_features: [],
89
- };
90
- if (record.lineHash !== undefined) {
91
- featureLine.attributes ??= {};
92
- featureLine.attributes._lineHash = [String(record.lineHash)];
93
- }
94
- const attrs = featureLine.attributes;
95
- const ids = attrs?.ID;
96
- const parents = attrs?.Parent;
97
- if (!ids && !parents) {
98
- items.push([featureLine]);
81
+ for (const line of str.split(/\r?\n/)) {
82
+ if (line.startsWith('##FASTA') || line.startsWith('>')) {
83
+ break;
99
84
  }
100
- else {
101
- let feature;
102
- if (ids) {
103
- const id = ids[0];
104
- const existing = byId.get(id);
105
- if (existing) {
106
- // Multi-location continuation: share child_features/derived_features
107
- // with the first line so children remain visible across all lines
108
- // regardless of arrival order.
109
- featureLine.child_features = existing[0].child_features;
110
- featureLine.derived_features = existing[0].derived_features;
111
- existing.push(featureLine);
112
- feature = existing;
113
- }
114
- else {
115
- feature = [featureLine];
116
- if (!parents) {
117
- items.push(feature);
118
- }
119
- byId.set(id, feature);
120
- const waiting = orphans.get(id);
121
- if (waiting) {
122
- for (const w of waiting) {
123
- featureLine.child_features.push(w);
124
- }
125
- orphans.delete(id);
126
- }
127
- }
128
- }
129
- else {
130
- feature = [featureLine];
131
- }
132
- if (parents) {
133
- for (const parentId of parents) {
134
- const parent = byId.get(parentId);
135
- if (parent) {
136
- // child_features is shared across all parent feature lines,
137
- // so push once via the first line.
138
- parent[0].child_features.push(feature);
139
- }
140
- else {
141
- appendOrphan(orphans, parentId, feature);
142
- }
143
- }
85
+ if (line.length !== 0 && !line.startsWith('#')) {
86
+ const feature = parseFeature(line);
87
+ if (linkFeature(feature, byId, orphans)) {
88
+ items.push(feature);
144
89
  }
145
90
  }
146
91
  }
147
92
  return items;
148
93
  }
149
94
  /**
150
- * Parse an array of LineRecord objects directly into JBrowse feature format.
151
- * Supports parent/child relationships via subfeatures.
95
+ * Parse an array of records wrapping raw GFF3 lines, resolving parent/child
96
+ * relationships into `subfeatures`. Returns each top-level feature paired with
97
+ * the record it came from, so callers can attach their own identity (e.g. a
98
+ * byte offset) without the parser stamping anything onto the feature.
152
99
  *
153
- * @param records - Array of LineRecord objects with raw line and metadata
154
- * @returns array of JBrowse-format features
100
+ * @param records - Array of records, each carrying a raw GFF3 `line`
101
+ * @returns top-level features, each paired with its originating record
155
102
  */
156
- export function parseRecordsJBrowse(records) {
103
+ export function parseRecords(records) {
157
104
  const items = [];
158
105
  const byId = new Map();
159
106
  const orphans = new Map();
160
107
  for (const record of records) {
161
- const feature = record.hasEscapes
162
- ? parseFeatureJBrowse(record.line)
163
- : parseFeatureJBrowseNoUnescape(record.line);
164
- if (record.lineHash !== undefined) {
165
- feature._lineHash = String(record.lineHash);
166
- }
167
- const id = firstString(feature.id);
168
- const parents = toStringArray(feature.parent);
169
- if (!id && parents.length === 0) {
170
- items.push(feature);
171
- }
172
- else {
173
- // A parentless line is a top-level item. Every line of a top-level
174
- // discontinuous feature (e.g. cDNA_match/EST_match spanning several
175
- // segments under one shared ID, with no Parent) is its own top-level
176
- // item, so push here regardless of whether the id is already registered.
177
- if (parents.length === 0) {
178
- items.push(feature);
179
- }
180
- // Register the id only the first time it is seen. Continuation lines
181
- // (multi-location features such as a CDS spanning several segments share
182
- // one ID across lines) skip registration but must still be attached to
183
- // their parent below, so this is independent of the parent handling.
184
- if (id && !byId.has(id)) {
185
- byId.set(id, feature);
186
- const waiting = orphans.get(id);
187
- if (waiting) {
188
- for (const w of waiting) {
189
- feature.subfeatures.push(w);
190
- }
191
- orphans.delete(id);
192
- }
193
- }
194
- for (const parentId of parents) {
195
- const parentFeature = byId.get(parentId);
196
- if (parentFeature) {
197
- parentFeature.subfeatures.push(feature);
198
- }
199
- else {
200
- appendOrphan(orphans, parentId, feature);
201
- }
202
- }
108
+ const feature = parseFeature(record.line);
109
+ if (linkFeature(feature, byId, orphans)) {
110
+ items.push({ feature, record });
203
111
  }
204
112
  }
205
113
  return items;
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;AAuBlB,qFAAqF;AACrF,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AAK,CAAA;AACd,CAAC;AAED;;;;;;;;GAQG;AACH,MAAM,UAAU,YAAY,CAC1B,OAAqB;IAErB,MAAM,KAAK,GAAsB,EAAE,CAAA;IACnC,MAAM,IAAI,GAAG,IAAI,GAAG,EAAsB,CAAA;IAC1C,MAAM,OAAO,GAAG,IAAI,GAAG,EAAwB,CAAA;IAE/C,KAAK,MAAM,MAAM,IAAI,OAAO,EAAE,CAAC;QAC7B,MAAM,OAAO,GAAG,YAAY,CAAC,MAAM,CAAC,IAAI,CAAC,CAAA;QACzC,IAAI,WAAW,CAAC,OAAO,EAAE,IAAI,EAAE,OAAO,CAAC,EAAE,CAAC;YACxC,KAAK,CAAC,IAAI,CAAC,EAAE,OAAO,EAAE,MAAM,EAAE,CAAC,CAAA;QACjC,CAAC;IACH,CAAC;IAED,OAAO,KAAK,CAAA;AACd,CAAC"}
package/esm/index.d.ts CHANGED
@@ -1,2 +1,2 @@
1
- export { extractType, parseRecords, parseRecordsJBrowse, parseStringSync, parseStringSyncJBrowse, } from './api.ts';
2
- export type { GFF3Comment, GFF3Directive, GFF3Feature, GFF3FeatureLine, GFF3FeatureLineWithRefs, GFF3Item, GFF3Sequence, JBrowseFeature, LineRecord, } from './api.ts';
1
+ export { extractType, parseRecords, parseStringSync } from './api.ts';
2
+ export type { GffFeature, LineRecord, ParsedRecord } from './api.ts';
package/esm/index.js CHANGED
@@ -1,2 +1,2 @@
1
- export { extractType, parseRecords, parseRecordsJBrowse, parseStringSync, parseStringSyncJBrowse, } from "./api.js";
1
+ export { extractType, parseRecords, parseStringSync } 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,WAAW,EACX,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,EAAE,WAAW,EAAE,YAAY,EAAE,eAAe,EAAE,MAAM,UAAU,CAAA"}
package/esm/util.d.ts CHANGED
@@ -6,122 +6,11 @@
6
6
  */
7
7
  export declare function unescape(stringVal: string): string;
8
8
  /**
9
- * Parse the 9th column (attributes) of a GFF3 feature line.
10
- *
11
- * @param attrString - String of GFF3 9th column
12
- * @returns Parsed attributes
13
- */
14
- export declare function parseAttributes(attrString: string): GFF3Attributes;
15
- /**
16
- * Parse the 9th column (attributes) of a GFF3 feature line without unescaping.
17
- * Fast path for data known to contain no escaped characters.
18
- *
19
- * @param attrString - String of GFF3 9th column
20
- * @returns Parsed attributes
21
- */
22
- export declare function parseAttributesNoUnescape(attrString: string): GFF3Attributes;
23
- /**
24
- * Parse a GFF3 feature line
25
- *
26
- * @param line - GFF3 feature line
27
- * @returns The parsed feature
9
+ * A parsed GFF3 feature: a flat object with 0-based half-open coordinates,
10
+ * numeric strand (`1`/`-1`/`0`), attributes spread as lowercase top-level keys,
11
+ * and child features nested under `subfeatures`.
28
12
  */
29
- export declare function parseFeature(line: string): GFF3FeatureLine;
30
- /**
31
- * Parse a GFF3 feature line without unescaping.
32
- * Fast path for data known to contain no escaped characters.
33
- *
34
- * @param line - GFF3 feature line
35
- * @returns The parsed feature
36
- */
37
- export declare function parseFeatureNoUnescape(line: string): GFF3FeatureLine;
38
- /**
39
- * Parse a GFF3 directive line.
40
- *
41
- * @param line - GFF3 directive line
42
- * @returns The parsed directive
43
- */
44
- export declare function parseDirective(line: string): GFF3Directive | GFF3SequenceRegionDirective | GFF3GenomeBuildDirective | null;
45
- /** A record of GFF3 attribute identifiers and the values of those identifiers */
46
- export type GFF3Attributes = Record<string, string[] | undefined>;
47
- /** A representation of a single line of a GFF3 file */
48
- export interface GFF3FeatureLine {
49
- /** The ID of the landmark used to establish the coordinate system for the current feature */
50
- seq_id: string | null;
51
- /** A free text qualifier intended to describe the algorithm or operating procedure that generated this feature */
52
- source: string | null;
53
- /** The type of the feature */
54
- type: string | null;
55
- /** The start coordinates of the feature */
56
- start: number | null;
57
- /** The end coordinates of the feature */
58
- end: number | null;
59
- /** The score of the feature */
60
- score: number | null;
61
- /** The strand of the feature */
62
- strand: string | null;
63
- /** For features of type "CDS", the phase indicates where the next codon begins relative to the 5' end of the current CDS feature */
64
- phase: string | null;
65
- /** Feature attributes */
66
- attributes: GFF3Attributes | null;
67
- }
68
- /**
69
- * A GFF3 Feature line that includes references to other features defined in
70
- * their "Parent" or "Derives_from" attributes
71
- */
72
- export interface GFF3FeatureLineWithRefs extends GFF3FeatureLine {
73
- /** An array of child features */
74
- child_features: GFF3Feature[];
75
- /** An array of features derived from this feature */
76
- derived_features: GFF3Feature[];
77
- }
78
- /**
79
- * A GFF3 feature, which may include multiple individual feature lines
80
- */
81
- export type GFF3Feature = GFF3FeatureLineWithRefs[];
82
- /** A GFF3 directive */
83
- export interface GFF3Directive {
84
- /** The name of the directive */
85
- directive: string;
86
- /** The string value of the directive */
87
- value?: string;
88
- }
89
- /** A GFF3 sequence-region directive */
90
- export interface GFF3SequenceRegionDirective extends GFF3Directive {
91
- /** The string value of the directive */
92
- value: string;
93
- /** The sequence ID parsed from the directive */
94
- seq_id: string;
95
- /** The sequence start parsed from the directive */
96
- start: string;
97
- /** The sequence end parsed from the directive */
98
- end: string;
99
- }
100
- /** A GFF3 genome-build directive */
101
- export interface GFF3GenomeBuildDirective extends GFF3Directive {
102
- /** The string value of the directive */
103
- value: string;
104
- /** The genome build source parsed from the directive */
105
- source: string;
106
- /** The genome build name parsed from the directive */
107
- buildName: string;
108
- }
109
- /** A GFF3 comment */
110
- export interface GFF3Comment {
111
- /** The text of the comment */
112
- comment: string;
113
- }
114
- /** A GFF3 FASTA single sequence */
115
- export interface GFF3Sequence {
116
- /** The ID of the sequence */
117
- id: string;
118
- /** The description of the sequence */
119
- description?: string;
120
- /** The sequence */
121
- sequence: string;
122
- }
123
- export type GFF3Item = GFF3Feature | GFF3Directive | GFF3Comment | GFF3Sequence;
124
- export interface JBrowseFeature {
13
+ export interface GffFeature {
125
14
  start: number;
126
15
  end: number;
127
16
  strand?: number;
@@ -130,10 +19,20 @@ export interface JBrowseFeature {
130
19
  refName: string;
131
20
  phase?: number;
132
21
  score?: number;
133
- subfeatures: JBrowseFeature[];
22
+ subfeatures: GffFeature[];
134
23
  [key: string]: unknown;
135
24
  }
136
- export declare function parseAttributesJBrowse(attrString: string, result: Record<string, unknown>): void;
137
- export declare function parseAttributesJBrowseNoUnescape(attrString: string, result: Record<string, unknown>): void;
138
- export declare function parseFeatureJBrowse(line: string): JBrowseFeature;
139
- export declare function parseFeatureJBrowseNoUnescape(line: string): JBrowseFeature;
25
+ /**
26
+ * Parse the 9th column (attributes) of a GFF3 feature line into `result`,
27
+ * lowercasing keys and suffixing any that collide with a default field name.
28
+ * Pass shouldUnescape=false as a fast path for data with no escaped characters.
29
+ */
30
+ export declare function parseAttributes(attrString: string, result: Record<string, unknown>, shouldUnescape: boolean): void;
31
+ /**
32
+ * Parse a GFF3 feature line. Unescaping is skipped entirely for lines with no
33
+ * '%' character, which is the common case.
34
+ *
35
+ * @param line - GFF3 feature line
36
+ * @returns The parsed feature
37
+ */
38
+ export declare function parseFeature(line: string): GffFeature;