Patch a tricky bug in parsing of json header and save the last sequence from files

Former-commit-id: bfe3d0e9eb8e65113699d535bd1d9a5fe0d3ce1d
This commit is contained in:
Eric Coissac
2024-06-04 13:46:23 +02:00
parent aa42df326a
commit e843d2aa5c
4 changed files with 36 additions and 8 deletions

View File

@ -12,7 +12,6 @@ import (
) )
func _parse_json_header_(header string, annotations obiseq.Annotation) string { func _parse_json_header_(header string, annotations obiseq.Annotation) string {
start := -1 start := -1
stop := -1 stop := -1
level := 0 level := 0
@ -58,6 +57,9 @@ func _parse_json_header_(header string, annotations obiseq.Annotation) string {
if vt == math.Floor(vt) { if vt == math.Floor(vt) {
annotations[k] = int(vt) annotations[k] = int(vt)
} }
{
annotations[k] = vt
}
} }
} }
@ -69,8 +71,18 @@ func _parse_json_header_(header string, annotations obiseq.Annotation) string {
} }
func ParseFastSeqJsonHeader(sequence *obiseq.BioSequence) { func ParseFastSeqJsonHeader(sequence *obiseq.BioSequence) {
sequence.SetDefinition(_parse_json_header_(sequence.Definition(), definition := sequence.Definition()
sequence.Annotations())) sequence.SetDefinition("")
definition_part := _parse_json_header_(
definition,
sequence.Annotations())
if len(definition_part) > 0 {
if sequence.HasDefinition() {
definition_part = sequence.Definition() + " " + definition_part
}
sequence.SetDefinition(definition_part)
}
} }
func FormatFastSeqJsonHeader(sequence *obiseq.BioSequence) string { func FormatFastSeqJsonHeader(sequence *obiseq.BioSequence) string {
@ -80,7 +92,7 @@ func FormatFastSeqJsonHeader(sequence *obiseq.BioSequence) string {
text, err := obiutils.JsonMarshal(sequence.Annotations()) text, err := obiutils.JsonMarshal(sequence.Annotations())
if err != nil { if err != nil {
panic(err) log.Fatal(err)
} }
return string(text) return string(text)

View File

@ -285,11 +285,17 @@ func ParseOBIFeatures(text string, annotations obiseq.Annotation) string {
func ParseFastSeqOBIHeader(sequence *obiseq.BioSequence) { func ParseFastSeqOBIHeader(sequence *obiseq.BioSequence) {
annotations := sequence.Annotations() annotations := sequence.Annotations()
definition := sequence.Definition()
sequence.SetDefinition("")
definition := ParseOBIFeatures(sequence.Definition(), definition = ParseOBIFeatures(definition, annotations)
annotations)
sequence.SetDefinition(definition) if len(definition) > 0 {
if sequence.HasDefinition() {
definition = sequence.Definition() + " " + definition
}
sequence.SetDefinition(definition)
}
} }
func FormatFastSeqOBIHeader(sequence *obiseq.BioSequence) string { func FormatFastSeqOBIHeader(sequence *obiseq.BioSequence) string {

View File

@ -106,6 +106,16 @@ func ReadSeqFileChunk(reader io.Reader,
} }
} }
if err != nil && err != io.EOF && err != io.ErrUnexpectedEOF {
log.Fatalf("Error reading data from file : %s", err)
}
// Send the last chunk to the channel
if len(buff) > 0 {
io := bytes.NewBuffer(slices.Clone(buff))
chunk_channel <- SeqFileChunk{io, i}
}
// Close the readers channel when the end of the file is reached // Close the readers channel when the end of the file is reached
close(chunk_channel) close(chunk_channel)
}() }()

View File

@ -7,7 +7,7 @@ import (
// TODO: The version number is extracted from git. This induces that the version // TODO: The version number is extracted from git. This induces that the version
// corresponds to the last commit, and not the one when the file will be // corresponds to the last commit, and not the one when the file will be
// commited // commited
var _Commit = "f4fcc19" var _Commit = "b842d60"
var _Version = "Release 4.2.0" var _Version = "Release 4.2.0"
// Version returns the version of the obitools package. // Version returns the version of the obitools package.