forked from evolbioinfo/gotree
/
computesupport.go
85 lines (76 loc) · 2.53 KB
/
computesupport.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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
package cmd
import (
"os"
"github.com/evolbioinfo/gotree/io"
"github.com/spf13/cobra"
)
var supportIntree string
var supportBoottrees string
var supportOutFile string
var supportLogFile string
var movedtaxa bool
var taxperbranches bool // If we should compute all avg tax transfers per branches
//var hightaxperbranches bool // If we should compute all avg tax transfers per branches
// For booster computation : output tree with raw avg distances as supports
// in the form: branchid|avg_distance|depth
var rawSupportOutputFile string
var rawSupportOut *os.File
var supportOut *os.File
var supportLog *os.File
var supportSilent bool
// supportCmd represents the support command
var computesupportCmd = &cobra.Command{
Use: "support",
Short: "Computes different kind of branch supports",
Long: `Computes different kind of branch supports.
The supports implemented are :
- booster support
- Classical Felsenstein support
`,
PersistentPreRunE: func(cmd *cobra.Command, args []string) (err error) {
RootCmd.PersistentPreRun(cmd, args)
if supportOutFile != "stdout" && supportOutFile != "-" {
supportOut, err = os.Create(supportOutFile)
} else {
supportOut = os.Stdout
}
if err != nil {
io.LogError(err)
return
}
if supportLogFile != "stderr" {
supportLog, err = os.Create(supportLogFile)
} else {
supportLog = os.Stderr
}
if err != nil {
io.LogError(err)
return
}
if rawSupportOutputFile != "none" {
if rawSupportOutputFile != "stdout" && rawSupportOutputFile != "-" {
rawSupportOut, err = os.Create(rawSupportOutputFile)
} else {
rawSupportOut = os.Stdout
}
if err != nil {
io.LogError(err)
return
}
}
return
},
PersistentPostRun: func(cmd *cobra.Command, args []string) {
closeWriteFile(supportOut, supportOutFile)
closeWriteFile(supportLog, supportLogFile)
closeWriteFile(rawSupportOut, rawSupportOutputFile)
},
}
func init() {
computeCmd.AddCommand(computesupportCmd)
computesupportCmd.PersistentFlags().StringVarP(&supportIntree, "reftree", "i", "stdin", "Reference tree input file")
computesupportCmd.PersistentFlags().StringVarP(&supportBoottrees, "bootstrap", "b", "none", "Bootstrap trees input file")
computesupportCmd.PersistentFlags().StringVarP(&supportOutFile, "out", "o", "stdout", "Output tree file, with supports")
computesupportCmd.PersistentFlags().StringVarP(&supportLogFile, "log-file", "l", "stderr", "Output log file")
computesupportCmd.PersistentFlags().BoolVar(&supportSilent, "silent", false, "If true, progress messages will not be printed to stderr")
}