-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathconfig.go
More file actions
254 lines (209 loc) · 5.31 KB
/
config.go
File metadata and controls
254 lines (209 loc) · 5.31 KB
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
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
package indelligent
import "runtime"
// Format defines the output format.
type Format int
const (
// FASTA is the default output format for CLI.
FASTA Format = iota
// CompactJSON produces single-line JSON.
CompactJSON
// PrettyJSON produces indented JSON.
PrettyJSON
// TSV produces tab-separated values.
TSV
)
// Config keeps settings that affect analysis and output.
type Config struct {
// Format sets the output format.
Format Format
// JobsNum sets the level of parallelism.
JobsNum int
// BatchSize sets the maximum number of sequences in a batch.
BatchSize int
// WithDetails includes full stats in output.
WithDetails bool
// WithNoOrder allows unordered output for maximum throughput.
WithNoOrder bool
// WithStream enables stream mode vs batch mode.
WithStream bool
// MaxShift is the max phase shift size in bp (default: 15).
MaxShift int
// ShiftPenalty is the shift change penalty (default: 2).
ShiftPenalty int
// FixShifts restricts analysis to specific shift magnitudes.
FixShifts []int
// AlignAlleles aligns reconstructed alleles with gap chars.
AlignAlleles bool
// FloatAlign controls floating indel alignment: "left" or "right".
FloatAlign string
// LongIndels displays alternative longer indel variants.
LongIndels bool
// Port starts web service on this port (0 = no web service).
Port int
// WithColor enables ANSI color highlighting of mismatches in CLI output.
WithColor bool
// IsTest uses "test_version" in output.
IsTest bool
// MaxBatchSequences limits how many sequences a single API batch
// request may contain. 0 means no limit.
MaxBatchSequences int
// MaxSequenceLength limits the length of a single sequence accepted
// via the API. 0 means no limit.
MaxSequenceLength int
// MaxSimLength caps the simulated fragment length. 0 means no limit.
MaxSimLength int
// RateLimit sets the per-IP request rate (req/s). 0 means no limit.
RateLimit float64
// BodyLimit sets the maximum request body size (e.g. "1M"). Empty
// means no limit.
BodyLimit string
}
// Option is a function that modifies Config settings.
type Option func(*Config)
// OptFormat sets the output format.
func OptFormat(f Format) Option {
return func(cfg *Config) {
cfg.Format = f
}
}
// OptJobsNum sets the number of worker goroutines.
func OptJobsNum(i int) Option {
return func(cfg *Config) {
if i > 0 {
cfg.JobsNum = i
}
}
}
// OptBatchSize sets the max sequences per batch.
func OptBatchSize(i int) Option {
return func(cfg *Config) {
if i > 0 {
cfg.BatchSize = i
}
}
}
// OptWithDetails sets the WithDetails flag.
func OptWithDetails(b bool) Option {
return func(cfg *Config) {
cfg.WithDetails = b
}
}
// OptWithNoOrder sets the WithNoOrder flag.
func OptWithNoOrder(b bool) Option {
return func(cfg *Config) {
cfg.WithNoOrder = b
}
}
// OptWithStream sets the WithStream flag.
func OptWithStream(b bool) Option {
return func(cfg *Config) {
cfg.WithStream = b
}
}
// OptMaxShift sets the max phase shift size.
func OptMaxShift(i int) Option {
return func(cfg *Config) {
if i > 0 {
cfg.MaxShift = i
}
}
}
// OptShiftPenalty sets the shift change penalty.
func OptShiftPenalty(i int) Option {
return func(cfg *Config) {
if i > 0 {
cfg.ShiftPenalty = i
}
}
}
// OptFixShifts restricts analysis to specific shift magnitudes.
func OptFixShifts(shifts []int) Option {
return func(cfg *Config) {
cfg.FixShifts = shifts
}
}
// OptAlignAlleles sets the AlignAlleles flag.
func OptAlignAlleles(b bool) Option {
return func(cfg *Config) {
cfg.AlignAlleles = b
}
}
// OptFloatAlign sets the floating indel alignment direction.
func OptFloatAlign(s string) Option {
return func(cfg *Config) {
if s == "left" || s == "right" {
cfg.FloatAlign = s
}
}
}
// OptLongIndels sets the LongIndels flag.
func OptLongIndels(b bool) Option {
return func(cfg *Config) {
cfg.LongIndels = b
}
}
// OptPort sets the web service port.
func OptPort(i int) Option {
return func(cfg *Config) {
cfg.Port = i
}
}
// OptWithColor sets the WithColor flag.
func OptWithColor(b bool) Option {
return func(cfg *Config) {
cfg.WithColor = b
}
}
// OptIsTest sets the IsTest flag.
func OptIsTest(b bool) Option {
return func(cfg *Config) {
cfg.IsTest = b
}
}
// OptMaxBatchSequences sets the batch sequence limit.
func OptMaxBatchSequences(i int) Option {
return func(cfg *Config) {
cfg.MaxBatchSequences = i
}
}
// OptMaxSequenceLength sets the single-sequence length limit.
func OptMaxSequenceLength(i int) Option {
return func(cfg *Config) {
cfg.MaxSequenceLength = i
}
}
// OptMaxSimLength sets the simulated fragment length cap.
func OptMaxSimLength(i int) Option {
return func(cfg *Config) {
cfg.MaxSimLength = i
}
}
// OptRateLimit sets the per-IP request rate limit.
func OptRateLimit(f float64) Option {
return func(cfg *Config) {
cfg.RateLimit = f
}
}
// OptBodyLimit sets the maximum request body size.
func OptBodyLimit(s string) Option {
return func(cfg *Config) {
cfg.BodyLimit = s
}
}
// NewConfig creates a new Config with defaults, modified by opts.
func NewConfig(opts ...Option) Config {
cfg := Config{
Format: FASTA,
JobsNum: runtime.NumCPU(),
BatchSize: 50_000,
MaxShift: 15,
ShiftPenalty: 2,
AlignAlleles: true,
FloatAlign: "right",
WithColor: true,
}
for _, opt := range opts {
opt(&cfg)
}
return cfg
}