Skip to content

Commit

Permalink
Rename branchset to children
Browse files Browse the repository at this point in the history
  • Loading branch information
cmdcolin committed Aug 29, 2024
1 parent d5d12ad commit ea9da75
Show file tree
Hide file tree
Showing 11 changed files with 214 additions and 73 deletions.
2 changes: 1 addition & 1 deletion app/src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ const mymodel = AppGlobal.create(
},
)

let lastTime = 0
const lastTime = 0

Check warning on line 25 in app/src/App.tsx

View workflow job for this annotation

GitHub Actions / Test and typecheck on node 20.x and ubuntu-latest

'lastTime' is assigned a value but never used
// onSnapshot(mymodel, snap => {
// const now = Date.now()
// if (now - lastTime >= 1000) {
Expand Down
16 changes: 10 additions & 6 deletions lib/src/model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,11 @@ function stateModelFactory() {
* data from the loaded tree/msa/treeMetadata, generally loaded by
* autorun
*/
data: types.optional(DataModelF(), { tree: '', msa: '' }),
data: types.optional(DataModelF(), {
tree: '',
msa: '',
treeMetadata: '',
}),

/**
* #property
Expand Down Expand Up @@ -478,7 +482,7 @@ function stateModelFactory() {
/**
* #action
*/
setData(data: { msa?: string; tree?: string }) {
setData(data: { msa?: string; tree?: string; treeMetadata?: string }) {
self.data = cast(data)
},

Expand Down Expand Up @@ -651,7 +655,7 @@ function stateModelFactory() {
} else {
ret = this.MSA?.getTree() || {
noTree: true,
branchset: [],
children: [],
id: 'empty',
name: 'empty',
}
Expand All @@ -676,10 +680,10 @@ function stateModelFactory() {
* #getter
*/
get root() {
let hier = hierarchy(this.tree, d => d.branchset)
// todo: investigate whether needed, typescript says branchset always true
let hier = hierarchy(this.tree, d => d.children)
// todo: investigate whether needed, typescript says children always true
// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
.sum(d => (d.branchset ? 0 : 1))
.sum(d => (d.children ? 0 : 1))
.sort((a, b) => ascending(a.data.length || 1, b.data.length || 1))

if (self.showOnly) {
Expand Down
14 changes: 7 additions & 7 deletions lib/src/parseNewick.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,13 +34,13 @@
* Converted to JSON:
* {
* name: "F",
* branchset: [
* children: [
* {name: "A", length: 0.1},
* {name: "B", length: 0.2},
* {
* name: "E",
* length: 0.5,
* branchset: [
* children: [
* {name: "C", length: 0.3},
* {name: "D", length: 0.4}
* ]
Expand All @@ -50,9 +50,9 @@
*
* Converted to JSON, but with no names or lengths:
* {
* branchset: [
* children: [
* {}, {}, {
* branchset: [{}, {}]
* children: [{}, {}]
* }
* ]
* }
Expand All @@ -66,13 +66,13 @@ export default function parse(s: string) {
const token = tokens[i]!
const subtree = {}
switch (token) {
case '(': // new branchset
tree.branchset = [subtree]
case '(': // new children
tree.children = [subtree]
ancestors.push(tree)
tree = subtree
break
case ',': // another branch
ancestors.at(-1)?.branchset.push(subtree)
ancestors.at(-1)?.children.push(subtree)
tree = subtree
break
case ')': // optional name next
Expand Down
4 changes: 2 additions & 2 deletions lib/src/parsers/ClustalMSA.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,10 @@ export default class ClustalMSA {
id: 'root',
name: 'root',
noTree: true,
branchset: this.getNames().map(name => ({
children: this.getNames().map(name => ({
id: name,
name,
branchset: [],
children: [],
})),
}
}
Expand Down
4 changes: 2 additions & 2 deletions lib/src/parsers/EmfMSA.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,10 @@ export default class EmfMSA {
id: 'root',
name: 'root',
noTree: true,
branchset: this.getNames().map(name => ({
children: this.getNames().map(name => ({
id: name,
name,
branchset: [],
children: [],
})),
}
}
Expand Down
4 changes: 2 additions & 2 deletions lib/src/parsers/FastaMSA.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,9 +61,9 @@ export default class FastaMSA {
id: 'root',
name: 'root',
noTree: true,
branchset: this.getNames().map(name => ({
children: this.getNames().map(name => ({
id: name,
branchset: [],
children: [],
name,
})),
}
Expand Down
4 changes: 2 additions & 2 deletions lib/src/parsers/StockholmMSA.ts
Original file line number Diff line number Diff line change
Expand Up @@ -100,9 +100,9 @@ export default class StockholmMSA {
id: 'root',
name: 'root',
noTree: true,
branchset: this.getNames().map(name => ({
children: this.getNames().map(name => ({
id: name,
branchset: [],
children: [],
name,
})),
}
Expand Down
6 changes: 3 additions & 3 deletions lib/src/reparseTree.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@ import type { NodeWithIds } from './util'
export function reparseTree(tree: NodeWithIds): NodeWithIds {
return {
...tree,
branchset: tree.branchset.map(r =>
r.branchset.length
children: tree.children.map(r =>
r.children.length
? reparseTree(r)
: {
branchset: [r],
children: [r],
id: `${r.id}-leafnode`,
name: `${r.name}-hidden`,
},
Expand Down
10 changes: 5 additions & 5 deletions lib/src/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,23 +14,23 @@ export function transform<T>(
}

interface Node {
branchset?: Node[]
children?: Node[]
name?: string
[key: string]: unknown
}

export interface NodeWithIds {
id: string
name: string
branchset: NodeWithIds[]
children: NodeWithIds[]
length?: number
noTree?: boolean
}

export interface NodeWithIdsAndLength {
id: string
name: string
branchset: NodeWithIdsAndLength[]
children: NodeWithIdsAndLength[]
noTree?: boolean
length: number
}
Expand All @@ -46,8 +46,8 @@ export function generateNodeIds(
...tree,
id,
name: tree.name || id,
branchset:
tree.branchset?.map((b, i) =>
children:
tree.children?.map((b, i) =>
generateNodeIds(b, `${id}-${i}`, depth + 1),
) || [],
}
Expand Down
Loading

0 comments on commit ea9da75

Please sign in to comment.