Remove single sequence ierators. Only batch iterators persist

This commit is contained in:
2022-11-16 10:58:59 +01:00
parent f674200a6e
commit 6f853da9df
14 changed files with 4 additions and 651 deletions

View File

@@ -5,11 +5,12 @@ import (
"encoding/csv"
"fmt"
"io"
log "github.com/sirupsen/logrus"
"os"
"strconv"
"strings"
log "github.com/sirupsen/logrus"
"git.metabarcoding.org/lecasofts/go/obitools/pkg/obiiter"
"git.metabarcoding.org/lecasofts/go/obitools/pkg/obiseq"
)
@@ -206,11 +207,6 @@ func ReadEcoPCRBatch(reader io.Reader, options ...WithOption) obiiter.IBioSequen
return newIter
}
func ReadEcoPCR(reader io.Reader, options ...WithOption) obiiter.IBioSequence {
ib := ReadEcoPCRBatch(reader, options...)
return ib.SortBatches().IBioSequence()
}
func ReadEcoPCRBatchFromFile(filename string, options ...WithOption) (obiiter.IBioSequenceBatch, error) {
var reader io.Reader
var greader io.Reader
@@ -230,9 +226,3 @@ func ReadEcoPCRBatchFromFile(filename string, options ...WithOption) (obiiter.IB
return ReadEcoPCRBatch(reader, options...), nil
}
func ReadEcoPCRFromFile(filename string, options ...WithOption) (obiiter.IBioSequence, error) {
ib, err := ReadEcoPCRBatchFromFile(filename, options...)
return ib.SortBatches().IBioSequence(), err
}

View File

@@ -224,11 +224,6 @@ func ReadEMBLBatch(reader io.Reader, options ...WithOption) obiiter.IBioSequence
return newIter
}
func ReadEMBL(reader io.Reader, options ...WithOption) obiiter.IBioSequence {
ib := ReadEMBLBatch(reader, options...)
return ib.SortBatches().IBioSequence()
}
func ReadEMBLBatchFromFile(filename string, options ...WithOption) (obiiter.IBioSequenceBatch, error) {
var reader io.Reader
var greader io.Reader
@@ -249,9 +244,3 @@ func ReadEMBLBatchFromFile(filename string, options ...WithOption) (obiiter.IBio
return ReadEMBLBatch(reader, options...), nil
}
func ReadEMBLFromFile(filename string, options ...WithOption) (obiiter.IBioSequence, error) {
ib, err := ReadEMBLBatchFromFile(filename, options...)
return ib.SortBatches().IBioSequence(), err
}

View File

@@ -22,12 +22,3 @@ func IParseFastSeqHeaderBatch(iterator obiiter.IBioSequenceBatch,
opt.ParallelWorkers(),
opt.BufferSize())
}
func IParseFastSeqHeader(iterator obiiter.IBioSequence,
options ...WithOption) obiiter.IBioSequence {
opt := MakeOptions(options)
return IParseFastSeqHeaderBatch(iterator.IBioSequenceBatch(opt.BatchSize(),
opt.BufferSize()),
options...).SortBatches().IBioSequence()
}

View File

@@ -132,11 +132,6 @@ func ReadFastSeqBatchFromFile(filename string, options ...WithOption) (obiiter.I
return newIter, err
}
func ReadFastSeqFromFile(filename string, options ...WithOption) (obiiter.IBioSequence, error) {
ib, err := ReadFastSeqBatchFromFile(filename, options...)
return ib.SortBatches().IBioSequence(), err
}
func ReadFastSeqBatchFromStdin(options ...WithOption) obiiter.IBioSequenceBatch {
opt := MakeOptions(options)
newIter := obiiter.MakeIBioSequenceBatch(opt.BufferSize())
@@ -158,8 +153,3 @@ func ReadFastSeqBatchFromStdin(options ...WithOption) obiiter.IBioSequenceBatch
return newIter
}
func ReadFastSeqFromStdin(options ...WithOption) obiiter.IBioSequence {
ib := ReadFastSeqBatchFromStdin(options...)
return ib.SortBatches().IBioSequence()
}

View File

