mirror of
https://github.com/metabarcoding/obitools4.git
synced 2025-06-29 16:20:46 +00:00
Patch sequence writers to remove definition from header when json format is used.
Former-commit-id: a8a74cccb52d577d4ea1c0ad88b121a8e511149d
This commit is contained in:
@ -298,27 +298,29 @@ func FormatFastSeqOBIHeader(sequence *obiseq.BioSequence) string {
|
|||||||
var text strings.Builder
|
var text strings.Builder
|
||||||
|
|
||||||
for key, value := range annotations {
|
for key, value := range annotations {
|
||||||
switch t := value.(type) {
|
if key != "definition" {
|
||||||
case string:
|
switch t := value.(type) {
|
||||||
text.WriteString(fmt.Sprintf("%s=%s; ", key, t))
|
case string:
|
||||||
case map[string]int,
|
text.WriteString(fmt.Sprintf("%s=%s; ", key, t))
|
||||||
map[string]string,
|
case map[string]int,
|
||||||
map[string]interface{},
|
map[string]string,
|
||||||
obiseq.StatsOnValues:
|
map[string]interface{},
|
||||||
tv, err := obiutils.JsonMarshal(t)
|
obiseq.StatsOnValues:
|
||||||
if err != nil {
|
tv, err := obiutils.JsonMarshal(t)
|
||||||
log.Fatalf("Cannot convert %v value", value)
|
if err != nil {
|
||||||
|
log.Fatalf("Cannot convert %v value", value)
|
||||||
|
}
|
||||||
|
tv = bytes.ReplaceAll(tv, []byte(`"`), []byte("'"))
|
||||||
|
text.WriteString(fmt.Sprintf("%s=", key))
|
||||||
|
text.Write(tv)
|
||||||
|
text.WriteString("; ")
|
||||||
|
default:
|
||||||
|
text.WriteString(fmt.Sprintf("%s=%v; ", key, value))
|
||||||
}
|
}
|
||||||
tv = bytes.ReplaceAll(tv, []byte(`"`), []byte("'"))
|
|
||||||
text.WriteString(fmt.Sprintf("%s=", key))
|
|
||||||
text.Write(tv)
|
|
||||||
text.WriteString("; ")
|
|
||||||
default:
|
|
||||||
text.WriteString(fmt.Sprintf("%s=%v; ", key, value))
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return text.String()
|
return text.String() + " " + sequence.Definition()
|
||||||
}
|
}
|
||||||
|
|
||||||
return ""
|
return ""
|
||||||
|
@ -63,9 +63,8 @@ func FormatFasta(seq *obiseq.BioSequence, formater FormatHeader) string {
|
|||||||
}
|
}
|
||||||
|
|
||||||
info := formater(seq)
|
info := formater(seq)
|
||||||
return fmt.Sprintf(">%s %s %s\n%s",
|
return fmt.Sprintf(">%s %s\n%s",
|
||||||
seq.Id(), info,
|
seq.Id(), info,
|
||||||
seq.Definition(),
|
|
||||||
folded)
|
folded)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -199,7 +198,7 @@ func WriteFasta(iterator obiiter.IBioSequence,
|
|||||||
// configuration options as variadic arguments. It appends the option to not close the file
|
// configuration options as variadic arguments. It appends the option to not close the file
|
||||||
// to the options slice and then calls the WriteFasta function passing the iterator,
|
// to the options slice and then calls the WriteFasta function passing the iterator,
|
||||||
// os.Stdout as the output file, and the options slice.
|
// os.Stdout as the output file, and the options slice.
|
||||||
//
|
//
|
||||||
// The function returns the same bio sequence iterator and an error if any occurred.
|
// The function returns the same bio sequence iterator and an error if any occurred.
|
||||||
func WriteFastaToStdout(iterator obiiter.IBioSequence,
|
func WriteFastaToStdout(iterator obiiter.IBioSequence,
|
||||||
options ...WithOption) (obiiter.IBioSequence, error) {
|
options ...WithOption) (obiiter.IBioSequence, error) {
|
||||||
|
@ -32,9 +32,8 @@ func FormatFastq(seq *obiseq.BioSequence, quality_shift int, formater FormatHead
|
|||||||
info = formater(seq)
|
info = formater(seq)
|
||||||
}
|
}
|
||||||
|
|
||||||
return fmt.Sprintf("@%s %s %s\n%s\n+\n%s",
|
return fmt.Sprintf("@%s %s\n%s\n+\n%s",
|
||||||
seq.Id(), info,
|
seq.Id(), info,
|
||||||
seq.Definition(),
|
|
||||||
string(seq.Sequence()),
|
string(seq.Sequence()),
|
||||||
string(ascii),
|
string(ascii),
|
||||||
)
|
)
|
||||||
|
@ -403,7 +403,7 @@ func WopenFile(f string, flag int, perm os.FileMode) (*Writer, error) {
|
|||||||
if strings.HasSuffix(f2, ".gz") {
|
if strings.HasSuffix(f2, ".gz") {
|
||||||
gz, err := gzip.NewWriterLevel(wtr, Level)
|
gz, err := gzip.NewWriterLevel(wtr, Level)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
err = errors.New(fmt.Sprintf("xopen: %s", err))
|
err = fmt.Errorf("xopen: %s", err)
|
||||||
}
|
}
|
||||||
return &Writer{bufio.NewWriterSize(gz, bufSize), wtr, gz, nil, nil, nil}, err
|
return &Writer{bufio.NewWriterSize(gz, bufSize), wtr, gz, nil, nil, nil}, err
|
||||||
}
|
}
|
||||||
@ -418,7 +418,7 @@ func WopenFile(f string, flag int, perm os.FileMode) (*Writer, error) {
|
|||||||
}
|
}
|
||||||
zw, err := zstd.NewWriter(wtr, zstd.WithEncoderLevel(zstd.EncoderLevel(level)))
|
zw, err := zstd.NewWriter(wtr, zstd.WithEncoderLevel(zstd.EncoderLevel(level)))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
err = errors.New(fmt.Sprintf("xopen: zstd: %s", err))
|
err = fmt.Errorf("xopen: zstd: %s", err)
|
||||||
}
|
}
|
||||||
return &Writer{bufio.NewWriterSize(zw, bufSize), wtr, nil, nil, zw, nil}, err
|
return &Writer{bufio.NewWriterSize(zw, bufSize), wtr, nil, nil, zw, nil}, err
|
||||||
}
|
}
|
||||||
@ -429,7 +429,7 @@ func WopenFile(f string, flag int, perm os.FileMode) (*Writer, error) {
|
|||||||
}
|
}
|
||||||
bz2, err := bzip2.NewWriter(wtr, &bzip2.WriterConfig{Level: level})
|
bz2, err := bzip2.NewWriter(wtr, &bzip2.WriterConfig{Level: level})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
err = errors.New(fmt.Sprintf("xopen: %s", err))
|
err = fmt.Errorf("xopen: %s", err)
|
||||||
}
|
}
|
||||||
return &Writer{bufio.NewWriterSize(bz2, bufSize), wtr, nil, nil, nil, bz2}, err
|
return &Writer{bufio.NewWriterSize(bz2, bufSize), wtr, nil, nil, nil, bz2}, err
|
||||||
}
|
}
|
||||||
|
@ -61,7 +61,7 @@ func (s *XopenTest) TestWopen(c *C) {
|
|||||||
_, err = os.Stat(f)
|
_, err = os.Stat(f)
|
||||||
c.Assert(err, IsNil)
|
c.Assert(err, IsNil)
|
||||||
c.Assert(wtr.wtr, NotNil)
|
c.Assert(wtr.wtr, NotNil)
|
||||||
fmt.Fprintf(wtr, testString)
|
fmt.Fprint(wtr, testString)
|
||||||
wtr.Close()
|
wtr.Close()
|
||||||
|
|
||||||
rdr, err := Ropen(f)
|
rdr, err := Ropen(f)
|
||||||
@ -70,7 +70,7 @@ func (s *XopenTest) TestWopen(c *C) {
|
|||||||
str, err := rdr.ReadString(99)
|
str, err := rdr.ReadString(99)
|
||||||
c.Assert(str, Equals, testString)
|
c.Assert(str, Equals, testString)
|
||||||
c.Assert(err, Equals, io.EOF)
|
c.Assert(err, Equals, io.EOF)
|
||||||
str, err = rdr.ReadString(99)
|
str, _ = rdr.ReadString(99)
|
||||||
c.Assert(str, Equals, "")
|
c.Assert(str, Equals, "")
|
||||||
|
|
||||||
rdr.Close()
|
rdr.Close()
|
||||||
|
Reference in New Issue
Block a user