mirror of
https://github.com/metabarcoding/obitools4.git
synced 2025-12-08 16:50:27 +00:00
Adds a JSON output format
Former-commit-id: 26f07460772c0f735bf705d473f892878d3e57f0
This commit is contained in:
47
pkg/obiformats/fastqseq_write_generic.go
Normal file
47
pkg/obiformats/fastqseq_write_generic.go
Normal file
@@ -0,0 +1,47 @@
|
||||
package obiformats
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
|
||||
log "github.com/sirupsen/logrus"
|
||||
|
||||
"git.metabarcoding.org/lecasofts/go/obitools/pkg/obiiter"
|
||||
"git.metabarcoding.org/lecasofts/go/obitools/pkg/obiseq"
|
||||
)
|
||||
|
||||
type BioSequenceBatchFormater func(batch obiiter.BioSequenceBatch) []byte
|
||||
type BioSequenceFormater func(sequence *obiseq.BioSequence) string
|
||||
|
||||
func BuildFastxSeqFormater(format string, header FormatHeader) BioSequenceFormater {
|
||||
var f BioSequenceFormater
|
||||
|
||||
switch format {
|
||||
case "fastq":
|
||||
f = func(sequence *obiseq.BioSequence) string {
|
||||
return FormatFastq(sequence, header)
|
||||
}
|
||||
case "fasta":
|
||||
f = func(sequence *obiseq.BioSequence) string {
|
||||
return FormatFasta(sequence, header)
|
||||
}
|
||||
default:
|
||||
log.Fatal("Unknown output format")
|
||||
}
|
||||
|
||||
return f
|
||||
}
|
||||
|
||||
func BuildFastxFormater(format string, header FormatHeader) BioSequenceBatchFormater {
|
||||
fs := BuildFastxSeqFormater(format, header)
|
||||
|
||||
f := func(batch obiiter.BioSequenceBatch) []byte {
|
||||
var bs bytes.Buffer
|
||||
for _, seq := range batch.Slice() {
|
||||
bs.WriteString(fs(seq))
|
||||
bs.WriteString("\n")
|
||||
}
|
||||
return bs.Bytes()
|
||||
}
|
||||
|
||||
return f
|
||||
}
|
||||
Reference in New Issue
Block a user