@gmod/bed 2.1.3 → 2.1.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/CHANGELOG.md +3 -1
- package/dist/as/autoSqlSchemas.js +169 -10
- package/dist/as/autoSqlSchemas.js.map +1 -1
- package/dist/defaultTypes.js +24 -16
- package/dist/defaultTypes.js.map +1 -1
- package/dist/package.json +1 -0
- package/dist/parser.d.ts +2 -2
- package/dist/parser.js +41 -40
- package/dist/parser.js.map +1 -1
- package/dist/util.js +16 -21
- package/dist/util.js.map +1 -1
- package/esm/defaultTypes.js +3 -2
- package/esm/defaultTypes.js.map +1 -1
- package/esm/parser.d.ts +2 -2
- package/esm/parser.js +29 -25
- package/esm/parser.js.map +1 -1
- package/esm/util.js +3 -4
- package/esm/util.js.map +1 -1
- package/package.json +17 -21
- package/src/defaultTypes.ts +3 -2
- package/src/parser.ts +31 -24
- package/src/util.ts +3 -4
- package/dist/autoSql.d.ts +0 -14
- package/dist/autoSql.js +0 -1515
- package/dist/autoSql.js.map +0 -1
- package/esm/autoSql.d.ts +0 -14
- package/esm/autoSql.js +0 -1515
- package/esm/autoSql.js.map +0 -1
package/esm/parser.js
CHANGED
|
@@ -1,24 +1,27 @@
|
|
|
1
|
+
// @ts-expect-error
|
|
1
2
|
import parser from './autoSql';
|
|
2
3
|
import types from './defaultTypes';
|
|
3
4
|
import { detectTypes } from './util';
|
|
4
5
|
const strandMap = { '.': 0, '-': -1, '+': 1 };
|
|
5
|
-
// heuristic that a BED file is BED12 like...the number in col 10 is
|
|
6
|
+
// heuristic that a BED file is BED12 like...the number in col 10 is
|
|
7
|
+
// blockCount-like
|
|
6
8
|
function isBed12Like(fields) {
|
|
7
|
-
var _a;
|
|
8
9
|
return (fields.length >= 12 &&
|
|
9
|
-
!Number.isNaN(parseInt(fields[9], 10)) &&
|
|
10
|
-
|
|
10
|
+
!Number.isNaN(Number.parseInt(fields[9], 10)) &&
|
|
11
|
+
fields[10]?.split(',').filter(f => !!f).length ===
|
|
12
|
+
Number.parseInt(fields[9], 10));
|
|
11
13
|
}
|
|
12
14
|
export default class BED {
|
|
13
|
-
constructor(
|
|
14
|
-
if (
|
|
15
|
-
this.autoSql = detectTypes(parser.parse(
|
|
15
|
+
constructor(arguments_ = {}) {
|
|
16
|
+
if (arguments_.autoSql) {
|
|
17
|
+
this.autoSql = detectTypes(parser.parse(arguments_.autoSql));
|
|
16
18
|
}
|
|
17
|
-
else if (
|
|
18
|
-
|
|
19
|
+
else if (arguments_.type) {
|
|
20
|
+
// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
|
|
21
|
+
if (!types[arguments_.type]) {
|
|
19
22
|
throw new Error('Type not found');
|
|
20
23
|
}
|
|
21
|
-
this.autoSql = detectTypes(types[
|
|
24
|
+
this.autoSql = detectTypes(types[arguments_.type]);
|
|
22
25
|
}
|
|
23
26
|
else {
|
|
24
27
|
this.autoSql = detectTypes(types.defaultBedSchema);
|
|
@@ -32,41 +35,42 @@ export default class BED {
|
|
|
32
35
|
* @param opts - supply opts.uniqueId
|
|
33
36
|
* @return a object representing a feature
|
|
34
37
|
*/
|
|
35
|
-
parseLine(line,
|
|
38
|
+
parseLine(line, options = {}) {
|
|
36
39
|
const { autoSql } = this;
|
|
37
|
-
const { uniqueId } =
|
|
40
|
+
const { uniqueId } = options;
|
|
38
41
|
const fields = Array.isArray(line) ? line : line.split('\t');
|
|
39
42
|
let feature = {};
|
|
40
43
|
if (!this.attemptDefaultBed ||
|
|
44
|
+
// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
|
|
41
45
|
(this.attemptDefaultBed && isBed12Like(fields))) {
|
|
42
|
-
for (let
|
|
43
|
-
const autoField = autoSql.fields[
|
|
44
|
-
let
|
|
46
|
+
for (let index = 0; index < autoSql.fields.length; index++) {
|
|
47
|
+
const autoField = autoSql.fields[index];
|
|
48
|
+
let columnValue = fields[index];
|
|
45
49
|
const { isNumeric, isArray, arrayIsNumeric, name } = autoField;
|
|
46
|
-
if (
|
|
50
|
+
if (columnValue === null || columnValue === undefined) {
|
|
47
51
|
break;
|
|
48
52
|
}
|
|
49
|
-
if (
|
|
53
|
+
if (columnValue !== '.') {
|
|
50
54
|
if (isNumeric) {
|
|
51
|
-
const
|
|
52
|
-
|
|
55
|
+
const number_ = Number(columnValue);
|
|
56
|
+
columnValue = Number.isNaN(number_) ? columnValue : number_;
|
|
53
57
|
}
|
|
54
58
|
else if (isArray) {
|
|
55
|
-
|
|
56
|
-
if (
|
|
57
|
-
|
|
59
|
+
columnValue = columnValue.split(',');
|
|
60
|
+
if (columnValue.at(-1) === '') {
|
|
61
|
+
columnValue.pop();
|
|
58
62
|
}
|
|
59
63
|
if (arrayIsNumeric) {
|
|
60
|
-
|
|
64
|
+
columnValue = columnValue.map(Number);
|
|
61
65
|
}
|
|
62
66
|
}
|
|
63
|
-
feature[name] =
|
|
67
|
+
feature[name] = columnValue;
|
|
64
68
|
}
|
|
65
69
|
}
|
|
66
70
|
}
|
|
67
71
|
else {
|
|
68
72
|
const fieldNames = ['chrom', 'chromStart', 'chromEnd', 'name'];
|
|
69
|
-
feature = Object.fromEntries(fields.map((f,
|
|
73
|
+
feature = Object.fromEntries(fields.map((f, index) => [fieldNames[index] || 'field' + index, f]));
|
|
70
74
|
feature.chromStart = +feature.chromStart;
|
|
71
75
|
feature.chromEnd = +feature.chromEnd;
|
|
72
76
|
if (!Number.isNaN(Number.parseFloat(feature.field4))) {
|
package/esm/parser.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"parser.js","sourceRoot":"","sources":["../src/parser.ts"],"names":[],"mappings":"AAAA,OAAO,MAAM,MAAM,WAAW,CAAA;AAC9B,OAAO,KAAK,MAAM,gBAAgB,CAAA;AAClC,OAAO,EAAE,WAAW,EAAmC,MAAM,QAAQ,CAAA;AAErE,MAAM,SAAS,GAAG,EAAE,GAAG,EAAE,CAAC,EAAE,GAAG,EAAE,CAAC,CAAC,EAAE,GAAG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AAO,CAAC,MAAM,KAAK,GAAG,IAAI,OAAO,CAAC,MAAM,KAAK,GAAG,EAAE,CAAC;gBACrD,OAAO,CAAC,MAAM,GAAG,OAAO,CAAC,MAAM,CAAA;gBAC/B,OAAO,OAAO,CAAC,MAAM,CAAA;YACvB,CAAC;QACH,CAAC;QACD,IAAI,QAAQ,EAAE,CAAC;YACb,OAAO,CAAC,QAAQ,GAAG,QAAQ,CAAA;QAC7B,CAAC;QACD,OAAO,CAAC,MAAM,GAAG,SAAS,CAAC,OAAO,CAAC,MAAgC,CAAC,IAAI,CAAC,CAAA;QAEzE,OAAO,CAAC,KAAK,GAAG,kBAAkB,CAAC,OAAO,CAAC,KAAK,CAAC,CAAA;QACjD,OAAO,OAAO,CAAA;IAChB,CAAC;CACF"}
|
package/esm/util.js
CHANGED
|
@@ -1,8 +1,7 @@
|
|
|
1
1
|
/*
|
|
2
|
-
* adds some type annotations to the autoSql schema
|
|
3
|
-
*
|
|
4
|
-
* for array types "isArray" is
|
|
5
|
-
* for numeric array types "isArray" and "arrayIsNumeric" is set
|
|
2
|
+
* adds some type annotations to the autoSql schema for numeric fields ['uint',
|
|
3
|
+
* 'int', 'float', 'long'] "isNumeric" is added for array types "isArray" is
|
|
4
|
+
* added for numeric array types "isArray" and "arrayIsNumeric" is set
|
|
6
5
|
*
|
|
7
6
|
* @param autoSql - an autoSql schema from the peg parser
|
|
8
7
|
* @return autoSql with type annotations added
|
package/esm/util.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"util.js","sourceRoot":"","sources":["../src/util.ts"],"names":[],"mappings":"AAIA
|
|
1
|
+
{"version":3,"file":"util.js","sourceRoot":"","sources":["../src/util.ts"],"names":[],"mappings":"AAIA;;;;;;;GAOG;AACH,MAAM,UAAU,WAAW,CAAC,OAAyB;IACnD,MAAM,YAAY,GAAG,IAAI,GAAG,CAAC,CAAC,MAAM,EAAE,KAAK,EAAE,OAAO,EAAE,MAAM,CAAC,CAAC,CAAA;IAC9D,OAAO;QACL,GAAG,OAAO;QACV,MAAM,EAAE,OAAO,CAAC,MAAM;aACnB,GAAG,CAAC,SAAS,CAAC,EAAE,CAAC,CAAC;YACjB,GAAG,SAAS;YACZ,OAAO,EAAE,SAAS,CAAC,IAAI,IAAI,SAAS,CAAC,IAAI,KAAK,MAAM;YACpD,cAAc,EAAE,SAAS,CAAC,IAAI,IAAI,YAAY,CAAC,GAAG,CAAC,SAAS,CAAC,IAAI,CAAC;YAClE,SAAS,EAAE,CAAC,SAAS,CAAC,IAAI,IAAI,YAAY,CAAC,GAAG,CAAC,SAAS,CAAC,IAAI,CAAC;SAC/D,CAAC,CAAC;YAEH,oFAAoF;aACnF,MAAM,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC;KACzB,CAAA;AACH,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@gmod/bed",
|
|
3
|
-
"version": "2.1.
|
|
3
|
+
"version": "2.1.4",
|
|
4
4
|
"description": "A BED file format parser with autoSql support",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"module": "esm/index.js",
|
|
@@ -24,35 +24,31 @@
|
|
|
24
24
|
"node": ">=6"
|
|
25
25
|
},
|
|
26
26
|
"scripts": {
|
|
27
|
-
"lint": "eslint --report-unused-disable-directives --max-warnings 0
|
|
28
|
-
"test": "
|
|
29
|
-
"coverage": "npm test -- --coverage",
|
|
27
|
+
"lint": "eslint --report-unused-disable-directives --max-warnings 0 src test",
|
|
28
|
+
"test": "vitest",
|
|
30
29
|
"clean": "rimraf dist esm",
|
|
31
30
|
"generate": "pegjs -o src/autoSql.js autoSql.pegjs",
|
|
32
31
|
"prebuild": "npm run clean",
|
|
33
|
-
"build:esm": "tsc --target
|
|
34
|
-
"build:es5": "tsc --target
|
|
32
|
+
"build:esm": "tsc --target es2020 --outDir esm",
|
|
33
|
+
"build:es5": "tsc --target es2020 --module commonjs --outDir dist",
|
|
34
|
+
"postbuild:es5": "echo '{\"type\": \"commonjs\"}' > dist/package.json",
|
|
35
35
|
"build": "npm run generate && npm run build:esm && npm run build:es5",
|
|
36
|
-
"preversion": "npm test && npm run build",
|
|
36
|
+
"preversion": "npm test run && npm run build",
|
|
37
37
|
"version": "standard-changelog && git add CHANGELOG.md",
|
|
38
38
|
"postversion": "git push --follow-tags"
|
|
39
39
|
},
|
|
40
40
|
"devDependencies": {
|
|
41
|
-
"@
|
|
42
|
-
"@typescript-eslint/
|
|
43
|
-
"@
|
|
44
|
-
"eslint": "^
|
|
45
|
-
"eslint-config-prettier": "^9.1.0",
|
|
46
|
-
"eslint-plugin-import": "^2.27.5",
|
|
47
|
-
"eslint-plugin-prettier": "^5.1.3",
|
|
48
|
-
"eslint-plugin-unicorn": "^51.0.1",
|
|
49
|
-
"jest": "^29.5.0",
|
|
41
|
+
"@typescript-eslint/eslint-plugin": "^8.4.0",
|
|
42
|
+
"@typescript-eslint/parser": "^8.4.0",
|
|
43
|
+
"@vitest/coverage-v8": "^3.0.3",
|
|
44
|
+
"eslint": "^9.9.1",
|
|
50
45
|
"pegjs": "^0.10.0",
|
|
51
|
-
"prettier": "^3.
|
|
52
|
-
"rimraf": "^
|
|
53
|
-
"standard-changelog": "^
|
|
54
|
-
"
|
|
55
|
-
"typescript": "^
|
|
46
|
+
"prettier": "^3.3.3",
|
|
47
|
+
"rimraf": "^6.0.1",
|
|
48
|
+
"standard-changelog": "^6.0.0",
|
|
49
|
+
"typescript": "^5.5.4",
|
|
50
|
+
"typescript-eslint": "^8.4.0",
|
|
51
|
+
"vitest": "^3.0.1"
|
|
56
52
|
},
|
|
57
53
|
"keywords": [
|
|
58
54
|
"bed",
|
package/src/defaultTypes.ts
CHANGED
|
@@ -1,10 +1,11 @@
|
|
|
1
|
+
// @ts-expect-error
|
|
1
2
|
import { parse } from './autoSql'
|
|
2
3
|
import { AutoSqlPreSchema } from './util'
|
|
3
4
|
import * as types from './as/autoSqlSchemas'
|
|
4
5
|
|
|
5
6
|
export default Object.fromEntries(
|
|
6
|
-
Object.entries(types).map(([key,
|
|
7
|
+
Object.entries(types).map(([key, value]) => [
|
|
7
8
|
key,
|
|
8
|
-
parse(
|
|
9
|
+
parse(value.trim()) as AutoSqlPreSchema,
|
|
9
10
|
]),
|
|
10
11
|
)
|
package/src/parser.ts
CHANGED
|
@@ -1,15 +1,18 @@
|
|
|
1
|
+
// @ts-expect-error
|
|
1
2
|
import parser from './autoSql'
|
|
2
3
|
import types from './defaultTypes'
|
|
3
4
|
import { detectTypes, AutoSqlSchema, AutoSqlPreSchema } from './util'
|
|
4
5
|
|
|
5
6
|
const strandMap = { '.': 0, '-': -1, '+': 1 }
|
|
6
7
|
|
|
7
|
-
// heuristic that a BED file is BED12 like...the number in col 10 is
|
|
8
|
+
// heuristic that a BED file is BED12 like...the number in col 10 is
|
|
9
|
+
// blockCount-like
|
|
8
10
|
function isBed12Like(fields: string[]) {
|
|
9
11
|
return (
|
|
10
12
|
fields.length >= 12 &&
|
|
11
|
-
!Number.isNaN(parseInt(fields[9], 10)) &&
|
|
12
|
-
fields[10]?.split(',').filter(f => !!f).length ===
|
|
13
|
+
!Number.isNaN(Number.parseInt(fields[9], 10)) &&
|
|
14
|
+
fields[10]?.split(',').filter(f => !!f).length ===
|
|
15
|
+
Number.parseInt(fields[9], 10)
|
|
13
16
|
)
|
|
14
17
|
}
|
|
15
18
|
export default class BED {
|
|
@@ -17,14 +20,17 @@ export default class BED {
|
|
|
17
20
|
|
|
18
21
|
private attemptDefaultBed?: boolean
|
|
19
22
|
|
|
20
|
-
constructor(
|
|
21
|
-
if (
|
|
22
|
-
this.autoSql = detectTypes(
|
|
23
|
-
|
|
24
|
-
|
|
23
|
+
constructor(arguments_: { autoSql?: string; type?: string } = {}) {
|
|
24
|
+
if (arguments_.autoSql) {
|
|
25
|
+
this.autoSql = detectTypes(
|
|
26
|
+
parser.parse(arguments_.autoSql) as AutoSqlPreSchema,
|
|
27
|
+
)
|
|
28
|
+
} else if (arguments_.type) {
|
|
29
|
+
// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
|
|
30
|
+
if (!types[arguments_.type]) {
|
|
25
31
|
throw new Error('Type not found')
|
|
26
32
|
}
|
|
27
|
-
this.autoSql = detectTypes(types[
|
|
33
|
+
this.autoSql = detectTypes(types[arguments_.type])
|
|
28
34
|
} else {
|
|
29
35
|
this.autoSql = detectTypes(types.defaultBedSchema)
|
|
30
36
|
this.attemptDefaultBed = true
|
|
@@ -38,44 +44,45 @@ export default class BED {
|
|
|
38
44
|
* @param opts - supply opts.uniqueId
|
|
39
45
|
* @return a object representing a feature
|
|
40
46
|
*/
|
|
41
|
-
parseLine(line: string | string[],
|
|
47
|
+
parseLine(line: string | string[], options: { uniqueId?: string } = {}) {
|
|
42
48
|
const { autoSql } = this
|
|
43
|
-
const { uniqueId } =
|
|
49
|
+
const { uniqueId } = options
|
|
44
50
|
const fields = Array.isArray(line) ? line : line.split('\t')
|
|
45
51
|
|
|
46
52
|
let feature = {} as Record<string, any>
|
|
47
53
|
if (
|
|
48
54
|
!this.attemptDefaultBed ||
|
|
55
|
+
// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
|
|
49
56
|
(this.attemptDefaultBed && isBed12Like(fields))
|
|
50
57
|
) {
|
|
51
|
-
for (let
|
|
52
|
-
const autoField = autoSql.fields[
|
|
53
|
-
let
|
|
58
|
+
for (let index = 0; index < autoSql.fields.length; index++) {
|
|
59
|
+
const autoField = autoSql.fields[index]
|
|
60
|
+
let columnValue: any = fields[index]
|
|
54
61
|
const { isNumeric, isArray, arrayIsNumeric, name } = autoField
|
|
55
|
-
if (
|
|
62
|
+
if (columnValue === null || columnValue === undefined) {
|
|
56
63
|
break
|
|
57
64
|
}
|
|
58
|
-
if (
|
|
65
|
+
if (columnValue !== '.') {
|
|
59
66
|
if (isNumeric) {
|
|
60
|
-
const
|
|
61
|
-
|
|
67
|
+
const number_ = Number(columnValue)
|
|
68
|
+
columnValue = Number.isNaN(number_) ? columnValue : number_
|
|
62
69
|
} else if (isArray) {
|
|
63
|
-
|
|
64
|
-
if (
|
|
65
|
-
|
|
70
|
+
columnValue = columnValue.split(',')
|
|
71
|
+
if (columnValue.at(-1) === '') {
|
|
72
|
+
columnValue.pop()
|
|
66
73
|
}
|
|
67
74
|
if (arrayIsNumeric) {
|
|
68
|
-
|
|
75
|
+
columnValue = columnValue.map(Number)
|
|
69
76
|
}
|
|
70
77
|
}
|
|
71
78
|
|
|
72
|
-
feature[name] =
|
|
79
|
+
feature[name] = columnValue
|
|
73
80
|
}
|
|
74
81
|
}
|
|
75
82
|
} else {
|
|
76
83
|
const fieldNames = ['chrom', 'chromStart', 'chromEnd', 'name']
|
|
77
84
|
feature = Object.fromEntries(
|
|
78
|
-
fields.map((f,
|
|
85
|
+
fields.map((f, index) => [fieldNames[index] || 'field' + index, f]),
|
|
79
86
|
)
|
|
80
87
|
feature.chromStart = +feature.chromStart
|
|
81
88
|
feature.chromEnd = +feature.chromEnd
|
package/src/util.ts
CHANGED
|
@@ -3,10 +3,9 @@ export interface AutoSqlPreSchema {
|
|
|
3
3
|
}
|
|
4
4
|
|
|
5
5
|
/*
|
|
6
|
-
* adds some type annotations to the autoSql schema
|
|
7
|
-
*
|
|
8
|
-
* for array types "isArray" is
|
|
9
|
-
* for numeric array types "isArray" and "arrayIsNumeric" is set
|
|
6
|
+
* adds some type annotations to the autoSql schema for numeric fields ['uint',
|
|
7
|
+
* 'int', 'float', 'long'] "isNumeric" is added for array types "isArray" is
|
|
8
|
+
* added for numeric array types "isArray" and "arrayIsNumeric" is set
|
|
10
9
|
*
|
|
11
10
|
* @param autoSql - an autoSql schema from the peg parser
|
|
12
11
|
* @return autoSql with type annotations added
|
package/dist/autoSql.d.ts
DELETED
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
declare function peg$SyntaxError(message: any, expected: any, found: any, location: any): void;
|
|
2
|
-
declare class peg$SyntaxError {
|
|
3
|
-
constructor(message: any, expected: any, found: any, location: any);
|
|
4
|
-
message: any;
|
|
5
|
-
expected: any;
|
|
6
|
-
found: any;
|
|
7
|
-
location: any;
|
|
8
|
-
name: string;
|
|
9
|
-
}
|
|
10
|
-
declare namespace peg$SyntaxError {
|
|
11
|
-
function buildMessage(expected: any, found: any): string;
|
|
12
|
-
}
|
|
13
|
-
declare function peg$parse(input: any, options: any): {};
|
|
14
|
-
export { peg$SyntaxError as SyntaxError, peg$parse as parse };
|