-
Notifications
You must be signed in to change notification settings - Fork 16
/
roundlengths.go
65 lines (51 loc) · 1.64 KB
/
roundlengths.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
package cmd
import (
goio "io"
"os"
"github.com/evolbioinfo/gotree/io"
"github.com/evolbioinfo/gotree/tree"
"github.com/spf13/cobra"
)
var roundlengthprecision int
// roundlengthCmd represents the roundlength command
var roundlengthCmd = &cobra.Command{
Use: "round",
Short: "Rounds branch lengths of input trees",
Long: `Rounds branch lengths of input trees.
The precision is given by -p|--precision option, and is expressed in 1/10^precision
if -p 5 is given, precision of 10⁻5 is considered.
Does not do anything if precision is <=0;
Takes precision=15 if precision>15.
if --internal=false is given, it won't apply to internal branches (only external)
if --external=false is given, it won't apply to external branches (only internal)
`,
RunE: func(cmd *cobra.Command, args []string) (err error) {
var f *os.File
var treefile goio.Closer
var treechan <-chan tree.Trees
if f, err = openWriteFile(outtreefile); err != nil {
io.LogError(err)
return
}
defer closeWriteFile(f, outtreefile)
if treefile, treechan, err = readTrees(intreefile); err != nil {
io.LogError(err)
return
}
defer treefile.Close()
for t := range treechan {
if t.Err != nil {
io.LogError(t.Err)
return t.Err
}
t.Tree.RoundLengths(roundlengthprecision, brleninternal, brlenexternal)
f.WriteString(t.Tree.Newick() + "\n")
}
return
},
}
func init() {
brlenCmd.AddCommand(roundlengthCmd)
roundlengthCmd.Flags().IntVarP(&roundlengthprecision, "precision", "p", 3, "Rounding length precision (x means 10^-x)")
roundlengthCmd.PersistentFlags().StringVarP(&outtreefile, "output", "o", "stdout", "Rounded length output tree file")
}