From 8f08959ebba7fe51c1e8f285ade2a2063b2f6b78 Mon Sep 17 00:00:00 2001 From: Eric Coissac Date: Mon, 22 Apr 2024 12:01:43 +0200 Subject: [PATCH] Make the --no-progressbar option effective on graph building progress too. Former-commit-id: 3fabecfc9de69ad406d6840c8f821c16eebaef46 --- pkg/obitools/obiclean/obiclean.go | 57 +++++++++++++++++++------------ 1 file changed, 36 insertions(+), 21 deletions(-) diff --git a/pkg/obitools/obiclean/obiclean.go b/pkg/obitools/obiclean/obiclean.go index 4804aa6..8ee93e7 100644 --- a/pkg/obitools/obiclean/obiclean.go +++ b/pkg/obitools/obiclean/obiclean.go @@ -7,6 +7,7 @@ import ( "git.metabarcoding.org/obitools/obitools4/obitools4/pkg/obiiter" "git.metabarcoding.org/obitools/obitools4/obitools4/pkg/obioptions" "git.metabarcoding.org/obitools/obitools4/obitools4/pkg/obiseq" + "git.metabarcoding.org/obitools/obitools4/obitools4/pkg/obitools/obiconvert" "git.metabarcoding.org/obitools/obitools4/obitools4/pkg/obiutils" "github.com/schollz/progressbar/v3" log "github.com/sirupsen/logrus" @@ -300,36 +301,47 @@ func CLIOBIClean(itertator obiiter.IBioSequence) obiiter.IBioSequence { obioptions.CLIParallelWorkers()) if RatioMax() < 1.0 { + bar := (*progressbar.ProgressBar)(nil) + + if obiconvert.CLIProgressBar() { + + pbopt := make([]progressbar.Option, 0, 5) + pbopt = append(pbopt, + progressbar.OptionSetWriter(os.Stderr), + progressbar.OptionSetWidth(15), + progressbar.OptionShowIts(), + progressbar.OptionSetPredictTime(true), + progressbar.OptionSetDescription("[Filter graph on abundance ratio]"), + ) + + bar = progressbar.NewOptions(len(samples), pbopt...) + } + + for _, seqs := range samples { + FilterGraphOnRatio(seqs, RatioMax()) + if bar != nil { + bar.Add(1) + } + } + } + + Mutation(samples) + + bar := (*progressbar.ProgressBar)(nil) + + if obiconvert.CLIProgressBar() { pbopt := make([]progressbar.Option, 0, 5) pbopt = append(pbopt, progressbar.OptionSetWriter(os.Stderr), progressbar.OptionSetWidth(15), progressbar.OptionShowIts(), progressbar.OptionSetPredictTime(true), - progressbar.OptionSetDescription("[Filter graph on abundance ratio]"), + progressbar.OptionSetDescription("[Annotate sequence status]"), ) - bar := progressbar.NewOptions(len(samples), pbopt...) - - for _, seqs := range samples { - FilterGraphOnRatio(seqs, RatioMax()) - bar.Add(1) - } + bar = progressbar.NewOptions(len(samples), pbopt...) } - Mutation(samples) - - pbopt := make([]progressbar.Option, 0, 5) - pbopt = append(pbopt, - progressbar.OptionSetWriter(os.Stderr), - progressbar.OptionSetWidth(15), - progressbar.OptionShowIts(), - progressbar.OptionSetPredictTime(true), - progressbar.OptionSetDescription("[Annotate sequence status]"), - ) - - bar := progressbar.NewOptions(len(samples), pbopt...) - for name, seqs := range samples { for _, pcr := range *seqs { obistatus := Status(pcr.Sequence) @@ -338,7 +350,10 @@ func CLIOBIClean(itertator obiiter.IBioSequence) obiiter.IBioSequence { obiweight := Weight(pcr.Sequence) obiweight[name] = pcr.Weight } - bar.Add(1) + + if bar != nil { + bar.Add(1) + } } if SaveGraphToFiles() {