mirror of
https://github.com/metabarcoding/obitools4.git
synced 2025-12-08 16:50:27 +00:00
Refactoring related to iterators
This commit is contained in:
@@ -13,7 +13,7 @@ func ReadSequencesBatchFromFiles(filenames []string,
|
||||
options ...WithOption) obiiter.IBioSequenceBatch {
|
||||
|
||||
if reader == nil {
|
||||
reader = ReadSequencesBatchFromFile
|
||||
reader = ReadSequencesFromFile
|
||||
}
|
||||
|
||||
batchiter := obiiter.MakeIBioSequenceBatch(0)
|
||||
|
||||
@@ -119,7 +119,7 @@ func __read_ecopcr_bioseq__(file *__ecopcr_file__) (*obiseq.BioSequence, error)
|
||||
return bseq, nil
|
||||
}
|
||||
|
||||
func ReadEcoPCRBatch(reader io.Reader, options ...WithOption) obiiter.IBioSequenceBatch {
|
||||
func ReadEcoPCR(reader io.Reader, options ...WithOption) obiiter.IBioSequenceBatch {
|
||||
tag := make([]byte, 11)
|
||||
n, _ := reader.Read(tag)
|
||||
|
||||
@@ -224,5 +224,5 @@ func ReadEcoPCRBatchFromFile(filename string, options ...WithOption) (obiiter.IB
|
||||
reader = greader
|
||||
}
|
||||
|
||||
return ReadEcoPCRBatch(reader, options...), nil
|
||||
return ReadEcoPCR(reader, options...), nil
|
||||
}
|
||||
|
||||
@@ -201,7 +201,7 @@ func _ReadFlatFileChunk(reader io.Reader, readers chan _FileChunk) {
|
||||
// 6 5 43 2 1
|
||||
//
|
||||
// <CR>?<LF>//<CR>?<LF>
|
||||
func ReadEMBLBatch(reader io.Reader, options ...WithOption) obiiter.IBioSequenceBatch {
|
||||
func ReadEMBL(reader io.Reader, options ...WithOption) obiiter.IBioSequenceBatch {
|
||||
opt := MakeOptions(options)
|
||||
entry_channel := make(chan _FileChunk, opt.BufferSize())
|
||||
|
||||
@@ -224,7 +224,7 @@ func ReadEMBLBatch(reader io.Reader, options ...WithOption) obiiter.IBioSequence
|
||||
return newIter
|
||||
}
|
||||
|
||||
func ReadEMBLBatchFromFile(filename string, options ...WithOption) (obiiter.IBioSequenceBatch, error) {
|
||||
func ReadEMBLFromFile(filename string, options ...WithOption) (obiiter.IBioSequenceBatch, error) {
|
||||
var reader io.Reader
|
||||
var greader io.Reader
|
||||
var err error
|
||||
@@ -242,5 +242,5 @@ func ReadEMBLBatchFromFile(filename string, options ...WithOption) (obiiter.IBio
|
||||
reader = greader
|
||||
}
|
||||
|
||||
return ReadEMBLBatch(reader, options...), nil
|
||||
return ReadEMBL(reader, options...), nil
|
||||
}
|
||||
|
||||
@@ -87,7 +87,7 @@ func _FastseqReader(seqfile C.fast_kseq_p,
|
||||
|
||||
}
|
||||
|
||||
func ReadFastSeqBatchFromFile(filename string, options ...WithOption) (obiiter.IBioSequenceBatch, error) {
|
||||
func ReadFastSeqFromFile(filename string, options ...WithOption) (obiiter.IBioSequenceBatch, error) {
|
||||
opt := MakeOptions(options)
|
||||
|
||||
name := C.CString(filename)
|
||||
@@ -132,7 +132,7 @@ func ReadFastSeqBatchFromFile(filename string, options ...WithOption) (obiiter.I
|
||||
return newIter, err
|
||||
}
|
||||
|
||||
func ReadFastSeqBatchFromStdin(options ...WithOption) obiiter.IBioSequenceBatch {
|
||||
func ReadFastSeqFromStdin(options ...WithOption) obiiter.IBioSequenceBatch {
|
||||
opt := MakeOptions(options)
|
||||
newIter := obiiter.MakeIBioSequenceBatch(opt.BufferSize())
|
||||
|
||||
|
||||
@@ -61,7 +61,7 @@ func FormatFastaBatch(batch obiiter.BioSequenceBatch, formater FormatHeader) []b
|
||||
return bs.Bytes()
|
||||
}
|
||||
|
||||
func WriteFastaBatch(iterator obiiter.IBioSequenceBatch,
|
||||
func WriteFasta(iterator obiiter.IBioSequenceBatch,
|
||||
file io.Writer,
|
||||
options ...WithOption) (obiiter.IBioSequenceBatch, error) {
|
||||
opt := MakeOptions(options)
|
||||
@@ -136,13 +136,13 @@ func WriteFastaBatch(iterator obiiter.IBioSequenceBatch,
|
||||
return newIter, nil
|
||||
}
|
||||
|
||||
func WriteFastaBatchToStdout(iterator obiiter.IBioSequenceBatch,
|
||||
func WriteFastaToStdout(iterator obiiter.IBioSequenceBatch,
|
||||
options ...WithOption) (obiiter.IBioSequenceBatch, error) {
|
||||
options = append(options, OptionDontCloseFile())
|
||||
return WriteFastaBatch(iterator, os.Stdout, options...)
|
||||
return WriteFasta(iterator, os.Stdout, options...)
|
||||
}
|
||||
|
||||
func WriteFastaBatchToFile(iterator obiiter.IBioSequenceBatch,
|
||||
func WriteFastaToFile(iterator obiiter.IBioSequenceBatch,
|
||||
filename string,
|
||||
options ...WithOption) (obiiter.IBioSequenceBatch, error) {
|
||||
|
||||
@@ -155,5 +155,5 @@ func WriteFastaBatchToFile(iterator obiiter.IBioSequenceBatch,
|
||||
|
||||
options = append(options, OptionCloseFile())
|
||||
|
||||
return WriteFastaBatch(iterator, file, options...)
|
||||
return WriteFasta(iterator, file, options...)
|
||||
}
|
||||
|
||||
@@ -51,7 +51,7 @@ type FileChunck struct {
|
||||
order int
|
||||
}
|
||||
|
||||
func WriteFastqBatch(iterator obiiter.IBioSequenceBatch,
|
||||
func WriteFastq(iterator obiiter.IBioSequenceBatch,
|
||||
file io.Writer,
|
||||
options ...WithOption) (obiiter.IBioSequenceBatch, error) {
|
||||
opt := MakeOptions(options)
|
||||
@@ -129,13 +129,13 @@ func WriteFastqBatch(iterator obiiter.IBioSequenceBatch,
|
||||
return newIter, nil
|
||||
}
|
||||
|
||||
func WriteFastqBatchToStdout(iterator obiiter.IBioSequenceBatch,
|
||||
func WriteFastqToStdout(iterator obiiter.IBioSequenceBatch,
|
||||
options ...WithOption) (obiiter.IBioSequenceBatch, error) {
|
||||
options = append(options, OptionDontCloseFile())
|
||||
return WriteFastqBatch(iterator, os.Stdout, options...)
|
||||
return WriteFastq(iterator, os.Stdout, options...)
|
||||
}
|
||||
|
||||
func WriteFastqBatchToFile(iterator obiiter.IBioSequenceBatch,
|
||||
func WriteFastqToFile(iterator obiiter.IBioSequenceBatch,
|
||||
filename string,
|
||||
options ...WithOption) (obiiter.IBioSequenceBatch, error) {
|
||||
|
||||
@@ -148,5 +148,5 @@ func WriteFastqBatchToFile(iterator obiiter.IBioSequenceBatch,
|
||||
|
||||
options = append(options, OptionCloseFile())
|
||||
|
||||
return WriteFastqBatch(iterator, file, options...)
|
||||
return WriteFastq(iterator, file, options...)
|
||||
}
|
||||
|
||||
@@ -20,10 +20,10 @@ type gbstate int
|
||||
|
||||
const (
|
||||
inHeader gbstate = 0
|
||||
inEntry = 1
|
||||
inDefinition = 2
|
||||
inFeature = 3
|
||||
inSequence = 4
|
||||
inEntry gbstate = 1
|
||||
inDefinition gbstate = 2
|
||||
inFeature gbstate = 3
|
||||
inSequence gbstate = 4
|
||||
)
|
||||
|
||||
func _ParseGenbankFile(input <-chan _FileChunk, out obiiter.IBioSequenceBatch) {
|
||||
@@ -107,7 +107,7 @@ func _ParseGenbankFile(input <-chan _FileChunk, out obiiter.IBioSequenceBatch) {
|
||||
|
||||
}
|
||||
|
||||
func ReadGenbankBatch(reader io.Reader, options ...WithOption) obiiter.IBioSequenceBatch {
|
||||
func ReadGenbank(reader io.Reader, options ...WithOption) obiiter.IBioSequenceBatch {
|
||||
opt := MakeOptions(options)
|
||||
entry_channel := make(chan _FileChunk, opt.BufferSize())
|
||||
|
||||
@@ -130,7 +130,7 @@ func ReadGenbankBatch(reader io.Reader, options ...WithOption) obiiter.IBioSeque
|
||||
return newIter
|
||||
}
|
||||
|
||||
func ReadGenbankBatchFromFile(filename string, options ...WithOption) (obiiter.IBioSequenceBatch, error) {
|
||||
func ReadGenbankFromFile(filename string, options ...WithOption) (obiiter.IBioSequenceBatch, error) {
|
||||
var reader io.Reader
|
||||
var greader io.Reader
|
||||
var err error
|
||||
@@ -148,5 +148,5 @@ func ReadGenbankBatchFromFile(filename string, options ...WithOption) (obiiter.I
|
||||
reader = greader
|
||||
}
|
||||
|
||||
return ReadGenbankBatch(reader, options...), nil
|
||||
return ReadGenbank(reader, options...), nil
|
||||
}
|
||||
|
||||
@@ -42,7 +42,7 @@ func GuessSeqFileType(firstline string) string {
|
||||
}
|
||||
}
|
||||
|
||||
func ReadSequencesBatchFromFile(filename string,
|
||||
func ReadSequencesFromFile(filename string,
|
||||
options ...WithOption) (obiiter.IBioSequenceBatch, error) {
|
||||
var file *os.File
|
||||
var reader io.Reader
|
||||
@@ -85,14 +85,14 @@ func ReadSequencesBatchFromFile(filename string,
|
||||
switch filetype {
|
||||
case "fastq", "fasta":
|
||||
file.Close()
|
||||
is, _ := ReadFastSeqBatchFromFile(filename, options...)
|
||||
is, _ := ReadFastSeqFromFile(filename, options...)
|
||||
return is, nil
|
||||
case "ecopcr":
|
||||
return ReadEcoPCRBatch(reader, options...), nil
|
||||
return ReadEcoPCR(reader, options...), nil
|
||||
case "embl":
|
||||
return ReadEMBLBatch(reader, options...), nil
|
||||
return ReadEMBL(reader, options...), nil
|
||||
case "genbank":
|
||||
return ReadGenbankBatch(reader, options...), nil
|
||||
return ReadGenbank(reader, options...), nil
|
||||
default:
|
||||
log.Fatalf("File %s has guessed format %s which is not yet implemented",
|
||||
filename, filetype)
|
||||
|
||||
@@ -10,7 +10,7 @@ import (
|
||||
"git.metabarcoding.org/lecasofts/go/obitools/pkg/obiiter"
|
||||
)
|
||||
|
||||
func WriteSequenceBatch(iterator obiiter.IBioSequenceBatch,
|
||||
func WriteSequence(iterator obiiter.IBioSequenceBatch,
|
||||
file io.Writer,
|
||||
options ...WithOption) (obiiter.IBioSequenceBatch, error) {
|
||||
|
||||
@@ -27,12 +27,12 @@ func WriteSequenceBatch(iterator obiiter.IBioSequenceBatch,
|
||||
|
||||
if len(batch.Slice()) > 0 {
|
||||
if batch.Slice()[0].HasQualities() {
|
||||
newIter, err = WriteFastqBatch(iterator, file, options...)
|
||||
newIter, err = WriteFastq(iterator, file, options...)
|
||||
} else {
|
||||
newIter, err = WriteFastaBatch(iterator, file, options...)
|
||||
newIter, err = WriteFasta(iterator, file, options...)
|
||||
}
|
||||
} else {
|
||||
newIter, err = WriteFastaBatch(iterator, file, options...)
|
||||
newIter, err = WriteFasta(iterator, file, options...)
|
||||
}
|
||||
|
||||
return newIter, err
|
||||
@@ -45,13 +45,13 @@ func WriteSequenceBatch(iterator obiiter.IBioSequenceBatch,
|
||||
return obiiter.NilIBioSequenceBatch, fmt.Errorf("input iterator not ready")
|
||||
}
|
||||
|
||||
func WriteSequencesBatchToStdout(iterator obiiter.IBioSequenceBatch,
|
||||
func WriteSequencesToStdout(iterator obiiter.IBioSequenceBatch,
|
||||
options ...WithOption) (obiiter.IBioSequenceBatch, error) {
|
||||
options = append(options, OptionDontCloseFile())
|
||||
return WriteSequenceBatch(iterator, os.Stdout, options...)
|
||||
return WriteSequence(iterator, os.Stdout, options...)
|
||||
}
|
||||
|
||||
func WriteSequencesBatchToFile(iterator obiiter.IBioSequenceBatch,
|
||||
func WriteSequencesToFile(iterator obiiter.IBioSequenceBatch,
|
||||
filename string,
|
||||
options ...WithOption) (obiiter.IBioSequenceBatch, error) {
|
||||
|
||||
@@ -63,5 +63,5 @@ func WriteSequencesBatchToFile(iterator obiiter.IBioSequenceBatch,
|
||||
}
|
||||
|
||||
options = append(options, OptionCloseFile())
|
||||
return WriteSequenceBatch(iterator, file, options...)
|
||||
return WriteSequence(iterator, file, options...)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user