mirror of
https://github.com/metabarcoding/obitools4.git
synced 2025-12-13 02:30:26 +00:00
obicsv debug
This commit is contained in:
@@ -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)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -64,6 +64,7 @@ func CSVOptionSet(options *getoptions.GetOpt) {
|
||||
}
|
||||
|
||||
func OptionSet(options *getoptions.GetOpt) {
|
||||
obiconvert.InputOptionSet(options)
|
||||
obiconvert.OutputModeOptionSet(options)
|
||||
CSVOptionSet(options)
|
||||
}
|
||||
|
||||
@@ -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)
|
||||
|
||||
|
||||
@@ -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)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user