diff --git a/cmd/clearcomments.go b/cmd/clearcomments.go index a0068c5..b78ffff 100644 --- a/cmd/clearcomments.go +++ b/cmd/clearcomments.go @@ -10,6 +10,7 @@ import ( ) var edgecomments, nodecomments bool +var terminalcomments bool // commentsCmd represents the comments command var clearcommentsCmd = &cobra.Command{ @@ -54,10 +55,18 @@ If both or none are given, will remove every comments. return t.Err } if nodecomments { - t.Tree.ClearNodeComments() + if terminalcomments { + t.Tree.ClearTipsComments() + } else { + t.Tree.ClearNodeComments() + } } if edgecomments { - t.Tree.ClearEdgeComments() + if terminalcomments { + t.Tree.ClearTerminalEdgeComments() + } else { + t.Tree.ClearEdgeComments() + } } f.WriteString(t.Tree.Newick() + "\n") } @@ -69,4 +78,5 @@ func init() { commentCmd.AddCommand(clearcommentsCmd) clearcommentsCmd.PersistentFlags().BoolVar(&edgecomments, "edges-only", false, "Clear comments on edges only") clearcommentsCmd.PersistentFlags().BoolVar(&nodecomments, "nodes-only", false, "Clear comments on nodes only") + clearcommentsCmd.PersistentFlags().BoolVar(&terminalcomments, "terminal", false, "Clear comments on tips / terminal branches only") } diff --git a/tree/tree.go b/tree/tree.go index 7c7a946..cab2aa8 100644 --- a/tree/tree.go +++ b/tree/tree.go @@ -1390,6 +1390,22 @@ func (t *Tree) ClearEdgeComments() { } } +func (t *Tree) ClearTipsComments() { + nodes := t.Tips() + for _, n := range nodes { + n.ClearComments() + } +} + +func (t *Tree) ClearTerminalEdgeComments() { + edges := t.Edges() + for _, e := range edges { + if e.Right().Tip() { + e.ClearComments() + } + } +} + // RemoveEdges removes the given branches from the tree if they are not // tip edges. // If removeRoot is true: In the case of rooted tree, branches