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"
|
"os"
|
||||||
|
|
||||||
"git.metabarcoding.org/obitools/obitools4/obitools4/pkg/obioptions"
|
"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"
|
"git.metabarcoding.org/obitools/obitools4/obitools4/pkg/obitools/obifind"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -23,12 +24,8 @@ func main() {
|
|||||||
|
|
||||||
switch {
|
switch {
|
||||||
case obifind.CLIRequestsPathForTaxid() != "NA":
|
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 {
|
if taxon == nil {
|
||||||
fmt.Printf("%+v", err)
|
fmt.Printf("%+v", err)
|
||||||
@ -44,11 +41,7 @@ func main() {
|
|||||||
fmt.Sprintf("path:%s", taxon.String()))
|
fmt.Sprintf("path:%s", taxon.String()))
|
||||||
|
|
||||||
case len(args) == 0:
|
case len(args) == 0:
|
||||||
taxonomy, err := obifind.CLILoadSelectedTaxonomy()
|
taxonomy := obitax.DefaultTaxonomy()
|
||||||
if err != nil {
|
|
||||||
fmt.Printf("%+v", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
obifind.TaxonWriter(restrictions(taxonomy.Iterator()), "")
|
obifind.TaxonWriter(restrictions(taxonomy.Iterator()), "")
|
||||||
|
|
||||||
default:
|
default:
|
||||||
|
@ -1,10 +1,13 @@
|
|||||||
package obioptions
|
package obioptions
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"os"
|
"os"
|
||||||
"runtime"
|
"runtime"
|
||||||
|
|
||||||
|
"git.metabarcoding.org/obitools/obitools4/obitools4/pkg/obiformats/ncbitaxdump"
|
||||||
|
"git.metabarcoding.org/obitools/obitools4/obitools4/pkg/obitax"
|
||||||
log "github.com/sirupsen/logrus"
|
log "github.com/sirupsen/logrus"
|
||||||
|
|
||||||
"github.com/DavidGamba/go-getoptions"
|
"github.com/DavidGamba/go-getoptions"
|
||||||
@ -28,6 +31,9 @@ var _PprofGoroutine = 6060
|
|||||||
var _Quality_Shift_Input = byte(33)
|
var _Quality_Shift_Input = byte(33)
|
||||||
var _Quality_Shift_Output = byte(33)
|
var _Quality_Shift_Output = byte(33)
|
||||||
|
|
||||||
|
var __taxdump__ = ""
|
||||||
|
var __alternative_name__ = false
|
||||||
|
|
||||||
type ArgumentParser func([]string) (*getoptions.GetOpt, []string)
|
type ArgumentParser func([]string) (*getoptions.GetOpt, []string)
|
||||||
|
|
||||||
func GenerateOptionParser(optionset ...func(*getoptions.GetOpt)) ArgumentParser {
|
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'")
|
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
|
// Handle user errors
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Fprintf(os.Stderr, "ERROR: %s\n\n", err)
|
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.
|
// CLIIsDebugMode returns whether the CLI is in debug mode.
|
||||||
//
|
//
|
||||||
// The debug mode is activated by the command line option --debug or
|
// The debug mode is activated by the command line option --debug or
|
||||||
@ -420,3 +452,33 @@ func ParallelFilesRead() int {
|
|||||||
func SetParallelFilesRead(n int) {
|
func SetParallelFilesRead(n int) {
|
||||||
_ParallelFilesRead = n
|
_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
|
// 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
|
// corresponds to the last commit, and not the one when the file will be
|
||||||
// commited
|
// commited
|
||||||
var _Commit = "9471fed"
|
var _Commit = "7633fc4"
|
||||||
var _Version = "Release 4.2.0"
|
var _Version = "Release 4.2.0"
|
||||||
|
|
||||||
// Version returns the version of the obitools package.
|
// Version returns the version of the obitools package.
|
||||||
|
Reference in New Issue
Block a user