From 371e702423be39f019f792c427f12754eb9263dc Mon Sep 17 00:00:00 2001 From: Eric Coissac Date: Thu, 18 Dec 2025 14:10:56 +0100 Subject: [PATCH] obiannotate --cut bug --- pkg/obitools/obiannotate/obiannotate.go | 10 +++++----- pkg/obitools/obiannotate/options.go | 14 ++++++++++++-- 2 files changed, 17 insertions(+), 7 deletions(-) diff --git a/pkg/obitools/obiannotate/obiannotate.go b/pkg/obitools/obiannotate/obiannotate.go index 8c410d9..8ab5fce 100644 --- a/pkg/obitools/obiannotate/obiannotate.go +++ b/pkg/obitools/obiannotate/obiannotate.go @@ -134,12 +134,12 @@ func CutSequenceWorker(from, to int, breakOnError bool) obiseq.SeqWorker { t = to } - if from < 0 { - from = 0 + if f < 0 { + f = 0 } - if to >= s.Len() { - to = s.Len() + if t >= s.Len() { + t = s.Len() } rep, err := s.Subsequence(f, t, false) @@ -147,7 +147,7 @@ func CutSequenceWorker(from, to int, breakOnError bool) obiseq.SeqWorker { if breakOnError { log.Fatalf("Cannot cut sequence %s (%v)", s.Id(), err) } else { - err = fmt.Errorf("Cannot cut sequence %s (%v), sequence discarded", s.Id(), err) + err = fmt.Errorf("cannot cut sequence %s (%v), sequence discarded", s.Id(), err) } } return obiseq.BioSequenceSlice{rep}, err diff --git a/pkg/obitools/obiannotate/options.go b/pkg/obitools/obiannotate/options.go index 437e124..c7b3179 100644 --- a/pkg/obitools/obiannotate/options.go +++ b/pkg/obitools/obiannotate/options.go @@ -1,6 +1,7 @@ package obiannotate import ( + "math" "os" "strconv" "strings" @@ -266,6 +267,7 @@ func CLICut() (int, int) { return 0, 0 } values := strings.Split(_cut, ":") + log.Warnf("values: %v (%d-%d)", values, len(values), len(values[1])) if len(values) != 2 { log.Fatalf("Invalid cut value %s. value should be of the form start:end", _cut) @@ -274,12 +276,20 @@ func CLICut() (int, int) { start, err := strconv.Atoi(values[0]) if err != nil { - log.Fatalf("Invalid cut value %s. value %s should be an integer", _cut, values[0]) + if len(values[0]) == 0 { + start = 1 + } else { + log.Fatalf("Invalid start cut value %s. value %s should be an integer", _cut, values[0]) + } } end, err := strconv.Atoi(values[1]) if err != nil { - log.Fatalf("Invalid cut value %s. value %s should be an integer", _cut, values[1]) + if len(values[1]) == 0 { + end = math.MaxInt + } else { + log.Fatalf("Invalid end cut value %s. value %s should be an integer", _cut, values[1]) + } } return start, end