rename goutils to obiutils

Former-commit-id: 2147f53db972bba571dfdae30c51b62d3e69cec5
This commit is contained in:
2023-03-24 10:25:12 +07:00
parent 42aae88520
commit d5e84ec676
33 changed files with 245 additions and 156 deletions

20
doc/man/test.md Normal file
View File

@ -0,0 +1,20 @@
% obigrep(1)
% Eric Coissac
% February 2023
# NAME
obigrep -- filters sequence files according to numerous conditions
# SYNOPSIS
**snowplough**␣\[**-h**\]␣\[**--configfile**␣*CONFIGFILE*\]␣\[**--sort**\]␣\[**--vim**\]␣*keyword*␣\[*keyword␣...*\]␣\[**--configfile**␣*CONFIGFILE*\]␣\[**--sort**\]␣\[**--vim**\]␣*keyword*␣\[*keyword␣...*\]␣\[**--configfile**␣*CONFIGFILE*\]␣\[**--sort**\]␣\[**--vim**\]␣*keyword*␣\[*keyword␣...*\]
# DESCRIPTION
**snowplough** is a simple-minded tool which creates indices and body-searches vast quantities of ServiceNow tickets, which is useful to find out how someone before you solved one particular problem.
# GENERAL OPTIONS
**-h**, **--help**
: Display a friendly help message.

View File

@ -1,37 +0,0 @@
package goutils
func MinInt(x, y int) int {
if x < y {
return x
}
return y
}
func MaxInt(x, y int) int {
if x < y {
return y
}
return x
}
func MinMaxInt(x, y int) (int,int) {
if x < y {
return x,y
}
return y,x
}
func MinUInt16(x, y uint16) uint16 {
if x < y {
return x
}
return y
}
func MaxUInt16(x, y uint16) uint16 {
if x < y {
return y
}
return x
}

View File

@ -1,7 +1,7 @@
package obialign package obialign
// import ( // import (
// "git.metabarcoding.org/lecasofts/go/obitools/pkg/goutils" // "git.metabarcoding.org/lecasofts/go/obitools/pkg/obiutils"
// "git.metabarcoding.org/lecasofts/go/obitools/pkg/obiseq" // "git.metabarcoding.org/lecasofts/go/obitools/pkg/obiseq"
// ) // )
@ -113,11 +113,11 @@ var _notavail = encodeValues(0, 30000, false)
// // in_matrix := false // // in_matrix := false
// x1 := y - lB + extra // x1 := y - lB + extra
// x2 := extra - y // x2 := extra - y
// xs := goutils.MaxInt(goutils.MaxInt(x1, x2), 0) // xs := obiutils.MaxInt(obiutils.MaxInt(x1, x2), 0)
// x1 = y + extra // x1 = y + extra
// x2 = lA + extra - y // x2 = lA + extra - y
// xf := goutils.MinInt(goutils.MinInt(x1, x2), even-1) + 1 // xf := obiutils.MinInt(obiutils.MinInt(x1, x2), even-1) + 1
// for x := xs; x < xf; x++ { // for x := xs; x < xf; x++ {
@ -174,11 +174,11 @@ var _notavail = encodeValues(0, 30000, false)
// // . 9 10 + 2 - 1 // // . 9 10 + 2 - 1
// x1 = y - lB + extra + even // x1 = y - lB + extra + even
// x2 = extra - y + even - 1 // x2 = extra - y + even - 1
// xs = goutils.MaxInt(goutils.MaxInt(x1, x2), even) // xs = obiutils.MaxInt(obiutils.MaxInt(x1, x2), even)
// x1 = y + extra + even // x1 = y + extra + even
// x2 = lA + extra - y + even - 1 // x2 = lA + extra - y + even - 1
// xf = goutils.MinInt(goutils.MinInt(x1, x2), width-1) + 1 // xf = obiutils.MinInt(obiutils.MinInt(x1, x2), width-1) + 1
// for x := xs; x < xf; x++ { // for x := xs; x < xf; x++ {

View File

