WFA-JS/src/main.js

31 lines
1.0 KiB
JavaScript
Raw Normal View History

2024-03-25 21:29:30 +00:00
import wf_align from "./wfa.js";
2024-05-28 19:40:16 +00:00
import fs from "fs";
import ProgressBar from "progress";
2024-03-25 21:29:30 +00:00
2024-05-28 19:40:16 +00:00
let data = fs.readFileSync("./tests/tests.json");
data = JSON.parse(data);
const sequences = fs.readFileSync("./tests/sequences").toString().split("\n");
//const total = sequences.length;
const total = 500; // skip the later tests because of memory usage
2024-03-25 21:29:30 +00:00
2024-05-28 19:40:16 +00:00
for (const test_name of Object.keys(data)) {
const test = data[test_name];
const penalties = test.penalties;
const solutions = fs.readFileSync(test.solutions).toString().split("\n");
const bar = new ProgressBar(":bar :current/:total", { total: total / 2 });
console.log(`test: ${test_name}`);
let correct = 0;
let j = 0;
for (let i = 0; i < total; i += 2) {
const s1 = sequences[i].replace(">");
const s2 = sequences[i + 1].replace("<");
const { CIGAR, score } = wf_align(s1, s2, penalties);
const solution_score = Number(solutions[j].split("\t")[0]);
if (solution_score === -score) {
correct += 1;
}
j += 1;
bar.tick();
}
console.log(`correct: ${correct}\ntotal: ${total / 2}\n`);
}