-
Notifications
You must be signed in to change notification settings - Fork 16
/
Copy pathstartree.go
60 lines (50 loc) · 1.21 KB
/
startree.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
package cmd
import (
"os"
"github.com/evolbioinfo/gotree/io"
"github.com/evolbioinfo/gotree/tree"
"github.com/fredericlemoine/gostats"
"github.com/spf13/cobra"
)
func starTree(nbtrees int, nbtips int, output string) error {
var f *os.File
var err error
var t *tree.Tree
if output != "stdout" && output != "-" {
f, err = os.Create(output)
defer f.Close()
} else {
f = os.Stdout
}
if err != nil {
return err
}
for i := 0; i < nbtrees; i++ {
if t, err = tree.StarTree(nbtips); err != nil {
return err
}
for _, e := range t.Edges() {
e.SetLength(gostats.Exp(1.0 / setlengthmean))
}
f.WriteString(t.Newick() + "\n")
}
return nil
}
// startreeCmd represents the binarytree command
var startreeCmd = &cobra.Command{
Use: "startree",
Short: "Generates a star tree",
Long: `Generates a star tree.
--rooted option is not functional here.
`,
Run: func(cmd *cobra.Command, args []string) {
if err := starTree(generateNbTrees, generateNbTips, generateOutputfile); err != nil {
io.LogError(err)
return
}
},
}
func init() {
generateCmd.AddCommand(startreeCmd)
startreeCmd.PersistentFlags().IntVarP(&generateNbTips, "nbtips", "l", 10, "Number of tips/leaves of the tree to generate")
}