mirror of
https://github.com/metabarcoding/obitools4.git
synced 2026-08-24 05:41:19 +00:00
fix: respect config defaults when --allowed-mismatches is unset
The change replaces numeric threshold checks with an explicit flag state tracker for the `--allowed-mismatches` option. This ensures per-primer mismatch settings from configuration files are preserved when the CLI parameter is omitted or zero, making the command-line flag act strictly as an explicit override rather than a default fallback.
This commit is contained in:
@@ -777,7 +777,7 @@ func (library *NGSLibrary) ExtractMultiBarcodeSliceWorker(options ...WithOption)
|
|||||||
library.SetAllowsIndels(true)
|
library.SetAllowsIndels(true)
|
||||||
}
|
}
|
||||||
|
|
||||||
if opt.AllowedMismatches() > 0 {
|
if opt.AllowedMismatchesIsSet() {
|
||||||
library.SetAllowedMismatches(opt.AllowedMismatches())
|
library.SetAllowedMismatches(opt.AllowedMismatches())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -6,13 +6,14 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
type _Options struct {
|
type _Options struct {
|
||||||
discardErrors bool
|
discardErrors bool
|
||||||
unidentified string
|
unidentified string
|
||||||
allowedMismatch int
|
allowedMismatch int
|
||||||
allowsIndel bool
|
allowedMismatchSet bool
|
||||||
withProgressBar bool
|
allowsIndel bool
|
||||||
parallelWorkers int
|
withProgressBar bool
|
||||||
batchSize int
|
parallelWorkers int
|
||||||
|
batchSize int
|
||||||
}
|
}
|
||||||
|
|
||||||
// Options stores a set of option usable by the
|
// Options stores a set of option usable by the
|
||||||
@@ -52,6 +53,7 @@ func OptionWithProgressBar(yes bool) WithOption {
|
|||||||
func OptionAllowedMismatches(count int) WithOption {
|
func OptionAllowedMismatches(count int) WithOption {
|
||||||
f := WithOption(func(opt Options) {
|
f := WithOption(func(opt Options) {
|
||||||
opt.pointer.allowedMismatch = count
|
opt.pointer.allowedMismatch = count
|
||||||
|
opt.pointer.allowedMismatchSet = true
|
||||||
})
|
})
|
||||||
|
|
||||||
return f
|
return f
|
||||||
@@ -97,6 +99,12 @@ func (options Options) AllowedMismatches() int {
|
|||||||
return options.pointer.allowedMismatch
|
return options.pointer.allowedMismatch
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// AllowedMismatchesIsSet returns true if OptionAllowedMismatches
|
||||||
|
// was explicitly applied to these options.
|
||||||
|
func (options Options) AllowedMismatchesIsSet() bool {
|
||||||
|
return options.pointer.allowedMismatchSet
|
||||||
|
}
|
||||||
|
|
||||||
func (options Options) AllowsIndels() bool {
|
func (options Options) AllowsIndels() bool {
|
||||||
return options.pointer.allowsIndel
|
return options.pointer.allowsIndel
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -15,7 +15,6 @@ func IExtractBarcode(iterator obiiter.IBioSequence) (obiiter.IBioSequence, error
|
|||||||
opts := make([]obingslibrary.WithOption, 0, 10)
|
opts := make([]obingslibrary.WithOption, 0, 10)
|
||||||
|
|
||||||
opts = append(opts,
|
opts = append(opts,
|
||||||
obingslibrary.OptionAllowedMismatches(CLIAllowedMismatch()),
|
|
||||||
obingslibrary.OptionAllowedIndel(CLIAllowsIndel()),
|
obingslibrary.OptionAllowedIndel(CLIAllowsIndel()),
|
||||||
obingslibrary.OptionUnidentified(CLIUnidentifiedFileName()),
|
obingslibrary.OptionUnidentified(CLIUnidentifiedFileName()),
|
||||||
obingslibrary.OptionDiscardErrors(!CLIConservedErrors()),
|
obingslibrary.OptionDiscardErrors(!CLIConservedErrors()),
|
||||||
@@ -23,6 +22,14 @@ func IExtractBarcode(iterator obiiter.IBioSequence) (obiiter.IBioSequence, error
|
|||||||
obingslibrary.OptionBatchSize(obidefault.BatchSize()),
|
obingslibrary.OptionBatchSize(obidefault.BatchSize()),
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// Only propagate the CLI --allowed-mismatches value if the user
|
||||||
|
// explicitly set it: otherwise the per-primer values defined in
|
||||||
|
// the NGSFilter config file (@primer_mismatches, @forward_mismatches,
|
||||||
|
// @reverse_mismatches) must be preserved.
|
||||||
|
if CLIAllowedMismatchIsSet() {
|
||||||
|
opts = append(opts, obingslibrary.OptionAllowedMismatches(CLIAllowedMismatch()))
|
||||||
|
}
|
||||||
|
|
||||||
ngsfilter, err := CLINGSFIlter()
|
ngsfilter, err := CLINGSFIlter()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatalf("%v", err)
|
log.Fatalf("%v", err)
|
||||||
|
|||||||
@@ -18,6 +18,7 @@ var _UnidentifiedFile = ""
|
|||||||
var _AllowedMismatch = 2
|
var _AllowedMismatch = 2
|
||||||
var _AllowsIndel = false
|
var _AllowsIndel = false
|
||||||
var _ConservedError = false
|
var _ConservedError = false
|
||||||
|
var _optionsParser *getoptions.GetOpt
|
||||||
|
|
||||||
// PCROptionSet defines every options related to a simulated PCR.
|
// PCROptionSet defines every options related to a simulated PCR.
|
||||||
//
|
//
|
||||||
@@ -29,6 +30,8 @@ var _ConservedError = false
|
|||||||
// - option : is a pointer to a getoptions.GetOpt instance normaly
|
// - option : is a pointer to a getoptions.GetOpt instance normaly
|
||||||
// produced by the
|
// produced by the
|
||||||
func MultiplexOptionSet(options *getoptions.GetOpt) {
|
func MultiplexOptionSet(options *getoptions.GetOpt) {
|
||||||
|
_optionsParser = options
|
||||||
|
|
||||||
options.StringVar(&_NGSFilterFile, "tag-list", _NGSFilterFile,
|
options.StringVar(&_NGSFilterFile, "tag-list", _NGSFilterFile,
|
||||||
options.Alias("s"),
|
options.Alias("s"),
|
||||||
options.Description("File name of the NGSFilter file describing PCRs."))
|
options.Description("File name of the NGSFilter file describing PCRs."))
|
||||||
@@ -62,6 +65,15 @@ func CLIAllowedMismatch() int {
|
|||||||
return _AllowedMismatch
|
return _AllowedMismatch
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// CLIAllowedMismatchIsSet returns true if the user explicitly
|
||||||
|
// specified --allowed-mismatches on the command line, as opposed
|
||||||
|
// to relying on its default value. This allows per-primer mismatch
|
||||||
|
// settings from the NGSFilter config file to take precedence unless
|
||||||
|
// the user explicitly overrides them from the CLI.
|
||||||
|
func CLIAllowedMismatchIsSet() bool {
|
||||||
|
return _optionsParser != nil && _optionsParser.Called("allowed-mismatches")
|
||||||
|
}
|
||||||
|
|
||||||
func CLIAllowsIndel() bool {
|
func CLIAllowsIndel() bool {
|
||||||
return _AllowsIndel
|
return _AllowsIndel
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -55,7 +55,7 @@ func IPCRTagPESequencesBatch(iterator obiiter.IBioSequence,
|
|||||||
ngsfilter.SetAllowsIndels(true)
|
ngsfilter.SetAllowsIndels(true)
|
||||||
}
|
}
|
||||||
|
|
||||||
if obimultiplex.CLIAllowedMismatch() > 0 {
|
if obimultiplex.CLIAllowedMismatchIsSet() {
|
||||||
ngsfilter.SetAllowedMismatches(obimultiplex.CLIAllowedMismatch())
|
ngsfilter.SetAllowedMismatches(obimultiplex.CLIAllowedMismatch())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user