obicsv debug

This commit is contained in:
Eric Coissac
2024-11-24 23:38:49 +01:00
parent 3d06978808
commit 69ef1758a2
6 changed files with 41 additions and 16 deletions

View File

@ -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 = "36327c7"
var _Commit = "3d06978"
var _Version = "Release 4.2.0"
// Version returns the version of the obitools package.

View File

@ -141,6 +141,9 @@ func (taxonomy *Taxonomy) TaxidSting(id string) (string, error) {
// - If the taxid is unknown, the method will log a fatal error.
func (taxonomy *Taxonomy) Taxon(taxid string) *Taxon {
taxonomy = taxonomy.OrDefault(false)
if taxonomy == nil {
return nil
}
id, err := taxonomy.Id(taxid)

View File

@ -2,6 +2,7 @@ package obicsv
import (
"fmt"
"slices"
"sync"
"sync/atomic"
"time"
@ -222,7 +223,7 @@ func (iterator *ICSVRecord) SetHeader(header CSVHeader) {
}
func (iterator *ICSVRecord) AppendField(field string) {
iterator.header = append(iterator.header, field)
iterator.header.AppendField(field)
}
func (iterator *ICSVRecord) Next() bool {
@ -339,3 +340,9 @@ func (iterator *ICSVRecord) Consume() {
iterator.Get()
}
}
func (head *CSVHeader) AppendField(field string) {
if !slices.Contains(*head, field) {
*head = append(*head, field)
}
}

View File

@ -64,6 +64,7 @@ func CSVOptionSet(options *getoptions.GetOpt) {
}
func OptionSet(options *getoptions.GetOpt) {
obiconvert.InputOptionSet(options)
obiconvert.OutputModeOptionSet(options)
CSVOptionSet(options)
}

View File

@ -1,40 +1,45 @@
package obicsv
import (
"log"
"slices"
"git.metabarcoding.org/obitools/obitools4/obitools4/pkg/obiiter"
"git.metabarcoding.org/obitools/obitools4/obitools4/pkg/obioptions"
log "github.com/sirupsen/logrus"
)
func CSVSequenceHeader(opt Options) CSVHeader {
keys := opt.CSVKeys()
record := make([]string, 0, len(keys)+4)
record := make(CSVHeader, 0, len(keys)+4)
if opt.CSVId() {
record = append(record, "id")
record.AppendField("id")
}
if opt.CSVCount() {
record = append(record, "count")
record.AppendField("count")
}
if opt.CSVTaxon() {
record = append(record, "taxid")
record.AppendField("taxid")
}
if opt.CSVDefinition() {
record = append(record, "definition")
record.AppendField("definition")
}
record = append(record, opt.CSVKeys()...)
for _, field := range opt.CSVKeys() {
if field != "definition" {
record.AppendField(field)
}
}
if opt.CSVSequence() {
record = append(record, "sequence")
record.AppendField("sequence")
}
if opt.CSVQuality() {
record = append(record, "quality")
record.AppendField("quality")
}
return record
@ -110,11 +115,22 @@ func NewCSVSequenceIterator(iter obiiter.IBioSequence, options ...WithOption) *I
opt := MakeOptions(options)
if opt.CSVAutoColumn() {
if iter.Next() {
batch := iter.Get()
if len(batch.Slice()) == 0 {
log.Panicf("first batch should not be empty")
}
auto_slot := batch.Slice().AttributeKeys(true).Members()
slices.Sort(auto_slot)
CSVKeys(auto_slot)(opt)
iter.PushBack()
}
}
newIter := NewICSVRecord()
newIter.SetHeader(CSVSequenceHeader(opt))
log.Warnf("", newIter.Header())
nwriters := opt.ParallelWorkers()
newIter.Add(nwriters)

View File

@ -16,8 +16,6 @@ func FormatCVSBatch(batch CSVRecordBatch, header CSVHeader, navalue string) *byt
buff := new(bytes.Buffer)
csv := csv.NewWriter(buff)
log.Warn("Header:", header)
if batch.Order() == 0 {
csv.Write(header)
}