-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmodhmm.go
158 lines (140 loc) · 5.56 KB
/
modhmm.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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
/* Copyright (C) 2018 Philipp Benner
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package main
/* -------------------------------------------------------------------------- */
import "fmt"
import "log"
import "io"
import "os"
import "path"
import "github.com/pborman/getopt"
import . "github.com/pbenner/modhmm/config"
/* -------------------------------------------------------------------------- */
var Version string
var BuildTime string
var GitHash string
func printVersion(writer io.Writer) {
fmt.Fprintf(writer, "ModHMM (https://github.com/pbenner/modhmm)\n")
fmt.Fprintf(writer, " - Version : %s\n", Version)
fmt.Fprintf(writer, " - Build time: %s\n", BuildTime)
fmt.Fprintf(writer, " - Git Hash : %s\n", GitHash)
}
/* default model
* -------------------------------------------------------------------------- */
//go:generate go run modhmm_default_gen.go
/* -------------------------------------------------------------------------- */
func main() {
log.SetFlags(0)
options := getopt.New()
optConfig := options. StringLong("config", 'c', "", "configuration file")
optThreads := options. IntLong("threads", 't', 1, "number of threads")
optHelp := options. BoolLong("help", 'h', "print help")
optGenConf := options. BoolLong("genconf", 0 , "print default config file")
optVerbose := options.CounterLong("verbose", 'v', "verbose level [-v or -vv]")
optVersion := options. BoolLong("version", 0 , "print ModHMM version")
options.SetParameters("<COMMAND>\n\n" +
" Default usage:\n" +
" modhmm -c CONFIG.json segmentation\n\n" +
" Commands:\n" +
" coverage [stage 1] - compute single-feature coverages from bam files\n" +
" eval-enrichment [stage 2] - compute enrichment probabbilities\n" +
" eval-chromatin-state [stage 3] - apply chromatin state classifiers\n" +
" segmentation [stage 4] - compute genome segmentation\n" +
" eval-posterior-marginals [stage 5] - compute posterior marginals of hidden states\n\n" +
" ModHMM commands are structured in stages. Executing a command also executes all commands with\n" +
" lower stage number.\n\n" +
" Printing commands:\n" +
" print-transition-matrix - print estimated transition rates\n" +
" Peak calling commands:\n" +
" call-enrichment-peaks - call peaks of single-feature enrichment analysis\n" +
" call-chromatin-state-peaks - call peaks of multi-feature classifications\n" +
" call-posterior-marginal-peaks - call peaks of HMM marginal posterior tracks\n")
options.Parse(os.Args)
config := DefaultModHmmConfig()
// command options
if *optHelp {
options.PrintUsage(os.Stdout)
os.Exit(0)
}
if *optVersion {
printVersion(os.Stdout)
os.Exit(0)
}
if *optVerbose != 0 {
config.Verbose = *optVerbose
}
if *optGenConf {
if err := config.Export(os.Stdout); err != nil {
log.Fatal(err)
}
os.Exit(0)
}
if *optConfig != "" {
current_config := config
printStderr(current_config, 1, "Importing config file `%s'... ", *optConfig)
if err := config.ImportFile(*optConfig); err != nil {
printStderr(current_config, 1, "failed\n")
log.Fatalf("reading config file `%s' failed: %v", *optConfig, err)
}
printStderr(current_config, 1, "done\n")
}
if *optThreads < 1 {
log.Fatalf("invalid number of threads `%d'", *optThreads)
}
if options.Lookup('t').Seen() {
config.Threads = *optThreads
}
// command arguments
if len(options.Args()) == 0 {
options.PrintUsage(os.Stderr)
os.Exit(1)
}
command := options.Args()[0]
// print config
config.CompletePaths(path.Dir(*optConfig))
if str := config.String(); str != "" {
printStderr(config, 0, "%s\n", str)
}
switch command {
case "coverage":
modhmm_coverage_main(config, options.Args())
case "estimate-enrichment-model":
modhmm_enrichment_estimate_main(config, options.Args())
case "plot-enrichment-model":
modhmm_enrichment_plot_main(config, options.Args())
case "print-enrichment-model":
modhmm_enrichment_print_main(config, options.Args())
case "print-transition-matrix":
modhmm_transition_matrix_print_main(config, options.Args())
case "eval-enrichment":
modhmm_enrichment_eval_main(config, options.Args())
case "eval-chromatin-state":
modhmm_chromatin_state_eval_main(config, options.Args())
case "eval-posterior-marginals":
modhmm_posterior_main(config, options.Args())
case "segmentation":
modhmm_segmentation_main(config, options.Args())
case "call-enrichment-peaks":
modhmm_call_enrichment_peaks_main(config, options.Args())
case "call-chromatin-state-peaks":
modhmm_call_chromatin_state_peaks_main(config, options.Args())
case "call-posterior-marginal-peaks":
modhmm_call_posterior_peaks_main(config, options.Args())
default:
options.PrintUsage(os.Stderr)
os.Exit(1)
}
}