clustal-js
Advanced tools
Comparing version 1.0.2 to 1.0.3
@@ -0,1 +1,6 @@ | ||
# v1.0.3 | ||
- Add generated typescript declarations to output | ||
## v1.0.2 | ||
@@ -2,0 +7,0 @@ |
@@ -1,29 +0,25 @@ | ||
import { parseBlocks, parseHeader, getFirstNonEmptyLine } from "./util"; | ||
export function parseIter(arr) { | ||
const line = getFirstNonEmptyLine(arr); | ||
if (!line) throw new Error("Empty file received"); | ||
const header = parseHeader(line); | ||
const res = parseBlocks(arr); | ||
if (res === undefined) throw new Error("No blocks parsed"); | ||
const alns = res.seqs.map((n, index) => ({ | ||
id: res.ids[index], | ||
seq: n | ||
})); | ||
const { | ||
consensus | ||
} = res; | ||
if (consensus.length != alns[0].seq.length) { | ||
throw new Error(`Consensus length != sequence length. Con ${consensus.length} seq ${alns[0].seq.length}`); | ||
} | ||
return { | ||
consensus, | ||
alns, | ||
header | ||
}; | ||
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.parse = exports.parseIter = void 0; | ||
const util_1 = require("./util"); | ||
function parseIter(arr) { | ||
const line = util_1.getFirstNonEmptyLine(arr); | ||
if (!line) | ||
throw new Error("Empty file received"); | ||
const header = util_1.parseHeader(line); | ||
const res = util_1.parseBlocks(arr); | ||
if (res === undefined) | ||
throw new Error("No blocks parsed"); | ||
const alns = res.seqs.map((n, index) => ({ id: res.ids[index], seq: n })); | ||
const { consensus } = res; | ||
if (consensus.length != alns[0].seq.length) { | ||
throw new Error(`Consensus length != sequence length. Con ${consensus.length} seq ${alns[0].seq.length}`); | ||
} | ||
return { consensus, alns, header }; | ||
} | ||
export function parse(contents) { | ||
const iter = contents.split("\n")[Symbol.iterator](); | ||
return parseIter(iter); | ||
} | ||
exports.parseIter = parseIter; | ||
function parse(contents) { | ||
const iter = contents.split("\n")[Symbol.iterator](); | ||
return parseIter(iter); | ||
} | ||
exports.parse = parse; |
145
dist/util.js
@@ -1,80 +0,75 @@ | ||
export function parseVersion(line) { | ||
const res = line.match(/\(?(\d+(\.\d+)+)\)?/); | ||
return res && res.length > 1 ? res[1] : ""; | ||
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.parseBlocks = exports.parseBlock = exports.getSeqBounds = exports.getFirstNonEmptyLine = exports.parseHeader = exports.parseVersion = void 0; | ||
function parseVersion(line) { | ||
const res = line.match(/\(?(\d+(\.\d+)+)\)?/); | ||
return res && res.length > 1 ? res[1] : ""; | ||
} | ||
export function parseHeader(info) { | ||
const knownHeaders = ["CLUSTAL", "PROBCONS", "MUSCLE", "MSAPROBS", "Kalign"]; | ||
if (!knownHeaders.find(l => info.startsWith(l))) { | ||
console.warn(`${info} is not a known CLUSTAL header: ${knownHeaders.join(",")}, proceeding but could indicate an issue`); | ||
} | ||
const version = parseVersion(info); | ||
return { | ||
info, | ||
version | ||
}; | ||
exports.parseVersion = parseVersion; | ||
function parseHeader(info) { | ||
const knownHeaders = ["CLUSTAL", "PROBCONS", "MUSCLE", "MSAPROBS", "Kalign"]; | ||
if (!knownHeaders.find((l) => info.startsWith(l))) { | ||
console.warn(`${info} is not a known CLUSTAL header: ${knownHeaders.join(",")}, proceeding but could indicate an issue`); | ||
} | ||
const version = parseVersion(info); | ||
return { info, version }; | ||
} | ||
export function getFirstNonEmptyLine(arr) { | ||
// There should be two blank lines after the header line | ||
let line = arr.next(); | ||
while (!line.done && line.value.trim() === "") { | ||
line = arr.next(); | ||
} | ||
return line.value; | ||
exports.parseHeader = parseHeader; | ||
function getFirstNonEmptyLine(arr) { | ||
// There should be two blank lines after the header line | ||
let line = arr.next(); | ||
while (!line.done && line.value.trim() === "") { | ||
line = arr.next(); | ||
} | ||
return line.value; | ||
} | ||
export function getSeqBounds(line) { | ||
const fields = line.split(/\s+/); | ||
const temp = line.slice(fields[0].length); | ||
const s = fields[0].length + temp.indexOf(fields[1]); | ||
const e = s + fields[1].length; | ||
return [s, e]; | ||
} // Use the first block to get the sequence identifiers | ||
export function parseBlock(arr) { | ||
let line = getFirstNonEmptyLine(arr); | ||
const block = []; | ||
let consensusLine = ""; | ||
if (!line) return undefined; | ||
while (line) { | ||
if (line[0] !== " ") block.push(line);else consensusLine = line; | ||
line = arr.next().value; | ||
} | ||
const [start, end] = getSeqBounds(block[0]); | ||
const fields = block.map(s => s.split(/\s+/)); | ||
const ids = fields.map(s => s[0]); | ||
const seqs = block.map(s => s.slice(start, end)); | ||
let consensus = consensusLine.slice(start, end); // handle if the consensus trailing whitespace got trimmed | ||
const remainder = seqs[0].length - consensus.length; | ||
if (remainder) { | ||
consensus += " ".repeat(remainder); | ||
} | ||
return { | ||
ids, | ||
seqs, | ||
consensus | ||
}; | ||
exports.getFirstNonEmptyLine = getFirstNonEmptyLine; | ||
function getSeqBounds(line) { | ||
const fields = line.split(/\s+/); | ||
const temp = line.slice(fields[0].length); | ||
const s = fields[0].length + temp.indexOf(fields[1]); | ||
const e = s + fields[1].length; | ||
return [s, e]; | ||
} | ||
export function parseBlocks(arr) { | ||
let block; | ||
const res = parseBlock(arr); | ||
if (res !== undefined) { | ||
while (block = parseBlock(arr)) { | ||
for (let i = 0; i < block.seqs.length; i++) { | ||
res.seqs[i] += block.seqs[i]; | ||
} | ||
res.consensus += block.consensus; | ||
exports.getSeqBounds = getSeqBounds; | ||
// Use the first block to get the sequence identifiers | ||
function parseBlock(arr) { | ||
let line = getFirstNonEmptyLine(arr); | ||
const block = []; | ||
let consensusLine = ""; | ||
if (!line) | ||
return undefined; | ||
while (line) { | ||
if (line[0] !== " ") | ||
block.push(line); | ||
else | ||
consensusLine = line; | ||
line = arr.next().value; | ||
} | ||
} | ||
return res; | ||
} | ||
const [start, end] = getSeqBounds(block[0]); | ||
const fields = block.map((s) => s.split(/\s+/)); | ||
const ids = fields.map((s) => s[0]); | ||
const seqs = block.map((s) => s.slice(start, end)); | ||
let consensus = consensusLine.slice(start, end); | ||
// handle if the consensus trailing whitespace got trimmed | ||
const remainder = seqs[0].length - consensus.length; | ||
if (remainder) { | ||
consensus += " ".repeat(remainder); | ||
} | ||
return { ids, seqs, consensus }; | ||
} | ||
exports.parseBlock = parseBlock; | ||
function parseBlocks(arr) { | ||
let block; | ||
const res = parseBlock(arr); | ||
if (res !== undefined) { | ||
while ((block = parseBlock(arr))) { | ||
for (let i = 0; i < block.seqs.length; i++) { | ||
res.seqs[i] += block.seqs[i]; | ||
} | ||
res.consensus += block.consensus; | ||
} | ||
} | ||
return res; | ||
} | ||
exports.parseBlocks = parseBlocks; |
{ | ||
"name": "clustal-js", | ||
"version": "1.0.2", | ||
"version": "1.0.3", | ||
"main": "dist/index.js", | ||
"repository": "cmdcolin/clustal-js", | ||
"files": [ | ||
@@ -6,0 +7,0 @@ "dist" |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
No repository
Supply chain riskPackage does not have a linked source code repository. Without this field, a package will have no reference to the location of the source code use to generate the package.
Found 1 instance in 1 package
8256
9
130
0