mirror of
https://github.com/metabarcoding/obitools4.git
synced 2025-12-08 16:50:27 +00:00
Adds to every obitools the ability to save in gzip compressed files
This commit is contained in:
@@ -65,10 +65,12 @@ func FormatFastaBatch(batch obiiter.BioSequenceBatch, formater FormatHeader) []b
|
||||
}
|
||||
|
||||
func WriteFasta(iterator obiiter.IBioSequence,
|
||||
file io.Writer,
|
||||
file io.WriteCloser,
|
||||
options ...WithOption) (obiiter.IBioSequence, error) {
|
||||
opt := MakeOptions(options)
|
||||
|
||||
file,_ = goutils.CompressStream(file,opt.CompressedFile(),opt.CloseFile())
|
||||
|
||||
buffsize := iterator.BufferSize()
|
||||
newIter := obiiter.MakeIBioSequence(buffsize)
|
||||
|
||||
@@ -133,15 +135,8 @@ func WriteFasta(iterator obiiter.IBioSequence,
|
||||
|
||||
}
|
||||
|
||||
if opt.CloseFile() {
|
||||
switch file := file.(type) {
|
||||
case *os.File:
|
||||
file.Close()
|
||||
case *goutils.Wfile:
|
||||
file.Close()
|
||||
}
|
||||
}
|
||||
|
||||
file.Close()
|
||||
|
||||
log.Debugln("End of the fasta file writing")
|
||||
obiiter.UnregisterPipe()
|
||||
waitWriter.Done()
|
||||
@@ -163,11 +158,13 @@ func WriteFastaToFile(iterator obiiter.IBioSequence,
|
||||
|
||||
|
||||
opt := MakeOptions(options)
|
||||
flags := os.O_WRONLY | os.O_CREATE
|
||||
|
||||
file,err := goutils.OpenWritingFile(filename,
|
||||
opt.CompressedFile(),
|
||||
opt.AppendFile(),
|
||||
)
|
||||
if opt.AppendFile() {
|
||||
flags |= os.O_APPEND
|
||||
}
|
||||
file, err := os.OpenFile(filename, flags, 0660)
|
||||
|
||||
|
||||
if err != nil {
|
||||
log.Fatalf("open file error: %v", err)
|
||||
|
||||
@@ -54,10 +54,12 @@ type FileChunck struct {
|
||||
}
|
||||
|
||||
func WriteFastq(iterator obiiter.IBioSequence,
|
||||
file io.Writer,
|
||||
file io.WriteCloser,
|
||||
options ...WithOption) (obiiter.IBioSequence, error) {
|
||||
opt := MakeOptions(options)
|
||||
|
||||
file,_ = goutils.CompressStream(file,opt.CompressedFile(),opt.CloseFile())
|
||||
|
||||
buffsize := iterator.BufferSize()
|
||||
newIter := obiiter.MakeIBioSequence(buffsize)
|
||||
|
||||
@@ -123,14 +125,7 @@ func WriteFastq(iterator obiiter.IBioSequence,
|
||||
|
||||
}
|
||||
|
||||
if opt.CloseFile() {
|
||||
switch file := file.(type) {
|
||||
case *os.File:
|
||||
file.Close()
|
||||
case *goutils.Wfile:
|
||||
file.Close()
|
||||
}
|
||||
}
|
||||
file.Close()
|
||||
|
||||
log.Debugln("End of the fastq file writing")
|
||||
obiiter.UnregisterPipe()
|
||||
@@ -151,12 +146,13 @@ func WriteFastqToFile(iterator obiiter.IBioSequence,
|
||||
options ...WithOption) (obiiter.IBioSequence, error) {
|
||||
|
||||
opt := MakeOptions(options)
|
||||
flags := os.O_WRONLY | os.O_CREATE
|
||||
|
||||
file, err := goutils.OpenWritingFile(filename,
|
||||
opt.CompressedFile(),
|
||||
opt.AppendFile(),
|
||||
)
|
||||
|
||||
if opt.AppendFile() {
|
||||
flags |= os.O_APPEND
|
||||
}
|
||||
file, err := os.OpenFile(filename, flags, 0660)
|
||||
|
||||
if err != nil {
|
||||
log.Fatalf("open file error: %v", err)
|
||||
return obiiter.NilIBioSequence, err
|
||||
|
||||
@@ -110,17 +110,17 @@ func OptionDontCloseFile() WithOption {
|
||||
return f
|
||||
}
|
||||
|
||||
func OptionsAppendFile() WithOption {
|
||||
func OptionsAppendFile(append bool) WithOption {
|
||||
f := WithOption(func(opt Options) {
|
||||
opt.pointer.appendfile = true
|
||||
opt.pointer.appendfile = append
|
||||
})
|
||||
|
||||
return f
|
||||
}
|
||||
|
||||
func OptionsCompressed() WithOption {
|
||||
func OptionsCompressed(compressed bool) WithOption {
|
||||
f := WithOption(func(opt Options) {
|
||||
opt.pointer.compressed = true
|
||||
opt.pointer.compressed = compressed
|
||||
})
|
||||
|
||||
return f
|
||||
|
||||
@@ -7,12 +7,11 @@ import (
|
||||
|
||||
log "github.com/sirupsen/logrus"
|
||||
|
||||
"git.metabarcoding.org/lecasofts/go/obitools/pkg/goutils"
|
||||
"git.metabarcoding.org/lecasofts/go/obitools/pkg/obiiter"
|
||||
)
|
||||
|
||||
func WriteSequence(iterator obiiter.IBioSequence,
|
||||
file io.Writer,
|
||||
file io.WriteCloser,
|
||||
options ...WithOption) (obiiter.IBioSequence, error) {
|
||||
|
||||
iterator = iterator.Rebatch(1000)
|
||||
@@ -56,13 +55,13 @@ func WriteSequencesToFile(iterator obiiter.IBioSequence,
|
||||
filename string,
|
||||
options ...WithOption) (obiiter.IBioSequence, error) {
|
||||
|
||||
|
||||
opt := MakeOptions(options)
|
||||
flags := os.O_WRONLY | os.O_CREATE
|
||||
|
||||
file, err := goutils.OpenWritingFile(filename,
|
||||
opt.CompressedFile(),
|
||||
opt.AppendFile(),
|
||||
)
|
||||
if opt.AppendFile() {
|
||||
flags |= os.O_APPEND
|
||||
}
|
||||
file, err := os.OpenFile(filename, flags, 0660)
|
||||
|
||||
if err != nil {
|
||||
log.Fatalf("open file error: %v", err)
|
||||
|
||||
Reference in New Issue
Block a user