Skip to content

Commit

Permalink
Added --terminal option to comment comment clear
Browse files Browse the repository at this point in the history
  • Loading branch information
fredericlemoine committed Feb 8, 2024
1 parent 8907260 commit d6c6268
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 2 deletions.
14 changes: 12 additions & 2 deletions cmd/clearcomments.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
)

var edgecomments, nodecomments bool
var terminalcomments bool

// commentsCmd represents the comments command
var clearcommentsCmd = &cobra.Command{
Expand Down Expand Up @@ -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")
}
Expand All @@ -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")
}
16 changes: 16 additions & 0 deletions tree/tree.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit d6c6268

Please sign in to comment.