mirror of
https://github.com/metabarcoding/obitools4.git
synced 2025-12-09 01:00:26 +00:00
Refactoring codes for removing buffer size options. An some other changes...
Former-commit-id: 10b57cc1a27446ade3c444217341e9651e89cdce
This commit is contained in:
61
pkg/obitools/obicsv/obicsv.go
Normal file
61
pkg/obitools/obicsv/obicsv.go
Normal file
@@ -0,0 +1,61 @@
|
||||
package obicsv
|
||||
|
||||
import (
|
||||
"log"
|
||||
|
||||
"git.metabarcoding.org/lecasofts/go/obitools/pkg/obiformats"
|
||||
"git.metabarcoding.org/lecasofts/go/obitools/pkg/obiiter"
|
||||
"git.metabarcoding.org/lecasofts/go/obitools/pkg/obioptions"
|
||||
"git.metabarcoding.org/lecasofts/go/obitools/pkg/obitools/obiconvert"
|
||||
)
|
||||
|
||||
func CLIWriteCSV(iterator obiiter.IBioSequence,
|
||||
terminalAction bool, filenames ...string) (obiiter.IBioSequence, error) {
|
||||
|
||||
if obiconvert.CLIProgressBar() {
|
||||
iterator = iterator.Speed()
|
||||
}
|
||||
|
||||
var newIter obiiter.IBioSequence
|
||||
|
||||
opts := make([]obiformats.WithOption, 0, 10)
|
||||
|
||||
nworkers := obioptions.CLIParallelWorkers() / 4
|
||||
if nworkers < 2 {
|
||||
nworkers = 2
|
||||
}
|
||||
|
||||
opts = append(opts, obiformats.OptionsParallelWorkers(nworkers))
|
||||
opts = append(opts, obiformats.OptionsBatchSize(obioptions.CLIBatchSize()))
|
||||
|
||||
opts = append(opts, obiformats.OptionsQualityShift(obiconvert.CLIOutputQualityShift()))
|
||||
opts = append(opts, obiformats.OptionsCompressed(obiconvert.CLICompressed()))
|
||||
|
||||
opts = append(opts, obiformats.CSVId(CLIPrintId()),
|
||||
obiformats.CSVCount(CLIPrintCount()),
|
||||
obiformats.CSVTaxon(CLIPrintTaxon()),
|
||||
obiformats.CSVDefinition(CLIPrintDefinition()),
|
||||
obiformats.CSVKeys(CLIToBeKeptAttributes()),
|
||||
)
|
||||
|
||||
var err error
|
||||
|
||||
if len(filenames) == 0 {
|
||||
newIter, err = obiformats.WriteCSVToStdout(iterator, opts...)
|
||||
} else {
|
||||
newIter, err = obiformats.WriteCSVToFile(iterator, filenames[0], opts...)
|
||||
}
|
||||
|
||||
if err != nil {
|
||||
log.Fatalf("Write file error: %v", err)
|
||||
return obiiter.NilIBioSequence, err
|
||||
}
|
||||
|
||||
if terminalAction {
|
||||
newIter.Recycle()
|
||||
return obiiter.NilIBioSequence, nil
|
||||
}
|
||||
|
||||
return newIter, nil
|
||||
|
||||
}
|
||||
126
pkg/obitools/obicsv/options.go
Normal file
126
pkg/obitools/obicsv/options.go
Normal file
@@ -0,0 +1,126 @@
|
||||
package obicsv
|
||||
|
||||
import (
|
||||
"git.metabarcoding.org/lecasofts/go/obitools/pkg/goutils"
|
||||
"git.metabarcoding.org/lecasofts/go/obitools/pkg/obitools/obiconvert"
|
||||
"github.com/DavidGamba/go-getoptions"
|
||||
)
|
||||
|
||||
var _outputIds = true
|
||||
var _outputCount = false
|
||||
var _outputTaxon = false
|
||||
var _outputSequence = true
|
||||
var _outputQuality = true
|
||||
var _outputDefinition = false
|
||||
var _obipairing = false
|
||||
var _autoColumns = false
|
||||
var _keepOnly = make([]string, 0)
|
||||
var _naValue = "NA"
|
||||
|
||||
var _softAttributes = map[string][]string{
|
||||
"obipairing": {"mode", "seq_a_single", "seq_b_single",
|
||||
"ali_dir", "score", "score_norm",
|
||||
"seq_ab_match", "pairing_mismatches",
|
||||
},
|
||||
}
|
||||
|
||||
func CSVOptionSet(options *getoptions.GetOpt) {
|
||||
options.BoolVar(&_outputIds, "ids", _outputIds,
|
||||
options.Alias("i"),
|
||||
options.Description("Prints sequence ids in the ouput."))
|
||||
|
||||
options.BoolVar(&_outputSequence, "sequence", _outputSequence,
|
||||
options.Alias("s"),
|
||||
options.Description("Prints sequence itself in the output."))
|
||||
|
||||
options.BoolVar(&_outputQuality, "quality", _outputQuality,
|
||||
options.Alias("q"),
|
||||
options.Description("Prints sequence quality in the output."))
|
||||
|
||||
options.BoolVar(&_outputDefinition, "definition", _outputDefinition,
|
||||
options.Alias("d"),
|
||||
options.Description("Prints sequence definition in the output."))
|
||||
|
||||
options.BoolVar(&_autoColumns, "auto", _autoColumns,
|
||||
options.Description("Based on the first sequences, propose a list of attibutes to print"))
|
||||
|
||||
options.BoolVar(&_outputCount, "count", _outputCount,
|
||||
options.Description("Prints the count attribute in the output"))
|
||||
|
||||
options.BoolVar(&_outputTaxon, "taxon", _outputTaxon,
|
||||
options.Description("Prints the NCBI taxid and its related scientific name"))
|
||||
|
||||
options.BoolVar(&_obipairing, "obipairing", _obipairing,
|
||||
options.Description("Prints the attributes added by obipairing"))
|
||||
|
||||
options.StringSliceVar(&_keepOnly, "keep", 1, 1,
|
||||
options.Alias("k"),
|
||||
options.ArgName("KEY"),
|
||||
options.Description("Keeps only attribute with key <KEY>. Several -k options can be combined."))
|
||||
|
||||
options.StringVar(&_naValue, "na-value", _naValue,
|
||||
options.ArgName("NAVALUE"),
|
||||
options.Description("A string representing non available values in the CSV file."))
|
||||
}
|
||||
|
||||
func OptionSet(options *getoptions.GetOpt) {
|
||||
obiconvert.OutputModeOptionSet(options)
|
||||
CSVOptionSet(options)
|
||||
}
|
||||
|
||||
func CLIPrintId() bool {
|
||||
return _outputIds
|
||||
}
|
||||
|
||||
func CLIPrintSequence() bool {
|
||||
return _outputSequence
|
||||
}
|
||||
|
||||
func CLIPrintCount() bool {
|
||||
return _outputCount
|
||||
}
|
||||
func CLIPrintTaxon() bool {
|
||||
return _outputTaxon
|
||||
}
|
||||
func CLIPrintQuality() bool {
|
||||
return _outputQuality
|
||||
}
|
||||
|
||||
func CLIPrintDefinition() bool {
|
||||
return _outputDefinition
|
||||
}
|
||||
|
||||
func CLIAutoColumns() bool {
|
||||
return _autoColumns
|
||||
}
|
||||
|
||||
func CLIHasToBeKeptAttributes() bool {
|
||||
return len(_keepOnly) > 0
|
||||
}
|
||||
|
||||
func CLIToBeKeptAttributes() []string {
|
||||
if _obipairing {
|
||||
_keepOnly = append(_keepOnly, _softAttributes["obipairing"]...)
|
||||
}
|
||||
|
||||
if i := goutils.LookFor(_keepOnly, "count"); i >= 0 {
|
||||
_keepOnly = goutils.RemoveIndex(_keepOnly, i)
|
||||
_outputCount = true
|
||||
}
|
||||
|
||||
if i := goutils.LookFor(_keepOnly, "taxid"); i >= 0 {
|
||||
_keepOnly = goutils.RemoveIndex(_keepOnly, i)
|
||||
_outputTaxon = true
|
||||
}
|
||||
|
||||
if i := goutils.LookFor(_keepOnly, "scientific_name"); i >= 0 {
|
||||
_keepOnly = goutils.RemoveIndex(_keepOnly, i)
|
||||
_outputTaxon = true
|
||||
}
|
||||
|
||||
return _keepOnly
|
||||
}
|
||||
|
||||
func CLINAValue() string {
|
||||
return _naValue
|
||||
}
|
||||
Reference in New Issue
Block a user