mirror of
https://github.com/metabarcoding/obitools4.git
synced 2025-06-29 16:20:46 +00:00
Rename the Length methods Len to follow GO standart
This commit is contained in:
@ -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
|
||||
}
|
||||
|
@ -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, ' ',
|
||||
|
@ -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 {
|
||||
|
@ -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 {
|
||||
|
@ -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
|
||||
|
@ -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,14 +290,11 @@ 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 {
|
||||
|
||||
@ -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
|
||||
|
@ -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]
|
||||
|
@ -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
|
||||
|
@ -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() {
|
||||
|
21
pkg/obieval/language.go
Normal file
21
pkg/obieval/language.go
Normal 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)
|
||||
}
|
@ -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 {
|
||||
|
@ -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)
|
||||
|
@ -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
|
||||
|
@ -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)
|
||||
}
|
||||
|
||||
|
@ -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()
|
||||
|
@ -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,7 +40,6 @@ 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...)
|
||||
|
@ -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)
|
||||
}
|
||||
|
||||
|
@ -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)
|
||||
}
|
||||
|
@ -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
|
||||
}
|
||||
|
||||
|
@ -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)
|
||||
}
|
||||
|
||||
|
@ -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,
|
||||
},
|
||||
)
|
||||
|
@ -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 {
|
||||
|
@ -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 {
|
||||
|
@ -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)
|
||||
}
|
||||
|
||||
|
@ -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)
|
||||
}
|
||||
|
||||
|
@ -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)
|
||||
}
|
||||
|
@ -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()})
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -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())
|
||||
}
|
||||
|
||||
|
@ -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())
|
||||
//
|
||||
// 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,11 +101,10 @@ 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,
|
||||
@ -117,7 +118,7 @@ func AssemblePESequences(seqA, seqB *obiseq.BioSequence,
|
||||
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,
|
||||
|
@ -57,11 +57,11 @@ 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)
|
||||
|
Reference in New Issue
Block a user