mirror of
https://github.com/metabarcoding/obitools4.git
synced 2025-06-29 16:20:46 +00:00
break the import cyccle
This commit is contained in:
@ -1,4 +1,4 @@
|
||||
package obiiter
|
||||
package obiitercsv
|
||||
|
||||
import (
|
||||
"fmt"
|
@ -8,7 +8,7 @@ import (
|
||||
// corresponds to the last commit, and not the one when the file will be
|
||||
// commited
|
||||
|
||||
var _Commit = "0a567f6"
|
||||
var _Commit = "7c4042d"
|
||||
var _Version = "Release 4.2.0"
|
||||
|
||||
// Version returns the version of the obitools package.
|
||||
|
@ -1,11 +1,11 @@
|
||||
package obitax
|
||||
|
||||
// import (
|
||||
// "git.metabarcoding.org/obitools/obitools4/obitools4/pkg/obiiter"
|
||||
// )
|
||||
import (
|
||||
"git.metabarcoding.org/obitools/obitools4/obitools4/pkg/obiitercsv"
|
||||
)
|
||||
|
||||
// func WriteTaxonomyCSV(iterator obiiter.IBioSequence,
|
||||
// terminalAction bool, filenames ...string) *obiiter.ICSVRecord {
|
||||
func WriteTaxonomyCSV(iterator ITaxon,
|
||||
terminalAction bool, filenames ...string) *obiitercsv.ICSVRecord {
|
||||
|
||||
// return nil
|
||||
// }
|
||||
return nil
|
||||
}
|
||||
|
@ -2,7 +2,7 @@ package obicsv
|
||||
|
||||
import (
|
||||
"git.metabarcoding.org/obitools/obitools4/obitools4/pkg/obidefault"
|
||||
"git.metabarcoding.org/obitools/obitools4/obitools4/pkg/obiiter"
|
||||
"git.metabarcoding.org/obitools/obitools4/obitools4/pkg/obiitercsv"
|
||||
)
|
||||
|
||||
// __options__ holds configuration options for processing.
|
||||
@ -70,7 +70,7 @@ func MakeOptions(setters []WithOption) Options {
|
||||
csv_quality: false,
|
||||
csv_separator: ",",
|
||||
csv_navalue: "NA",
|
||||
csv_keys: make(obiiter.CSVHeader, 0),
|
||||
csv_keys: make(obiitercsv.CSVHeader, 0),
|
||||
csv_auto: false,
|
||||
source: "unknown",
|
||||
}
|
||||
|
@ -5,11 +5,12 @@ import (
|
||||
|
||||
"git.metabarcoding.org/obitools/obitools4/obitools4/pkg/obidefault"
|
||||
"git.metabarcoding.org/obitools/obitools4/obitools4/pkg/obiiter"
|
||||
"git.metabarcoding.org/obitools/obitools4/obitools4/pkg/obiitercsv"
|
||||
"git.metabarcoding.org/obitools/obitools4/obitools4/pkg/obitools/obiconvert"
|
||||
)
|
||||
|
||||
func CLIWriteSequenceCSV(iterator obiiter.IBioSequence,
|
||||
terminalAction bool, filenames ...string) *obiiter.ICSVRecord {
|
||||
terminalAction bool, filenames ...string) *obiitercsv.ICSVRecord {
|
||||
|
||||
if obiconvert.CLIProgressBar() {
|
||||
iterator = iterator.Speed("Writing CSV")
|
||||
@ -42,12 +43,12 @@ func CLIWriteSequenceCSV(iterator obiiter.IBioSequence,
|
||||
|
||||
}
|
||||
|
||||
func CLICSVWriter(iterator *obiiter.ICSVRecord,
|
||||
func CLICSVWriter(iterator *obiitercsv.ICSVRecord,
|
||||
terminalAction bool,
|
||||
options ...WithOption) *obiiter.ICSVRecord {
|
||||
options ...WithOption) *obiitercsv.ICSVRecord {
|
||||
|
||||
var err error
|
||||
var newIter *obiiter.ICSVRecord
|
||||
var newIter *obiitercsv.ICSVRecord
|
||||
|
||||
if obiconvert.CLIOutPutFileName() != "-" {
|
||||
options = append(options, OptionFileName(obiconvert.CLIOutPutFileName()))
|
||||
|
@ -6,11 +6,12 @@ import (
|
||||
|
||||
"git.metabarcoding.org/obitools/obitools4/obitools4/pkg/obidefault"
|
||||
"git.metabarcoding.org/obitools/obitools4/obitools4/pkg/obiiter"
|
||||
"git.metabarcoding.org/obitools/obitools4/obitools4/pkg/obiitercsv"
|
||||
)
|
||||
|
||||
func CSVSequenceHeader(opt Options) obiiter.CSVHeader {
|
||||
func CSVSequenceHeader(opt Options) obiitercsv.CSVHeader {
|
||||
keys := opt.CSVKeys()
|
||||
record := make(obiiter.CSVHeader, 0, len(keys)+4)
|
||||
record := make(obiitercsv.CSVHeader, 0, len(keys)+4)
|
||||
|
||||
if opt.CSVId() {
|
||||
record.AppendField("id")
|
||||
@ -45,12 +46,12 @@ func CSVSequenceHeader(opt Options) obiiter.CSVHeader {
|
||||
return record
|
||||
}
|
||||
|
||||
func CSVBatchFromSequences(batch obiiter.BioSequenceBatch, opt Options) obiiter.CSVRecordBatch {
|
||||
func CSVBatchFromSequences(batch obiiter.BioSequenceBatch, opt Options) obiitercsv.CSVRecordBatch {
|
||||
keys := opt.CSVKeys()
|
||||
csvslice := make([]obiiter.CSVRecord, batch.Len())
|
||||
csvslice := make([]obiitercsv.CSVRecord, batch.Len())
|
||||
|
||||
for i, sequence := range batch.Slice() {
|
||||
record := make(obiiter.CSVRecord)
|
||||
record := make(obiitercsv.CSVRecord)
|
||||
|
||||
if opt.CSVId() {
|
||||
record["id"] = sequence.Id()
|
||||
@ -108,10 +109,10 @@ func CSVBatchFromSequences(batch obiiter.BioSequenceBatch, opt Options) obiiter.
|
||||
csvslice[i] = record
|
||||
}
|
||||
|
||||
return obiiter.MakeCSVRecordBatch(batch.Source(), batch.Order(), csvslice)
|
||||
return obiitercsv.MakeCSVRecordBatch(batch.Source(), batch.Order(), csvslice)
|
||||
}
|
||||
|
||||
func NewCSVSequenceIterator(iter obiiter.IBioSequence, options ...WithOption) *obiiter.ICSVRecord {
|
||||
func NewCSVSequenceIterator(iter obiiter.IBioSequence, options ...WithOption) *obiitercsv.ICSVRecord {
|
||||
|
||||
opt := MakeOptions(options)
|
||||
|
||||
@ -128,7 +129,7 @@ func NewCSVSequenceIterator(iter obiiter.IBioSequence, options ...WithOption) *o
|
||||
}
|
||||
}
|
||||
|
||||
newIter := obiiter.NewICSVRecord()
|
||||
newIter := obiitercsv.NewICSVRecord()
|
||||
newIter.SetHeader(CSVSequenceHeader(opt))
|
||||
|
||||
nwriters := opt.ParallelWorkers()
|
||||
|
@ -7,13 +7,13 @@ import (
|
||||
"os"
|
||||
|
||||
"git.metabarcoding.org/obitools/obitools4/obitools4/pkg/obiformats"
|
||||
"git.metabarcoding.org/obitools/obitools4/obitools4/pkg/obiiter"
|
||||
"git.metabarcoding.org/obitools/obitools4/obitools4/pkg/obiitercsv"
|
||||
"git.metabarcoding.org/obitools/obitools4/obitools4/pkg/obiutils"
|
||||
|
||||
log "github.com/sirupsen/logrus"
|
||||
)
|
||||
|
||||
func FormatCVSBatch(batch obiiter.CSVRecordBatch, header obiiter.CSVHeader, navalue string) *bytes.Buffer {
|
||||
func FormatCVSBatch(batch obiitercsv.CSVRecordBatch, header obiitercsv.CSVHeader, navalue string) *bytes.Buffer {
|
||||
buff := new(bytes.Buffer)
|
||||
csv := csv.NewWriter(buff)
|
||||
|
||||
@ -45,14 +45,14 @@ func FormatCVSBatch(batch obiiter.CSVRecordBatch, header obiiter.CSVHeader, nava
|
||||
return buff
|
||||
}
|
||||
|
||||
func WriteCSV(iterator *obiiter.ICSVRecord,
|
||||
func WriteCSV(iterator *obiitercsv.ICSVRecord,
|
||||
file io.WriteCloser,
|
||||
options ...WithOption) (*obiiter.ICSVRecord, error) {
|
||||
options ...WithOption) (*obiitercsv.ICSVRecord, error) {
|
||||
opt := MakeOptions(options)
|
||||
|
||||
file, _ = obiutils.CompressStream(file, opt.CompressedFile(), opt.CloseFile())
|
||||
|
||||
newIter := obiiter.NewICSVRecord()
|
||||
newIter := obiitercsv.NewICSVRecord()
|
||||
|
||||
nwriters := opt.ParallelWorkers()
|
||||
|
||||
@ -66,7 +66,7 @@ func WriteCSV(iterator *obiiter.ICSVRecord,
|
||||
log.Debugf("Writing CSV file done")
|
||||
}()
|
||||
|
||||
ff := func(iterator *obiiter.ICSVRecord) {
|
||||
ff := func(iterator *obiitercsv.ICSVRecord) {
|
||||
for iterator.Next() {
|
||||
|
||||
batch := iterator.Get()
|
||||
@ -109,8 +109,8 @@ func WriteCSV(iterator *obiiter.ICSVRecord,
|
||||
// os.Stdout as the output file, and the options slice.
|
||||
//
|
||||
// The function returns the same bio sequence iterator and an error if any occurred.
|
||||
func WriteCSVToStdout(iterator *obiiter.ICSVRecord,
|
||||
options ...WithOption) (*obiiter.ICSVRecord, error) {
|
||||
func WriteCSVToStdout(iterator *obiitercsv.ICSVRecord,
|
||||
options ...WithOption) (*obiitercsv.ICSVRecord, error) {
|
||||
// options = append(options, OptionDontCloseFile())
|
||||
options = append(options, OptionCloseFile())
|
||||
return WriteCSV(iterator, os.Stdout, options...)
|
||||
@ -127,9 +127,9 @@ func WriteCSVToStdout(iterator *obiiter.ICSVRecord,
|
||||
// Returns:
|
||||
// - obiiter.IBioSequence: The updated biosequence iterator.
|
||||
// - error: Any error that occurred during the writing process.
|
||||
func WriteCSVToFile(iterator *obiiter.ICSVRecord,
|
||||
func WriteCSVToFile(iterator *obiitercsv.ICSVRecord,
|
||||
filename string,
|
||||
options ...WithOption) (*obiiter.ICSVRecord, error) {
|
||||
options ...WithOption) (*obiitercsv.ICSVRecord, error) {
|
||||
|
||||
opt := MakeOptions(options)
|
||||
flags := os.O_WRONLY | os.O_CREATE
|
||||
|
@ -4,7 +4,7 @@ import (
|
||||
"slices"
|
||||
|
||||
"git.metabarcoding.org/obitools/obitools4/obitools4/pkg/obidefault"
|
||||
"git.metabarcoding.org/obitools/obitools4/obitools4/pkg/obiiter"
|
||||
"git.metabarcoding.org/obitools/obitools4/obitools4/pkg/obiitercsv"
|
||||
"git.metabarcoding.org/obitools/obitools4/obitools4/pkg/obitax"
|
||||
)
|
||||
|
||||
@ -192,12 +192,12 @@ func OptionsWithMetadata(values ...string) WithOption {
|
||||
return f
|
||||
}
|
||||
|
||||
func NewCSVTaxaIterator(iterator *obitax.ITaxon, options ...WithOption) *obiiter.ICSVRecord {
|
||||
func NewCSVTaxaIterator(iterator *obitax.ITaxon, options ...WithOption) *obiitercsv.ICSVRecord {
|
||||
|
||||
opt := MakeOptions(options)
|
||||
metakeys := make([]string, 0)
|
||||
|
||||
newIter := obiiter.NewICSVRecord()
|
||||
newIter := obiitercsv.NewICSVRecord()
|
||||
|
||||
newIter.Add(1)
|
||||
|
||||
@ -240,11 +240,11 @@ func NewCSVTaxaIterator(iterator *obitax.ITaxon, options ...WithOption) *obiiter
|
||||
|
||||
go func() {
|
||||
o := 0
|
||||
data := make([]obiiter.CSVRecord, 0, batch_size)
|
||||
data := make([]obiitercsv.CSVRecord, 0, batch_size)
|
||||
for iterator.Next() {
|
||||
|
||||
taxon := iterator.Get()
|
||||
record := make(obiiter.CSVRecord)
|
||||
record := make(obiitercsv.CSVRecord)
|
||||
|
||||
if opt.WithPattern() {
|
||||
record["query"] = taxon.MetadataAsString("query")
|
||||
@ -282,15 +282,15 @@ func NewCSVTaxaIterator(iterator *obitax.ITaxon, options ...WithOption) *obiiter
|
||||
|
||||
data = append(data, record)
|
||||
if len(data) >= batch_size {
|
||||
newIter.Push(obiiter.MakeCSVRecordBatch(opt.Source(), o, data))
|
||||
data = make([]obiiter.CSVRecord, 0, batch_size)
|
||||
newIter.Push(obiitercsv.MakeCSVRecordBatch(opt.Source(), o, data))
|
||||
data = make([]obiitercsv.CSVRecord, 0, batch_size)
|
||||
o++
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
if len(data) > 0 {
|
||||
newIter.Push(obiiter.MakeCSVRecordBatch(opt.Source(), o, data))
|
||||
newIter.Push(obiitercsv.MakeCSVRecordBatch(opt.Source(), o, data))
|
||||
}
|
||||
|
||||
newIter.Done()
|
||||
|
@ -2,7 +2,7 @@ package obifind
|
||||
|
||||
import (
|
||||
"git.metabarcoding.org/obitools/obitools4/obitools4/pkg/obidefault"
|
||||
"git.metabarcoding.org/obitools/obitools4/obitools4/pkg/obiiter"
|
||||
"git.metabarcoding.org/obitools/obitools4/obitools4/pkg/obiitercsv"
|
||||
"git.metabarcoding.org/obitools/obitools4/obitools4/pkg/obitax"
|
||||
"git.metabarcoding.org/obitools/obitools4/obitools4/pkg/obitools/obicsv"
|
||||
|
||||
@ -40,7 +40,7 @@ func CLIFilterRankRestriction(iterator *obitax.ITaxon) *obitax.ITaxon {
|
||||
return iterator
|
||||
}
|
||||
|
||||
func CLICSVTaxaIterator(iterator *obitax.ITaxon) *obiiter.ICSVRecord {
|
||||
func CLICSVTaxaIterator(iterator *obitax.ITaxon) *obiitercsv.ICSVRecord {
|
||||
if iterator == nil {
|
||||
return nil
|
||||
}
|
||||
@ -60,6 +60,6 @@ func CLICSVTaxaIterator(iterator *obitax.ITaxon) *obiiter.ICSVRecord {
|
||||
return NewCSVTaxaIterator(iterator, options...)
|
||||
}
|
||||
|
||||
func CLICSVTaxaWriter(iterator *obitax.ITaxon, terminalAction bool) *obiiter.ICSVRecord {
|
||||
func CLICSVTaxaWriter(iterator *obitax.ITaxon, terminalAction bool) *obiitercsv.ICSVRecord {
|
||||
return obicsv.CLICSVWriter(CLICSVTaxaIterator(iterator), terminalAction)
|
||||
}
|
||||
|
Reference in New Issue
Block a user