mirror of
https://github.com/metabarcoding/obitools4.git
synced 2025-12-08 16:50:27 +00:00
Adds the possiblility to append to files to obidistribute
This commit is contained in:
@@ -157,7 +157,19 @@ func WriteFastaToFile(iterator obiiter.IBioSequence,
|
||||
filename string,
|
||||
options ...WithOption) (obiiter.IBioSequence, error) {
|
||||
|
||||
file, err := os.Create(filename)
|
||||
var file *os.File
|
||||
var err error
|
||||
|
||||
opt := MakeOptions(options)
|
||||
|
||||
if opt.AppendFile() {
|
||||
log.Debug("Open files in appending mode")
|
||||
file, err = os.OpenFile(filename,
|
||||
os.O_APPEND|os.O_CREATE|os.O_WRONLY, 0644)
|
||||
} else {
|
||||
file, err = os.Create(filename)
|
||||
}
|
||||
|
||||
|
||||
if err != nil {
|
||||
log.Fatalf("open file error: %v", err)
|
||||
|
||||
@@ -147,7 +147,18 @@ func WriteFastqToFile(iterator obiiter.IBioSequence,
|
||||
filename string,
|
||||
options ...WithOption) (obiiter.IBioSequence, error) {
|
||||
|
||||
file, err := os.Create(filename)
|
||||
var file *os.File
|
||||
var err error
|
||||
|
||||
opt := MakeOptions(options)
|
||||
|
||||
if opt.AppendFile() {
|
||||
log.Debug("Open files in appending mode")
|
||||
file, err = os.OpenFile(filename,
|
||||
os.O_APPEND|os.O_CREATE|os.O_WRONLY, 0644)
|
||||
} else {
|
||||
file, err = os.Create(filename)
|
||||
}
|
||||
|
||||
if err != nil {
|
||||
log.Fatalf("open file error: %v", err)
|
||||
|
||||
@@ -13,6 +13,7 @@ type __options__ struct {
|
||||
quality_shift int
|
||||
parallel_workers int
|
||||
closefile bool
|
||||
appendfile bool
|
||||
}
|
||||
|
||||
type Options struct {
|
||||
@@ -31,6 +32,7 @@ func MakeOptions(setters []WithOption) Options {
|
||||
parallel_workers: 4,
|
||||
batch_size: 5000,
|
||||
closefile: false,
|
||||
appendfile: false,
|
||||
}
|
||||
|
||||
opt := Options{&o}
|
||||
@@ -74,6 +76,10 @@ func (opt Options) CloseFile() bool {
|
||||
return opt.pointer.closefile
|
||||
}
|
||||
|
||||
func (opt Options) AppendFile() bool {
|
||||
return opt.pointer.appendfile
|
||||
}
|
||||
|
||||
func OptionsBufferSize(size int) WithOption {
|
||||
f := WithOption(func(opt Options) {
|
||||
opt.pointer.buffer_size = size
|
||||
@@ -98,6 +104,22 @@ func OptionDontCloseFile() WithOption {
|
||||
return f
|
||||
}
|
||||
|
||||
func OptionsAppendFile() WithOption {
|
||||
f := WithOption(func(opt Options) {
|
||||
opt.pointer.appendfile = true
|
||||
})
|
||||
|
||||
return f
|
||||
}
|
||||
|
||||
func OptionsNewFile() WithOption {
|
||||
f := WithOption(func(opt Options) {
|
||||
opt.pointer.appendfile = false
|
||||
})
|
||||
|
||||
return f
|
||||
}
|
||||
|
||||
// Allows to specify the ascii code corresponding to
|
||||
// a quality of 0 in fastq encoded quality scores.
|
||||
func OptionsQualityShift(shift int) WithOption {
|
||||
|
||||
@@ -55,7 +55,18 @@ func WriteSequencesToFile(iterator obiiter.IBioSequence,
|
||||
filename string,
|
||||
options ...WithOption) (obiiter.IBioSequence, error) {
|
||||
|
||||
file, err := os.Create(filename)
|
||||
var file *os.File
|
||||
var err error
|
||||
|
||||
opt := MakeOptions(options)
|
||||
|
||||
if opt.AppendFile() {
|
||||
log.Debug("Open files in appending mode")
|
||||
file, err = os.OpenFile(filename,
|
||||
os.O_APPEND|os.O_CREATE|os.O_WRONLY, 0644)
|
||||
} else {
|
||||
file, err = os.Create(filename)
|
||||
}
|
||||
|
||||
if err != nil {
|
||||
log.Fatalf("open file error: %v", err)
|
||||
|
||||
Reference in New Issue
Block a user