From 29563aa94e1e69b8bf38e6074e0d4a0bce4d0218 Mon Sep 17 00:00:00 2001 From: Eric Coissac Date: Thu, 17 Nov 2022 11:09:58 +0100 Subject: [PATCH] Rename the Length methods Len to follow GO standart --- pkg/goutils/goutils.go | 12 +++++++--- pkg/obialign/alignment.go | 12 +++++----- pkg/obialign/fastlcs.go | 6 ++--- pkg/obialign/fourbitsencode.go | 2 +- pkg/obialign/is_d0_or_d1.go | 4 ++-- pkg/obialign/pairedendalign.go | 25 +++++++++----------- pkg/obiapat/pattern.go | 14 +++++------ pkg/obiapat/pcr.go | 24 +++++++++---------- pkg/obichunk/subchunks.go | 10 ++++---- pkg/obieval/language.go | 21 +++++++++++++++++ pkg/obiformats/fastseq_read.go | 7 ------ pkg/obiformats/fastseq_write_fastq.go | 4 ++-- pkg/obiformats/ncbitaxdump/read.go | 5 ++-- pkg/obiiter/batch.go | 2 +- pkg/obiiter/batchiterator.go | 4 ++-- pkg/obiiter/merge.go | 7 +++--- pkg/obiiter/pairedbatchiterator.go | 6 ++--- pkg/obiiter/speed.go | 2 +- pkg/obikmer/encodefourmer.go | 5 ++-- pkg/obiseq/biosequence.go | 2 +- pkg/obiseq/predicate.go | 22 ++++------------- pkg/obiseq/revcomp.go | 6 ++--- pkg/obiseq/subseq.go | 8 +++---- pkg/obitax/taxonomy.go | 2 +- pkg/obitax/taxonset.go | 2 +- pkg/obitax/taxonslice.go | 2 +- pkg/obitools/obiclean/graph.go | 4 ++-- pkg/obitools/obifind/iterator.go | 4 ++-- pkg/obitools/obipairing/pairing.go | 34 +++++++++++++-------------- pkg/obitools/obitag/obitag.go | 6 ++--- 30 files changed, 134 insertions(+), 130 deletions(-) create mode 100644 pkg/obieval/language.go diff --git a/pkg/goutils/goutils.go b/pkg/goutils/goutils.go index 0237ba3..58ac343 100644 --- a/pkg/goutils/goutils.go +++ b/pkg/goutils/goutils.go @@ -269,14 +269,20 @@ func IsASlice(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 - if HasLength(value) { + + if IsAMap(value) || IsAnArray(value) || IsASlice(value) { vc := reflect.ValueOf(value) l = vc.Len() } + if vc, ok := value.(interface{ Len() int }); ok { + l = vc.Len() + } + return l } diff --git a/pkg/obialign/alignment.go b/pkg/obialign/alignment.go index 13b6714..c43dd00 100644 --- a/pkg/obialign/alignment.go +++ b/pkg/obialign/alignment.go @@ -73,10 +73,10 @@ func _BuildAlignment(seqA, seqB []byte, path []int, gap byte, bufferA, bufferB * func BuildAlignment(seqA, seqB *obiseq.BioSequence, path []int, gap byte) (*obiseq.BioSequence, *obiseq.BioSequence) { - bufferSA := obiseq.GetSlice(seqA.Length()) + bufferSA := obiseq.GetSlice(seqA.Len()) defer obiseq.RecycleSlice(&bufferSA) - bufferSB := obiseq.GetSlice(seqB.Length()) + bufferSB := obiseq.GetSlice(seqB.Len()) defer obiseq.RecycleSlice(&bufferSB) _BuildAlignment(seqA.Sequence(), seqB.Sequence(), path, gap, @@ -117,12 +117,12 @@ func BuildAlignment(seqA, seqB *obiseq.BioSequence, // return. func BuildQualityConsensus(seqA, seqB *obiseq.BioSequence, path []int, statOnMismatch bool) (*obiseq.BioSequence, int) { - bufferSA := obiseq.GetSlice(seqA.Length()) - bufferSB := obiseq.GetSlice(seqB.Length()) + bufferSA := obiseq.GetSlice(seqA.Len()) + bufferSB := obiseq.GetSlice(seqB.Len()) defer obiseq.RecycleSlice(&bufferSB) - bufferQA := obiseq.GetSlice(seqA.Length()) - bufferQB := obiseq.GetSlice(seqB.Length()) + bufferQA := obiseq.GetSlice(seqA.Len()) + bufferQB := obiseq.GetSlice(seqB.Len()) defer obiseq.RecycleSlice(&bufferQB) _BuildAlignment(seqA.Sequence(), seqB.Sequence(), path, ' ', diff --git a/pkg/obialign/fastlcs.go b/pkg/obialign/fastlcs.go index e9d41b8..6bbad17 100644 --- a/pkg/obialign/fastlcs.go +++ b/pkg/obialign/fastlcs.go @@ -60,8 +60,8 @@ var _notavail = encodeValues(0, 30000, false) func FastLCSScore(seqA, seqB *obiseq.BioSequence, maxError int, buffer *[]uint64) (int, int) { - lA := seqA.Length() - lB := seqB.Length() + lA := seqA.Len() + lB := seqB.Len() // Ensure that A is the longest if lA < lB { @@ -70,7 +70,7 @@ func FastLCSScore(seqA, seqB *obiseq.BioSequence, maxError int, buffer *[]uint64 } if maxError == -1 { - maxError = lA*2 + maxError = lA * 2 } delta := lA - lB diff --git a/pkg/obialign/fourbitsencode.go b/pkg/obialign/fourbitsencode.go index d65d1c0..07df30a 100644 --- a/pkg/obialign/fourbitsencode.go +++ b/pkg/obialign/fourbitsencode.go @@ -58,7 +58,7 @@ var _FourBitsBaseDecode = []byte{ // A byte slice can be provided (buffer) to preveent allocation of a new // memory chunk by th function. func Encode4bits(seq *obiseq.BioSequence, buffer []byte) []byte { - length := seq.Length() + length := seq.Len() rawseq := seq.Sequence() if buffer == nil { diff --git a/pkg/obialign/is_d0_or_d1.go b/pkg/obialign/is_d0_or_d1.go index 0ecfcde..96553dd 100644 --- a/pkg/obialign/is_d0_or_d1.go +++ b/pkg/obialign/is_d0_or_d1.go @@ -14,8 +14,8 @@ func D1Or0(seq1, seq2 *obiseq.BioSequence) (int, int, byte, byte) { pos := -1 - l1 := seq1.Length() - l2 := seq2.Length() + l1 := seq1.Len() + l2 := seq2.Len() if abs(l1-l2) > 1 { return -1, pos, 0, 0 diff --git a/pkg/obialign/pairedendalign.go b/pkg/obialign/pairedendalign.go index 1ae870b..821c30b 100644 --- a/pkg/obialign/pairedendalign.go +++ b/pkg/obialign/pairedendalign.go @@ -229,7 +229,7 @@ func PELeftAlign(seqA, seqB *obiseq.BioSequence, gap float64, } if arena.pointer == nil { - arena = MakePEAlignArena(seqA.Length(), seqB.Length()) + arena = MakePEAlignArena(seqA.Len(), seqB.Len()) } score := _FillMatrixPeLeftAlign(seqA.Sequence(), seqA.Qualities(), @@ -238,7 +238,7 @@ func PELeftAlign(seqA, seqB *obiseq.BioSequence, gap float64, &arena.pointer.pathMatrix) arena.pointer.path = _Backtracking(arena.pointer.pathMatrix, - seqA.Length(), seqB.Length(), + seqA.Len(), seqB.Len(), &arena.pointer.path) return score, arena.pointer.path @@ -253,7 +253,7 @@ func PERightAlign(seqA, seqB *obiseq.BioSequence, gap float64, } if arena.pointer == nil { - arena = MakePEAlignArena(seqA.Length(), seqB.Length()) + arena = MakePEAlignArena(seqA.Len(), seqB.Len()) } score := _FillMatrixPeRightAlign(seqA.Sequence(), seqA.Qualities(), @@ -262,7 +262,7 @@ func PERightAlign(seqA, seqB *obiseq.BioSequence, gap float64, &arena.pointer.pathMatrix) arena.pointer.path = _Backtracking(arena.pointer.pathMatrix, - seqA.Length(), seqB.Length(), + seqA.Len(), seqB.Len(), &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) if shift > 0 { - over = seqA.Length() - shift + over = seqA.Len() - shift } 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 { // At least one mismatch exists in the overlaping region @@ -315,7 +312,7 @@ func PEAlign(seqA, seqB *obiseq.BioSequence, partLen = len(rawSeqA) rawSeqB = seqB.Sequence()[0:partLen] qualSeqB = seqB.Qualities()[0:partLen] - extra3 = seqB.Length() - partLen + extra3 = seqB.Len() - partLen score = _FillMatrixPeLeftAlign( rawSeqA, qualSeqA, rawSeqB, qualSeqB, gap, &arena.pointer.scoreMatrix, @@ -335,7 +332,7 @@ func PEAlign(seqA, seqB *obiseq.BioSequence, partLen = len(rawSeqB) rawSeqA = seqA.Sequence()[:partLen] qualSeqA = seqA.Qualities()[:partLen] - extra3 = partLen - seqA.Length() + extra3 = partLen - seqA.Len() score = _FillMatrixPeRightAlign( rawSeqA, qualSeqA, rawSeqB, qualSeqB, gap, &arena.pointer.scoreMatrix, @@ -354,7 +351,7 @@ func PEAlign(seqA, seqB *obiseq.BioSequence, qualSeqA = seqA.Qualities()[startA:] partLen = len(qualSeqA) qualSeqB = seqB.Qualities()[0:partLen] - extra3 = seqB.Length() - partLen + extra3 = seqB.Len() - partLen score = 0 } else { startA = 0 @@ -362,7 +359,7 @@ func PEAlign(seqA, seqB *obiseq.BioSequence, extra5 = startB qualSeqB = seqB.Qualities()[startB:] partLen = len(qualSeqB) - extra3 = partLen - seqA.Length() + extra3 = partLen - seqA.Len() qualSeqA = seqA.Qualities()[:partLen] } score = 0 diff --git a/pkg/obiapat/pattern.go b/pkg/obiapat/pattern.go index 15bd08a..703b73e 100644 --- a/pkg/obiapat/pattern.go +++ b/pkg/obiapat/pattern.go @@ -119,8 +119,8 @@ func (pattern ApatPattern) String() string { return C.GoString(pattern.pointer.pointer.cpat) } -// Length method returns the length of the matched pattern. -func (pattern ApatPattern) Length() int { +// Len method returns the length of the matched pattern. +func (pattern ApatPattern) Len() int { 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 errmsg *C.char var p unsafe.Pointer - seqlen := sequence.Length() + seqlen := sequence.Len() ic := 0 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 cBuf := (*[1 << 31]byte)(p) 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), (*C.Seq)(out), @@ -240,8 +240,8 @@ func MakeApatSequence(sequence *obiseq.BioSequence, circular bool, recycle ...Ap return ApatSequence{recycle[0].pointer}, nil } -// Length method returns the length of the ApatSequence. -func (sequence ApatSequence) Length() int { +// Len method returns the length of the ApatSequence. +func (sequence ApatSequence) Len() int { 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. func (pattern ApatPattern) FindAllIndex(sequence ApatSequence, limits ...int) (loc [][3]int) { begin := 0 - length := sequence.Length() + length := sequence.Len() if len(limits) > 0 { begin = limits[0] diff --git a/pkg/obiapat/pcr.go b/pkg/obiapat/pcr.go index b6b498e..8239a9d 100644 --- a/pkg/obiapat/pcr.go +++ b/pkg/obiapat/pcr.go @@ -234,15 +234,15 @@ func _Pcr(seq ApatSequence, if len(forwardMatches) > 0 { begin := forwardMatches[0][0] - length := seq.Length() - begin + length := seq.Len() - begin 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() { begin = 0 - length = seq.Length() + _MaxPatLen + length = seq.Len() + _MaxPatLen } reverseMatches := crev.FindAllIndex(seq, begin, length) @@ -252,13 +252,13 @@ func _Pcr(seq ApatSequence, posi := fm[0] - if posi < seq.Length() { + if posi < seq.Len() { erri := fm[2] for _, rm := range reverseMatches { posj := rm[0] - if posj < seq.Length() { + if posj < seq.Len() { posj := rm[1] errj := rm[2] length = 0 @@ -267,7 +267,7 @@ func _Pcr(seq ApatSequence, length = rm[0] - fm[1] } else { 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 @@ -307,15 +307,15 @@ func _Pcr(seq ApatSequence, if forwardMatches != nil { begin := forwardMatches[0][0] - length := seq.Length() - begin + length := seq.Len() - begin 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() { begin = 0 - length = seq.Length() + _MaxPatLen + length = seq.Len() + _MaxPatLen } reverseMatches := cfwd.FindAllIndex(seq, begin, length) @@ -325,13 +325,13 @@ func _Pcr(seq ApatSequence, posi := fm[0] - if posi < seq.Length() { + if posi < seq.Len() { erri := fm[2] for _, rm := range reverseMatches { posj := rm[0] - if posj < seq.Length() { + if posj < seq.Len() { posj := rm[1] errj := rm[2] length = 0 @@ -340,7 +340,7 @@ func _Pcr(seq ApatSequence, length = rm[0] - fm[1] } else { 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 diff --git a/pkg/obichunk/subchunks.go b/pkg/obichunk/subchunks.go index dc40edf..e0a393d 100644 --- a/pkg/obichunk/subchunks.go +++ b/pkg/obichunk/subchunks.go @@ -97,14 +97,14 @@ func ISequenceSubChunk(iterator obiiter.IBioSequenceBatch, batch := iterator.Get() - if batch.Length() > 1 { + if batch.Len() > 1 { classifier.Reset() - if cap(ordered) < batch.Length() { - log.Debugln("Allocate a new ordered sequences : ", batch.Length()) - ordered = make([]sSS, batch.Length()) + if cap(ordered) < batch.Len() { + log.Debugln("Allocate a new ordered sequences : ", batch.Len()) + ordered = make([]sSS, batch.Len()) } else { - ordered = ordered[:batch.Length()] + ordered = ordered[:batch.Len()] } for i, s := range batch.Slice() { diff --git a/pkg/obieval/language.go b/pkg/obieval/language.go new file mode 100644 index 0000000..6494a7a --- /dev/null +++ b/pkg/obieval/language.go @@ -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) +} diff --git a/pkg/obiformats/fastseq_read.go b/pkg/obiformats/fastseq_read.go index 05c9380..8bf31fc 100644 --- a/pkg/obiformats/fastseq_read.go +++ b/pkg/obiformats/fastseq_read.go @@ -65,19 +65,12 @@ func _FastseqReader(seqfile C.fast_kseq_p, slice = append(slice, rep) ii++ if ii >= batch_size { - //log.Printf("\n==> Pushing sequence batch\n") - // start := time.Now() - iterator.Push(obiiter.MakeBioSequenceBatch(i, slice)) - // elapsed := time.Since(start) - // log.Printf("\n==>sequences pushed after %s\n", elapsed) - slice = obiseq.MakeBioSequenceSlice() i++ ii = 0 } - // log.Println("longueur : ",l,rep.Length()) } if len(slice) > 0 { diff --git a/pkg/obiformats/fastseq_write_fastq.go b/pkg/obiformats/fastseq_write_fastq.go index 845636e..5a5b452 100644 --- a/pkg/obiformats/fastseq_write_fastq.go +++ b/pkg/obiformats/fastseq_write_fastq.go @@ -15,9 +15,9 @@ import ( func FormatFastq(seq *obiseq.BioSequence, quality_shift int, formater FormatHeader) string { - l := seq.Length() + l := seq.Len() q := seq.Qualities() - ascii := make([]byte, seq.Length()) + ascii := make([]byte, seq.Len()) for j := 0; j < l; j++ { ascii[j] = uint8(q[j]) + uint8(quality_shift) diff --git a/pkg/obiformats/ncbitaxdump/read.go b/pkg/obiformats/ncbitaxdump/read.go index a6c5d46..9e0cd9c 100644 --- a/pkg/obiformats/ncbitaxdump/read.go +++ b/pkg/obiformats/ncbitaxdump/read.go @@ -5,12 +5,13 @@ import ( "encoding/csv" "fmt" "io" - log "github.com/sirupsen/logrus" "os" "path" "strconv" "strings" + log "github.com/sirupsen/logrus" + "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) 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 diff --git a/pkg/obiiter/batch.go b/pkg/obiiter/batch.go index 014a6df..47b7b82 100644 --- a/pkg/obiiter/batch.go +++ b/pkg/obiiter/batch.go @@ -31,7 +31,7 @@ func (batch BioSequenceBatch) Slice() obiseq.BioSequenceSlice { return batch.slice } -func (batch BioSequenceBatch) Length() int { +func (batch BioSequenceBatch) Len() int { return len(batch.slice) } diff --git a/pkg/obiiter/batchiterator.go b/pkg/obiiter/batchiterator.go index 6f39d61..3f0b55e 100644 --- a/pkg/obiiter/batchiterator.go +++ b/pkg/obiiter/batchiterator.go @@ -218,7 +218,7 @@ func (iterator IBioSequenceBatch) Push(batch BioSequenceBatch) { if batch.IsNil() { 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") } @@ -453,7 +453,7 @@ func (iterator IBioSequenceBatch) Count(recycle bool) (int, int, int) { for _, seq := range batch.Slice() { variants++ reads += seq.Count() - nucleotides += seq.Length() + nucleotides += seq.Len() if recycle { seq.Recycle() diff --git a/pkg/obiiter/merge.go b/pkg/obiiter/merge.go index 1e91104..06311db 100644 --- a/pkg/obiiter/merge.go +++ b/pkg/obiiter/merge.go @@ -30,7 +30,7 @@ func (iterator IBioSequenceBatch) IMergeSequenceBatch(na string, statsOn []strin seqs := iterator.Get() batch.slice = append(batch.slice, seqs.slice.Merge(na, statsOn)) } - if batch.Length() > 0 { + if batch.Len() > 0 { newIter.Push(batch) } } @@ -40,11 +40,10 @@ func (iterator IBioSequenceBatch) IMergeSequenceBatch(na string, statsOn []strin return newIter } - func MergePipe(na string, statsOn []string, sizes ...int) Pipeable { f := func(iterator IBioSequenceBatch) IBioSequenceBatch { - return iterator.IMergeSequenceBatch(na,statsOn,sizes...) + return iterator.IMergeSequenceBatch(na, statsOn, sizes...) } return f -} \ No newline at end of file +} diff --git a/pkg/obiiter/pairedbatchiterator.go b/pkg/obiiter/pairedbatchiterator.go index 4a9fbc7..0b851bc 100644 --- a/pkg/obiiter/pairedbatchiterator.go +++ b/pkg/obiiter/pairedbatchiterator.go @@ -1,9 +1,10 @@ package obiiter import ( - log "github.com/sirupsen/logrus" "sync" + log "github.com/sirupsen/logrus" + "git.metabarcoding.org/lecasofts/go/obitools/pkg/obiseq" ) @@ -41,8 +42,7 @@ func (batch PairedBioSequenceBatch) Reorder(newOrder int) PairedBioSequenceBatch return batch } - -func (batch PairedBioSequenceBatch) Length() int { +func (batch PairedBioSequenceBatch) Len() int { return len(batch.forward) } diff --git a/pkg/obiiter/speed.go b/pkg/obiiter/speed.go index a00a428..6625797 100644 --- a/pkg/obiiter/speed.go +++ b/pkg/obiiter/speed.go @@ -39,7 +39,7 @@ func (iterator IBioSequenceBatch) Speed(message ...string) IBioSequenceBatch { for iterator.Next() { batch := iterator.Get() - l := batch.Length() + l := batch.Len() newIter.Push(batch) bar.Add(l) } diff --git a/pkg/obikmer/encodefourmer.go b/pkg/obikmer/encodefourmer.go index b2db7e1..2954ac8 100644 --- a/pkg/obikmer/encodefourmer.go +++ b/pkg/obikmer/encodefourmer.go @@ -31,7 +31,7 @@ var __single_base_code__ = []byte{0, // the slice is used to store the result, overwise a new slice is // created. func Encode4mer(seq *obiseq.BioSequence, buffer *[]byte) []byte { - slength := seq.Length() + slength := seq.Len() length := slength - 3 rawseq := seq.Sequence() @@ -101,7 +101,7 @@ func FastShiftFourMer(index [][]int, seq *obiseq.BioSequence, buffer *[]byte) (i 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 _, refpos := range index[code] { @@ -127,4 +127,3 @@ func FastShiftFourMer(index [][]int, seq *obiseq.BioSequence, buffer *[]byte) (i return maxshift, maxcount } - diff --git a/pkg/obiseq/biosequence.go b/pkg/obiseq/biosequence.go index 4d66d78..756ce60 100644 --- a/pkg/obiseq/biosequence.go +++ b/pkg/obiseq/biosequence.go @@ -162,7 +162,7 @@ func (s *BioSequence) String() string { } // Returning the length of the sequence. -func (s *BioSequence) Length() int { +func (s *BioSequence) Len() int { return len(s.sequence) } diff --git a/pkg/obiseq/predicate.go b/pkg/obiseq/predicate.go index 7832c4d..37d2557 100644 --- a/pkg/obiseq/predicate.go +++ b/pkg/obiseq/predicate.go @@ -5,10 +5,8 @@ import ( "fmt" "regexp" - "git.metabarcoding.org/lecasofts/go/obitools/pkg/goutils" + "git.metabarcoding.org/lecasofts/go/obitools/pkg/obieval" log "github.com/sirupsen/logrus" - - "github.com/PaesslerAG/gval" ) type SequencePredicate func(*BioSequence) bool @@ -130,7 +128,7 @@ func IsLessAbundantOrEqualTo(count int) SequencePredicate { func IsLongerOrEqualTo(length int) SequencePredicate { f := func(sequence *BioSequence) bool { - return sequence.Length() >= length + return sequence.Len() >= length } return f @@ -138,7 +136,7 @@ func IsLongerOrEqualTo(length int) SequencePredicate { func IsShorterOrEqualTo(length int) SequencePredicate { f := func(sequence *BioSequence) bool { - return sequence.Length() <= length + return sequence.Len() <= length } return f @@ -203,17 +201,7 @@ func IsIdIn(ids ...string) SequencePredicate { func ExpressionPredicat(expression string) SequencePredicate { - lang := gval.NewLanguage( - 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) + exp, err := obieval.OBILang.NewEvaluable(expression) if err != nil { log.Fatalf("Error in the expression : %s", expression) } @@ -223,7 +211,7 @@ func ExpressionPredicat(expression string) SequencePredicate { map[string]interface{}{ "annot": sequence.Annotations(), "count": sequence.Count(), - "seqlength": sequence.Length(), + "seqlength": sequence.Len(), "sequence": sequence, }, ) diff --git a/pkg/obiseq/revcomp.go b/pkg/obiseq/revcomp.go index 190d1c0..ec65488 100644 --- a/pkg/obiseq/revcomp.go +++ b/pkg/obiseq/revcomp.go @@ -13,7 +13,7 @@ func (sequence *BioSequence) ReverseComplement(inplace bool) *BioSequence { 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 & 0x20 -> Foce lower case @@ -25,7 +25,7 @@ func (sequence *BioSequence) ReverseComplement(inplace bool) *BioSequence { if sequence.HasQualities() { 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] j++ } @@ -49,7 +49,7 @@ func (sequence *BioSequence) _revcmpMutation() *BioSequence { return string(b) } - lseq := sequence.Length() + lseq := sequence.Len() mut, ok := sequence.GetIntMap("pairing_mismatches") if ok && len(mut) > 0 { diff --git a/pkg/obiseq/subseq.go b/pkg/obiseq/subseq.go index 4ba1265..6cc5778 100644 --- a/pkg/obiseq/subseq.go +++ b/pkg/obiseq/subseq.go @@ -13,11 +13,11 @@ func (sequence *BioSequence) Subsequence(from, to int, circular bool) (*BioSeque 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") } - if to <= 0 || to > sequence.Length() { + if to <= 0 || to > sequence.Len() { 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.definition = sequence.definition } else { - newSeq, _ = sequence.Subsequence(from, sequence.Length(), false) + newSeq, _ = sequence.Subsequence(from, sequence.Len(), false) newSeq.Write(sequence.Sequence()[0:to]) if sequence.HasQualities() { @@ -52,7 +52,7 @@ func (sequence *BioSequence) Subsequence(from, to int, circular bool) (*BioSeque func (sequence *BioSequence) _subseqMutation(shift int) *BioSequence { - lseq := sequence.Length() + lseq := sequence.Len() mut, ok := sequence.GetIntMap("pairing_mismatches") if ok && len(mut) > 0 { diff --git a/pkg/obitax/taxonomy.go b/pkg/obitax/taxonomy.go index aca5289..4d4ee65 100644 --- a/pkg/obitax/taxonomy.go +++ b/pkg/obitax/taxonomy.go @@ -36,7 +36,7 @@ func (taxonomy *Taxonomy) Index() *map[string]*TaxonSet { return &(taxonomy.index) } -func (taxonomy *Taxonomy) Length() int { +func (taxonomy *Taxonomy) Len() int { return len(*taxonomy.nodes) } diff --git a/pkg/obitax/taxonset.go b/pkg/obitax/taxonset.go index ef61a4e..7aae346 100644 --- a/pkg/obitax/taxonset.go +++ b/pkg/obitax/taxonset.go @@ -6,7 +6,7 @@ func (set *TaxonSet) Get(i int) *TaxNode { return (*set)[i] } -func (set *TaxonSet) Length() int { +func (set *TaxonSet) Len() int { return len(*set) } diff --git a/pkg/obitax/taxonslice.go b/pkg/obitax/taxonslice.go index 92164e5..b7bc082 100644 --- a/pkg/obitax/taxonslice.go +++ b/pkg/obitax/taxonslice.go @@ -6,6 +6,6 @@ func (set *TaxonSlice) Get(i int) *TaxNode { return (*set)[i] } -func (set *TaxonSlice) Length() int { +func (set *TaxonSlice) Len() int { return len(*set) } diff --git a/pkg/obitools/obiclean/graph.go b/pkg/obitools/obiclean/graph.go index 4a7576a..ae579e7 100644 --- a/pkg/obitools/obiclean/graph.go +++ b/pkg/obitools/obiclean/graph.go @@ -386,7 +386,7 @@ func extendSimilarityGraph(seqs *[]*seqPCR, step int, workers int) int { ff := func() { var matrix []uint64 - + for i := range lineChan { linePairs(&matrix, i) } @@ -463,7 +463,7 @@ func EstimateRatio(samples map[string]*[]*seqPCR, minStatRatio int) [][]Ratio { for _, edge := range seq.Edges { father := (*seqs)[edge.Father] 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()}) } } diff --git a/pkg/obitools/obifind/iterator.go b/pkg/obitools/obifind/iterator.go index bdbd9cc..0b995b3 100644 --- a/pkg/obitools/obifind/iterator.go +++ b/pkg/obitools/obifind/iterator.go @@ -63,9 +63,9 @@ func TaxonAsString(taxon *obitax.TaxNode, pattern string) string { 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()) } diff --git a/pkg/obitools/obipairing/pairing.go b/pkg/obitools/obipairing/pairing.go index aad96f7..73146f8 100644 --- a/pkg/obitools/obipairing/pairing.go +++ b/pkg/obitools/obipairing/pairing.go @@ -1,11 +1,12 @@ package obipairing import ( - log "github.com/sirupsen/logrus" "math" "os" "runtime" + log "github.com/sirupsen/logrus" + "git.metabarcoding.org/lecasofts/go/obitools/pkg/obialign" "git.metabarcoding.org/lecasofts/go/obitools/pkg/obiiter" "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 // to the added dots. // -// Parameters +// # Parameters // // - 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. // the gap and delta parametters. // -// Returns +// # Returns // // An obiseq.BioSequence corresponding to the pasting of the both // input sequences. @@ -41,14 +42,15 @@ func _Abs(x int) int { // Examples: // // . -// seqA := obiseq.BioSequence("A","cgatgcta","Sequence A") -// seqB := obiseq.BioSequence("B","aatcgtacga","Sequence B") -// seqC := obipairing.JoinPairedSequence(seqA, seqB, false) -// fmt.Println(seqC.String()) +// +// seqA := obiseq.BioSequence("A","cgatgcta","Sequence A") +// seqB := obiseq.BioSequence("B","aatcgtacga","Sequence B") +// seqC := obipairing.JoinPairedSequence(seqA, seqB, false) +// fmt.Println(seqC.String()) // // Outputs: -// cgatgcta..........aatcgtacga // +// cgatgcta..........aatcgtacga func JoinPairedSequence(seqA, seqB *obiseq.BioSequence, inplace bool) *obiseq.BioSequence { 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 // pasted using the obipairing.JoinPairedSequence function. // -// Parameters +// # Parameters // // - 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. // the gap and delta parametters. // -// Returns +// # Returns // // An obiseq.BioSequence corresponding to the assembling of the both // input sequence. -// func AssemblePESequences(seqA, seqB *obiseq.BioSequence, gap float64, delta, minOverlap int, minIdentity float64, withStats bool, inplace bool, arenaAlign obialign.PEAlignArena) *obiseq.BioSequence { 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] right := 0 if path[len(path)-1] == 0 { right = path[len(path)-2] } - lcons := cons.Length() + lcons := cons.Len() aliLength := lcons - _Abs(left) - _Abs(right) 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 // juction of both the sequences. // -// Parameters +// # Parameters // // - iterator: is an iterator of paired sequences as produced by the method // 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 second allows too specify the size of the channel buffer. // -// Returns +// # Returns // // The function returns an iterator over batches of obiseq.Biosequence object. // each pair of processed sequences produces one sequence in the result iterator. -// func IAssemblePESequencesBatch(iterator obiiter.IPairedBioSequenceBatch, gap float64, delta, minOverlap int, minIdentity float64, @@ -251,7 +251,7 @@ func IAssemblePESequencesBatch(iterator obiiter.IPairedBioSequenceBatch, processed += 59 } } - bar.Add(batch.Length() - processed) + bar.Add(batch.Len() - processed) newIter.Push(obiiter.MakeBioSequenceBatch( batch.Order(), cons, diff --git a/pkg/obitools/obitag/obitag.go b/pkg/obitools/obitag/obitag.go index adcca21..9111bf1 100644 --- a/pkg/obitools/obitag/obitag.go +++ b/pkg/obitools/obitag/obitag.go @@ -57,16 +57,16 @@ func FindClosests(sequence *obiseq.BioSequence, for i, j := range o { 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 if i == 0 { - maxe = goutils.MaxInt(sequence.Length(), ref.Length()) + maxe = goutils.MaxInt(sequence.Len(), ref.Len()) } // log.Println(sequence.Id(),cw[j], maxe) 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) n++ if lcs == -1 {