diff --git a/cmd/obitools/obicomplement/main.go b/cmd/obitools/obicomplement/main.go index bced10c..8742486 100644 --- a/cmd/obitools/obicomplement/main.go +++ b/cmd/obitools/obicomplement/main.go @@ -14,7 +14,7 @@ func main() { optionParser := obioptions.GenerateOptionParser( "obicomplement", "reverse complement of sequences", - obiconvert.OptionSet) + obiconvert.OptionSet(true)) _, args := optionParser(os.Args) diff --git a/cmd/obitools/obiconvert/main.go b/cmd/obitools/obiconvert/main.go index 6a40ecc..38e9550 100644 --- a/cmd/obitools/obiconvert/main.go +++ b/cmd/obitools/obiconvert/main.go @@ -17,7 +17,7 @@ func main() { optionParser := obioptions.GenerateOptionParser( "obiconvert", "convertion of sequence files to various formats", - obiconvert.OptionSet) + obiconvert.OptionSet(true)) _, args := optionParser(os.Args) diff --git a/pkg/obialign/alignment.go b/pkg/obialign/alignment.go index ed5a392..2cd39e1 100644 --- a/pkg/obialign/alignment.go +++ b/pkg/obialign/alignment.go @@ -169,7 +169,7 @@ func BuildQualityConsensus(seqA, seqB *obiseq.BioSequence, path []int, statOnMis right = len(*bufferQA) - right - // log.Warnf("BuildQualityConsensus: left = %d right = %d\n", left, right) + // obilog.Warnf("BuildQualityConsensus: left = %d right = %d\n", left, right) for i, qA = range *bufferQA { nA := (*bufferSA)[i] diff --git a/pkg/obialign/dnamatrix.go b/pkg/obialign/dnamatrix.go index b82b453..5505135 100644 --- a/pkg/obialign/dnamatrix.go +++ b/pkg/obialign/dnamatrix.go @@ -117,7 +117,7 @@ func _MatchScoreRatio(QF, QR byte) (float64, float64) { term1 := _Logaddexp(qF, qR) term2 := _Logdiffexp(term1, qF+qR) - // log.Warnf("MatchScoreRatio: %v, %v , %v, %v", QF, QR, term1, term2) + // obilog.Warnf("MatchScoreRatio: %v, %v , %v, %v", QF, QR, term1, term2) match_logp := _Log1mexp(term2 + l3 - l4) match_score := match_logp - _Log1mexp(match_logp) diff --git a/pkg/obialign/locatepattern.go b/pkg/obialign/locatepattern.go index 2a8f1de..23b5538 100644 --- a/pkg/obialign/locatepattern.go +++ b/pkg/obialign/locatepattern.go @@ -152,7 +152,7 @@ func LocatePattern(id string, pattern, sequence []byte) (int, int, int) { } - // log.Warnf("from : %d to: %d error: %d match: %v", + // obilog.Warnf("from : %d to: %d error: %d match: %v", // i, end+1, -buffer[buffIndex(len(sequence)-1, len(pattern)-1, width)], // string(sequence[i:(end+1)])) return i, end + 1, -buffer[buffIndex(len(sequence)-1, len(pattern)-1, width)] diff --git a/pkg/obialign/readalign.go b/pkg/obialign/readalign.go index 4c1136a..d31021c 100644 --- a/pkg/obialign/readalign.go +++ b/pkg/obialign/readalign.go @@ -53,10 +53,10 @@ func ReadAlign(seqA, seqB *obiseq.BioSequence, over = min(seqA.Len(), seqB.Len()) } - // log.Warnf("fw/fw: %v shift=%d fastCount=%d/over=%d fastScore=%f", + // obilog.Warnf("fw/fw: %v shift=%d fastCount=%d/over=%d fastScore=%f", // directAlignment, shift, fastCount, over, fastScore) - // log.Warnf(("seqA: %s\nseqB: %s\n"), seqA.String(), seqB.String()) + // obilog.Warnf(("seqA: %s\nseqB: %s\n"), seqA.String(), seqB.String()) // At least one mismatch exists in the overlaping region if fastCount+3 < over { diff --git a/pkg/obiapat/pattern.go b/pkg/obiapat/pattern.go index 2edbac8..d48b0db 100644 --- a/pkg/obiapat/pattern.go +++ b/pkg/obiapat/pattern.go @@ -410,8 +410,8 @@ func (pattern ApatPattern) FilterBestMatch(sequence ApatSequence, begin, length best := [3]int{0, 0, 10000} for _, m := range res { - // log.Warnf("Current : Begin : %d End : %d Err : %d", m[0], m[1], m[2]) - // log.Warnf("Best : Begin : %d End : %d Err : %d", best[0], best[1], best[2]) + // obilog.Warnf("Current : Begin : %d End : %d Err : %d", m[0], m[1], m[2]) + // obilog.Warnf("Best : Begin : %d End : %d Err : %d", best[0], best[1], best[2]) if (m[0] - m[2]) < best[1]+best[2] { // match are overlapping // log.Warnln("overlap") @@ -467,7 +467,7 @@ func (pattern ApatPattern) AllMatches(sequence ApatSequence, begin, length int) // Recompute the start and end position of the match // when the pattern allows for indels if m[2] > 0 && pattern.pointer.pointer.hasIndel { - // log.Warnf("Locating indel on sequence %s[%s]", sequence.pointer.reference.Id(), pattern.String()) + // obilog.Warnf("Locating indel on sequence %s[%s]", sequence.pointer.reference.Id(), pattern.String()) start := m[0] - m[2]*2 start = max(start, 0) end := start + int(pattern.pointer.pointer.patlen) + 4*m[2] @@ -489,7 +489,7 @@ func (pattern ApatPattern) AllMatches(sequence ApatSequence, begin, length int) m[0] = start + pb m[1] = start + pe - // log.Warnf("seq[%d@%d:%d] %d: %s %d - %s:%s:%s", i, m[0], m[1], olderr, sequence.pointer.reference.Id(), score, + // obilog.Warnf("seq[%d@%d:%d] %d: %s %d - %s:%s:%s", i, m[0], m[1], olderr, sequence.pointer.reference.Id(), score, // frg, (*cpattern)[0:int(pattern.pointer.pointer.patlen)], sequence.pointer.reference.Sequence()[m[0]:m[1]]) } diff --git a/pkg/obidefault/logger.go b/pkg/obidefault/logger.go new file mode 100644 index 0000000..0d8a256 --- /dev/null +++ b/pkg/obidefault/logger.go @@ -0,0 +1,11 @@ +package obidefault + +var __silent_warning__ = false + +func SilentWarning() bool { + return __silent_warning__ +} + +func SilentWarningPtr() *bool { + return &__silent_warning__ +} diff --git a/pkg/obiformats/fastaseq_read.go b/pkg/obiformats/fastaseq_read.go index 2a8114e..a2fc3be 100644 --- a/pkg/obiformats/fastaseq_read.go +++ b/pkg/obiformats/fastaseq_read.go @@ -213,7 +213,7 @@ func _ParseFastaFile( for chunks := range input { sequences, err := parser(chunks.Source, chunks.Raw) - // log.Warnf("Chunck(%d:%d) -%d- ", chunks.Order, l, sequences.Len()) + // obilog.Warnf("Chunck(%d:%d) -%d- ", chunks.Order, l, sequences.Len()) if err != nil { log.Fatalf("File %s : Cannot parse the fasta file : %v", chunks.Source, err) diff --git a/pkg/obiformats/fastqseq_read.go b/pkg/obiformats/fastqseq_read.go index cab6a5f..f7f79fb 100644 --- a/pkg/obiformats/fastqseq_read.go +++ b/pkg/obiformats/fastqseq_read.go @@ -17,7 +17,7 @@ import ( func EndOfLastFastqEntry(buffer []byte) int { var i int - // log.Warnf("EndOfLastFastqEntry(%d): %s", len(buffer), string(buffer[0:20])) + // obilog.Warnf("EndOfLastFastqEntry(%d): %s", len(buffer), string(buffer[0:20])) imax := len(buffer) state := 0 restart := imax - 1 @@ -74,7 +74,7 @@ func EndOfLastFastqEntry(buffer []byte) int { state = 3 } else { // it was not the sequence part - // log.Warnf("it was not the sequence part : %c", C) + // obilog.Warnf("it was not the sequence part : %c", C) state = 0 i = restart } @@ -101,7 +101,7 @@ func EndOfLastFastqEntry(buffer []byte) int { // log.Warn("====> End of the last sequence") state = 7 } else { - // log.Warnf("%s: Strange it was not the end of the last sequence : %c : %s", string(buffer[0:40]), C, string(buffer[i-20:i+5])) + // obilog.Warnf("%s: Strange it was not the end of the last sequence : %c : %s", string(buffer[0:40]), C, string(buffer[i-20:i+5])) state = 5 } } diff --git a/pkg/obiformats/fastseq_write_fasta.go b/pkg/obiformats/fastseq_write_fasta.go index 7aa71fb..9934ad8 100644 --- a/pkg/obiformats/fastseq_write_fasta.go +++ b/pkg/obiformats/fastseq_write_fasta.go @@ -12,6 +12,7 @@ import ( log "github.com/sirupsen/logrus" "git.metabarcoding.org/obitools/obitools4/obitools4/pkg/obiiter" + "git.metabarcoding.org/obitools/obitools4/obitools4/pkg/obilog" "git.metabarcoding.org/obitools/obitools4/obitools4/pkg/obiseq" "git.metabarcoding.org/obitools/obitools4/obitools4/pkg/obiutils" ) @@ -106,7 +107,7 @@ func FormatFastaBatch(batch obiiter.BioSequenceBatch, formater FormatHeader, ski // Handle empty sequences if skipEmpty { // Skip empty sequences if skipEmpty is true - log.Warnf("Sequence %s is empty and skipped in output", seq.Id()) + obilog.Warnf("Sequence %s is empty and skipped in output", seq.Id()) } else { // Terminate the program if skipEmpty is false log.Fatalf("Sequence %s is empty", seq.Id()) diff --git a/pkg/obiformats/fastseq_write_fastq.go b/pkg/obiformats/fastseq_write_fastq.go index 08e47f6..845993a 100644 --- a/pkg/obiformats/fastseq_write_fastq.go +++ b/pkg/obiformats/fastseq_write_fastq.go @@ -9,6 +9,7 @@ import ( log "github.com/sirupsen/logrus" "git.metabarcoding.org/obitools/obitools4/obitools4/pkg/obiiter" + "git.metabarcoding.org/obitools/obitools4/obitools4/pkg/obilog" "git.metabarcoding.org/obitools/obitools4/obitools4/pkg/obiseq" "git.metabarcoding.org/obitools/obitools4/obitools4/pkg/obiutils" ) @@ -75,7 +76,7 @@ func FormatFastqBatch(batch obiiter.BioSequenceBatch, } else { if skipEmpty { - log.Warnf("Sequence %s is empty and skiped in output", seq.Id()) + obilog.Warnf("Sequence %s is empty and skiped in output", seq.Id()) } else { log.Fatalf("Sequence %s is empty", seq.Id()) } diff --git a/pkg/obiformats/file_chunk_read.go b/pkg/obiformats/file_chunk_read.go index b42b883..20c8c22 100644 --- a/pkg/obiformats/file_chunk_read.go +++ b/pkg/obiformats/file_chunk_read.go @@ -172,7 +172,7 @@ func ReadFileChunk( } else { end = -1 } - // log.Warnf("Splitter not found, attempting %d to read in %d B increments : len(buff) = %d/%d", ic, fileChunkSize, len(extbuff), len(buff)) + // obilog.Warnf("Splitter not found, attempting %d to read in %d B increments : len(buff) = %d/%d", ic, fileChunkSize, len(extbuff), len(buff)) } pieces = pieces.Head().Pack() @@ -204,7 +204,7 @@ func ReadFileChunk( } if len(pieces.data) > 0 { - // log.Warnf("chuck %d :Read %d bytes from file %s", i, io.Len(), source) + // obilog.Warnf("chuck %d :Read %d bytes from file %s", i, io.Len(), source) chunk_channel <- pieces.FileChunk(source, i) i++ } diff --git a/pkg/obiformats/ngsfilter_read.go b/pkg/obiformats/ngsfilter_read.go index 7eb2c55..fb409ce 100644 --- a/pkg/obiformats/ngsfilter_read.go +++ b/pkg/obiformats/ngsfilter_read.go @@ -13,6 +13,7 @@ import ( log "github.com/sirupsen/logrus" + "git.metabarcoding.org/obitools/obitools4/obitools4/pkg/obilog" "git.metabarcoding.org/obitools/obitools4/obitools4/pkg/obingslibrary" "git.metabarcoding.org/obitools/obitools4/obitools4/pkg/obiseq" "git.metabarcoding.org/obitools/obitools4/obitools4/pkg/obiutils" @@ -663,7 +664,7 @@ func ReadCSVNGSFilter(reader io.Reader) (*obingslibrary.NGSLibrary, error) { if ok { setparam(&ngsfilter, data...) } else { - log.Warnf("At line %d: Skipping unknown parameter %s: %v", i, param, data) + obilog.Warnf("At line %d: Skipping unknown parameter %s: %v", i, param, data) } } diff --git a/pkg/obifp/uint128.go b/pkg/obifp/uint128.go index 2c62928..b66d2b8 100644 --- a/pkg/obifp/uint128.go +++ b/pkg/obifp/uint128.go @@ -4,6 +4,7 @@ import ( "math" "math/bits" + "git.metabarcoding.org/obitools/obitools4/obitools4/pkg/obilog" log "github.com/sirupsen/logrus" ) @@ -46,7 +47,7 @@ func (u Uint128) IsZero() bool { // Returns a Uint64 value. func (u Uint128) Uint64() Uint64 { if u.w1 != 0 { - log.Warnf("Uint128 overflow at Uint64(%v)", u) + obilog.Warnf("Uint128 overflow at Uint64(%v)", u) } return Uint64{w0: u.w0} } diff --git a/pkg/obifp/uint256.go b/pkg/obifp/uint256.go index c685d4d..527a895 100644 --- a/pkg/obifp/uint256.go +++ b/pkg/obifp/uint256.go @@ -4,6 +4,7 @@ import ( "math" "math/bits" + "git.metabarcoding.org/obitools/obitools4/obitools4/pkg/obilog" log "github.com/sirupsen/logrus" ) @@ -51,7 +52,7 @@ func (u Uint256) IsZero() bool { // Returns a Uint64 value. func (u Uint256) Uint64() Uint64 { if u.w3 != 0 || u.w2 != 0 || u.w1 != 0 { - log.Warnf("Uint256 overflow at Uint64(%v)", u) + obilog.Warnf("Uint256 overflow at Uint64(%v)", u) } return Uint64{w0: u.w0} } @@ -64,7 +65,7 @@ func (u Uint256) Uint64() Uint64 { // Returns a Uint128 value. func (u Uint256) Uint128() Uint128 { if u.w3 != 0 || u.w2 != 0 { - log.Warnf("Uint256 overflow at Uint128(%v)", u) + obilog.Warnf("Uint256 overflow at Uint128(%v)", u) } return Uint128{u.w1, u.w0} } diff --git a/pkg/obifp/uint64.go b/pkg/obifp/uint64.go index fd46624..1c298fe 100644 --- a/pkg/obifp/uint64.go +++ b/pkg/obifp/uint64.go @@ -4,6 +4,7 @@ import ( "math" "math/bits" + "git.metabarcoding.org/obitools/obitools4/obitools4/pkg/obilog" log "github.com/sirupsen/logrus" ) @@ -100,7 +101,7 @@ func (u Uint64) LeftShift64(n uint, carryIn uint64) (value, carry uint64) { } - log.Warnf("Uint64 overflow at LeftShift64(%v, %v)", u, n) + obilog.Warnf("Uint64 overflow at LeftShift64(%v, %v)", u, n) return 0, 0 } @@ -129,7 +130,7 @@ func (u Uint64) RightShift64(n uint, carryIn uint64) (value, carry uint64) { return carryIn, u.w0 >> (n - 64) } - log.Warnf("Uint64 overflow at RightShift64(%v, %v)", u, n) + obilog.Warnf("Uint64 overflow at RightShift64(%v, %v)", u, n) return 0, 0 } diff --git a/pkg/obiiter/limitmemory.go b/pkg/obiiter/limitmemory.go index 6a10212..4092a98 100644 --- a/pkg/obiiter/limitmemory.go +++ b/pkg/obiiter/limitmemory.go @@ -3,8 +3,8 @@ package obiiter import ( "runtime" + "git.metabarcoding.org/obitools/obitools4/obitools4/pkg/obilog" "github.com/pbnjay/memory" - log "github.com/sirupsen/logrus" ) func (iterator IBioSequence) LimitMemory(fraction float64) IBioSequence { @@ -25,11 +25,11 @@ func (iterator IBioSequence) LimitMemory(fraction float64) IBioSequence { runtime.Gosched() nwait++ if nwait%1000 == 0 { - log.Warnf("Wait for memory limit %f/%f", fracLoad(), fraction) + obilog.Warnf("Wait for memory limit %f/%f", fracLoad(), fraction) } if nwait > 10000 { - log.Warnf("Very long wait for memory limit %f/%f", fracLoad(), fraction) + obilog.Warnf("Very long wait for memory limit %f/%f", fracLoad(), fraction) break } } diff --git a/pkg/obikmer/kmermap.go b/pkg/obikmer/kmermap.go index f154683..8ab2752 100644 --- a/pkg/obikmer/kmermap.go +++ b/pkg/obikmer/kmermap.go @@ -6,9 +6,9 @@ import ( "unsafe" "git.metabarcoding.org/obitools/obitools4/obitools4/pkg/obifp" + "git.metabarcoding.org/obitools/obitools4/obitools4/pkg/obilog" "git.metabarcoding.org/obitools/obitools4/obitools4/pkg/obiseq" "github.com/schollz/progressbar/v3" - log "github.com/sirupsen/logrus" ) type KmerMap[T obifp.FPUint[T]] struct { @@ -226,12 +226,12 @@ func NewKmerMap[T obifp.FPUint[T]]( sparseAt := -1 if sparse && kmersize%2 == 0 { - log.Warnf("Kmer size must be odd when using sparse mode") + obilog.Warnf("Kmer size must be odd when using sparse mode") kmersize++ } if !sparse && kmersize%2 == 1 { - log.Warnf("Kmer size must be even when not using sparse mode") + obilog.Warnf("Kmer size must be even when not using sparse mode") kmersize-- } diff --git a/pkg/obilog/warning.go b/pkg/obilog/warning.go new file mode 100644 index 0000000..0575cb7 --- /dev/null +++ b/pkg/obilog/warning.go @@ -0,0 +1,12 @@ +package obilog + +import ( + "git.metabarcoding.org/obitools/obitools4/obitools4/pkg/obidefault" + "github.com/sirupsen/logrus" +) + +func Warnf(format string, args ...interface{}) { + if !obidefault.SilentWarning() { + logrus.Warnf(format, args...) + } +} diff --git a/pkg/obilua/lua.go b/pkg/obilua/lua.go index f39d1fa..017c902 100644 --- a/pkg/obilua/lua.go +++ b/pkg/obilua/lua.go @@ -8,6 +8,7 @@ import ( "git.metabarcoding.org/obitools/obitools4/obitools4/pkg/obidefault" "git.metabarcoding.org/obitools/obitools4/obitools4/pkg/obiiter" + "git.metabarcoding.org/obitools/obitools4/obitools4/pkg/obilog" "git.metabarcoding.org/obitools/obitools4/obitools4/pkg/obiseq" log "github.com/sirupsen/logrus" lua "github.com/yuin/gopher-lua" @@ -230,7 +231,7 @@ func LuaProcessor(iterator obiiter.IBioSequence, name, program string, breakOnEr if breakOnError { log.Fatalf("Error during Lua sequence processing : %v", err) } else { - log.Warnf("Error during Lua sequence processing : %v", err) + obilog.Warnf("Error during Lua sequence processing : %v", err) } } diff --git a/pkg/obingslibrary/multimatch.go b/pkg/obingslibrary/multimatch.go index 017c946..cbd6ebf 100644 --- a/pkg/obingslibrary/multimatch.go +++ b/pkg/obingslibrary/multimatch.go @@ -87,7 +87,7 @@ func lookForTag(seq string, delimiter byte) string { i := len(seq) - 1 - // log.Warnf("Provided fragment : %s", string(seq)) + // obilog.Warnf("Provided fragment : %s", string(seq)) for i >= 0 && seq[i] != delimiter { i-- @@ -109,7 +109,7 @@ func lookForTag(seq string, delimiter byte) string { return "" } - // log.Warnf("extracted : %s", string(seq[begin:end])) + // obilog.Warnf("extracted : %s", string(seq[begin:end])) return seq[begin:end] } @@ -340,8 +340,8 @@ func (marker *Marker) beginTagExtractor( sequence *obiseq.BioSequence, begin int, forward bool) string { - // log.Warnf("Forward : %v -> %d %c", forward, marker.Forward_spacer, marker.Forward_tag_delimiter) - // log.Warnf("Forward : %v -> %d %c", forward, marker.Reverse_spacer, marker.Reverse_tag_delimiter) + // obilog.Warnf("Forward : %v -> %d %c", forward, marker.Forward_spacer, marker.Forward_tag_delimiter) + // obilog.Warnf("Forward : %v -> %d %c", forward, marker.Reverse_spacer, marker.Reverse_tag_delimiter) if forward { if marker.Forward_tag_length == 0 { return "" @@ -351,10 +351,10 @@ func (marker *Marker) beginTagExtractor( return marker.beginFixedTagExtractor(sequence, begin, forward) } else { if marker.Forward_tag_indels == 0 { - // log.Warnf("Delimited tag for forward primers %s", marker.forward.String()) + // obilog.Warnf("Delimited tag for forward primers %s", marker.forward.String()) return marker.beginDelimitedTagExtractor(sequence, begin, forward) } else { - // log.Warnf("Rescue tag for forward primers %s", marker.forward.String()) + // obilog.Warnf("Rescue tag for forward primers %s", marker.forward.String()) return marker.beginRescueTagExtractor(sequence, begin, forward) } } @@ -367,10 +367,10 @@ func (marker *Marker) beginTagExtractor( return marker.beginFixedTagExtractor(sequence, begin, forward) } else { if marker.Reverse_tag_indels == 0 { - // log.Warnf("Delimited tag for reverse/complement primers %s", marker.creverse.String()) + // obilog.Warnf("Delimited tag for reverse/complement primers %s", marker.creverse.String()) return marker.beginDelimitedTagExtractor(sequence, begin, forward) } else { - // log.Warnf("Rescue tag for reverse/complement primers %s", marker.creverse.String()) + // obilog.Warnf("Rescue tag for reverse/complement primers %s", marker.creverse.String()) return marker.beginRescueTagExtractor(sequence, begin, forward) } } @@ -390,10 +390,10 @@ func (marker *Marker) endTagExtractor( return marker.endFixedTagExtractor(sequence, end, forward) } else { if marker.Reverse_tag_indels == 0 { - // log.Warnf("Delimited tag for reverse primers %s", marker.reverse.String()) + // obilog.Warnf("Delimited tag for reverse primers %s", marker.reverse.String()) return marker.endDelimitedTagExtractor(sequence, end, forward) } else { - // log.Warnf("Rescue tag for reverse primers %s", marker.reverse.String()) + // obilog.Warnf("Rescue tag for reverse primers %s", marker.reverse.String()) return marker.endRescueTagExtractor(sequence, end, forward) } } @@ -406,10 +406,10 @@ func (marker *Marker) endTagExtractor( return marker.endFixedTagExtractor(sequence, end, forward) } else { if marker.Forward_tag_indels == 0 { - // log.Warnf("Delimited tag for forward/complement primers %s", marker.cforward.String()) + // obilog.Warnf("Delimited tag for forward/complement primers %s", marker.cforward.String()) return marker.endDelimitedTagExtractor(sequence, end, forward) } else { - // log.Warnf("Rescue tag for forward/complement primers %s", marker.cforward.String()) + // obilog.Warnf("Rescue tag for forward/complement primers %s", marker.cforward.String()) return marker.endRescueTagExtractor(sequence, end, forward) } } diff --git a/pkg/obioptions/options.go b/pkg/obioptions/options.go index 7e6f126..77d4886 100644 --- a/pkg/obioptions/options.go +++ b/pkg/obioptions/options.go @@ -73,6 +73,11 @@ func GenerateOptionParser(program string, options.GetEnv("OBISOLEXA"), options.Description("Decodes quality string according to the Solexa specification.")) + options.BoolVar(obidefault.SilentWarningPtr(), "silent-warning", obidefault.SilentWarning(), + options.GetEnv("OBIWARNING"), + options.Description("Stop printing of the warning message"), + ) + for _, o := range optionset { o(options) } diff --git a/pkg/obioptions/version.go b/pkg/obioptions/version.go index 4c56538..e5ddddc 100644 --- a/pkg/obioptions/version.go +++ b/pkg/obioptions/version.go @@ -8,7 +8,7 @@ import ( // corresponds to the last commit, and not the one when the file will be // commited -var _Commit = "8b379d3" +var _Commit = "2ab6f67" var _Version = "Release 4.4.0" // Version returns the version of the obitools package. diff --git a/pkg/obiseq/attributes.go b/pkg/obiseq/attributes.go index b3bea02..8a9ebc9 100644 --- a/pkg/obiseq/attributes.go +++ b/pkg/obiseq/attributes.go @@ -4,6 +4,7 @@ import ( "fmt" "strconv" + "git.metabarcoding.org/obitools/obitools4/obitools4/pkg/obilog" "git.metabarcoding.org/obitools/obitools4/obitools4/pkg/obiutils" log "github.com/sirupsen/logrus" ) @@ -136,7 +137,12 @@ func (s *BioSequence) SetAttribute(key string, value interface{}) { } if key == "sequence" { - s.SetSequence(value.([]byte)) + data, err := obiutils.InterfaceToString(value) + if err != nil { + obilog.Warnf("%s: cannot convert value %v to sequence", s.Id(), value) + return + } + s.SetSequence([]byte(data)) return } diff --git a/pkg/obiseq/biosequence.go b/pkg/obiseq/biosequence.go index 1864f29..628f52c 100644 --- a/pkg/obiseq/biosequence.go +++ b/pkg/obiseq/biosequence.go @@ -444,6 +444,15 @@ func (s *BioSequence) SetSequence(sequence []byte) { s.sequence = obiutils.InPlaceToLower(CopySlice(sequence)) } +func (s *BioSequence) HasValidSequence() bool { + for _, c := range s.sequence { + if !((c >= 'a' && c <= 'z') || c == '-' || c == '.' || c == '[' || c == ']') { + return false + } + } + return true +} + // Setting the qualities of the BioSequence. func (s *BioSequence) SetQualities(qualities Quality) { if s.qualities != nil { diff --git a/pkg/obiseq/biosequenceslice.go b/pkg/obiseq/biosequenceslice.go index 7ba22b0..ca666b2 100644 --- a/pkg/obiseq/biosequenceslice.go +++ b/pkg/obiseq/biosequenceslice.go @@ -1,6 +1,7 @@ package obiseq import ( + "git.metabarcoding.org/obitools/obitools4/obitools4/pkg/obilog" "git.metabarcoding.org/obitools/obitools4/obitools4/pkg/obitax" "git.metabarcoding.org/obitools/obitools4/obitools4/pkg/obiutils" log "github.com/sirupsen/logrus" @@ -61,7 +62,7 @@ func (s *BioSequenceSlice) EnsureCapacity(capacity int) *BioSequenceSlice { if c < capacity { n++ if n < 4 { - log.Warnf("cannot allocate a Biosequence Slice of size %d (only %d from %d)", capacity, c, old_c) + obilog.Warnf("cannot allocate a Biosequence Slice of size %d (only %d from %d)", capacity, c, old_c) } else { log.Panicf("cannot allocate a Biosequence Slice of size %d (only %d from %d)", capacity, c, old_c) } diff --git a/pkg/obiseq/predicate.go b/pkg/obiseq/predicate.go index 3d492eb..1258f2b 100644 --- a/pkg/obiseq/predicate.go +++ b/pkg/obiseq/predicate.go @@ -5,6 +5,7 @@ import ( "fmt" "regexp" + "git.metabarcoding.org/obitools/obitools4/obitools4/pkg/obilog" log "github.com/sirupsen/logrus" ) @@ -278,9 +279,10 @@ func ExpressionPredicat(expression string) SequencePredicate { ) if err != nil { - log.Fatalf("Expression '%s' cannot be evaluated on sequence %s", + obilog.Warnf("Expression '%s' cannot be evaluated on sequence %s", expression, sequence.Id()) + return false } return value diff --git a/pkg/obiseq/taxonomy_methods.go b/pkg/obiseq/taxonomy_methods.go index 91bace3..5d0c639 100644 --- a/pkg/obiseq/taxonomy_methods.go +++ b/pkg/obiseq/taxonomy_methods.go @@ -6,6 +6,7 @@ import ( log "github.com/sirupsen/logrus" "git.metabarcoding.org/obitools/obitools4/obitools4/pkg/obidefault" + "git.metabarcoding.org/obitools/obitools4/obitools4/pkg/obilog" "git.metabarcoding.org/obitools/obitools4/obitools4/pkg/obitax" "git.metabarcoding.org/obitools/obitools4/obitools4/pkg/obiutils" ) @@ -41,7 +42,7 @@ func (s *BioSequence) SetTaxid(taxid string, rank ...string) { taxon, isAlias, err = taxonomy.Taxon(taxid) if err != nil { - logger := log.Warnf + logger := obilog.Warnf if obidefault.FailOnTaxonomy() { logger = log.Fatalf } @@ -51,7 +52,7 @@ func (s *BioSequence) SetTaxid(taxid string, rank ...string) { if isAlias { if obidefault.UpdateTaxid() { - log.Warnf("%s: Taxid: %v is updated to %s", + obilog.Warnf("%s: Taxid: %v is updated to %s", s.Id(), taxid, taxon.String()) taxid = taxon.String() } else { @@ -59,7 +60,7 @@ func (s *BioSequence) SetTaxid(taxid string, rank ...string) { log.Fatalf("%s: Taxid: %v is an alias from taxonomy (%v) to %s", s.Id(), taxid, taxonomy.Name(), taxon.String()) } - log.Warnf("%s: Taxid %v has to be updated to %s", + obilog.Warnf("%s: Taxid %v has to be updated to %s", s.Id(), taxid, taxon.String()) } diff --git a/pkg/obiseq/taxonomy_predicate.go b/pkg/obiseq/taxonomy_predicate.go index 54c2e72..f8e9ede 100644 --- a/pkg/obiseq/taxonomy_predicate.go +++ b/pkg/obiseq/taxonomy_predicate.go @@ -3,6 +3,7 @@ package obiseq import ( log "github.com/sirupsen/logrus" + "git.metabarcoding.org/obitools/obitools4/obitools4/pkg/obilog" "git.metabarcoding.org/obitools/obitools4/obitools4/pkg/obitax" "git.metabarcoding.org/obitools/obitools4/obitools4/pkg/obiutils" ) @@ -66,7 +67,7 @@ func IsSubCladeOfSlot(taxonomy *obitax.Taxonomy, key string) SequencePredicate { parent, _, err := taxonomy.Taxon(val) if err != nil { - log.Warnf("%s: %s is unkown from the taxonomy (%v)", sequence.Id(), val, err) + obilog.Warnf("%s: %s is unkown from the taxonomy (%v)", sequence.Id(), val, err) } taxon := sequence.Taxon(taxonomy) diff --git a/pkg/obiseq/worker.go b/pkg/obiseq/worker.go index 4c0c04a..3202bcc 100644 --- a/pkg/obiseq/worker.go +++ b/pkg/obiseq/worker.go @@ -4,7 +4,7 @@ import ( "fmt" "slices" - log "github.com/sirupsen/logrus" + "git.metabarcoding.org/obitools/obitools4/obitools4/pkg/obilog" ) type SeqAnnotator func(*BioSequence) @@ -119,7 +119,7 @@ func SeqToSliceWorker(worker SeqWorker, s.Id(), err) return BioSequenceSlice{}, err } else { - log.Warnf("got an error on sequence %s processing : %v", + obilog.Warnf("got an error on sequence %s processing : %v", s.Id(), err) } } @@ -208,7 +208,7 @@ func SeqToSliceConditionalWorker( s.Id(), err) return BioSequenceSlice{}, err } else { - log.Warnf("got an error on sequence %s processing : %v", + obilog.Warnf("got an error on sequence %s processing : %v", s.Id(), err) } } diff --git a/pkg/obistats/kmeans.go b/pkg/obistats/kmeans.go index b4a8eeb..067e0c0 100644 --- a/pkg/obistats/kmeans.go +++ b/pkg/obistats/kmeans.go @@ -8,6 +8,7 @@ import ( "golang.org/x/exp/rand" "gonum.org/v1/gonum/stat/sampleuv" + "git.metabarcoding.org/obitools/obitools4/obitools4/pkg/obilog" "git.metabarcoding.org/obitools/obitools4/obitools4/pkg/obiutils" log "github.com/sirupsen/logrus" ) @@ -280,7 +281,7 @@ func (clustering *KmeansClustering) AssignToClass() { nreset := clustering.ResetEmptyCenters() if nreset > 0 { - log.Warnf("Reseted %d empty centers", nreset) + obilog.Warnf("Reseted %d empty centers", nreset) } } diff --git a/pkg/obitax/taxid.go b/pkg/obitax/taxid.go index 549163c..f22ec4d 100644 --- a/pkg/obitax/taxid.go +++ b/pkg/obitax/taxid.go @@ -35,7 +35,7 @@ func (f *TaxidFactory) FromString(taxid string) (Taxid, error) { if len(part2) == 0 { taxid = part1 } else { - //log.Warnf("TaxidFactory.FromString: taxid %s -> -%s- -%s- ", taxid, part1, part2) + //obilog.Warnf("TaxidFactory.FromString: taxid %s -> -%s- -%s- ", taxid, part1, part2) if part1 != f.code { return nil, fmt.Errorf("taxid %s string does not start with taxonomy code %s", taxid, f.code) } diff --git a/pkg/obitools/obiannotate/obiannotate.go b/pkg/obitools/obiannotate/obiannotate.go index 1d65125..9368aaa 100644 --- a/pkg/obitools/obiannotate/obiannotate.go +++ b/pkg/obitools/obiannotate/obiannotate.go @@ -322,7 +322,7 @@ func CLIAnnotationWorker() obiseq.SeqWorker { if CLIHasCut() { from, to := CLICut() - w := CutSequenceWorker(from, to, false) + w := CutSequenceWorker(from, to, true) annotator = annotator.ChainWorkers(w) } diff --git a/pkg/obitools/obiannotate/options.go b/pkg/obitools/obiannotate/options.go index 071cdaa..b3c02c6 100644 --- a/pkg/obitools/obiannotate/options.go +++ b/pkg/obitools/obiannotate/options.go @@ -130,7 +130,7 @@ func SequenceAnnotationOptionSet(options *getoptions.GetOpt) { // OptionSet adds to the basic option set every options declared for // the obipcr command func OptionSet(options *getoptions.GetOpt) { - obiconvert.OptionSet(options) + obiconvert.OptionSet(false)(options) obigrep.SequenceSelectionOptionSet(options) SequenceAnnotationOptionSet(options) } diff --git a/pkg/obitools/obiclean/chimera.go b/pkg/obitools/obiclean/chimera.go index 270af1a..b13637a 100644 --- a/pkg/obitools/obiclean/chimera.go +++ b/pkg/obitools/obiclean/chimera.go @@ -53,7 +53,7 @@ func commonSuffix(a, b *obiseq.BioSequence) int { if obiutils.UnsafeString(as[i+1:]) != obiutils.UnsafeString(bs[j+1:]) { log.Fatalf("i: %d, j: %d (%s/%s)", i, j, as[i+1:], bs[j+1:]) } - // log.Warnf("i: %d, j: %d (%s)", i, j, as[i+1:]) + // obilog.Warnf("i: %d, j: %d (%s)", i, j, as[i+1:]) return l } diff --git a/pkg/obitools/obicleandb/obicleandb.go b/pkg/obitools/obicleandb/obicleandb.go index a9dd675..91e5776 100644 --- a/pkg/obitools/obicleandb/obicleandb.go +++ b/pkg/obitools/obicleandb/obicleandb.go @@ -113,10 +113,10 @@ func MakeSequenceFamilyGenusWorker(references obiseq.BioSequenceSlice) obiseq.Se } // level, _ := sequence.GetAttribute("obicleandb_level") - // log.Warnf("%s - level: %v", sequence.Id(), level) - // log.Warnf("%s - gdist: %v", sequence.Id(), indist) - // log.Warnf("%s - fdist: %v", sequence.Id(), outdist) - // log.Warnf("%s - pval: %f", sequence.Id(), pval) + // obilog.Warnf("%s - level: %v", sequence.Id(), level) + // obilog.Warnf("%s - gdist: %v", sequence.Id(), indist) + // obilog.Warnf("%s - fdist: %v", sequence.Id(), outdist) + // obilog.Warnf("%s - pval: %f", sequence.Id(), pval) } if pval < 0.0 { diff --git a/pkg/obitools/obiconvert/options.go b/pkg/obitools/obiconvert/options.go index 9b1a94d..47b0a98 100644 --- a/pkg/obitools/obiconvert/options.go +++ b/pkg/obitools/obiconvert/options.go @@ -126,11 +126,16 @@ func PairedFilesOptionSet(options *getoptions.GetOpt) { ) } -func OptionSet(options *getoptions.GetOpt) { - obioptions.LoadTaxonomyOptionSet(options, false, false) - InputOptionSet(options) - OutputOptionSet(options) - PairedFilesOptionSet(options) +func OptionSet(allow_paired bool) func(options *getoptions.GetOpt) { + f := func(options *getoptions.GetOpt) { + obioptions.LoadTaxonomyOptionSet(options, false, false) + InputOptionSet(options) + OutputOptionSet(options) + if allow_paired { + PairedFilesOptionSet(options) + } + } + return f } // Returns true if the number of reads described in the diff --git a/pkg/obitools/obidemerge/options.go b/pkg/obitools/obidemerge/options.go index 331a7d5..1fa1cdf 100644 --- a/pkg/obitools/obidemerge/options.go +++ b/pkg/obitools/obidemerge/options.go @@ -17,7 +17,7 @@ func DemergeOptionSet(options *getoptions.GetOpt) { // OptionSet adds to the basic option set every options declared for // the obipcr command func OptionSet(options *getoptions.GetOpt) { - obiconvert.OptionSet(options) + obiconvert.OptionSet(false)(options) DemergeOptionSet(options) } diff --git a/pkg/obitools/obigrep/options.go b/pkg/obitools/obigrep/options.go index 3bb6755..1b06e5a 100644 --- a/pkg/obitools/obigrep/options.go +++ b/pkg/obitools/obigrep/options.go @@ -166,7 +166,7 @@ func SequenceSelectionOptionSet(options *getoptions.GetOpt) { // OptionSet adds to the basic option set every options declared for // the obipcr command func OptionSet(options *getoptions.GetOpt) { - obiconvert.OptionSet(options) + obiconvert.OptionSet(true)(options) SequenceSelectionOptionSet(options) options.StringVar(&_SaveRejected, "save-discarded", _SaveRejected, diff --git a/pkg/obitools/obijoin/options.go b/pkg/obitools/obijoin/options.go index aab9aff..82f4de8 100644 --- a/pkg/obitools/obijoin/options.go +++ b/pkg/obitools/obijoin/options.go @@ -46,7 +46,7 @@ func JoinOptionSet(options *getoptions.GetOpt) { // OptionSet adds to the basic option set every options declared for // the obipcr command func OptionSet(options *getoptions.GetOpt) { - obiconvert.OptionSet(options) + obiconvert.OptionSet(false)(options) JoinOptionSet(options) } diff --git a/pkg/obitools/obikmersim/options.go b/pkg/obitools/obikmersim/options.go index cd40e1e..0c5dcf9 100644 --- a/pkg/obitools/obikmersim/options.go +++ b/pkg/obitools/obikmersim/options.go @@ -76,12 +76,12 @@ func KmerSimMatchOptionSet(options *getoptions.GetOpt) { } func CountOptionSet(options *getoptions.GetOpt) { - obiconvert.OptionSet(options) + obiconvert.OptionSet(false)(options) KmerSimCountOptionSet(options) } func MatchOptionSet(options *getoptions.GetOpt) { - obiconvert.OptionSet(options) + obiconvert.OptionSet(false)(options) KmerSimCountOptionSet(options) KmerSimMatchOptionSet(options) } diff --git a/pkg/obitools/obimicrosat/options.go b/pkg/obitools/obimicrosat/options.go index 5d22604..04fb465 100644 --- a/pkg/obitools/obimicrosat/options.go +++ b/pkg/obitools/obimicrosat/options.go @@ -49,7 +49,7 @@ func MicroSatelliteOptionSet(options *getoptions.GetOpt) { } func OptionSet(options *getoptions.GetOpt) { - obiconvert.OptionSet(options) + obiconvert.OptionSet(false)(options) MicroSatelliteOptionSet(options) } diff --git a/pkg/obitools/obimultiplex/options.go b/pkg/obitools/obimultiplex/options.go index b88c8ae..c48f8ff 100644 --- a/pkg/obitools/obimultiplex/options.go +++ b/pkg/obitools/obimultiplex/options.go @@ -54,7 +54,7 @@ func MultiplexOptionSet(options *getoptions.GetOpt) { } func OptionSet(options *getoptions.GetOpt) { - obiconvert.OptionSet(options) + obiconvert.OptionSet(false)(options) MultiplexOptionSet(options) } diff --git a/pkg/obitools/obipcr/options.go b/pkg/obitools/obipcr/options.go index bbf79e6..288b0b9 100644 --- a/pkg/obitools/obipcr/options.go +++ b/pkg/obitools/obipcr/options.go @@ -67,7 +67,7 @@ func PCROptionSet(options *getoptions.GetOpt) { // OptionSet adds to the basic option set every options declared for // the obipcr command func OptionSet(options *getoptions.GetOpt) { - obiconvert.OptionSet(options) + obiconvert.OptionSet(false)(options) PCROptionSet(options) } diff --git a/pkg/obitools/obirefidx/obirefidx.go b/pkg/obitools/obirefidx/obirefidx.go index 1ecca14..cc7cf6d 100644 --- a/pkg/obitools/obirefidx/obirefidx.go +++ b/pkg/obitools/obirefidx/obirefidx.go @@ -88,7 +88,7 @@ func IndexSequence(seqidx int, // Initialize a matrix to store alignment scores var matrix []uint64 - // log.Warnf("%s : %s", sequence.Id(), pseq.String()) + // obilog.Warnf("%s : %s", sequence.Id(), pseq.String()) for idx_path := 1; idx_path < path_len; idx_path++ { mini := -1 seqidcs := refs[pseq.Taxon(idx_path).Node] @@ -144,8 +144,8 @@ func IndexSequence(seqidx int, } if mini == 0 { - // log.Warnf("%s: %s", sequence.Id(), sequence.String()) - // log.Warnf("%s: %s", suject.Id(), suject.String()) + // obilog.Warnf("%s: %s", sequence.Id(), sequence.String()) + // obilog.Warnf("%s: %s", suject.Id(), suject.String()) break } } @@ -158,7 +158,7 @@ func IndexSequence(seqidx int, // insure than closest is strictly increasing for k := idx_path - 1; k >= 0 && mini < closest[k]; k-- { closest[k] = mini - // log.Warnf("(%s,%s) Smaller alignment found than previous (%d,%d). Resetting closest.", sequence.Id(), pseq.Taxon(idx_path).String(), mini, closest[k]) + // obilog.Warnf("(%s,%s) Smaller alignment found than previous (%d,%d). Resetting closest.", sequence.Id(), pseq.Taxon(idx_path).String(), mini, closest[k]) } } else { closest[idx_path] = seq_len @@ -167,7 +167,7 @@ func IndexSequence(seqidx int, obitag_index := make(map[int]string, pseq.Len()) - // log.Warnf("(%s,%s): %v", sequence.Id(), pseq.Taxon(0).String(), closest) + // obilog.Warnf("(%s,%s): %v", sequence.Id(), pseq.Taxon(0).String(), closest) for i, d := range closest { if i < (len(closest)-1) && d < closest[i+1] { current_taxon := pseq.Taxon(i) diff --git a/pkg/obitools/obirefidx/options.go b/pkg/obitools/obirefidx/options.go index 0e8241d..bd42b0e 100644 --- a/pkg/obitools/obirefidx/options.go +++ b/pkg/obitools/obirefidx/options.go @@ -8,5 +8,5 @@ import ( // OptionSet adds to the basic option set every options declared for // the obiuniq command func OptionSet(options *getoptions.GetOpt) { - obiconvert.OptionSet(options) + obiconvert.OptionSet(false)(options) } diff --git a/pkg/obitools/obiscript/options.go b/pkg/obitools/obiscript/options.go index 3de95eb..9634be0 100644 --- a/pkg/obitools/obiscript/options.go +++ b/pkg/obitools/obiscript/options.go @@ -26,7 +26,7 @@ func ScriptOptionSet(options *getoptions.GetOpt) { func OptionSet(options *getoptions.GetOpt) { ScriptOptionSet(options) - obiconvert.OptionSet(options) + obiconvert.OptionSet(false)(options) obigrep.SequenceSelectionOptionSet(options) } diff --git a/pkg/obitools/obisplit/options.go b/pkg/obitools/obisplit/options.go index 778cb23..5edad7f 100644 --- a/pkg/obitools/obisplit/options.go +++ b/pkg/obitools/obisplit/options.go @@ -39,7 +39,7 @@ func SplitOptionSet(options *getoptions.GetOpt) { func OptionSet(options *getoptions.GetOpt) { SplitOptionSet(options) - obiconvert.OptionSet(options) + obiconvert.OptionSet(false)(options) } func CLIHasConfig() bool { diff --git a/pkg/obitools/obitag/obitag.go b/pkg/obitools/obitag/obitag.go index 7100ba0..b07f66f 100644 --- a/pkg/obitools/obitag/obitag.go +++ b/pkg/obitools/obitag/obitag.go @@ -11,6 +11,7 @@ import ( "git.metabarcoding.org/obitools/obitools4/obitools4/pkg/obidefault" "git.metabarcoding.org/obitools/obitools4/obitools4/pkg/obiiter" "git.metabarcoding.org/obitools/obitools4/obitools4/pkg/obikmer" + "git.metabarcoding.org/obitools/obitools4/obitools4/pkg/obilog" "git.metabarcoding.org/obitools/obitools4/obitools4/pkg/obiseq" "git.metabarcoding.org/obitools/obitools4/obitools4/pkg/obitax" "git.metabarcoding.org/obitools/obitools4/obitools4/pkg/obitools/obirefidx" @@ -260,7 +261,7 @@ func CLIAssignTaxonomy(iterator obiiter.IBioSequence, if taxon != nil { j++ } else { - log.Warnf("Taxid %s is not described in the taxonomy %s."+ + obilog.Warnf("Taxid %s is not described in the taxonomy %s."+ " Sequence %s is discared from the reference database", seq.Taxid(), taxo.Name(), seq.Id()) } diff --git a/pkg/obitools/obitag/options.go b/pkg/obitools/obitag/options.go index 6b87fdc..35cd54a 100644 --- a/pkg/obitools/obitag/options.go +++ b/pkg/obitools/obitag/options.go @@ -41,7 +41,7 @@ func TagOptionSet(options *getoptions.GetOpt) { // OptionSet adds to the basic option set every options declared for // the obiuniq command func OptionSet(options *getoptions.GetOpt) { - obiconvert.OptionSet(options) + obiconvert.OptionSet(false)(options) TagOptionSet(options) } diff --git a/pkg/obitools/obiuniq/options.go b/pkg/obitools/obiuniq/options.go index 1b56fae..d58cb91 100644 --- a/pkg/obitools/obiuniq/options.go +++ b/pkg/obitools/obiuniq/options.go @@ -45,13 +45,12 @@ func UniqueOptionSet(options *getoptions.GetOpt) { } - // OptionSet adds to the basic option set every options declared for // the obiuniq command // // It takes a pointer to a GetOpt struct as its parameter and does not return anything. func OptionSet(options *getoptions.GetOpt) { - obiconvert.OptionSet(options) + obiconvert.OptionSet(false)(options) UniqueOptionSet(options) } @@ -150,4 +149,4 @@ func CLINoSingleton() bool { // noSingleton bool - The boolean value to set for _NoSingleton. func SetNoSingleton(noSingleton bool) { _NoSingleton = noSingleton -} \ No newline at end of file +}