mirror of
https://github.com/metabarcoding/obitools4.git
synced 2025-12-13 02:30:26 +00:00
add the --download-ncbi option to obitaxonomy
This commit is contained in:
@@ -1,10 +1,15 @@
|
||||
package obitaxonomy
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"time"
|
||||
|
||||
"git.metabarcoding.org/obitools/obitools4/obitools4/pkg/obidefault"
|
||||
"git.metabarcoding.org/obitools/obitools4/obitools4/pkg/obiitercsv"
|
||||
"git.metabarcoding.org/obitools/obitools4/obitools4/pkg/obitax"
|
||||
"git.metabarcoding.org/obitools/obitools4/obitools4/pkg/obitools/obiconvert"
|
||||
"git.metabarcoding.org/obitools/obitools4/obitools4/pkg/obitools/obicsv"
|
||||
"git.metabarcoding.org/obitools/obitools4/obitools4/pkg/obiutils"
|
||||
|
||||
log "github.com/sirupsen/logrus"
|
||||
)
|
||||
@@ -73,3 +78,18 @@ func CLICSVTaxaIterator(iterator *obitax.ITaxon) *obiitercsv.ICSVRecord {
|
||||
func CLICSVTaxaWriter(iterator *obitax.ITaxon, terminalAction bool) *obiitercsv.ICSVRecord {
|
||||
return obicsv.CLICSVWriter(CLICSVTaxaIterator(iterator), terminalAction)
|
||||
}
|
||||
|
||||
func CLIDownloadNCBITaxdump() error {
|
||||
now := time.Now()
|
||||
dateStr := now.Format("20060102") // In Go, this specific date is used as reference for formatting
|
||||
|
||||
filename := fmt.Sprintf("ncbitaxo_%s.tgz", dateStr)
|
||||
|
||||
if obiconvert.CLIOutPutFileName() != "-" {
|
||||
filename = obiconvert.CLIOutPutFileName()
|
||||
}
|
||||
|
||||
log.Infof("Downloading NCBI Taxdump to %s", filename)
|
||||
return obiutils.DownloadFile("https://ftp.ncbi.nlm.nih.gov/pub/taxonomy/taxdump.tar.gz", filename)
|
||||
|
||||
}
|
||||
@@ -22,6 +22,7 @@ var __taxid_path__ = "NA"
|
||||
var __taxid_sons__ = "NA"
|
||||
var __restrict_rank__ = ""
|
||||
var __to_dump__ = ""
|
||||
var __download_ncbi__ = false
|
||||
|
||||
func FilterTaxonomyOptionSet(options *getoptions.GetOpt) {
|
||||
options.BoolVar(&__rank_list__, "rank-list", false,
|
||||
@@ -34,7 +35,7 @@ func FilterTaxonomyOptionSet(options *getoptions.GetOpt) {
|
||||
}
|
||||
|
||||
func OptionSet(options *getoptions.GetOpt) {
|
||||
obioptions.LoadTaxonomyOptionSet(options, true, true)
|
||||
obioptions.LoadTaxonomyOptionSet(options, false, true)
|
||||
FilterTaxonomyOptionSet(options)
|
||||
options.BoolVar(&__fixed_pattern__, "fixed", false,
|
||||
options.Alias("F"),
|
||||
@@ -70,6 +71,10 @@ func OptionSet(options *getoptions.GetOpt) {
|
||||
options.ArgName("TAXID"),
|
||||
options.Description("Dump a sub-taxonomy corresponding to the precised clade"),
|
||||
)
|
||||
options.BoolVar(&__download_ncbi__, "download-ncbi", __download_ncbi__,
|
||||
options.Description("Download the current NCBI taxonomy taxdump"),
|
||||
)
|
||||
|
||||
}
|
||||
|
||||
func CLITaxonomicalRestrictions() (*obitax.TaxonSet, error) {
|
||||
@@ -144,3 +149,7 @@ func CLIDumpSubtaxonomy() bool {
|
||||
func CLISubTaxonomyNode() string {
|
||||
return __to_dump__
|
||||
}
|
||||
|
||||
func CLIDownloadNCBI() bool {
|
||||
return __download_ncbi__
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user