clustal-js 1.0.2 → 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/CHANGELOG.md CHANGED
@@ -1,3 +1,8 @@
1
+ # v1.0.3
2
+
3
+ - Add generated typescript declarations to output
4
+
5
+
1
6
  ## v1.0.2
2
7
 
3
8
  - Add dist folder to package.json
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,7 +1,8 @@
1
1
  {
2
2
  "name": "clustal-js",
3
- "version": "1.0.2",
3
+ "version": "1.0.4",
4
4
  "main": "dist/index.js",
5
+ "repository": "cmdcolin/clustal-js",
5
6
  "files": [
6
7
  "dist"
7
8
  ],
package/dist/index.js DELETED
@@ -1,29 +0,0 @@
1
- import { parseBlocks, parseHeader, getFirstNonEmptyLine } from "./util";
2
- export function parseIter(arr) {
3
- const line = getFirstNonEmptyLine(arr);
4
- if (!line) throw new Error("Empty file received");
5
- const header = parseHeader(line);
6
- const res = parseBlocks(arr);
7
- if (res === undefined) throw new Error("No blocks parsed");
8
- const alns = res.seqs.map((n, index) => ({
9
- id: res.ids[index],
10
- seq: n
11
- }));
12
- const {
13
- consensus
14
- } = res;
15
-
16
- if (consensus.length != alns[0].seq.length) {
17
- throw new Error(`Consensus length != sequence length. Con ${consensus.length} seq ${alns[0].seq.length}`);
18
- }
19
-
20
- return {
21
- consensus,
22
- alns,
23
- header
24
- };
25
- }
26
- export function parse(contents) {
27
- const iter = contents.split("\n")[Symbol.iterator]();
28
- return parseIter(iter);
29
- }
package/dist/types.js DELETED
File without changes
package/dist/util.js DELETED
@@ -1,80 +0,0 @@
1
- export function parseVersion(line) {
2
- const res = line.match(/\(?(\d+(\.\d+)+)\)?/);
3
- return res && res.length > 1 ? res[1] : "";
4
- }
5
- export function parseHeader(info) {
6
- const knownHeaders = ["CLUSTAL", "PROBCONS", "MUSCLE", "MSAPROBS", "Kalign"];
7
-
8
- if (!knownHeaders.find(l => info.startsWith(l))) {
9
- console.warn(`${info} is not a known CLUSTAL header: ${knownHeaders.join(",")}, proceeding but could indicate an issue`);
10
- }
11
-
12
- const version = parseVersion(info);
13
- return {
14
- info,
15
- version
16
- };
17
- }
18
- export function getFirstNonEmptyLine(arr) {
19
- // There should be two blank lines after the header line
20
- let line = arr.next();
21
-
22
- while (!line.done && line.value.trim() === "") {
23
- line = arr.next();
24
- }
25
-
26
- return line.value;
27
- }
28
- export function getSeqBounds(line) {
29
- const fields = line.split(/\s+/);
30
- const temp = line.slice(fields[0].length);
31
- const s = fields[0].length + temp.indexOf(fields[1]);
32
- const e = s + fields[1].length;
33
- return [s, e];
34
- } // Use the first block to get the sequence identifiers
35
-
36
- export function parseBlock(arr) {
37
- let line = getFirstNonEmptyLine(arr);
38
- const block = [];
39
- let consensusLine = "";
40
- if (!line) return undefined;
41
-
42
- while (line) {
43
- if (line[0] !== " ") block.push(line);else consensusLine = line;
44
- line = arr.next().value;
45
- }
46
-
47
- const [start, end] = getSeqBounds(block[0]);
48
- const fields = block.map(s => s.split(/\s+/));
49
- const ids = fields.map(s => s[0]);
50
- const seqs = block.map(s => s.slice(start, end));
51
- let consensus = consensusLine.slice(start, end); // handle if the consensus trailing whitespace got trimmed
52
-
53
- const remainder = seqs[0].length - consensus.length;
54
-
55
- if (remainder) {
56
- consensus += " ".repeat(remainder);
57
- }
58
-
59
- return {
60
- ids,
61
- seqs,
62
- consensus
63
- };
64
- }
65
- export function parseBlocks(arr) {
66
- let block;
67
- const res = parseBlock(arr);
68
-
69
- if (res !== undefined) {
70
- while (block = parseBlock(arr)) {
71
- for (let i = 0; i < block.seqs.length; i++) {
72
- res.seqs[i] += block.seqs[i];
73
- }
74
-
75
- res.consensus += block.consensus;
76
- }
77
- }
78
-
79
- return res;
80
- }