clustal-js 2.0.0 → 2.0.1
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 +4 -0
- package/dist/index.d.ts +36 -0
- package/dist/index.js +49 -0
- package/dist/pairwise.d.ts +11 -0
- package/dist/pairwise.js +57 -0
- package/dist/util.d.ts +17 -0
- package/dist/util.js +78 -0
- package/package.json +4 -1
package/CHANGELOG.md
CHANGED
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
export declare function parseClustalIter(arr: Iterator<string>): {
|
|
2
|
+
consensus: string;
|
|
3
|
+
alns: {
|
|
4
|
+
id: any;
|
|
5
|
+
seq: any;
|
|
6
|
+
}[];
|
|
7
|
+
header: {
|
|
8
|
+
info: string;
|
|
9
|
+
version: string;
|
|
10
|
+
};
|
|
11
|
+
};
|
|
12
|
+
export declare function parsePairwiseIter(arr: string): {
|
|
13
|
+
consensus: string;
|
|
14
|
+
alns: {
|
|
15
|
+
id: any;
|
|
16
|
+
seq: any;
|
|
17
|
+
}[];
|
|
18
|
+
};
|
|
19
|
+
export declare function parse(contents: string): {
|
|
20
|
+
consensus: string;
|
|
21
|
+
alns: {
|
|
22
|
+
id: any;
|
|
23
|
+
seq: any;
|
|
24
|
+
}[];
|
|
25
|
+
header: {
|
|
26
|
+
info: string;
|
|
27
|
+
version: string;
|
|
28
|
+
};
|
|
29
|
+
};
|
|
30
|
+
export declare function parsePairwise(contents: string): {
|
|
31
|
+
consensus: string;
|
|
32
|
+
alns: {
|
|
33
|
+
id: any;
|
|
34
|
+
seq: any;
|
|
35
|
+
}[];
|
|
36
|
+
};
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.parsePairwise = exports.parse = exports.parsePairwiseIter = exports.parseClustalIter = void 0;
|
|
4
|
+
const pairwise_1 = require("./pairwise");
|
|
5
|
+
const util_1 = require("./util");
|
|
6
|
+
function parseClustalIter(arr) {
|
|
7
|
+
const line = (0, util_1.getFirstNonEmptyLine)(arr);
|
|
8
|
+
if (!line) {
|
|
9
|
+
throw new Error('Empty file received');
|
|
10
|
+
}
|
|
11
|
+
const header = (0, util_1.parseHeader)(line);
|
|
12
|
+
const res = (0, util_1.parseBlocks)(arr);
|
|
13
|
+
if (res === undefined) {
|
|
14
|
+
throw new Error('No blocks parsed');
|
|
15
|
+
}
|
|
16
|
+
const alns = res.seqs.map((n, index) => ({ id: res.ids[index], seq: n }));
|
|
17
|
+
const { consensus } = res;
|
|
18
|
+
if (consensus.length != alns[0].seq.length) {
|
|
19
|
+
throw new Error(`Consensus length != sequence length. Con ${consensus.length} seq ${alns[0].seq.length}`);
|
|
20
|
+
}
|
|
21
|
+
return { consensus, alns, header };
|
|
22
|
+
}
|
|
23
|
+
exports.parseClustalIter = parseClustalIter;
|
|
24
|
+
function parsePairwiseIter(arr) {
|
|
25
|
+
const res = (0, pairwise_1.parsePairwiseBlocks)(arr.split('\n')[Symbol.iterator]());
|
|
26
|
+
if (res === undefined) {
|
|
27
|
+
throw new Error('No blocks parsed');
|
|
28
|
+
}
|
|
29
|
+
const alns = res.seqs.map((n, index) => ({ id: res.ids[index], seq: n }));
|
|
30
|
+
const { consensus } = res;
|
|
31
|
+
if (consensus.length != alns[0].seq.length) {
|
|
32
|
+
throw new Error(`Consensus length != sequence length. Con ${consensus.length} seq ${alns[0].seq.length}`);
|
|
33
|
+
}
|
|
34
|
+
return { consensus, alns };
|
|
35
|
+
}
|
|
36
|
+
exports.parsePairwiseIter = parsePairwiseIter;
|
|
37
|
+
function parse(contents) {
|
|
38
|
+
const iter = contents.split('\n')[Symbol.iterator]();
|
|
39
|
+
return parseClustalIter(iter);
|
|
40
|
+
}
|
|
41
|
+
exports.parse = parse;
|
|
42
|
+
function parsePairwise(contents) {
|
|
43
|
+
const res = contents
|
|
44
|
+
.split('\n')
|
|
45
|
+
.filter(f => !f.startsWith('#'))
|
|
46
|
+
.join('\n');
|
|
47
|
+
return parsePairwiseIter(res);
|
|
48
|
+
}
|
|
49
|
+
exports.parsePairwise = parsePairwise;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
export declare function getSeqBounds(line: string): readonly [number, number];
|
|
2
|
+
export declare function parsePairwiseBlock(arr: Iterator<string>): {
|
|
3
|
+
ids: any[];
|
|
4
|
+
seqs: any[];
|
|
5
|
+
consensus: string;
|
|
6
|
+
} | undefined;
|
|
7
|
+
export declare function parsePairwiseBlocks(arr: Iterator<string>): {
|
|
8
|
+
ids: any[];
|
|
9
|
+
seqs: any[];
|
|
10
|
+
consensus: string;
|
|
11
|
+
} | undefined;
|
package/dist/pairwise.js
ADDED
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.parsePairwiseBlocks = exports.parsePairwiseBlock = exports.getSeqBounds = void 0;
|
|
4
|
+
const util_1 = require("./util");
|
|
5
|
+
function getSeqBounds(line) {
|
|
6
|
+
const fields = line.split(/\s+/);
|
|
7
|
+
const k1 = fields[0].length + fields[1].length;
|
|
8
|
+
const temp = line.slice(k1);
|
|
9
|
+
const s = k1 + temp.indexOf(fields[2]);
|
|
10
|
+
const e = s + fields[2].length;
|
|
11
|
+
return [s, e];
|
|
12
|
+
}
|
|
13
|
+
exports.getSeqBounds = getSeqBounds;
|
|
14
|
+
// Use the first block to get the sequence identifiers
|
|
15
|
+
function parsePairwiseBlock(arr) {
|
|
16
|
+
let line = (0, util_1.getFirstNonEmptyLine)(arr);
|
|
17
|
+
const block = [];
|
|
18
|
+
let consensusLine = '';
|
|
19
|
+
if (!line) {
|
|
20
|
+
return undefined;
|
|
21
|
+
}
|
|
22
|
+
while (line) {
|
|
23
|
+
if (line[0] !== ' ') {
|
|
24
|
+
block.push(line);
|
|
25
|
+
}
|
|
26
|
+
else {
|
|
27
|
+
consensusLine = line;
|
|
28
|
+
}
|
|
29
|
+
line = arr.next().value;
|
|
30
|
+
}
|
|
31
|
+
const [start, end] = getSeqBounds(block[0]);
|
|
32
|
+
const fields = block.map(s => s.split(/\s+/));
|
|
33
|
+
const ids = fields.map(s => s[0]);
|
|
34
|
+
const seqs = fields.map(s => s[2]);
|
|
35
|
+
let consensus = consensusLine.slice(start, end);
|
|
36
|
+
// handle if the consensus trailing whitespace got trimmed
|
|
37
|
+
const remainder = seqs[0].length - consensus.length;
|
|
38
|
+
if (remainder) {
|
|
39
|
+
consensus += ' '.repeat(remainder);
|
|
40
|
+
}
|
|
41
|
+
return { ids, seqs, consensus };
|
|
42
|
+
}
|
|
43
|
+
exports.parsePairwiseBlock = parsePairwiseBlock;
|
|
44
|
+
function parsePairwiseBlocks(arr) {
|
|
45
|
+
let block;
|
|
46
|
+
const res = parsePairwiseBlock(arr);
|
|
47
|
+
if (res !== undefined) {
|
|
48
|
+
while ((block = parsePairwiseBlock(arr))) {
|
|
49
|
+
for (let i = 0; i < block.seqs.length; i++) {
|
|
50
|
+
res.seqs[i] += block.seqs[i];
|
|
51
|
+
}
|
|
52
|
+
res.consensus += block.consensus;
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
return res;
|
|
56
|
+
}
|
|
57
|
+
exports.parsePairwiseBlocks = parsePairwiseBlocks;
|
package/dist/util.d.ts
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
export declare function parseVersion(line: string): string;
|
|
2
|
+
export declare function parseHeader(info: string): {
|
|
3
|
+
info: string;
|
|
4
|
+
version: string;
|
|
5
|
+
};
|
|
6
|
+
export declare function getFirstNonEmptyLine(arr: Iterator<string>): any;
|
|
7
|
+
export declare function getSeqBounds(line: string): readonly [number, number];
|
|
8
|
+
export declare function parseBlock(arr: Iterator<string>): {
|
|
9
|
+
ids: any[];
|
|
10
|
+
seqs: any[];
|
|
11
|
+
consensus: string;
|
|
12
|
+
} | undefined;
|
|
13
|
+
export declare function parseBlocks(arr: Iterator<string>): {
|
|
14
|
+
ids: any[];
|
|
15
|
+
seqs: any[];
|
|
16
|
+
consensus: string;
|
|
17
|
+
} | undefined;
|
package/dist/util.js
ADDED
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.parseBlocks = exports.parseBlock = exports.getSeqBounds = exports.getFirstNonEmptyLine = exports.parseHeader = exports.parseVersion = void 0;
|
|
4
|
+
function parseVersion(line) {
|
|
5
|
+
const res = line.match(/\(?(\d+(\.\d+)+)\)?/);
|
|
6
|
+
return res && res.length > 1 ? res[1] : '';
|
|
7
|
+
}
|
|
8
|
+
exports.parseVersion = parseVersion;
|
|
9
|
+
function parseHeader(info) {
|
|
10
|
+
const knownHeaders = ['CLUSTAL', 'PROBCONS', 'MUSCLE', 'MSAPROBS', 'Kalign'];
|
|
11
|
+
if (!knownHeaders.some(l => info.startsWith(l))) {
|
|
12
|
+
console.warn(`${info} is not a known CLUSTAL header: ${knownHeaders.join(',')}, proceeding but could indicate an issue`);
|
|
13
|
+
}
|
|
14
|
+
const version = parseVersion(info);
|
|
15
|
+
return { info, version };
|
|
16
|
+
}
|
|
17
|
+
exports.parseHeader = parseHeader;
|
|
18
|
+
function getFirstNonEmptyLine(arr) {
|
|
19
|
+
// There should be two blank lines after the header line
|
|
20
|
+
let line = arr.next();
|
|
21
|
+
while (!line.done && line.value.trim() === '') {
|
|
22
|
+
line = arr.next();
|
|
23
|
+
}
|
|
24
|
+
return line.value;
|
|
25
|
+
}
|
|
26
|
+
exports.getFirstNonEmptyLine = getFirstNonEmptyLine;
|
|
27
|
+
function getSeqBounds(line) {
|
|
28
|
+
const fields = line.split(/\s+/);
|
|
29
|
+
const temp = line.slice(fields[0].length);
|
|
30
|
+
const s = fields[0].length + temp.indexOf(fields[1]);
|
|
31
|
+
const e = s + fields[1].length;
|
|
32
|
+
return [s, e];
|
|
33
|
+
}
|
|
34
|
+
exports.getSeqBounds = getSeqBounds;
|
|
35
|
+
// Use the first block to get the sequence identifiers
|
|
36
|
+
function parseBlock(arr) {
|
|
37
|
+
let line = getFirstNonEmptyLine(arr);
|
|
38
|
+
const block = [];
|
|
39
|
+
let consensusLine = '';
|
|
40
|
+
if (!line) {
|
|
41
|
+
return undefined;
|
|
42
|
+
}
|
|
43
|
+
while (line) {
|
|
44
|
+
if (line[0] !== ' ') {
|
|
45
|
+
block.push(line);
|
|
46
|
+
}
|
|
47
|
+
else {
|
|
48
|
+
consensusLine = line;
|
|
49
|
+
}
|
|
50
|
+
line = arr.next().value;
|
|
51
|
+
}
|
|
52
|
+
const [start, end] = getSeqBounds(block[0]);
|
|
53
|
+
const fields = block.map(s => s.split(/\s+/));
|
|
54
|
+
const ids = fields.map(s => s[0]);
|
|
55
|
+
const seqs = block.map(s => s.slice(start, end));
|
|
56
|
+
let consensus = consensusLine.slice(start, end);
|
|
57
|
+
// handle if the consensus trailing whitespace got trimmed
|
|
58
|
+
const remainder = seqs[0].length - consensus.length;
|
|
59
|
+
if (remainder) {
|
|
60
|
+
consensus += ' '.repeat(remainder);
|
|
61
|
+
}
|
|
62
|
+
return { ids, seqs, consensus };
|
|
63
|
+
}
|
|
64
|
+
exports.parseBlock = parseBlock;
|
|
65
|
+
function parseBlocks(arr) {
|
|
66
|
+
let block;
|
|
67
|
+
const res = parseBlock(arr);
|
|
68
|
+
if (res !== undefined) {
|
|
69
|
+
while ((block = parseBlock(arr))) {
|
|
70
|
+
for (let i = 0; i < block.seqs.length; i++) {
|
|
71
|
+
res.seqs[i] += block.seqs[i];
|
|
72
|
+
}
|
|
73
|
+
res.consensus += block.consensus;
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
return res;
|
|
77
|
+
}
|
|
78
|
+
exports.parseBlocks = parseBlocks;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "clustal-js",
|
|
3
|
-
"version": "2.0.
|
|
3
|
+
"version": "2.0.1",
|
|
4
4
|
"main": "dist/index.js",
|
|
5
5
|
"repository": "cmdcolin/clustal-js",
|
|
6
6
|
"files": [
|
|
@@ -22,9 +22,12 @@
|
|
|
22
22
|
"typescript": "^5.3.3"
|
|
23
23
|
},
|
|
24
24
|
"scripts": {
|
|
25
|
+
"clean": "rimraf dist",
|
|
25
26
|
"test": "jest",
|
|
26
27
|
"lint": "eslint --ext .ts src test",
|
|
27
28
|
"build": "tsc",
|
|
29
|
+
"prebuild": "npm run clean",
|
|
30
|
+
"preversion": "npm run lint && npm test && npm run build",
|
|
28
31
|
"postversion": "git push --follow-tags"
|
|
29
32
|
}
|
|
30
33
|
}
|