mirror of
https://github.com/metabarcoding/obitools4.git
synced 2025-06-29 16:20:46 +00:00
Add default taxonomy
This commit is contained in:
@ -5,6 +5,7 @@ import (
|
||||
"os"
|
||||
|
||||
"git.metabarcoding.org/obitools/obitools4/obitools4/pkg/obioptions"
|
||||
"git.metabarcoding.org/obitools/obitools4/obitools4/pkg/obitax"
|
||||
"git.metabarcoding.org/obitools/obitools4/obitools4/pkg/obitools/obifind"
|
||||
)
|
||||
|
||||
@ -23,12 +24,8 @@ func main() {
|
||||
|
||||
switch {
|
||||
case obifind.CLIRequestsPathForTaxid() != "NA":
|
||||
taxonomy, err := obifind.CLILoadSelectedTaxonomy()
|
||||
if err != nil {
|
||||
fmt.Printf("%+v", err)
|
||||
}
|
||||
|
||||
taxon := taxonomy.Taxon(obifind.CLIRequestsPathForTaxid())
|
||||
taxon := obitax.DefaultTaxonomy().Taxon(obifind.CLIRequestsPathForTaxid())
|
||||
|
||||
if taxon == nil {
|
||||
fmt.Printf("%+v", err)
|
||||
@ -44,11 +41,7 @@ func main() {
|
||||
fmt.Sprintf("path:%s", taxon.String()))
|
||||
|
||||
case len(args) == 0:
|
||||
taxonomy, err := obifind.CLILoadSelectedTaxonomy()
|
||||
if err != nil {
|
||||
fmt.Printf("%+v", err)
|
||||
}
|
||||
|
||||
taxonomy := obitax.DefaultTaxonomy()
|
||||
obifind.TaxonWriter(restrictions(taxonomy.Iterator()), "")
|
||||
|
||||
default:
|
||||
|
@ -1,10 +1,13 @@
|
||||
package obioptions
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"os"
|
||||
"runtime"
|
||||
|
||||
"git.metabarcoding.org/obitools/obitools4/obitools4/pkg/obiformats/ncbitaxdump"
|
||||
"git.metabarcoding.org/obitools/obitools4/obitools4/pkg/obitax"
|
||||
log "github.com/sirupsen/logrus"
|
||||
|
||||
"github.com/DavidGamba/go-getoptions"
|
||||
@ -28,6 +31,9 @@ var _PprofGoroutine = 6060
|
||||
var _Quality_Shift_Input = byte(33)
|
||||
var _Quality_Shift_Output = byte(33)
|
||||
|
||||
var __taxdump__ = ""
|
||||
var __alternative_name__ = false
|
||||
|
||||
type ArgumentParser func([]string) (*getoptions.GetOpt, []string)
|
||||
|
||||
func GenerateOptionParser(optionset ...func(*getoptions.GetOpt)) ArgumentParser {
|
||||
@ -124,6 +130,14 @@ func GenerateOptionParser(optionset ...func(*getoptions.GetOpt)) ArgumentParser
|
||||
log.Info(" go tool pprof -http=127.0.0.1:8080 'http://localhost:6060/debug/pprof/block'")
|
||||
}
|
||||
|
||||
if options.Called("taxdump") {
|
||||
taxonomy, err := ncbitaxdump.LoadNCBITaxDump(CLISelectedNCBITaxDump(),
|
||||
!CLIAreAlternativeNamesSelected())
|
||||
if err != nil {
|
||||
log.Fatalf("Loading taxonomy error: %v", err)
|
||||
}
|
||||
taxonomy.SetAsDefault()
|
||||
}
|
||||
// Handle user errors
|
||||
if err != nil {
|
||||
fmt.Fprintf(os.Stderr, "ERROR: %s\n\n", err)
|
||||
@ -169,6 +183,24 @@ func GenerateOptionParser(optionset ...func(*getoptions.GetOpt)) ArgumentParser
|
||||
}
|
||||
}
|
||||
|
||||
func LoadTaxonomyOptionSet(options *getoptions.GetOpt, required, alternatiive bool) {
|
||||
if required {
|
||||
options.StringVar(&__taxdump__, "taxdump", "",
|
||||
options.Alias("t"),
|
||||
options.Required(),
|
||||
options.Description("Points to the directory containing the NCBI Taxonomy database dump."))
|
||||
} else {
|
||||
options.StringVar(&__taxdump__, "taxdump", "",
|
||||
options.Alias("t"),
|
||||
options.Description("Points to the directory containing the NCBI Taxonomy database dump."))
|
||||
}
|
||||
if alternatiive {
|
||||
options.BoolVar(&__alternative_name__, "alternative-names", false,
|
||||
options.Alias("a"),
|
||||
options.Description("Enable the search on all alternative names and not only scientific names."))
|
||||
}
|
||||
}
|
||||
|
||||
// CLIIsDebugMode returns whether the CLI is in debug mode.
|
||||
//
|
||||
// The debug mode is activated by the command line option --debug or
|
||||
@ -420,3 +452,33 @@ func ParallelFilesRead() int {
|
||||
func SetParallelFilesRead(n int) {
|
||||
_ParallelFilesRead = n
|
||||
}
|
||||
|
||||
func CLISelectedNCBITaxDump() string {
|
||||
return __taxdump__
|
||||
}
|
||||
|
||||
func CLIHasSelectedTaxonomy() bool {
|
||||
return __taxdump__ != ""
|
||||
}
|
||||
|
||||
func CLIAreAlternativeNamesSelected() bool {
|
||||
return __alternative_name__
|
||||
}
|
||||
|
||||
func CLILoadSelectedTaxonomy() (*obitax.Taxonomy, error) {
|
||||
if obitax.IsDefaultTaxonomyDefined() {
|
||||
return obitax.DefaultTaxonomy(), nil
|
||||
}
|
||||
|
||||
if CLISelectedNCBITaxDump() != "" {
|
||||
taxonomy, err := ncbitaxdump.LoadNCBITaxDump(CLISelectedNCBITaxDump(),
|
||||
!CLIAreAlternativeNamesSelected())
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
taxonomy.SetAsDefault()
|
||||
return taxonomy, nil
|
||||
}
|
||||
|
||||
return nil, errors.New("no NCBI taxdump selected using option -t|--taxdump")
|
||||
}
|
||||
|
@ -7,7 +7,7 @@ import (
|
||||
// TODO: The version number is extracted from git. This induces that the version
|
||||
// corresponds to the last commit, and not the one when the file will be
|
||||
// commited
|
||||
var _Commit = "9471fed"
|
||||
var _Commit = "7633fc4"
|
||||
var _Version = "Release 4.2.0"
|
||||
|
||||
// Version returns the version of the obitools package.
|
||||
|
Reference in New Issue
Block a user