@ -1,8 +1,8 @@
package obialign package obialign
import ( import (
"git.metabarcoding.org/lecasofts/go/obitools/pkg/goutils"
"git.metabarcoding.org/lecasofts/go/obitools/pkg/obiseq" "git.metabarcoding.org/lecasofts/go/obitools/pkg/obiseq"
"git.metabarcoding.org/lecasofts/go/obitools/pkg/obiutils"
log "github.com/sirupsen/logrus" log "github.com/sirupsen/logrus"
) )
@ -109,11 +109,11 @@ func FastLCSEGFScoreByte(bA, bB []byte, maxError int, endgapfree bool, buffer *[
// in_matrix := false // in_matrix := false
x1 := y - lB + extra x1 := y - lB + extra
x2 := extra - y x2 := extra - y
xs := goutils.MaxInt(goutils.MaxInt(x1, x2), 0) xs := obiutils.MaxInt(obiutils.MaxInt(x1, x2), 0)
x1 = y + extra x1 = y + extra
x2 = lA + extra - y x2 = lA + extra - y
xf := goutils.MinInt(goutils.MinInt(x1, x2), even-1) + 1 xf := obiutils.MinInt(obiutils.MinInt(x1, x2), even-1) + 1
for x := xs; x < xf; x++ { for x := xs; x < xf; x++ {
@ -201,11 +201,11 @@ func FastLCSEGFScoreByte(bA, bB []byte, maxError int, endgapfree bool, buffer *[
// . 9 10 + 2 - 1 // . 9 10 + 2 - 1
x1 = y - lB + extra + even x1 = y - lB + extra + even
x2 = extra - y + even - 1 x2 = extra - y + even - 1
xs = goutils.MaxInt(goutils.MaxInt(x1, x2), even) xs = obiutils.MaxInt(obiutils.MaxInt(x1, x2), even)
x1 = y + extra + even x1 = y + extra + even
x2 = lA + extra - y + even - 1 x2 = lA + extra - y + even - 1
xf = goutils.MinInt(goutils.MinInt(x1, x2), width-1) + 1 xf = obiutils.MinInt(obiutils.MinInt(x1, x2), width-1) + 1
for x := xs; x < xf; x++ { for x := xs; x < xf; x++ {

View File

@ -13,9 +13,9 @@ import (
log "github.com/sirupsen/logrus" log "github.com/sirupsen/logrus"
"git.metabarcoding.org/lecasofts/go/obitools/pkg/goutils"
"git.metabarcoding.org/lecasofts/go/obitools/pkg/obialign" "git.metabarcoding.org/lecasofts/go/obitools/pkg/obialign"
"git.metabarcoding.org/lecasofts/go/obitools/pkg/obiseq" "git.metabarcoding.org/lecasofts/go/obitools/pkg/obiseq"
"git.metabarcoding.org/lecasofts/go/obitools/pkg/obiutils"
) )
var _MaxPatLen = int(C.MAX_PAT_LEN) var _MaxPatLen = int(C.MAX_PAT_LEN)
@ -355,8 +355,8 @@ func (pattern ApatPattern) BestMatch(sequence ApatSequence, begin, length int) (
start = best[0] - nerr start = best[0] - nerr
end = best[0] + int(pattern.pointer.pointer.patlen) + nerr end = best[0] + int(pattern.pointer.pointer.patlen) + nerr
start = goutils.MaxInt(start, 0) start = obiutils.MaxInt(start, 0)
end = goutils.MinInt(end, sequence.Len()) end = obiutils.MinInt(end, sequence.Len())
cpattern := (*[1 << 30]byte)(unsafe.Pointer(pattern.pointer.pointer.cpat)) cpattern := (*[1 << 30]byte)(unsafe.Pointer(pattern.pointer.pointer.cpat))
cseq := (*[1 << 30]byte)(unsafe.Pointer(sequence.pointer.pointer.cseq)) cseq := (*[1 << 30]byte)(unsafe.Pointer(sequence.pointer.pointer.cseq))
@ -374,7 +374,7 @@ func (pattern ApatPattern) BestMatch(sequence ApatSequence, begin, length int) (
nerr = lali - score nerr = lali - score
start = best[0] + int(pattern.pointer.pointer.patlen) - lali start = best[0] + int(pattern.pointer.pointer.patlen) - lali
end = start + lali end = start + lali
log.Debugln("results", score, lali, start, nerr) log.Debugln("results", score, lali, start, nerr)
return return
} }

View File

@ -3,8 +3,8 @@ package obiapat
import ( import (
log "github.com/sirupsen/logrus" log "github.com/sirupsen/logrus"
"git.metabarcoding.org/lecasofts/go/obitools/pkg/goutils"
"git.metabarcoding.org/lecasofts/go/obitools/pkg/obiseq" "git.metabarcoding.org/lecasofts/go/obitools/pkg/obiseq"
"git.metabarcoding.org/lecasofts/go/obitools/pkg/obiutils"
) )
type _Options struct { type _Options struct {
@ -210,7 +210,7 @@ func _Pcr(seq ApatSequence,
reverse := opt.pointer.reverse reverse := opt.pointer.reverse
crev := opt.pointer.crev crev := opt.pointer.crev
forwardMatches := forward.FindAllIndex(seq,0,-1) forwardMatches := forward.FindAllIndex(seq, 0, -1)
if len(forwardMatches) > 0 { if len(forwardMatches) > 0 {
@ -256,7 +256,7 @@ func _Pcr(seq ApatSequence,
(opt.MaxLength() == 0 || length <= opt.MaxLength()) { (opt.MaxLength() == 0 || length <= opt.MaxLength()) {
amplicon, _ := sequence.Subsequence(fm[1], rm[0], opt.pointer.circular) amplicon, _ := sequence.Subsequence(fm[1], rm[0], opt.pointer.circular)
annot := amplicon.Annotations() annot := amplicon.Annotations()
goutils.MustFillMap(annot, sequence.Annotations()) obiutils.MustFillMap(annot, sequence.Annotations())
annot["forward_primer"] = forward.String() annot["forward_primer"] = forward.String()
match, _ := sequence.Subsequence(fm[0], fm[1], opt.pointer.circular) match, _ := sequence.Subsequence(fm[0], fm[1], opt.pointer.circular)
@ -284,7 +284,7 @@ func _Pcr(seq ApatSequence,
} }
} }
forwardMatches = reverse.FindAllIndex(seq,0,-1) forwardMatches = reverse.FindAllIndex(seq, 0, -1)
if forwardMatches != nil { if forwardMatches != nil {
begin := forwardMatches[0][0] begin := forwardMatches[0][0]
@ -331,7 +331,7 @@ func _Pcr(seq ApatSequence,
amplicon = amplicon.ReverseComplement(true) amplicon = amplicon.ReverseComplement(true)
annot := amplicon.Annotations() annot := amplicon.Annotations()
goutils.MustFillMap(annot, sequence.Annotations()) obiutils.MustFillMap(annot, sequence.Annotations())
annot["forward_primer"] = forward.String() annot["forward_primer"] = forward.String()
match, _ := sequence.Subsequence(rm[0], rm[1], opt.pointer.circular) match, _ := sequence.Subsequence(rm[0], rm[1], opt.pointer.circular)

View File

@ -3,8 +3,8 @@ package obiformats
import ( import (
"log" "log"
"git.metabarcoding.org/lecasofts/go/obitools/pkg/goutils"
"git.metabarcoding.org/lecasofts/go/obitools/pkg/obiiter" "git.metabarcoding.org/lecasofts/go/obitools/pkg/obiiter"
"git.metabarcoding.org/lecasofts/go/obitools/pkg/obiutils"
) )
func ReadSequencesBatchFromFiles(filenames []string, func ReadSequencesBatchFromFiles(filenames []string,
@ -17,7 +17,7 @@ func ReadSequencesBatchFromFiles(filenames []string,
} }
batchiter := obiiter.MakeIBioSequence(0) batchiter := obiiter.MakeIBioSequence(0)
nextCounter := goutils.AtomicCounter() nextCounter := obiutils.AtomicCounter()
batchiter.Add(concurrent_readers) batchiter.Add(concurrent_readers)

View File

@ -9,9 +9,9 @@ import (
"sync" "sync"
"time" "time"
"git.metabarcoding.org/lecasofts/go/obitools/pkg/goutils"
"git.metabarcoding.org/lecasofts/go/obitools/pkg/obiiter" "git.metabarcoding.org/lecasofts/go/obitools/pkg/obiiter"
"git.metabarcoding.org/lecasofts/go/obitools/pkg/obiseq" "git.metabarcoding.org/lecasofts/go/obitools/pkg/obiseq"
"git.metabarcoding.org/lecasofts/go/obitools/pkg/obiutils"
log "github.com/sirupsen/logrus" log "github.com/sirupsen/logrus"
) )
@ -52,7 +52,7 @@ func CSVRecord(sequence *obiseq.BioSequence, opt Options) []string {
value = opt.CSVNAValue() value = opt.CSVNAValue()
} }
svalue, _ := goutils.InterfaceToString(value) svalue, _ := obiutils.InterfaceToString(value)
record = append(record, svalue) record = append(record, svalue)
} }
@ -132,7 +132,7 @@ func WriteCSV(iterator obiiter.IBioSequence,
options ...WithOption) (obiiter.IBioSequence, error) { options ...WithOption) (obiiter.IBioSequence, error) {
opt := MakeOptions(options) opt := MakeOptions(options)
file, _ = goutils.CompressStream(file, opt.CompressedFile(), opt.CloseFile()) file, _ = obiutils.CompressStream(file, opt.CompressedFile(), opt.CloseFile())
newIter := obiiter.MakeIBioSequence() newIter := obiiter.MakeIBioSequence()

View File

@ -6,8 +6,8 @@ import (
log "github.com/sirupsen/logrus" log "github.com/sirupsen/logrus"
"git.metabarcoding.org/lecasofts/go/obitools/pkg/goutils"
"git.metabarcoding.org/lecasofts/go/obitools/pkg/obiseq" "git.metabarcoding.org/lecasofts/go/obitools/pkg/obiseq"
"git.metabarcoding.org/lecasofts/go/obitools/pkg/obiutils"
"github.com/goccy/go-json" "github.com/goccy/go-json"
) )
@ -71,7 +71,7 @@ func FormatFastSeqJsonHeader(sequence *obiseq.BioSequence) string {
annotations := sequence.Annotations() annotations := sequence.Annotations()
if len(annotations) > 0 { if len(annotations) > 0 {
text, err := goutils.JsonMarshal(sequence.Annotations()) text, err := obiutils.JsonMarshal(sequence.Annotations())
if err != nil { if err != nil {
panic(err) panic(err)

View File

@ -9,8 +9,8 @@ import (
"strconv" "strconv"
"strings" "strings"
"git.metabarcoding.org/lecasofts/go/obitools/pkg/goutils"
"git.metabarcoding.org/lecasofts/go/obitools/pkg/obiseq" "git.metabarcoding.org/lecasofts/go/obitools/pkg/obiseq"
"git.metabarcoding.org/lecasofts/go/obitools/pkg/obiutils"
"github.com/goccy/go-json" "github.com/goccy/go-json"
) )
@ -305,7 +305,7 @@ func FormatFastSeqOBIHeader(sequence *obiseq.BioSequence) string {
map[string]string, map[string]string,
map[string]interface{}, map[string]interface{},
obiseq.StatsOnValues: obiseq.StatsOnValues:
tv, err := goutils.JsonMarshal(t) tv, err := obiutils.JsonMarshal(t)
if err != nil { if err != nil {
log.Fatalf("Cannot convert %v value", value) log.Fatalf("Cannot convert %v value", value)
} }

View File

@ -11,9 +11,9 @@ import (
log "github.com/sirupsen/logrus" log "github.com/sirupsen/logrus"
"git.metabarcoding.org/lecasofts/go/obitools/pkg/goutils"
"git.metabarcoding.org/lecasofts/go/obitools/pkg/obiiter" "git.metabarcoding.org/lecasofts/go/obitools/pkg/obiiter"
"git.metabarcoding.org/lecasofts/go/obitools/pkg/obiseq" "git.metabarcoding.org/lecasofts/go/obitools/pkg/obiseq"
"git.metabarcoding.org/lecasofts/go/obitools/pkg/obiutils"
) )
func min(x, y int) int { func min(x, y int) int {
@ -70,7 +70,7 @@ func WriteFasta(iterator obiiter.IBioSequence,
opt := MakeOptions(options) opt := MakeOptions(options)
iterator = iterator.Rebatch(10000) iterator = iterator.Rebatch(10000)
file, _ = goutils.CompressStream(file, opt.CompressedFile(), opt.CloseFile()) file, _ = obiutils.CompressStream(file, opt.CompressedFile(), opt.CloseFile())
newIter := obiiter.MakeIBioSequence() newIter := obiiter.MakeIBioSequence()

View File

@ -10,9 +10,9 @@ import (
log "github.com/sirupsen/logrus" log "github.com/sirupsen/logrus"
"git.metabarcoding.org/lecasofts/go/obitools/pkg/goutils"
"git.metabarcoding.org/lecasofts/go/obitools/pkg/obiiter" "git.metabarcoding.org/lecasofts/go/obitools/pkg/obiiter"
"git.metabarcoding.org/lecasofts/go/obitools/pkg/obiseq" "git.metabarcoding.org/lecasofts/go/obitools/pkg/obiseq"
"git.metabarcoding.org/lecasofts/go/obitools/pkg/obiutils"
) )
func FormatFastq(seq *obiseq.BioSequence, quality_shift int, formater FormatHeader) string { func FormatFastq(seq *obiseq.BioSequence, quality_shift int, formater FormatHeader) string {
@ -61,7 +61,7 @@ func WriteFastq(iterator obiiter.IBioSequence,
opt := MakeOptions(options) opt := MakeOptions(options)
file, _ = goutils.CompressStream(file, opt.CompressedFile(), opt.CloseFile()) file, _ = obiutils.CompressStream(file, opt.CompressedFile(), opt.CloseFile())
newIter := obiiter.MakeIBioSequence() newIter := obiiter.MakeIBioSequence()

View File

@ -10,8 +10,8 @@ import (
log "github.com/sirupsen/logrus" log "github.com/sirupsen/logrus"
"git.metabarcoding.org/lecasofts/go/obitools/pkg/goutils"
"git.metabarcoding.org/lecasofts/go/obitools/pkg/obiseq" "git.metabarcoding.org/lecasofts/go/obitools/pkg/obiseq"
"git.metabarcoding.org/lecasofts/go/obitools/pkg/obiutils"
"github.com/tevino/abool/v2" "github.com/tevino/abool/v2"
) )
@ -375,7 +375,7 @@ func (iterator IBioSequence) Pool(iterators ...IBioSequence) IBioSequence {
allPaired = allPaired && i.IsPaired() allPaired = allPaired && i.IsPaired()
} }
nextCounter := goutils.AtomicCounter() nextCounter := obiutils.AtomicCounter()
newIter := MakeIBioSequence() newIter := MakeIBioSequence()
newIter.Add(niterator) newIter.Add(niterator)

View File

@ -2,7 +2,7 @@ package obiiter
// func MakeSetAttributeWorker(rank string) obiiter.SeqWorker { // func MakeSetAttributeWorker(rank string) obiiter.SeqWorker {
// if !goutils.Contains(taxonomy.RankList(), rank) { // if !obiutils.Contains(taxonomy.RankList(), rank) {
// log.Fatalf("%s is not a valid rank (allowed ranks are %v)", // log.Fatalf("%s is not a valid rank (allowed ranks are %v)",
// rank, // rank,
// taxonomy.RankList()) // taxonomy.RankList())
@ -14,4 +14,4 @@ package obiiter
// } // }
// return w // return w
// } // }

View File

@ -3,8 +3,8 @@ package obikmer
import ( import (
"math" "math"
"git.metabarcoding.org/lecasofts/go/obitools/pkg/goutils"
"git.metabarcoding.org/lecasofts/go/obitools/pkg/obiseq" "git.metabarcoding.org/lecasofts/go/obitools/pkg/obiseq"
"git.metabarcoding.org/lecasofts/go/obitools/pkg/obiutils"
) )
type Table4mer [256]uint16 type Table4mer [256]uint16
@ -32,7 +32,7 @@ func Count4Mer(seq *obiseq.BioSequence, buffer *[]byte, counts *Table4mer) *Tabl
func Common4Mer(count1, count2 *Table4mer) int { func Common4Mer(count1, count2 *Table4mer) int {
sum := 0 sum := 0
for i := 0; i < 256; i++ { for i := 0; i < 256; i++ {
sum += int(goutils.MinUInt16((*count1)[i], (*count2)[i])) sum += int(obiutils.MinUInt16((*count1)[i], (*count2)[i]))
} }
return sum return sum
} }
@ -48,7 +48,7 @@ func Sum4Mer(count *Table4mer) int {
func LCS4MerBounds(count1, count2 *Table4mer) (int, int) { func LCS4MerBounds(count1, count2 *Table4mer) (int, int) {
s1 := Sum4Mer(count1) s1 := Sum4Mer(count1)
s2 := Sum4Mer(count2) s2 := Sum4Mer(count2)
smin := goutils.MinInt(s1, s2) smin := obiutils.MinInt(s1, s2)
cw := Common4Mer(count1, count2) cw := Common4Mer(count1, count2)
@ -65,11 +65,11 @@ func LCS4MerBounds(count1, count2 *Table4mer) (int, int) {
func Error4MerBounds(count1, count2 *Table4mer) (int, int) { func Error4MerBounds(count1, count2 *Table4mer) (int, int) {
s1 := Sum4Mer(count1) s1 := Sum4Mer(count1)
s2 := Sum4Mer(count2) s2 := Sum4Mer(count2)
smax := goutils.MaxInt(s1, s2) smax := obiutils.MaxInt(s1, s2)
cw := Common4Mer(count1, count2) cw := Common4Mer(count1, count2)
errorMax := smax - cw + 2* int(math.Floor(float64(cw+5)/8.0)) errorMax := smax - cw + 2*int(math.Floor(float64(cw+5)/8.0))
errorMin := int(math.Ceil(float64(errorMax) / 4.0)) errorMin := int(math.Ceil(float64(errorMax) / 4.0))
return errorMin, errorMax return errorMin, errorMax

View File

@ -7,9 +7,9 @@ import (
log "github.com/sirupsen/logrus" log "github.com/sirupsen/logrus"
"git.metabarcoding.org/lecasofts/go/obitools/pkg/goutils"
"git.metabarcoding.org/lecasofts/go/obitools/pkg/obiapat" "git.metabarcoding.org/lecasofts/go/obitools/pkg/obiapat"
"git.metabarcoding.org/lecasofts/go/obitools/pkg/obiseq" "git.metabarcoding.org/lecasofts/go/obitools/pkg/obiseq"
"git.metabarcoding.org/lecasofts/go/obitools/pkg/obiutils"
) )
type DemultiplexMatch struct { type DemultiplexMatch struct {
@ -104,16 +104,14 @@ func (marker *Marker) Compile(forward, reverse string, maxError int, allowsIndel
return nil return nil
} }
func (marker *Marker) Match(sequence *obiseq.BioSequence) *DemultiplexMatch { func (marker *Marker) Match(sequence *obiseq.BioSequence) *DemultiplexMatch {
aseq, _ := obiapat.MakeApatSequence(sequence, false) aseq, _ := obiapat.MakeApatSequence(sequence, false)
start, end, nerr ,matched := marker.forward.BestMatch(aseq, marker.taglength,-1) start, end, nerr, matched := marker.forward.BestMatch(aseq, marker.taglength, -1)
if matched { if matched {
sseq := sequence.String() sseq := sequence.String()
direct := sseq[start:end] direct := sseq[start:end]
tagstart := goutils.MaxInt(start - marker.taglength,0) tagstart := obiutils.MaxInt(start-marker.taglength, 0)
ftag := strings.ToLower(sseq[tagstart:start]) ftag := strings.ToLower(sseq[tagstart:start])
m := DemultiplexMatch{ m := DemultiplexMatch{
@ -125,15 +123,15 @@ func (marker *Marker) Match(sequence *obiseq.BioSequence) *DemultiplexMatch {
Error: nil, Error: nil,
} }
start, end, nerr ,matched = marker.creverse.BestMatch(aseq, start,-1) start, end, nerr, matched = marker.creverse.BestMatch(aseq, start, -1)
if matched { if matched {
// extracting primer matches // extracting primer matches
reverse, _ := sequence.Subsequence(start,end, false) reverse, _ := sequence.Subsequence(start, end, false)
defer reverse.Recycle() defer reverse.Recycle()
reverse = reverse.ReverseComplement(true) reverse = reverse.ReverseComplement(true)
endtag := goutils.MinInt(end+marker.taglength,sequence.Len()) endtag := obiutils.MinInt(end+marker.taglength, sequence.Len())
rtag, err := sequence.Subsequence(end, endtag, false) rtag, err := sequence.Subsequence(end, endtag, false)
defer rtag.Recycle() defer rtag.Recycle()
srtag := "" srtag := ""
@ -165,14 +163,13 @@ func (marker *Marker) Match(sequence *obiseq.BioSequence) *DemultiplexMatch {
return &m return &m
} }
start, end, nerr, matched = marker.reverse.BestMatch(aseq, marker.taglength, -1)
start, end, nerr ,matched = marker.reverse.BestMatch(aseq, marker.taglength,-1)
if matched { if matched {
sseq := sequence.String() sseq := sequence.String()
reverse := strings.ToLower(sseq[start:end]) reverse := strings.ToLower(sseq[start:end])
tagstart := goutils.MaxInt(start - marker.taglength,0) tagstart := obiutils.MaxInt(start-marker.taglength, 0)
rtag := strings.ToLower(sseq[tagstart:start]) rtag := strings.ToLower(sseq[tagstart:start])
m := DemultiplexMatch{ m := DemultiplexMatch{
@ -184,16 +181,16 @@ func (marker *Marker) Match(sequence *obiseq.BioSequence) *DemultiplexMatch {
Error: nil, Error: nil,
} }
start, end, nerr ,matched = marker.cforward.BestMatch(aseq, end,-1) start, end, nerr, matched = marker.cforward.BestMatch(aseq, end, -1)
if matched { if matched {
direct, _ := sequence.Subsequence(start,end, false) direct, _ := sequence.Subsequence(start, end, false)
defer direct.Recycle() defer direct.Recycle()
direct = direct.ReverseComplement(true) direct = direct.ReverseComplement(true)
endtag := goutils.MinInt(end+marker.taglength,sequence.Len()) endtag := obiutils.MinInt(end+marker.taglength, sequence.Len())
ftag, err := sequence.Subsequence(end,endtag, false) ftag, err := sequence.Subsequence(end, endtag, false)
defer ftag.Recycle() defer ftag.Recycle()
sftag := "" sftag := ""
if err != nil { if err != nil {

View File

@ -4,7 +4,7 @@ import (
"fmt" "fmt"
"strconv" "strconv"
"git.metabarcoding.org/lecasofts/go/obitools/pkg/goutils" "git.metabarcoding.org/lecasofts/go/obitools/pkg/obiutils"
log "github.com/sirupsen/logrus" log "github.com/sirupsen/logrus"
) )
@ -17,6 +17,7 @@ func (s *BioSequence) HasAttribute(key string) bool {
return ok return ok
} }
// A method that returns the value of the key in the annotation map. // A method that returns the value of the key in the annotation map.
func (s *BioSequence) GetAttribute(key string) (interface{}, bool) { func (s *BioSequence) GetAttribute(key string) (interface{}, bool) {
var val interface{} var val interface{}
@ -43,7 +44,7 @@ func (s *BioSequence) GetIntAttribute(key string) (int, bool) {
v, ok := s.GetAttribute(key) v, ok := s.GetAttribute(key)
if ok { if ok {
val, err = goutils.InterfaceToInt(v) val, err = obiutils.InterfaceToInt(v)
ok = err == nil ok = err == nil
} }
@ -52,15 +53,15 @@ func (s *BioSequence) GetIntAttribute(key string) (int, bool) {
// Deleting the key from the annotation map. // Deleting the key from the annotation map.
func (s *BioSequence) DeleteAttribute(key string) { func (s *BioSequence) DeleteAttribute(key string) {
delete(s.Annotations(),key) delete(s.Annotations(), key)
} }
// Renaming the key in the annotation map. // Renaming the key in the annotation map.
func (s *BioSequence) RenameAttribute(newName, oldName string) { func (s *BioSequence) RenameAttribute(newName, oldName string) {
val,ok := s.GetAttribute(oldName) val, ok := s.GetAttribute(oldName)
if (ok) { if ok {
s.SetAttribute(newName,val) s.SetAttribute(newName, val)
s.DeleteAttribute(oldName) s.DeleteAttribute(oldName)
} }
} }
@ -73,14 +74,13 @@ func (s *BioSequence) GetNumericAttribute(key string) (float64, bool) {
v, ok := s.GetAttribute(key) v, ok := s.GetAttribute(key)
if ok { if ok {
val, err = goutils.InterfaceToFloat64(v) val, err = obiutils.InterfaceToFloat64(v)
ok = err == nil ok = err == nil
} }
return val, ok return val, ok
} }
// A method that returns the value of the key in the annotation map. // A method that returns the value of the key in the annotation map.
func (s *BioSequence) GetStringAttribute(key string) (string, bool) { func (s *BioSequence) GetStringAttribute(key string) (string, bool) {
var val string var val string
@ -101,7 +101,7 @@ func (s *BioSequence) GetBoolAttribute(key string) (bool, bool) {
v, ok := s.GetAttribute(key) v, ok := s.GetAttribute(key)
if ok { if ok {
val, err = goutils.InterfaceToBool(v) val, err = obiutils.InterfaceToBool(v)
ok = err == nil ok = err == nil
} }
@ -115,7 +115,7 @@ func (s *BioSequence) GetIntMap(key string) (map[string]int, bool) {
v, ok := s.GetAttribute(key) v, ok := s.GetAttribute(key)
if ok { if ok {
val, err = goutils.InterfaceToIntMap(v) val, err = obiutils.InterfaceToIntMap(v)
ok = err == nil ok = err == nil
} }
@ -139,7 +139,6 @@ func (s *BioSequence) SetCount(count int) {
annot["count"] = count annot["count"] = count
} }
// Returning the taxid of the sequence. // Returning the taxid of the sequence.
func (s *BioSequence) Taxid() int { func (s *BioSequence) Taxid() int {
taxid, ok := s.GetIntAttribute("taxid") taxid, ok := s.GetIntAttribute("taxid")
@ -157,7 +156,6 @@ func (s *BioSequence) SetTaxid(taxid int) {
annot["taxid"] = taxid annot["taxid"] = taxid
} }
func (s *BioSequence) OBITagRefIndex() map[int]string { func (s *BioSequence) OBITagRefIndex() map[int]string {
var val map[int]string var val map[int]string
@ -179,7 +177,7 @@ func (s *BioSequence) OBITagRefIndex() map[int]string {
log.Panicln(err) log.Panicln(err)
} }
val[score], err = goutils.InterfaceToString(v) val[score], err = obiutils.InterfaceToString(v)
if err != nil { if err != nil {
log.Panicln(err) log.Panicln(err)
} }

View File

@ -6,7 +6,7 @@ import (
"strconv" "strconv"
"sync" "sync"
"git.metabarcoding.org/lecasofts/go/obitools/pkg/goutils" "git.metabarcoding.org/lecasofts/go/obitools/pkg/obiutils"
log "github.com/sirupsen/logrus" log "github.com/sirupsen/logrus"
) )
@ -135,7 +135,7 @@ func DualAnnotationClassifier(key1, key2 string, na string) *BioSequenceClassifi
locke.Lock() locke.Lock()
defer locke.Unlock() defer locke.Unlock()
jb, _ := goutils.JsonMarshal([2]string{val1, val2}) jb, _ := obiutils.JsonMarshal([2]string{val1, val2})
json := string(jb) json := string(jb)
k, ok := encode[json] k, ok := encode[json]

View File

@ -5,7 +5,7 @@ import (
"log" "log"
"strings" "strings"
"git.metabarcoding.org/lecasofts/go/obitools/pkg/goutils" "git.metabarcoding.org/lecasofts/go/obitools/pkg/obiutils"
"github.com/PaesslerAG/gval" "github.com/PaesslerAG/gval"
) )
@ -136,11 +136,11 @@ func minFloatMap(values map[string]float64) float64 {
var OBILang = gval.NewLanguage( var OBILang = gval.NewLanguage(
gval.Full(), gval.Full(),
gval.Function("len", func(args ...interface{}) (interface{}, error) { gval.Function("len", func(args ...interface{}) (interface{}, error) {
length := goutils.Len(args[0]) length := obiutils.Len(args[0])
return (float64)(length), nil return (float64)(length), nil
}), }),
gval.Function("ismap", func(args ...interface{}) (interface{}, error) { gval.Function("ismap", func(args ...interface{}) (interface{}, error) {
ismap := goutils.IsAMap(args[0]) ismap := obiutils.IsAMap(args[0])
return ismap, nil return ismap, nil
}), }),
gval.Function("printf", func(args ...interface{}) (interface{}, error) { gval.Function("printf", func(args ...interface{}) (interface{}, error) {
@ -152,7 +152,7 @@ var OBILang = gval.NewLanguage(
return text, nil return text, nil
}), }),
gval.Function("int", func(args ...interface{}) (interface{}, error) { gval.Function("int", func(args ...interface{}) (interface{}, error) {
val, err := goutils.InterfaceToInt(args[0]) val, err := obiutils.InterfaceToInt(args[0])
if err != nil { if err != nil {
log.Fatalf("%v cannot be converted to an integer value", args[0]) log.Fatalf("%v cannot be converted to an integer value", args[0])
@ -160,7 +160,7 @@ var OBILang = gval.NewLanguage(
return val, nil return val, nil
}), }),
gval.Function("numeric", func(args ...interface{}) (interface{}, error) { gval.Function("numeric", func(args ...interface{}) (interface{}, error) {
val, err := goutils.InterfaceToFloat64(args[0]) val, err := obiutils.InterfaceToFloat64(args[0])
if err != nil { if err != nil {
log.Fatalf("%v cannot be converted to a numeric value", args[0]) log.Fatalf("%v cannot be converted to a numeric value", args[0])
@ -168,7 +168,7 @@ var OBILang = gval.NewLanguage(
return val, nil return val, nil
}), }),
gval.Function("bool", func(args ...interface{}) (interface{}, error) { gval.Function("bool", func(args ...interface{}) (interface{}, error) {
val, err := goutils.InterfaceToBool(args[0]) val, err := obiutils.InterfaceToBool(args[0])
if err != nil { if err != nil {
log.Fatalf("%v cannot be converted to a boolan value", args[0]) log.Fatalf("%v cannot be converted to a boolan value", args[0])
@ -189,4 +189,3 @@ var OBILang = gval.NewLanguage(
gval.Function("composition", func(args ...interface{}) (interface{}, error) { gval.Function("composition", func(args ...interface{}) (interface{}, error) {
return (args[0].(*BioSequence)).Composition(), nil return (args[0].(*BioSequence)).Composition(), nil
})) }))

View File

@ -5,7 +5,7 @@ import (
"reflect" "reflect"
"strings" "strings"
"git.metabarcoding.org/lecasofts/go/obitools/pkg/goutils" "git.metabarcoding.org/lecasofts/go/obitools/pkg/obiutils"
log "github.com/sirupsen/logrus" log "github.com/sirupsen/logrus"
) )
@ -53,7 +53,7 @@ func (sequence *BioSequence) StatsOn(key string, na string) StatsOnValues {
newstat = false newstat = false
var err error var err error
for k, v := range istat { for k, v := range istat {
stats[k], err = goutils.InterfaceToInt(v) stats[k], err = obiutils.InterfaceToInt(v)
if err != nil { if err != nil {
log.Panicf("In sequence %s : %s stat tag not only containing integer values %s", log.Panicf("In sequence %s : %s stat tag not only containing integer values %s",
sequence.Id(), mkey, istat) sequence.Id(), mkey, istat)

View File

@ -4,7 +4,7 @@ import (
"log" "log"
"sync" "sync"
"git.metabarcoding.org/lecasofts/go/obitools/pkg/goutils" "git.metabarcoding.org/lecasofts/go/obitools/pkg/obiutils"
) )
var _BioSequenceByteSlicePool = sync.Pool{ var _BioSequenceByteSlicePool = sync.Pool{
@ -72,7 +72,7 @@ func GetAnnotation(values ...Annotation) Annotation {
} }
if len(values) > 0 { if len(values) > 0 {
goutils.MustFillMap(a, values[0]) obiutils.MustFillMap(a, values[0])
} }
return a return a

View File

@ -3,8 +3,8 @@ package obitax
import ( import (
log "github.com/sirupsen/logrus" log "github.com/sirupsen/logrus"
"git.metabarcoding.org/lecasofts/go/obitools/pkg/goutils"
"git.metabarcoding.org/lecasofts/go/obitools/pkg/obiseq" "git.metabarcoding.org/lecasofts/go/obitools/pkg/obiseq"
"git.metabarcoding.org/lecasofts/go/obitools/pkg/obiutils"
) )
func (taxonomy *Taxonomy) IsAValidTaxon(withAutoCorrection ...bool) obiseq.SequencePredicate { func (taxonomy *Taxonomy) IsAValidTaxon(withAutoCorrection ...bool) obiseq.SequencePredicate {
@ -59,7 +59,7 @@ func (taxonomy *Taxonomy) IsSubCladeOf(taxid int) obiseq.SequencePredicate {
func (taxonomy *Taxonomy) HasRequiredRank(rank string) obiseq.SequencePredicate { func (taxonomy *Taxonomy) HasRequiredRank(rank string) obiseq.SequencePredicate {
if !goutils.Contains(taxonomy.RankList(), rank) { if !obiutils.Contains(taxonomy.RankList(), rank) {
log.Fatalf("%s is not a valid rank (allowed ranks are %v)", log.Fatalf("%s is not a valid rank (allowed ranks are %v)",
rank, rank,
taxonomy.RankList()) taxonomy.RankList())

View File

@ -1,14 +1,14 @@
package obitax package obitax
import ( import (
"git.metabarcoding.org/lecasofts/go/obitools/pkg/goutils"
"git.metabarcoding.org/lecasofts/go/obitools/pkg/obiseq" "git.metabarcoding.org/lecasofts/go/obitools/pkg/obiseq"
"git.metabarcoding.org/lecasofts/go/obitools/pkg/obiutils"
log "github.com/sirupsen/logrus" log "github.com/sirupsen/logrus"
) )
func (taxonomy *Taxonomy) MakeSetTaxonAtRankWorker(rank string) obiseq.SeqWorker { func (taxonomy *Taxonomy) MakeSetTaxonAtRankWorker(rank string) obiseq.SeqWorker {
if !goutils.Contains(taxonomy.RankList(), rank) { if !obiutils.Contains(taxonomy.RankList(), rank) {
log.Fatalf("%s is not a valid rank (allowed ranks are %v)", log.Fatalf("%s is not a valid rank (allowed ranks are %v)",
rank, rank,
taxonomy.RankList()) taxonomy.RankList())

View File

@ -4,10 +4,10 @@ import (
"fmt" "fmt"
"os" "os"
"git.metabarcoding.org/lecasofts/go/obitools/pkg/goutils"
"git.metabarcoding.org/lecasofts/go/obitools/pkg/obiiter" "git.metabarcoding.org/lecasofts/go/obitools/pkg/obiiter"
"git.metabarcoding.org/lecasofts/go/obitools/pkg/obioptions" "git.metabarcoding.org/lecasofts/go/obitools/pkg/obioptions"
"git.metabarcoding.org/lecasofts/go/obitools/pkg/obiseq" "git.metabarcoding.org/lecasofts/go/obitools/pkg/obiseq"
"git.metabarcoding.org/lecasofts/go/obitools/pkg/obiutils"
"github.com/schollz/progressbar/v3" "github.com/schollz/progressbar/v3"
log "github.com/sirupsen/logrus" log "github.com/sirupsen/logrus"
) )
@ -120,7 +120,7 @@ func HeadCount(sequence *obiseq.BioSequence) int {
value := 0 value := 0
if ok { if ok {
value, err = goutils.InterfaceToInt(value) value, err = obiutils.InterfaceToInt(value)
if err != nil { if err != nil {
log.Panic("obiclean_headcount attribute of sequence %s must be an integer value not : %v", sequence.Id(), ivalue) log.Panic("obiclean_headcount attribute of sequence %s must be an integer value not : %v", sequence.Id(), ivalue)
} }
@ -136,7 +136,7 @@ func InternalCount(sequence *obiseq.BioSequence) int {
value := 0 value := 0
if ok { if ok {
value, err = goutils.InterfaceToInt(value) value, err = obiutils.InterfaceToInt(value)
if err != nil { if err != nil {
log.Panic("obiclean_internalcount attribute of sequence %s must be an integer value not : %v", sequence.Id(), ivalue) log.Panic("obiclean_internalcount attribute of sequence %s must be an integer value not : %v", sequence.Id(), ivalue)
} }
@ -152,7 +152,7 @@ func SingletonCount(sequence *obiseq.BioSequence) int {
value := 0 value := 0
if ok { if ok {
value, err = goutils.InterfaceToInt(value) value, err = obiutils.InterfaceToInt(value)
if err != nil { if err != nil {
log.Panic("obiclean_samplecount attribute of sequence %s must be an integer value not : %v", sequence.Id(), ivalue) log.Panic("obiclean_samplecount attribute of sequence %s must be an integer value not : %v", sequence.Id(), ivalue)
} }
@ -271,7 +271,7 @@ func Weight(sequence *obiseq.BioSequence) map[string]int {
case map[string]interface{}: case map[string]interface{}:
weight = make(map[string]int) weight = make(map[string]int)
for k, v := range iobistatus { for k, v := range iobistatus {
weight[k], err = goutils.InterfaceToInt(v) weight[k], err = obiutils.InterfaceToInt(v)
if err != nil { if err != nil {
log.Panicf("Weight value %v cannnot be casted to an integer value\n", v) log.Panicf("Weight value %v cannnot be casted to an integer value\n", v)
} }

View File

@ -1,8 +1,8 @@
package obicsv package obicsv
import ( import (
"git.metabarcoding.org/lecasofts/go/obitools/pkg/goutils"
"git.metabarcoding.org/lecasofts/go/obitools/pkg/obitools/obiconvert" "git.metabarcoding.org/lecasofts/go/obitools/pkg/obitools/obiconvert"
"git.metabarcoding.org/lecasofts/go/obitools/pkg/obiutils"
"github.com/DavidGamba/go-getoptions" "github.com/DavidGamba/go-getoptions"
) )
@ -103,18 +103,18 @@ func CLIToBeKeptAttributes() []string {
_keepOnly = append(_keepOnly, _softAttributes["obipairing"]...) _keepOnly = append(_keepOnly, _softAttributes["obipairing"]...)
} }
if i := goutils.LookFor(_keepOnly, "count"); i >= 0 { if i := obiutils.LookFor(_keepOnly, "count"); i >= 0 {
_keepOnly = goutils.RemoveIndex(_keepOnly, i) _keepOnly = obiutils.RemoveIndex(_keepOnly, i)
_outputCount = true _outputCount = true
} }
if i := goutils.LookFor(_keepOnly, "taxid"); i >= 0 { if i := obiutils.LookFor(_keepOnly, "taxid"); i >= 0 {
_keepOnly = goutils.RemoveIndex(_keepOnly, i) _keepOnly = obiutils.RemoveIndex(_keepOnly, i)
_outputTaxon = true _outputTaxon = true
} }
if i := goutils.LookFor(_keepOnly, "scientific_name"); i >= 0 { if i := obiutils.LookFor(_keepOnly, "scientific_name"); i >= 0 {
_keepOnly = goutils.RemoveIndex(_keepOnly, i) _keepOnly = obiutils.RemoveIndex(_keepOnly, i)
_outputTaxon = true _outputTaxon = true
} }

View File

@ -5,11 +5,11 @@ import (
log "github.com/sirupsen/logrus" log "github.com/sirupsen/logrus"
"git.metabarcoding.org/lecasofts/go/obitools/pkg/goutils"
"git.metabarcoding.org/lecasofts/go/obitools/pkg/obiformats/ncbitaxdump" "git.metabarcoding.org/lecasofts/go/obitools/pkg/obiformats/ncbitaxdump"
"git.metabarcoding.org/lecasofts/go/obitools/pkg/obiseq" "git.metabarcoding.org/lecasofts/go/obitools/pkg/obiseq"
"git.metabarcoding.org/lecasofts/go/obitools/pkg/obitax" "git.metabarcoding.org/lecasofts/go/obitools/pkg/obitax"
"git.metabarcoding.org/lecasofts/go/obitools/pkg/obitools/obiconvert" "git.metabarcoding.org/lecasofts/go/obitools/pkg/obitools/obiconvert"
"git.metabarcoding.org/lecasofts/go/obitools/pkg/obiutils"
"github.com/DavidGamba/go-getoptions" "github.com/DavidGamba/go-getoptions"
) )
@ -345,7 +345,7 @@ func CLIIdPatternPredicate() obiseq.SequencePredicate {
func CLIIdListPredicate() obiseq.SequencePredicate { func CLIIdListPredicate() obiseq.SequencePredicate {
if _IdList != "" { if _IdList != "" {
ids, err := goutils.ReadLines(_IdList) ids, err := obiutils.ReadLines(_IdList)
if err != nil { if err != nil {
log.Fatalf("cannot read the id file %s : %v", _IdList, err) log.Fatalf("cannot read the id file %s : %v", _IdList, err)

View File

@ -5,7 +5,6 @@ import (
"log" "log"
"os" "os"
"git.metabarcoding.org/lecasofts/go/obitools/pkg/goutils"
"git.metabarcoding.org/lecasofts/go/obitools/pkg/obialign" "git.metabarcoding.org/lecasofts/go/obitools/pkg/obialign"
"git.metabarcoding.org/lecasofts/go/obitools/pkg/obiiter" "git.metabarcoding.org/lecasofts/go/obitools/pkg/obiiter"
"git.metabarcoding.org/lecasofts/go/obitools/pkg/obikmer" "git.metabarcoding.org/lecasofts/go/obitools/pkg/obikmer"
@ -13,6 +12,7 @@ import (
"git.metabarcoding.org/lecasofts/go/obitools/pkg/obiseq" "git.metabarcoding.org/lecasofts/go/obitools/pkg/obiseq"
"git.metabarcoding.org/lecasofts/go/obitools/pkg/obitax" "git.metabarcoding.org/lecasofts/go/obitools/pkg/obitax"
"git.metabarcoding.org/lecasofts/go/obitools/pkg/obitools/obifind" "git.metabarcoding.org/lecasofts/go/obitools/pkg/obitools/obifind"
"git.metabarcoding.org/lecasofts/go/obitools/pkg/obiutils"
"github.com/schollz/progressbar/v3" "github.com/schollz/progressbar/v3"
) )
@ -38,7 +38,7 @@ func IndexSequence(seqidx int,
// log.Println("Redone : ",r,"/",t,"(",w,")") // log.Println("Redone : ",r,"/",t,"(",w,")")
o := goutils.IntOrder(score) o := obiutils.IntOrder(score)
current_taxid, err := taxo.Taxon(references[o[0]].Taxid()) current_taxid, err := taxo.Taxon(references[o[0]].Taxid())
current_score := score[o[0]] current_score := score[o[0]]
@ -121,7 +121,7 @@ func IndexReferenceDB(iterator obiiter.IBioSequence) obiiter.IBioSequence {
indexed := obiiter.MakeIBioSequence() indexed := obiiter.MakeIBioSequence()
go func() { go func() {
for i := 0; i < len(references); i += 10 { for i := 0; i < len(references); i += 10 {
limits <- [2]int{i, goutils.MinInt(i+10, len(references))} limits <- [2]int{i, obiutils.MinInt(i+10, len(references))}
} }
close(limits) close(limits)
}() }()

View File

@ -6,7 +6,6 @@ import (
"strconv" "strconv"
"strings" "strings"
"git.metabarcoding.org/lecasofts/go/obitools/pkg/goutils"
"git.metabarcoding.org/lecasofts/go/obitools/pkg/obialign" "git.metabarcoding.org/lecasofts/go/obitools/pkg/obialign"
"git.metabarcoding.org/lecasofts/go/obitools/pkg/obiiter" "git.metabarcoding.org/lecasofts/go/obitools/pkg/obiiter"
"git.metabarcoding.org/lecasofts/go/obitools/pkg/obikmer" "git.metabarcoding.org/lecasofts/go/obitools/pkg/obikmer"
@ -15,6 +14,7 @@ import (
"git.metabarcoding.org/lecasofts/go/obitools/pkg/obitax" "git.metabarcoding.org/lecasofts/go/obitools/pkg/obitax"
"git.metabarcoding.org/lecasofts/go/obitools/pkg/obitools/obifind" "git.metabarcoding.org/lecasofts/go/obitools/pkg/obitools/obifind"
"git.metabarcoding.org/lecasofts/go/obitools/pkg/obitools/obirefidx" "git.metabarcoding.org/lecasofts/go/obitools/pkg/obitools/obirefidx"
"git.metabarcoding.org/lecasofts/go/obitools/pkg/obiutils"
) )
func FindClosests(sequence *obiseq.BioSequence, func FindClosests(sequence *obiseq.BioSequence,
@ -31,7 +31,7 @@ func FindClosests(sequence *obiseq.BioSequence,
cw[i] = obikmer.Common4Mer(seqwords, ref) cw[i] = obikmer.Common4Mer(seqwords, ref)
} }
o := goutils.ReverseIntOrder(cw) o := obiutils.ReverseIntOrder(cw)
// mcw := 100000 // mcw := 100000
// for _, i := range o { // for _, i := range o {
@ -57,11 +57,11 @@ func FindClosests(sequence *obiseq.BioSequence,
for i, j := range o { for i, j := range o {
ref := references[j] ref := references[j]
lmin, lmax := goutils.MinMaxInt(sequence.Len(), ref.Len()) lmin, lmax := obiutils.MinMaxInt(sequence.Len(), ref.Len())
atMost := lmax - lmin + int(math.Ceil(float64(lmin-3-cw[j])/4.0)) - 2 atMost := lmax - lmin + int(math.Ceil(float64(lmin-3-cw[j])/4.0)) - 2
if i == 0 { if i == 0 {
maxe = goutils.MaxInt(sequence.Len(), ref.Len()) maxe = obiutils.MaxInt(sequence.Len(), ref.Len())
} }
// log.Println(sequence.Id(),cw[j], maxe) // log.Println(sequence.Id(),cw[j], maxe)

View File

@ -1,4 +1,4 @@
package goutils package obiutils
import ( import (
"bufio" "bufio"
@ -13,7 +13,6 @@ import (
"github.com/barkimedes/go-deepcopy" "github.com/barkimedes/go-deepcopy"
) )
// InterfaceToInt converts a interface{} to an integer value if possible. // InterfaceToInt converts a interface{} to an integer value if possible.
// If not a "NotAnInteger" error is returned via the err // If not a "NotAnInteger" error is returned via the err
// return value and val is set to 0. // return value and val is set to 0.
@ -197,7 +196,6 @@ func InterfaceToFloat64Map(i interface{}) (val map[string]float64, err error) {
return return
} }
// NotABoolean defines a new type of Error : "NotABoolean" // NotABoolean defines a new type of Error : "NotABoolean"
type NotABoolean struct { type NotABoolean struct {
message string message string

View File

@ -1,4 +1,4 @@
package goutils package obiutils
import ( import (
"bufio" "bufio"

83
pkg/obiutils/minmax.go Normal file
View File

@ -0,0 +1,83 @@
package obiutils
import "golang.org/x/exp/constraints"
func MinInt(x, y int) int {
if x < y {
return x
}
return y
}
func MaxInt(x, y int) int {
if x < y {
return y
}
return x
}
func MinMaxInt(x, y int) (int, int) {
if x < y {
return x, y
}
return y, x
}
func MinUInt16(x, y uint16) uint16 {
if x < y {
return x
}
return y
}
func MaxUInt16(x, y uint16) uint16 {
if x < y {
return y
}
return x
}
func MinSlice[T constraints.Ordered](vec []T) T {
if len(vec) == 0 {
panic("empty slice")
}
min := vec[0]
for _, v := range vec {
if v < min {
min = v
}
}
return min
}
func MaxSlice[T constraints.Ordered](vec []T) T {
if len(vec) == 0 {
panic("empty slice")
}
max := vec[0]
for _, v := range vec {
if v > max {
max = v
}
}
return max
}
func RangeSlice[T constraints.Ordered](vec []T) (min, max T) {
if len(vec) == 0 {
panic("empty slice")
}
min = vec[0]
max = vec[0]
for _, v := range vec {
if v > max {
max = v
}
if v < min {
min = v
}
}
return
}

View File

@ -1,6 +1,8 @@
package goutils package obiutils
import "sort" import (
"sort"
)
// intRanker is a helper type for the rank function. // intRanker is a helper type for the rank function.
type intRanker struct { type intRanker struct {
@ -29,7 +31,7 @@ func IntOrder(data []int) []int {
} }
sort.Sort(rk) sort.Sort(rk)
return r return r
} }
@ -49,6 +51,36 @@ func ReverseIntOrder(data []int) []int {
} }
sort.Sort(sort.Reverse(rk)) sort.Sort(sort.Reverse(rk))
return r
}
type Ranker[T sort.Interface] struct {
x T // Data to be ranked.
r []int // A list of indexes into f that reflects rank order after sorting.
}
// ranker satisfies the sort.Interface without mutating the reference slice, f.
func (r Ranker[_]) Len() int { return len(r.r) }
func (r Ranker[T]) Less(i, j int) bool { return r.x.Less(r.r[i], r.r[j]) }
func (r Ranker[_]) Swap(i, j int) { r.r[i], r.r[j] = r.r[j], r.r[i] }
func Order[T sort.Interface](data T) []int {
ldata := data.Len()
if ldata == 0 {
return nil
}
r := make([]int, ldata)
rk := Ranker[T]{
x: data,
r: r,
}
for i := 0; i < ldata; i++ {
rk.r[i] = i
}
sort.Sort(rk)
return r return r
} }

View File

@ -1,5 +1,4 @@
package goutils package obiutils
func Contains[T comparable](arr []T, x T) bool { func Contains[T comparable](arr []T, x T) bool {
for _, v := range arr { for _, v := range arr {
@ -20,5 +19,5 @@ func LookFor[T comparable](arr []T, x T) int {
} }
func RemoveIndex[T comparable](s []T, index int) []T { func RemoveIndex[T comparable](s []T, index int) []T {
return append(s[:index], s[index+1:]...) return append(s[:index], s[index+1:]...)
} }