diff --git a/cmd/comparetrees.go b/cmd/comparetrees.go index e476a02..a075e20 100644 --- a/cmd/comparetrees.go +++ b/cmd/comparetrees.go @@ -13,6 +13,7 @@ import ( ) var comparetreeidentical bool +var comparetreerf bool // compareCmd represents the compare command var compareTreesCmd = &cobra.Command{ @@ -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 @@ -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 { @@ -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") } diff --git a/docs/commands/compare.md b/docs/commands/compare.md index d432632..b009ae9 100644 --- a/docs/commands/compare.md +++ b/docs/commands/compare.md @@ -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 ) < TipName`, * For each missing tip in the reference tree, will print: `(Tree ) > TipName`, * Then print the number of common tips: `(Tree ) = `, -* `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; @@ -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")