Skip to content

Commit

Permalink
Addded --rf option to compare trees #10
Browse files Browse the repository at this point in the history
  • Loading branch information
fredericlemoine committed Jan 6, 2021
1 parent 29e8076 commit b7b35cd
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
15 changes: 15 additions & 0 deletions cmd/comparetrees.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import (
)

var comparetreeidentical bool
var comparetreerf bool

// compareCmd represents the compare command
var compareTreesCmd = &cobra.Command{
Expand All @@ -33,6 +34,8 @@ For each trees in the compared tree file, it will print tab separated values wit
3) The number of branches that are common to both trees
4) The number of branches that are specific to the compared tree
If --rf is given, it only computes the Robinson-Foulds distance, as the sum of
reference + compared specific branches.
`,
RunE: func(cmd *cobra.Command, args []string) (err error) {
var treefile goio.Closer
Expand Down Expand Up @@ -81,6 +84,17 @@ For each trees in the compared tree file, it will print tab separated values wit
}
fmt.Printf("%d\t%v\n", st.Id, st.Sametree)
}
} else if comparetreerf {
for st := range stats {
if st.Err != nil {
/* We empty the channel if needed*/
for range stats {
}
io.LogError(st.Err)
return st.Err
}
fmt.Printf("%d\n", st.Tree1+st.Tree2)
}
} else {
fmt.Printf("tree\treference\tcommon\tcompared\n")
for st := range stats {
Expand All @@ -102,4 +116,5 @@ func init() {
compareCmd.AddCommand(compareTreesCmd)
compareTreesCmd.Flags().BoolVarP(&compareTips, "tips", "l", false, "Include tips in the comparison")
compareTreesCmd.Flags().BoolVar(&comparetreeidentical, "binary", false, "If true, then just print true (identical tree) or false (different tree) for each compared tree")
compareTreesCmd.Flags().BoolVar(&comparetreerf, "rf", false, "If true, outputs Robinson-Foulds distance, as the sum of reference + compared specific branches")
}
3 changes: 2 additions & 1 deletion docs/commands/compare.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ This command compares a reference tree -given with `-i` with a set of compared t
* For each missing tip in the compared tree, will print: `(Tree <id>) < TipName`,
* For each missing tip in the reference tree, will print: `(Tree <id>) > TipName`,
* Then print the number of common tips: `(Tree <id>) = <nb common>`,
* `gotree compare trees`: Compares the reference tree with all the compared trees, in terms of common bi-partitions. Output is tab separated with:
* `gotree compare trees`: Compares the reference tree with all the compared trees, in terms of common bi-partitions. If `--rf` option is given, only "number of branches specific to reference tree" + "number of branches specific to compared tree" is given. Otherwise, the output is tab separated with the following columns:
1. Compared tree index;
2. Number of branches specific to the reference tree;
3. Number of common branches between reference and compared trees;
Expand Down Expand Up @@ -77,6 +77,7 @@ Usage:
Flags:
--binary If true, then just print true (identical tree) or false (different tree) for each compared tree
-l, --tips Include tips in the comparison
--rf If true, outputs Robinson-Foulds distance, as the sum of reference + compared specific branches
Global Flags:
-c, --compared string Compared trees input file (default "none")
Expand Down

0 comments on commit b7b35cd

Please sign in to comment.