-
Notifications
You must be signed in to change notification settings - Fork 16
/
Copy pathrandsupport.go
60 lines (50 loc) · 1.35 KB
/
randsupport.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 (
goio "io"
"os"
"github.com/fredericlemoine/gostats"
"github.com/evolbioinfo/gotree/io"
"github.com/evolbioinfo/gotree/tree"
"github.com/spf13/cobra"
)
// randsupportCmd represents the randbrlen command
var randsupportCmd = &cobra.Command{
Use: "setrand",
Short: "Assign a random support to edges of input trees",
Long: `Assign a random support to edges of input trees.
Support follows a uniform distribution in [0,1].
`,
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 tr := range treechan {
if tr.Err != nil {
io.LogError(tr.Err)
return tr.Err
}
for _, e := range tr.Tree.Edges() {
if !e.Right().Tip() {
e.SetSupport(gostats.Float64Range(0, 1))
}
}
f.WriteString(tr.Tree.Newick() + "\n")
}
return
},
}
func init() {
supportCmd.AddCommand(randsupportCmd)
randsupportCmd.PersistentFlags().StringVarP(&intreefile, "input", "i", "stdin", "Input tree")
randsupportCmd.PersistentFlags().StringVarP(&outtreefile, "output", "o", "stdout", "Output file")
}