clustal-js 1.0.3 → 1.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 CHANGED
@@ -8,7 +8,7 @@ This parses clustal output format
8
8
  ## Usage
9
9
 
10
10
  ```js
11
- import {parse} from '@gmod/clustal'
11
+ import {parse} from 'clustal-js'
12
12
  const file = fs.readFileSync('test.aln', 'utf8')
13
13
  const ret = parse(file)
14
14
  ```
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "clustal-js",
3
- "version": "1.0.3",
3
+ "version": "1.0.4",
4
4
  "main": "dist/index.js",
5
5
  "repository": "cmdcolin/clustal-js",
6
6
  "files": [
package/dist/index.d.ts DELETED
@@ -1,3 +0,0 @@
1
- import { Results } from "./types";
2
- export declare function parseIter(arr: Iterator<string>): Results;
3
- export declare function parse(contents: string): Results;
package/dist/index.js DELETED
@@ -1,25 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.parse = exports.parseIter = void 0;
4
- const util_1 = require("./util");
5
- function parseIter(arr) {
6
- const line = util_1.getFirstNonEmptyLine(arr);
7
- if (!line)
8
- throw new Error("Empty file received");
9
- const header = util_1.parseHeader(line);
10
- const res = util_1.parseBlocks(arr);
11
- if (res === undefined)
12
- throw new Error("No blocks parsed");
13
- const alns = res.seqs.map((n, index) => ({ id: res.ids[index], seq: n }));
14
- const { consensus } = res;
15
- if (consensus.length != alns[0].seq.length) {
16
- throw new Error(`Consensus length != sequence length. Con ${consensus.length} seq ${alns[0].seq.length}`);
17
- }
18
- return { consensus, alns, header };
19
- }
20
- exports.parseIter = parseIter;
21
- function parse(contents) {
22
- const iter = contents.split("\n")[Symbol.iterator]();
23
- return parseIter(iter);
24
- }
25
- exports.parse = parse;
package/dist/types.d.ts DELETED
@@ -1,18 +0,0 @@
1
- export interface Header {
2
- version: string;
3
- info: string;
4
- }
5
- export interface Alignment {
6
- id: string;
7
- seq: string;
8
- }
9
- export interface Block {
10
- consensus: string;
11
- seqs: string[];
12
- ids: string[];
13
- }
14
- export interface Results {
15
- header: Header;
16
- alns: Alignment[];
17
- consensus: string;
18
- }
package/dist/types.js DELETED
@@ -1,2 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
package/dist/util.d.ts DELETED
@@ -1,7 +0,0 @@
1
- import { Header, Block } from "./types";
2
- export declare function parseVersion(line: string): string;
3
- export declare function parseHeader(info: string): Header;
4
- export declare function getFirstNonEmptyLine(arr: Iterator<string>): string;
5
- export declare function getSeqBounds(line: string): number[];
6
- export declare function parseBlock(arr: Iterator<string>): Block | undefined;
7
- export declare function parseBlocks(arr: Iterator<string>): Block | undefined;
package/dist/util.js DELETED
@@ -1,75 +0,0 @@
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.find((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
- while (line) {
43
- if (line[0] !== " ")
44
- block.push(line);
45
- else
46
- consensusLine = line;
47
- line = arr.next().value;
48
- }
49
- const [start, end] = getSeqBounds(block[0]);
50
- const fields = block.map((s) => s.split(/\s+/));
51
- const ids = fields.map((s) => s[0]);
52
- const seqs = block.map((s) => s.slice(start, end));
53
- let consensus = consensusLine.slice(start, end);
54
- // handle if the consensus trailing whitespace got trimmed
55
- const remainder = seqs[0].length - consensus.length;
56
- if (remainder) {
57
- consensus += " ".repeat(remainder);
58
- }
59
- return { ids, seqs, consensus };
60
- }
61
- exports.parseBlock = parseBlock;
62
- function parseBlocks(arr) {
63
- let block;
64
- const res = parseBlock(arr);
65
- if (res !== undefined) {
66
- while ((block = parseBlock(arr))) {
67
- for (let i = 0; i < block.seqs.length; i++) {
68
- res.seqs[i] += block.seqs[i];
69
- }
70
- res.consensus += block.consensus;
71
- }
72
- }
73
- return res;
74
- }
75
- exports.parseBlocks = parseBlocks;