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