obiannotate --cut bug

This commit is contained in:
Eric Coissac
2025-12-18 14:10:56 +01:00
parent ac0d3f3fe4
commit 371e702423
2 changed files with 17 additions and 7 deletions

View File

@@ -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

View File

@@ -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