@@ -61,47 +61,6 @@ func FormatFastaBatch(batch obiiter.BioSequenceBatch, formater FormatHeader) []b
return bs.Bytes()
}
func WriteFasta(iterator obiiter.IBioSequence, file io.Writer, options ...WithOption) error {
opt := MakeOptions(options)
header_format := opt.FormatFastSeqHeader()
for iterator.Next() {
seq := iterator.Get()
fmt.Fprintln(file, FormatFasta(seq, header_format))
}
if opt.CloseFile() {
switch file := file.(type) {
case *os.File:
file.Close()
}
}
return nil
}
func WriteFastaToFile(iterator obiiter.IBioSequence,
filename string,
options ...WithOption) error {
file, err := os.Create(filename)
if err != nil {
log.Fatalf("open file error: %v", err)
return err
}
options = append(options, OptionCloseFile())
return WriteFasta(iterator, file, options...)
}
func WriteFastaToStdout(iterator obiiter.IBioSequence, options ...WithOption) error {
options = append(options, OptionDontCloseFile())
return WriteFasta(iterator, os.Stdout, options...)
}
func WriteFastaBatch(iterator obiiter.IBioSequenceBatch,
file io.Writer,
options ...WithOption) (obiiter.IBioSequenceBatch, error) {

View File

@@ -46,47 +46,6 @@ func FormatFastqBatch(batch obiiter.BioSequenceBatch, quality_shift int,
return bs.Bytes()
}
func WriteFastq(iterator obiiter.IBioSequence, file io.Writer, options ...WithOption) error {
opt := MakeOptions(options)
header_format := opt.FormatFastSeqHeader()
quality := opt.QualityShift()
for iterator.Next() {
seq := iterator.Get()
fmt.Fprintln(file, FormatFastq(seq, quality, header_format))
}
if opt.CloseFile() {
switch file := file.(type) {
case *os.File:
file.Close()
}
}
return nil
}
func WriteFastqToFile(iterator obiiter.IBioSequence,
filename string,
options ...WithOption) error {
file, err := os.Create(filename)
if err != nil {
log.Fatalf("open file error: %v", err)
return err
}
options = append(options, OptionCloseFile())
return WriteFastq(iterator, file, options...)
}
func WriteFastqToStdout(iterator obiiter.IBioSequence, options ...WithOption) error {
options = append(options, OptionDontCloseFile())
return WriteFastq(iterator, os.Stdout, options...)
}
type FileChunck struct {
text []byte
order int

View File

@@ -130,11 +130,6 @@ func ReadGenbankBatch(reader io.Reader, options ...WithOption) obiiter.IBioSeque
return newIter
}
func ReadGenbank(reader io.Reader, options ...WithOption) obiiter.IBioSequence {
ib := ReadGenbankBatch(reader, options...)
return ib.SortBatches().IBioSequence()
}
func ReadGenbankBatchFromFile(filename string, options ...WithOption) (obiiter.IBioSequenceBatch, error) {
var reader io.Reader
var greader io.Reader
@@ -155,9 +150,3 @@ func ReadGenbankBatchFromFile(filename string, options ...WithOption) (obiiter.I
return ReadGenbankBatch(reader, options...), nil
}
func ReadGenbankFromFile(filename string, options ...WithOption) (obiiter.IBioSequence, error) {
ib, err := ReadGenbankBatchFromFile(filename, options...)
return ib.SortBatches().IBioSequence(), err
}

View File

@@ -100,10 +100,3 @@ func ReadSequencesBatchFromFile(filename string,
return obiiter.NilIBioSequenceBatch, nil
}
func ReadSequencesFromFile(filename string,
options ...WithOption) (obiiter.IBioSequence, error) {
ib, err := ReadSequencesBatchFromFile(filename, options...)
return ib.SortBatches().IBioSequence(), err
}

View File

@@ -3,55 +3,13 @@ package obiformats
import (
"fmt"
"io"
log "github.com/sirupsen/logrus"
"os"
log "github.com/sirupsen/logrus"
"git.metabarcoding.org/lecasofts/go/obitools/pkg/obiiter"
)
func WriteSequences(iterator obiiter.IBioSequence,
file io.Writer,
options ...WithOption) error {
opts := MakeOptions(options)
header_format := opts.FormatFastSeqHeader()
quality := opts.QualityShift()
ok := iterator.Next()
if ok {
seq := iterator.Get()
if seq.HasQualities() {
fmt.Fprintln(file, FormatFastq(seq, quality, header_format))
WriteFastq(iterator, file, options...)
} else {
fmt.Fprintln(file, FormatFasta(seq, header_format))
WriteFasta(iterator, file, options...)
}
}
return nil
}
func WriteSequencesToFile(iterator obiiter.IBioSequence,
filename string,
options ...WithOption) error {
file, err := os.Create(filename)
if err != nil {
log.Fatalf("open file error: %v", err)
return err
}
return WriteSequences(iterator, file, options...)
}
func WriteSequencesToStdout(iterator obiiter.IBioSequence, options ...WithOption) error {
return WriteSequences(iterator, os.Stdout, options...)
}
func WriteSequenceBatch(iterator obiiter.IBioSequenceBatch,
file io.Writer,
options ...WithOption) (obiiter.IBioSequenceBatch, error) {