Rename the Length methods Len to follow GO standart

This commit is contained in:
2022-11-17 11:09:58 +01:00
parent eb32089305
commit 29563aa94e
30 changed files with 134 additions and 130 deletions

View File

@ -269,14 +269,20 @@ func IsASlice(value interface{}) bool {
} }
func HasLength(value interface{}) bool { func HasLength(value interface{}) bool {
return IsAMap(value) || IsAnArray(value) || IsASlice(value) _, ok := value.(interface{ Len() int })
return IsAMap(value) || IsAnArray(value) || IsASlice(value) || ok
} }
func Length(value interface{}) int { func Len(value interface{}) int {
l := 1 l := 1
if HasLength(value) {
if IsAMap(value) || IsAnArray(value) || IsASlice(value) {
vc := reflect.ValueOf(value) vc := reflect.ValueOf(value)
l = vc.Len() l = vc.Len()
} }
if vc, ok := value.(interface{ Len() int }); ok {
l = vc.Len()
}
return l return l
} }

View File

@ -73,10 +73,10 @@ func _BuildAlignment(seqA, seqB []byte, path []int, gap byte, bufferA, bufferB *
func BuildAlignment(seqA, seqB *obiseq.BioSequence, func BuildAlignment(seqA, seqB *obiseq.BioSequence,
path []int, gap byte) (*obiseq.BioSequence, *obiseq.BioSequence) { path []int, gap byte) (*obiseq.BioSequence, *obiseq.BioSequence) {
bufferSA := obiseq.GetSlice(seqA.Length()) bufferSA := obiseq.GetSlice(seqA.Len())
defer obiseq.RecycleSlice(&bufferSA) defer obiseq.RecycleSlice(&bufferSA)
bufferSB := obiseq.GetSlice(seqB.Length()) bufferSB := obiseq.GetSlice(seqB.Len())
defer obiseq.RecycleSlice(&bufferSB) defer obiseq.RecycleSlice(&bufferSB)
_BuildAlignment(seqA.Sequence(), seqB.Sequence(), path, gap, _BuildAlignment(seqA.Sequence(), seqB.Sequence(), path, gap,
@ -117,12 +117,12 @@ func BuildAlignment(seqA, seqB *obiseq.BioSequence,
// return. // return.
func BuildQualityConsensus(seqA, seqB *obiseq.BioSequence, path []int, statOnMismatch bool) (*obiseq.BioSequence, int) { func BuildQualityConsensus(seqA, seqB *obiseq.BioSequence, path []int, statOnMismatch bool) (*obiseq.BioSequence, int) {
bufferSA := obiseq.GetSlice(seqA.Length()) bufferSA := obiseq.GetSlice(seqA.Len())
bufferSB := obiseq.GetSlice(seqB.Length()) bufferSB := obiseq.GetSlice(seqB.Len())
defer obiseq.RecycleSlice(&bufferSB) defer obiseq.RecycleSlice(&bufferSB)
bufferQA := obiseq.GetSlice(seqA.Length()) bufferQA := obiseq.GetSlice(seqA.Len())
bufferQB := obiseq.GetSlice(seqB.Length()) bufferQB := obiseq.GetSlice(seqB.Len())
defer obiseq.RecycleSlice(&bufferQB) defer obiseq.RecycleSlice(&bufferQB)
_BuildAlignment(seqA.Sequence(), seqB.Sequence(), path, ' ', _BuildAlignment(seqA.Sequence(), seqB.Sequence(), path, ' ',

View File

@ -60,8 +60,8 @@ var _notavail = encodeValues(0, 30000, false)
func FastLCSScore(seqA, seqB *obiseq.BioSequence, maxError int, buffer *[]uint64) (int, int) { func FastLCSScore(seqA, seqB *obiseq.BioSequence, maxError int, buffer *[]uint64) (int, int) {
lA := seqA.Length() lA := seqA.Len()
lB := seqB.Length() lB := seqB.Len()
// Ensure that A is the longest // Ensure that A is the longest
if lA < lB { if lA < lB {
@ -70,7 +70,7 @@ func FastLCSScore(seqA, seqB *obiseq.BioSequence, maxError int, buffer *[]uint64
} }
if maxError == -1 { if maxError == -1 {
maxError = lA*2 maxError = lA * 2
} }
delta := lA - lB delta := lA - lB

View File

@ -58,7 +58,7 @@ var _FourBitsBaseDecode = []byte{
// A byte slice can be provided (buffer) to preveent allocation of a new // A byte slice can be provided (buffer) to preveent allocation of a new
// memory chunk by th function. // memory chunk by th function.
func Encode4bits(seq *obiseq.BioSequence, buffer []byte) []byte { func Encode4bits(seq *obiseq.BioSequence, buffer []byte) []byte {
length := seq.Length() length := seq.Len()
rawseq := seq.Sequence() rawseq := seq.Sequence()
if buffer == nil { if buffer == nil {

View File

@ -14,8 +14,8 @@ func D1Or0(seq1, seq2 *obiseq.BioSequence) (int, int, byte, byte) {
pos := -1 pos := -1
l1 := seq1.Length() l1 := seq1.Len()
l2 := seq2.Length() l2 := seq2.Len()
if abs(l1-l2) > 1 { if abs(l1-l2) > 1 {
return -1, pos, 0, 0 return -1, pos, 0, 0

View File

@ -229,7 +229,7 @@ func PELeftAlign(seqA, seqB *obiseq.BioSequence, gap float64,
} }
if arena.pointer == nil { if arena.pointer == nil {
arena = MakePEAlignArena(seqA.Length(), seqB.Length()) arena = MakePEAlignArena(seqA.Len(), seqB.Len())
} }
score := _FillMatrixPeLeftAlign(seqA.Sequence(), seqA.Qualities(), score := _FillMatrixPeLeftAlign(seqA.Sequence(), seqA.Qualities(),
@ -238,7 +238,7 @@ func PELeftAlign(seqA, seqB *obiseq.BioSequence, gap float64,
&arena.pointer.pathMatrix) &arena.pointer.pathMatrix)
arena.pointer.path = _Backtracking(arena.pointer.pathMatrix, arena.pointer.path = _Backtracking(arena.pointer.pathMatrix,
seqA.Length(), seqB.Length(), seqA.Len(), seqB.Len(),
&arena.pointer.path) &arena.pointer.path)
return score, arena.pointer.path return score, arena.pointer.path
@ -253,7 +253,7 @@ func PERightAlign(seqA, seqB *obiseq.BioSequence, gap float64,
} }
if arena.pointer == nil { if arena.pointer == nil {
arena = MakePEAlignArena(seqA.Length(), seqB.Length()) arena = MakePEAlignArena(seqA.Len(), seqB.Len())
} }
score := _FillMatrixPeRightAlign(seqA.Sequence(), seqA.Qualities(), score := _FillMatrixPeRightAlign(seqA.Sequence(), seqA.Qualities(),
@ -262,7 +262,7 @@ func PERightAlign(seqA, seqB *obiseq.BioSequence, gap float64,
&arena.pointer.pathMatrix) &arena.pointer.pathMatrix)
arena.pointer.path = _Backtracking(arena.pointer.pathMatrix, arena.pointer.path = _Backtracking(arena.pointer.pathMatrix,
seqA.Length(), seqB.Length(), seqA.Len(), seqB.Len(),
&arena.pointer.path) &arena.pointer.path)
return score, arena.pointer.path return score, arena.pointer.path
@ -290,15 +290,12 @@ func PEAlign(seqA, seqB *obiseq.BioSequence,
shift, fastScore := obikmer.FastShiftFourMer(index, seqB, nil) shift, fastScore := obikmer.FastShiftFourMer(index, seqB, nil)
if shift > 0 { if shift > 0 {
over = seqA.Length() - shift over = seqA.Len() - shift
} else { } else {
over = seqB.Length() + shift over = seqB.Len() + shift
} }
// log.Println(seqA.String())
// log.Println(seqB.String())
// log.Printf("Shift : %d Score : %d Over : %d La : %d:%d Lb: %d:%d\n", shift, fastScore, over, seqA.Length(), len(seqA.Qualities()), seqB.Length(), len(seqB.Qualities()))
if fastScore+3 < over { if fastScore+3 < over {
// At least one mismatch exists in the overlaping region // At least one mismatch exists in the overlaping region
@ -315,7 +312,7 @@ func PEAlign(seqA, seqB *obiseq.BioSequence,
partLen = len(rawSeqA) partLen = len(rawSeqA)
rawSeqB = seqB.Sequence()[0:partLen] rawSeqB = seqB.Sequence()[0:partLen]
qualSeqB = seqB.Qualities()[0:partLen] qualSeqB = seqB.Qualities()[0:partLen]
extra3 = seqB.Length() - partLen extra3 = seqB.Len() - partLen
score = _FillMatrixPeLeftAlign( score = _FillMatrixPeLeftAlign(
rawSeqA, qualSeqA, rawSeqB, qualSeqB, gap, rawSeqA, qualSeqA, rawSeqB, qualSeqB, gap,
&arena.pointer.scoreMatrix, &arena.pointer.scoreMatrix,
@ -335,7 +332,7 @@ func PEAlign(seqA, seqB *obiseq.BioSequence,
partLen = len(rawSeqB) partLen = len(rawSeqB)
rawSeqA = seqA.Sequence()[:partLen] rawSeqA = seqA.Sequence()[:partLen]
qualSeqA = seqA.Qualities()[:partLen] qualSeqA = seqA.Qualities()[:partLen]
extra3 = partLen - seqA.Length() extra3 = partLen - seqA.Len()
score = _FillMatrixPeRightAlign( score = _FillMatrixPeRightAlign(
rawSeqA, qualSeqA, rawSeqB, qualSeqB, gap, rawSeqA, qualSeqA, rawSeqB, qualSeqB, gap,
&arena.pointer.scoreMatrix, &arena.pointer.scoreMatrix,
@ -354,7 +351,7 @@ func PEAlign(seqA, seqB *obiseq.BioSequence,
qualSeqA = seqA.Qualities()[startA:] qualSeqA = seqA.Qualities()[startA:]
partLen = len(qualSeqA) partLen = len(qualSeqA)
qualSeqB = seqB.Qualities()[0:partLen] qualSeqB = seqB.Qualities()[0:partLen]
extra3 = seqB.Length() - partLen extra3 = seqB.Len() - partLen
score = 0 score = 0
} else { } else {
startA = 0 startA = 0
@ -362,7 +359,7 @@ func PEAlign(seqA, seqB *obiseq.BioSequence,
extra5 = startB extra5 = startB
qualSeqB = seqB.Qualities()[startB:] qualSeqB = seqB.Qualities()[startB:]
partLen = len(qualSeqB) partLen = len(qualSeqB)
extra3 = partLen - seqA.Length() extra3 = partLen - seqA.Len()
qualSeqA = seqA.Qualities()[:partLen] qualSeqA = seqA.Qualities()[:partLen]
} }
score = 0 score = 0

View File

@ -119,8 +119,8 @@ func (pattern ApatPattern) String() string {
return C.GoString(pattern.pointer.pointer.cpat) return C.GoString(pattern.pointer.pointer.cpat)
} }
// Length method returns the length of the matched pattern. // Len method returns the length of the matched pattern.
func (pattern ApatPattern) Length() int { func (pattern ApatPattern) Len() int {
return int(pattern.pointer.pointer.patlen) return int(pattern.pointer.pointer.patlen)
} }
@ -159,7 +159,7 @@ func MakeApatSequence(sequence *obiseq.BioSequence, circular bool, recycle ...Ap
var errno C.int32_t var errno C.int32_t
var errmsg *C.char var errmsg *C.char
var p unsafe.Pointer var p unsafe.Pointer
seqlen := sequence.Length() seqlen := sequence.Len()
ic := 0 ic := 0
if circular { if circular {
@ -195,7 +195,7 @@ func MakeApatSequence(sequence *obiseq.BioSequence, circular bool, recycle ...Ap
// copy the data into the buffer, by converting it to a Go array // copy the data into the buffer, by converting it to a Go array
cBuf := (*[1 << 31]byte)(p) cBuf := (*[1 << 31]byte)(p)
copy(cBuf[:], sequence.Sequence()) copy(cBuf[:], sequence.Sequence())
cBuf[sequence.Length()] = 0 cBuf[sequence.Len()] = 0
pseqc := C.new_apatseq((*C.char)(p), C.int32_t(ic), C.int32_t(seqlen), pseqc := C.new_apatseq((*C.char)(p), C.int32_t(ic), C.int32_t(seqlen),
(*C.Seq)(out), (*C.Seq)(out),
@ -240,8 +240,8 @@ func MakeApatSequence(sequence *obiseq.BioSequence, circular bool, recycle ...Ap
return ApatSequence{recycle[0].pointer}, nil return ApatSequence{recycle[0].pointer}, nil
} }
// Length method returns the length of the ApatSequence. // Len method returns the length of the ApatSequence.
func (sequence ApatSequence) Length() int { func (sequence ApatSequence) Len() int {
return int(sequence.pointer.pointer.seqlen) return int(sequence.pointer.pointer.seqlen)
} }
@ -283,7 +283,7 @@ func (sequence ApatSequence) Free() {
// match. The third value indicates the number of error detected for this occurrence. // match. The third value indicates the number of error detected for this occurrence.
func (pattern ApatPattern) FindAllIndex(sequence ApatSequence, limits ...int) (loc [][3]int) { func (pattern ApatPattern) FindAllIndex(sequence ApatSequence, limits ...int) (loc [][3]int) {
begin := 0 begin := 0
length := sequence.Length() length := sequence.Len()
if len(limits) > 0 { if len(limits) > 0 {
begin = limits[0] begin = limits[0]

View File

@ -234,15 +234,15 @@ func _Pcr(seq ApatSequence,
if len(forwardMatches) > 0 { if len(forwardMatches) > 0 {
begin := forwardMatches[0][0] begin := forwardMatches[0][0]
length := seq.Length() - begin length := seq.Len() - begin
if opt.pointer.maxLength > 0 { if opt.pointer.maxLength > 0 {
length = forwardMatches[len(forwardMatches)-1][2] - begin + opt.MaxLength() + reverse.Length() length = forwardMatches[len(forwardMatches)-1][2] - begin + opt.MaxLength() + reverse.Len()
} }
if opt.Circular() { if opt.Circular() {
begin = 0 begin = 0
length = seq.Length() + _MaxPatLen length = seq.Len() + _MaxPatLen
} }
reverseMatches := crev.FindAllIndex(seq, begin, length) reverseMatches := crev.FindAllIndex(seq, begin, length)
@ -252,13 +252,13 @@ func _Pcr(seq ApatSequence,
posi := fm[0] posi := fm[0]
if posi < seq.Length() { if posi < seq.Len() {
erri := fm[2] erri := fm[2]
for _, rm := range reverseMatches { for _, rm := range reverseMatches {
posj := rm[0] posj := rm[0]
if posj < seq.Length() { if posj < seq.Len() {
posj := rm[1] posj := rm[1]
errj := rm[2] errj := rm[2]
length = 0 length = 0
@ -267,7 +267,7 @@ func _Pcr(seq ApatSequence,
length = rm[0] - fm[1] length = rm[0] - fm[1]
} else { } else {
if opt.Circular() { if opt.Circular() {
length = rm[0] + seq.Length() - posi - forward.Length() length = rm[0] + seq.Len() - posi - forward.Len()
} }
} }
if length > 0 && // For when primers touch or overlap if length > 0 && // For when primers touch or overlap
@ -307,15 +307,15 @@ func _Pcr(seq ApatSequence,
if forwardMatches != nil { if forwardMatches != nil {
begin := forwardMatches[0][0] begin := forwardMatches[0][0]
length := seq.Length() - begin length := seq.Len() - begin
if opt.pointer.maxLength > 0 { if opt.pointer.maxLength > 0 {
length = forwardMatches[len(forwardMatches)-1][2] - begin + opt.MaxLength() + reverse.Length() length = forwardMatches[len(forwardMatches)-1][2] - begin + opt.MaxLength() + reverse.Len()
} }
if opt.Circular() { if opt.Circular() {
begin = 0 begin = 0
length = seq.Length() + _MaxPatLen length = seq.Len() + _MaxPatLen
} }
reverseMatches := cfwd.FindAllIndex(seq, begin, length) reverseMatches := cfwd.FindAllIndex(seq, begin, length)
@ -325,13 +325,13 @@ func _Pcr(seq ApatSequence,
posi := fm[0] posi := fm[0]
if posi < seq.Length() { if posi < seq.Len() {
erri := fm[2] erri := fm[2]
for _, rm := range reverseMatches { for _, rm := range reverseMatches {
posj := rm[0] posj := rm[0]
if posj < seq.Length() { if posj < seq.Len() {
posj := rm[1] posj := rm[1]
errj := rm[2] errj := rm[2]
length = 0 length = 0
@ -340,7 +340,7 @@ func _Pcr(seq ApatSequence,
length = rm[0] - fm[1] length = rm[0] - fm[1]
} else { } else {
if opt.Circular() { if opt.Circular() {
length = rm[0] + seq.Length() - posi - forward.Length() length = rm[0] + seq.Len() - posi - forward.Len()
} }
} }
if length > 0 && // For when primers touch or overlap if length > 0 && // For when primers touch or overlap

View File

@ -97,14 +97,14 @@ func ISequenceSubChunk(iterator obiiter.IBioSequenceBatch,
batch := iterator.Get() batch := iterator.Get()
if batch.Length() > 1 { if batch.Len() > 1 {
classifier.Reset() classifier.Reset()
if cap(ordered) < batch.Length() { if cap(ordered) < batch.Len() {
log.Debugln("Allocate a new ordered sequences : ", batch.Length()) log.Debugln("Allocate a new ordered sequences : ", batch.Len())
ordered = make([]sSS, batch.Length()) ordered = make([]sSS, batch.Len())
} else { } else {
ordered = ordered[:batch.Length()] ordered = ordered[:batch.Len()]
} }
for i, s := range batch.Slice() { for i, s := range batch.Slice() {

21
pkg/obieval/language.go Normal file
View File

@ -0,0 +1,21 @@
package obieval
import (
"git.metabarcoding.org/lecasofts/go/obitools/pkg/goutils"
"github.com/PaesslerAG/gval"
)
var OBILang = gval.NewLanguage(
gval.Full(),
gval.Function("len", func(args ...interface{}) (interface{}, error) {
length := goutils.Len(args[0])
return (float64)(length), nil
}),
gval.Function("ismap", func(args ...interface{}) (interface{}, error) {
ismap := goutils.IsAMap(args[0])
return ismap, nil
}))
func Expression(expression string) (gval.Evaluable, error) {
return OBILang.NewEvaluable(expression)
}

View File

@ -65,19 +65,12 @@ func _FastseqReader(seqfile C.fast_kseq_p,
slice = append(slice, rep) slice = append(slice, rep)
ii++ ii++
if ii >= batch_size { if ii >= batch_size {
//log.Printf("\n==> Pushing sequence batch\n")
// start := time.Now()
iterator.Push(obiiter.MakeBioSequenceBatch(i, slice)) iterator.Push(obiiter.MakeBioSequenceBatch(i, slice))
// elapsed := time.Since(start)
// log.Printf("\n==>sequences pushed after %s\n", elapsed)
slice = obiseq.MakeBioSequenceSlice() slice = obiseq.MakeBioSequenceSlice()
i++ i++
ii = 0 ii = 0
} }
// log.Println("longueur : ",l,rep.Length())
} }
if len(slice) > 0 { if len(slice) > 0 {

View File

@ -15,9 +15,9 @@ import (
func FormatFastq(seq *obiseq.BioSequence, quality_shift int, formater FormatHeader) string { func FormatFastq(seq *obiseq.BioSequence, quality_shift int, formater FormatHeader) string {
l := seq.Length() l := seq.Len()
q := seq.Qualities() q := seq.Qualities()
ascii := make([]byte, seq.Length()) ascii := make([]byte, seq.Len())
for j := 0; j < l; j++ { for j := 0; j < l; j++ {
ascii[j] = uint8(q[j]) + uint8(quality_shift) ascii[j] = uint8(q[j]) + uint8(quality_shift)

View File

@ -5,12 +5,13 @@ import (
"encoding/csv" "encoding/csv"
"fmt" "fmt"
"io" "io"
log "github.com/sirupsen/logrus"
"os" "os"
"path" "path"
"strconv" "strconv"
"strings" "strings"
log "github.com/sirupsen/logrus"
"git.metabarcoding.org/lecasofts/go/obitools/pkg/obitax" "git.metabarcoding.org/lecasofts/go/obitools/pkg/obitax"
) )
@ -101,7 +102,7 @@ func LoadNCBITaxDump(directory string, onlysn bool) (*obitax.Taxonomy, error) {
buffered := bufio.NewReader(nodefile) buffered := bufio.NewReader(nodefile)
loadNodeTable(buffered, taxonomy) loadNodeTable(buffered, taxonomy)
log.Printf("%d Taxonomy nodes read\n", taxonomy.Length()) log.Printf("%d Taxonomy nodes read\n", taxonomy.Len())
// //
// Load the Taxonomy nodes // Load the Taxonomy nodes

View File

@ -31,7 +31,7 @@ func (batch BioSequenceBatch) Slice() obiseq.BioSequenceSlice {
return batch.slice return batch.slice
} }
func (batch BioSequenceBatch) Length() int { func (batch BioSequenceBatch) Len() int {
return len(batch.slice) return len(batch.slice)
} }

View File

@ -218,7 +218,7 @@ func (iterator IBioSequenceBatch) Push(batch BioSequenceBatch) {
if batch.IsNil() { if batch.IsNil() {
log.Panicln("A Nil batch is pushed on the channel") log.Panicln("A Nil batch is pushed on the channel")
} }
if batch.Length() == 0 { if batch.Len() == 0 {
log.Panicln("An empty batch is pushed on the channel") log.Panicln("An empty batch is pushed on the channel")
} }
@ -453,7 +453,7 @@ func (iterator IBioSequenceBatch) Count(recycle bool) (int, int, int) {
for _, seq := range batch.Slice() { for _, seq := range batch.Slice() {
variants++ variants++
reads += seq.Count() reads += seq.Count()
nucleotides += seq.Length() nucleotides += seq.Len()
if recycle { if recycle {
seq.Recycle() seq.Recycle()

View File

@ -30,7 +30,7 @@ func (iterator IBioSequenceBatch) IMergeSequenceBatch(na string, statsOn []strin
seqs := iterator.Get() seqs := iterator.Get()
batch.slice = append(batch.slice, seqs.slice.Merge(na, statsOn)) batch.slice = append(batch.slice, seqs.slice.Merge(na, statsOn))
} }
if batch.Length() > 0 { if batch.Len() > 0 {
newIter.Push(batch) newIter.Push(batch)
} }
} }
@ -40,11 +40,10 @@ func (iterator IBioSequenceBatch) IMergeSequenceBatch(na string, statsOn []strin
return newIter return newIter
} }
func MergePipe(na string, statsOn []string, sizes ...int) Pipeable { func MergePipe(na string, statsOn []string, sizes ...int) Pipeable {
f := func(iterator IBioSequenceBatch) IBioSequenceBatch { f := func(iterator IBioSequenceBatch) IBioSequenceBatch {
return iterator.IMergeSequenceBatch(na,statsOn,sizes...) return iterator.IMergeSequenceBatch(na, statsOn, sizes...)
} }
return f return f
} }

View File

@ -1,9 +1,10 @@
package obiiter package obiiter
import ( import (
log "github.com/sirupsen/logrus"
"sync" "sync"
log "github.com/sirupsen/logrus"
"git.metabarcoding.org/lecasofts/go/obitools/pkg/obiseq" "git.metabarcoding.org/lecasofts/go/obitools/pkg/obiseq"
) )
@ -41,8 +42,7 @@ func (batch PairedBioSequenceBatch) Reorder(newOrder int) PairedBioSequenceBatch
return batch return batch
} }
func (batch PairedBioSequenceBatch) Len() int {
func (batch PairedBioSequenceBatch) Length() int {
return len(batch.forward) return len(batch.forward)
} }

View File

@ -39,7 +39,7 @@ func (iterator IBioSequenceBatch) Speed(message ...string) IBioSequenceBatch {
for iterator.Next() { for iterator.Next() {
batch := iterator.Get() batch := iterator.Get()
l := batch.Length() l := batch.Len()
newIter.Push(batch) newIter.Push(batch)
bar.Add(l) bar.Add(l)
} }

View File

@ -31,7 +31,7 @@ var __single_base_code__ = []byte{0,
// the slice is used to store the result, overwise a new slice is // the slice is used to store the result, overwise a new slice is
// created. // created.
func Encode4mer(seq *obiseq.BioSequence, buffer *[]byte) []byte { func Encode4mer(seq *obiseq.BioSequence, buffer *[]byte) []byte {
slength := seq.Length() slength := seq.Len()
length := slength - 3 length := slength - 3
rawseq := seq.Sequence() rawseq := seq.Sequence()
@ -101,7 +101,7 @@ func FastShiftFourMer(index [][]int, seq *obiseq.BioSequence, buffer *[]byte) (i
iternal_buffer := Encode4mer(seq, buffer) iternal_buffer := Encode4mer(seq, buffer)
shifts := make(map[int]int, 3*seq.Length()) shifts := make(map[int]int, 3*seq.Len())
for pos, code := range iternal_buffer { for pos, code := range iternal_buffer {
for _, refpos := range index[code] { for _, refpos := range index[code] {
@ -127,4 +127,3 @@ func FastShiftFourMer(index [][]int, seq *obiseq.BioSequence, buffer *[]byte) (i
return maxshift, maxcount return maxshift, maxcount
} }

View File

@ -162,7 +162,7 @@ func (s *BioSequence) String() string {
} }
// Returning the length of the sequence. // Returning the length of the sequence.
func (s *BioSequence) Length() int { func (s *BioSequence) Len() int {
return len(s.sequence) return len(s.sequence)
} }

View File

@ -5,10 +5,8 @@ import (
"fmt" "fmt"
"regexp" "regexp"
"git.metabarcoding.org/lecasofts/go/obitools/pkg/goutils" "git.metabarcoding.org/lecasofts/go/obitools/pkg/obieval"
log "github.com/sirupsen/logrus" log "github.com/sirupsen/logrus"
"github.com/PaesslerAG/gval"
) )
type SequencePredicate func(*BioSequence) bool type SequencePredicate func(*BioSequence) bool
@ -130,7 +128,7 @@ func IsLessAbundantOrEqualTo(count int) SequencePredicate {
func IsLongerOrEqualTo(length int) SequencePredicate { func IsLongerOrEqualTo(length int) SequencePredicate {
f := func(sequence *BioSequence) bool { f := func(sequence *BioSequence) bool {
return sequence.Length() >= length return sequence.Len() >= length
} }
return f return f
@ -138,7 +136,7 @@ func IsLongerOrEqualTo(length int) SequencePredicate {
func IsShorterOrEqualTo(length int) SequencePredicate { func IsShorterOrEqualTo(length int) SequencePredicate {
f := func(sequence *BioSequence) bool { f := func(sequence *BioSequence) bool {
return sequence.Length() <= length return sequence.Len() <= length
} }
return f return f
@ -203,17 +201,7 @@ func IsIdIn(ids ...string) SequencePredicate {
func ExpressionPredicat(expression string) SequencePredicate { func ExpressionPredicat(expression string) SequencePredicate {
lang := gval.NewLanguage( exp, err := obieval.OBILang.NewEvaluable(expression)
gval.Full(),
gval.Function("len", func(args ...interface{}) (interface{}, error) {
length := goutils.Length(args[0])
return (float64)(length), nil
}),
gval.Function("ismap", func(args ...interface{}) (interface{}, error) {
ismap := goutils.IsAMap(args[0])
return ismap, nil
}))
exp, err := lang.NewEvaluable(expression)
if err != nil { if err != nil {
log.Fatalf("Error in the expression : %s", expression) log.Fatalf("Error in the expression : %s", expression)
} }
@ -223,7 +211,7 @@ func ExpressionPredicat(expression string) SequencePredicate {
map[string]interface{}{ map[string]interface{}{
"annot": sequence.Annotations(), "annot": sequence.Annotations(),
"count": sequence.Count(), "count": sequence.Count(),
"seqlength": sequence.Length(), "seqlength": sequence.Len(),
"sequence": sequence, "sequence": sequence,
}, },
) )

View File

@ -13,7 +13,7 @@ func (sequence *BioSequence) ReverseComplement(inplace bool) *BioSequence {
s := sequence.sequence s := sequence.sequence
for i, j := sequence.Length()-1, 0; i >= j; i-- { for i, j := sequence.Len()-1, 0; i >= j; i-- {
// ASCII code & 31 -> builds an index in witch (a|A) is 1 // ASCII code & 31 -> builds an index in witch (a|A) is 1
// ASCII code & 0x20 -> Foce lower case // ASCII code & 0x20 -> Foce lower case
@ -25,7 +25,7 @@ func (sequence *BioSequence) ReverseComplement(inplace bool) *BioSequence {
if sequence.HasQualities() { if sequence.HasQualities() {
s := sequence.qualities s := sequence.qualities
for i, j := sequence.Length()-1, 0; i >= j; i-- { for i, j := sequence.Len()-1, 0; i >= j; i-- {
s[j], s[i] = s[i], s[j] s[j], s[i] = s[i], s[j]
j++ j++
} }
@ -49,7 +49,7 @@ func (sequence *BioSequence) _revcmpMutation() *BioSequence {
return string(b) return string(b)
} }
lseq := sequence.Length() lseq := sequence.Len()
mut, ok := sequence.GetIntMap("pairing_mismatches") mut, ok := sequence.GetIntMap("pairing_mismatches")
if ok && len(mut) > 0 { if ok && len(mut) > 0 {

View File

@ -13,11 +13,11 @@ func (sequence *BioSequence) Subsequence(from, to int, circular bool) (*BioSeque
return nil, errors.New("from greater than to") return nil, errors.New("from greater than to")
} }
if from < 0 || from >= sequence.Length() { if from < 0 || from >= sequence.Len() {
return nil, errors.New("from out of bounds") return nil, errors.New("from out of bounds")
} }
if to <= 0 || to > sequence.Length() { if to <= 0 || to > sequence.Len() {
return nil, errors.New("to out of bounds") return nil, errors.New("to out of bounds")
} }
@ -34,7 +34,7 @@ func (sequence *BioSequence) Subsequence(from, to int, circular bool) (*BioSeque
newSeq.id = fmt.Sprintf("%s_sub[%d..%d]", sequence.Id(), from+1, to) newSeq.id = fmt.Sprintf("%s_sub[%d..%d]", sequence.Id(), from+1, to)
newSeq.definition = sequence.definition newSeq.definition = sequence.definition
} else { } else {
newSeq, _ = sequence.Subsequence(from, sequence.Length(), false) newSeq, _ = sequence.Subsequence(from, sequence.Len(), false)
newSeq.Write(sequence.Sequence()[0:to]) newSeq.Write(sequence.Sequence()[0:to])
if sequence.HasQualities() { if sequence.HasQualities() {
@ -52,7 +52,7 @@ func (sequence *BioSequence) Subsequence(from, to int, circular bool) (*BioSeque
func (sequence *BioSequence) _subseqMutation(shift int) *BioSequence { func (sequence *BioSequence) _subseqMutation(shift int) *BioSequence {
lseq := sequence.Length() lseq := sequence.Len()
mut, ok := sequence.GetIntMap("pairing_mismatches") mut, ok := sequence.GetIntMap("pairing_mismatches")
if ok && len(mut) > 0 { if ok && len(mut) > 0 {

View File

@ -36,7 +36,7 @@ func (taxonomy *Taxonomy) Index() *map[string]*TaxonSet {
return &(taxonomy.index) return &(taxonomy.index)
} }
func (taxonomy *Taxonomy) Length() int { func (taxonomy *Taxonomy) Len() int {
return len(*taxonomy.nodes) return len(*taxonomy.nodes)
} }

View File

@ -6,7 +6,7 @@ func (set *TaxonSet) Get(i int) *TaxNode {
return (*set)[i] return (*set)[i]
} }
func (set *TaxonSet) Length() int { func (set *TaxonSet) Len() int {
return len(*set) return len(*set)
} }

View File

@ -6,6 +6,6 @@ func (set *TaxonSlice) Get(i int) *TaxNode {
return (*set)[i] return (*set)[i]
} }
func (set *TaxonSlice) Length() int { func (set *TaxonSlice) Len() int {
return len(*set) return len(*set)
} }

View File

@ -386,7 +386,7 @@ func extendSimilarityGraph(seqs *[]*seqPCR, step int, workers int) int {
ff := func() { ff := func() {
var matrix []uint64 var matrix []uint64
for i := range lineChan { for i := range lineChan {
linePairs(&matrix, i) linePairs(&matrix, i)
} }
@ -463,7 +463,7 @@ func EstimateRatio(samples map[string]*[]*seqPCR, minStatRatio int) [][]Ratio {
for _, edge := range seq.Edges { for _, edge := range seq.Edges {
father := (*seqs)[edge.Father] father := (*seqs)[edge.Father]
if father.Weight >= minStatRatio && edge.Dist == 1 { if father.Weight >= minStatRatio && edge.Dist == 1 {
ratio[edge.NucPair] = append(ratio[edge.NucPair], Ratio{name, father.Weight, seq.Weight, father.Count, seq.Count, edge.Pos, father.Sequence.Length()}) ratio[edge.NucPair] = append(ratio[edge.NucPair], Ratio{name, father.Weight, seq.Weight, father.Count, seq.Count, edge.Pos, father.Sequence.Len()})
} }
} }

View File

@ -63,9 +63,9 @@ func TaxonAsString(taxon *obitax.TaxNode, pattern string) string {
fmt.Printf("%+v", err) fmt.Printf("%+v", err)
} }
bf.WriteString(path.Get(path.Length() - 1).ScientificName()) bf.WriteString(path.Get(path.Len() - 1).ScientificName())
for i := path.Length() - 2; i >= 0; i-- { for i := path.Len() - 2; i >= 0; i-- {
fmt.Fprintf(&bf, ":%s", path.Get(i).ScientificName()) fmt.Fprintf(&bf, ":%s", path.Get(i).ScientificName())
} }

View File

@ -1,11 +1,12 @@
package obipairing package obipairing
import ( import (
log "github.com/sirupsen/logrus"
"math" "math"
"os" "os"
"runtime" "runtime"
log "github.com/sirupsen/logrus"
"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/obiseq" "git.metabarcoding.org/lecasofts/go/obitools/pkg/obiseq"
@ -25,7 +26,7 @@ func _Abs(x int) int {
// if both sequences have quality scores, a quality of 0 is associated // if both sequences have quality scores, a quality of 0 is associated
// to the added dots. // to the added dots.
// //
// Parameters // # Parameters
// //
// - seqA, seqB: the pair of sequences to align. // - seqA, seqB: the pair of sequences to align.
// //
@ -33,7 +34,7 @@ func _Abs(x int) int {
// destroyed during the assembling process and cannot be reuse later on. // destroyed during the assembling process and cannot be reuse later on.
// the gap and delta parametters. // the gap and delta parametters.
// //
// Returns // # Returns
// //
// An obiseq.BioSequence corresponding to the pasting of the both // An obiseq.BioSequence corresponding to the pasting of the both
// input sequences. // input sequences.
@ -41,14 +42,15 @@ func _Abs(x int) int {
// Examples: // Examples:
// //
// . // .
// seqA := obiseq.BioSequence("A","cgatgcta","Sequence A") //
// seqB := obiseq.BioSequence("B","aatcgtacga","Sequence B") // seqA := obiseq.BioSequence("A","cgatgcta","Sequence A")
// seqC := obipairing.JoinPairedSequence(seqA, seqB, false) // seqB := obiseq.BioSequence("B","aatcgtacga","Sequence B")
// fmt.Println(seqC.String()) // seqC := obipairing.JoinPairedSequence(seqA, seqB, false)
// fmt.Println(seqC.String())
// //
// Outputs: // Outputs:
// cgatgcta..........aatcgtacga
// //
// cgatgcta..........aatcgtacga
func JoinPairedSequence(seqA, seqB *obiseq.BioSequence, inplace bool) *obiseq.BioSequence { func JoinPairedSequence(seqA, seqB *obiseq.BioSequence, inplace bool) *obiseq.BioSequence {
if !inplace { if !inplace {
@ -78,7 +80,7 @@ func JoinPairedSequence(seqA, seqB *obiseq.BioSequence, inplace bool) *obiseq.Bi
// a given length, it is discarded and booth sequences are only // a given length, it is discarded and booth sequences are only
// pasted using the obipairing.JoinPairedSequence function. // pasted using the obipairing.JoinPairedSequence function.
// //
// Parameters // # Parameters
// //
// - seqA, seqB: the pair of sequences to align. // - seqA, seqB: the pair of sequences to align.
// //
@ -99,25 +101,24 @@ func JoinPairedSequence(seqA, seqB *obiseq.BioSequence, inplace bool) *obiseq.Bi
// destroyed during the assembling process and cannot be reuse later on. // destroyed during the assembling process and cannot be reuse later on.
// the gap and delta parametters. // the gap and delta parametters.
// //
// Returns // # Returns
// //
// An obiseq.BioSequence corresponding to the assembling of the both // An obiseq.BioSequence corresponding to the assembling of the both
// input sequence. // input sequence.
//
func AssemblePESequences(seqA, seqB *obiseq.BioSequence, func AssemblePESequences(seqA, seqB *obiseq.BioSequence,
gap float64, delta, minOverlap int, minIdentity float64, withStats bool, gap float64, delta, minOverlap int, minIdentity float64, withStats bool,
inplace bool, inplace bool,
arenaAlign obialign.PEAlignArena) *obiseq.BioSequence { arenaAlign obialign.PEAlignArena) *obiseq.BioSequence {
score, path := obialign.PEAlign(seqA, seqB, gap, delta, arenaAlign) score, path := obialign.PEAlign(seqA, seqB, gap, delta, arenaAlign)
cons, match := obialign.BuildQualityConsensus(seqA, seqB, path,true) cons, match := obialign.BuildQualityConsensus(seqA, seqB, path, true)
left := path[0] left := path[0]
right := 0 right := 0
if path[len(path)-1] == 0 { if path[len(path)-1] == 0 {
right = path[len(path)-2] right = path[len(path)-2]
} }
lcons := cons.Length() lcons := cons.Len()
aliLength := lcons - _Abs(left) - _Abs(right) aliLength := lcons - _Abs(left) - _Abs(right)
identity := float64(match) / float64(aliLength) identity := float64(match) / float64(aliLength)
@ -176,7 +177,7 @@ func AssemblePESequences(seqA, seqB *obiseq.BioSequence,
// sequences are pasted together and a strech of ten dots is added at the // sequences are pasted together and a strech of ten dots is added at the
// juction of both the sequences. // juction of both the sequences.
// //
// Parameters // # Parameters
// //
// - iterator: is an iterator of paired sequences as produced by the method // - iterator: is an iterator of paired sequences as produced by the method
// IBioSequenceBatch.PairWith // IBioSequenceBatch.PairWith
@ -198,11 +199,10 @@ func AssemblePESequences(seqA, seqB *obiseq.BioSequence,
// The first one indicates how many parallel workers run for aligning the sequences. // The first one indicates how many parallel workers run for aligning the sequences.
// The second allows too specify the size of the channel buffer. // The second allows too specify the size of the channel buffer.
// //
// Returns // # Returns
// //
// The function returns an iterator over batches of obiseq.Biosequence object. // The function returns an iterator over batches of obiseq.Biosequence object.
// each pair of processed sequences produces one sequence in the result iterator. // each pair of processed sequences produces one sequence in the result iterator.
//
func IAssemblePESequencesBatch(iterator obiiter.IPairedBioSequenceBatch, func IAssemblePESequencesBatch(iterator obiiter.IPairedBioSequenceBatch,
gap float64, delta, minOverlap int, gap float64, delta, minOverlap int,
minIdentity float64, minIdentity float64,
@ -251,7 +251,7 @@ func IAssemblePESequencesBatch(iterator obiiter.IPairedBioSequenceBatch,
processed += 59 processed += 59
} }
} }
bar.Add(batch.Length() - processed) bar.Add(batch.Len() - processed)
newIter.Push(obiiter.MakeBioSequenceBatch( newIter.Push(obiiter.MakeBioSequenceBatch(
batch.Order(), batch.Order(),
cons, cons,

View File

@ -57,16 +57,16 @@ 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.Length(), ref.Length()) lmin, lmax := goutils.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.Length(), ref.Length()) maxe = goutils.MaxInt(sequence.Len(), ref.Len())
} }
// log.Println(sequence.Id(),cw[j], maxe) // log.Println(sequence.Id(),cw[j], maxe)
if runExact || (atMost <= (maxe + 1)) { if runExact || (atMost <= (maxe + 1)) {
lcs, alilength := obialign.FastLCSScore(sequence, ref, maxe+1,&matrix) lcs, alilength := obialign.FastLCSScore(sequence, ref, maxe+1, &matrix)
// lcs, alilength := obialign.LCSScore(sequence, ref, maxe+1, matrix) // lcs, alilength := obialign.LCSScore(sequence, ref, maxe+1, matrix)
n++ n++
if lcs == -1 { if lcs == -1 {