forked from BurntSushi/cablastp
/
dbconf.go
148 lines (135 loc) · 3.64 KB
/
dbconf.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
package cablastp
import (
"flag"
"fmt"
"io"
"github.com/BurntSushi/toml"
)
type DBConf struct {
MinMatchLen int
MatchKmerSize int
GappedWindowSize int
UngappedWindowSize int
ExtSeqIdThreshold int
MatchSeqIdThreshold int
MatchExtend int
MapSeedSize int
ExtSeedSize int
LowComplexity int
SeedLowComplexity int
SavePlain bool
ReadOnly bool
BlastMakeBlastDB string
BlastDBSize uint64
}
var DefaultDBConf = &DBConf{
MinMatchLen: 40,
MatchKmerSize: 4,
GappedWindowSize: 25,
UngappedWindowSize: 10,
ExtSeqIdThreshold: 60,
MatchSeqIdThreshold: 70,
MatchExtend: 30,
MapSeedSize: 12,
ExtSeedSize: 0,
LowComplexity: 10,
SeedLowComplexity: 6,
SavePlain: false,
ReadOnly: true,
BlastMakeBlastDB: "makeblastdb",
BlastDBSize: 0,
}
func (conf *DBConf) DeepCopy() *DBConf {
copied := DBConf{
MinMatchLen: conf.MinMatchLen,
MatchKmerSize: conf.MatchKmerSize,
GappedWindowSize: conf.GappedWindowSize,
UngappedWindowSize: conf.UngappedWindowSize,
ExtSeqIdThreshold: conf.ExtSeqIdThreshold,
MatchSeqIdThreshold: conf.MatchSeqIdThreshold,
MatchExtend: conf.MatchExtend,
MapSeedSize: conf.MapSeedSize,
ExtSeedSize: conf.ExtSeedSize,
LowComplexity: conf.LowComplexity,
SeedLowComplexity: conf.SeedLowComplexity,
SavePlain: conf.SavePlain,
ReadOnly: conf.ReadOnly,
BlastMakeBlastDB: conf.BlastMakeBlastDB,
BlastDBSize: conf.BlastDBSize,
}
return &copied
}
func LoadDBConf(r io.Reader) (conf *DBConf, err error) {
defer func() {
if perr := recover(); perr != nil {
err = perr.(error)
}
}()
conf = DefaultDBConf.DeepCopy()
if _, err := toml.DecodeReader(r, &conf); err != nil {
return nil, err
}
return conf, nil
}
func (flagConf *DBConf) FlagMerge(fileConf *DBConf) (*DBConf, error) {
only := make(map[string]bool, 0)
flag.Visit(func(f *flag.Flag) { only[f.Name] = true })
if only["map-seed-size"] {
return flagConf, fmt.Errorf("The map seed size cannot be changed for " +
"an existing database.")
}
if only["read-only"] {
return flagConf, fmt.Errorf("The read-only setting cannot be changed " +
"for an existing database.")
}
if !only["min-match-len"] {
flagConf.MinMatchLen = fileConf.MinMatchLen
}
if !only["match-kmer-size"] {
flagConf.MatchKmerSize = fileConf.MatchKmerSize
}
if !only["gapped-window-size"] {
flagConf.GappedWindowSize = fileConf.GappedWindowSize
}
if !only["ungapped-window-size"] {
flagConf.UngappedWindowSize = fileConf.UngappedWindowSize
}
if !only["ext-seq-id-threshold"] {
flagConf.ExtSeqIdThreshold = fileConf.ExtSeqIdThreshold
}
if !only["match-seq-id-threshold"] {
flagConf.MatchSeqIdThreshold = fileConf.MatchSeqIdThreshold
}
if !only["match-extend"] {
flagConf.MatchExtend = fileConf.MatchExtend
}
if !only["ext-seed-size"] {
flagConf.ExtSeedSize = fileConf.ExtSeedSize
}
if !only["low-complexity"] {
flagConf.LowComplexity = fileConf.LowComplexity
}
if !only["seed-low-complexity"] {
flagConf.SeedLowComplexity = fileConf.SeedLowComplexity
}
if !only["plain"] {
flagConf.SavePlain = fileConf.SavePlain
}
if !only["read-only"] {
flagConf.ReadOnly = fileConf.ReadOnly
}
if !only["makeblastdb"] {
flagConf.BlastMakeBlastDB = fileConf.BlastMakeBlastDB
}
if !only["dbsize"] {
flagConf.BlastDBSize = fileConf.BlastDBSize
}
return flagConf, nil
}
func (dbConf DBConf) Write(w io.Writer) error {
encoder := toml.NewEncoder(w)
if err := encoder.Encode(dbConf); err != nil {
return err
}
return nil
}