Skip to content

Commit

Permalink
Merge pull request #53 from clockor2/new-nwk-parser
Browse files Browse the repository at this point in the history
perf: faster newick parser and better annotation writing
  • Loading branch information
LeoFeatherstone authored Mar 14, 2024
2 parents 503c37c + 97d744f commit ce8ee97
Show file tree
Hide file tree
Showing 17 changed files with 683 additions and 14,199 deletions.
9 changes: 9 additions & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,5 +28,14 @@ module.exports = {
'@typescript-eslint/no-var-requires': 'off',
'@typescript-eslint/ban-ts-comment': 'off',
'@typescript-eslint/no-explicit-any': 'off',
"no-unused-vars": "off",
"@typescript-eslint/no-unused-vars": [
"warn", // or "error"
{
"argsIgnorePattern": "^_",
"varsIgnorePattern": "^_",
"caughtErrorsIgnorePattern": "^_"
}
]
},
};
2 changes: 1 addition & 1 deletion .husky/pre-commit
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/bin/sh
. "$(dirname "$0")/_/husky.sh"

npx lint-staged
npx lint-staged
2 changes: 1 addition & 1 deletion .husky/prepare-commit-msg
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/bin/sh
. "$(dirname "$0")/_/husky.sh"

exec </dev/tty && node_modules/.bin/cz --hook || true
# Check if /dev/tty exists or is accessible
10 changes: 5 additions & 5 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"editor.formatOnSave": true,
"[typescript]": {
"editor.defaultFormatter": "esbenp.prettier-vscode"
}
}
"editor.formatOnSave": true,
"[typescript]": {
"editor.defaultFormatter": "vscode.typescript-language-features"
}
}
23 changes: 12 additions & 11 deletions docs/examples/test/examples.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
/////////////////////////////////////////////////////

import { readNewick, readTreesFromPhyloXML, readTreesFromNewick, writeNewick, Tree } from '@phylojs';
import { beastAnnotation } from '../../../src/io/writers/newick';

describe('Examples', () => {
test('RTTR', () => {
Expand Down Expand Up @@ -115,7 +116,7 @@ describe('Examples', () => {
}
}
}
expect(writeNewick(tree, true)).not.toEqual(newick);
expect(writeNewick(tree, beastAnnotation)).not.toEqual(newick);
});

test('annotations subset', () => {
Expand All @@ -132,7 +133,7 @@ describe('Examples', () => {
}
}

expect(writeNewick(tree, true)).not.toEqual(newick);
expect(writeNewick(tree, beastAnnotation)).not.toEqual(newick);
});

test('multiple trees', () => {
Expand Down Expand Up @@ -284,7 +285,7 @@ describe('Examples', () => {
});

// Expect annotations in newick with `true` flag
expect(writeNewick(tree, true)).not.toBe(nwk)
expect(writeNewick(tree, beastAnnotation)).not.toBe(nwk)
})

test('Pruning', () => {
Expand All @@ -298,10 +299,10 @@ describe('Examples', () => {
.nodeList[node.parent.id] // Select node's parent by `id`
.removeChild(node) // Pruning step

console.log(`
Original Nwk: ${nwk}
Pruned Tree: ${writeNewick(tree)}
`)
// console.log(`
// Original Nwk: ${nwk}
// Pruned Tree: ${writeNewick(tree)}
// `)
// Returns
// Original Nwk: ((A,B),(C,D));
// Pruned Tree: (("C":0.0,"D":0.0):0.0):0.0;
Expand All @@ -324,10 +325,10 @@ describe('Examples', () => {
.addChild(node.copy()) // .copy() to ensure we don't bump into recursion issues
}

console.log(`
Original Nwk: ${nwk}
Pruned Tree: ${writeNewick(tree)}
`)
// console.log(`
// Original Nwk: ${nwk}
// Pruned Tree: ${writeNewick(tree)}
// `)
// Return
// Original Nwk: ((A,B),(C,D));
// Pruned Tree: (((("A":0.0,"B":0.0):0.0)"A":0.0,(((("A":0.0,"B":0.0):0.0)"A":0.0,"B":0.0):0.0)"B":0.0):0.0,("C":0.0,"D":0.0):0.0):0.0;
Expand Down
Loading

0 comments on commit ce8ee97

Please sign in to comment.