From 791d253edcde885521cf9d002c83c961d4c4b1b3 Mon Sep 17 00:00:00 2001 From: Eric Coissac Date: Thu, 27 Feb 2025 09:06:07 +0100 Subject: [PATCH] Generate the ratio file as compressed if -Z option enabled. --- pkg/obioptions/version.go | 2 +- pkg/obitools/obiclean/graph.go | 12 ++++++++---- pkg/obitools/obiclean/obiclean.go | 2 +- 3 files changed, 10 insertions(+), 6 deletions(-) diff --git a/pkg/obioptions/version.go b/pkg/obioptions/version.go index 99f162c..c3826e5 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 = "db284f1" +var _Commit = "6245d7f" var _Version = "Release 4.2.0" // Version returns the version of the obitools package. diff --git a/pkg/obitools/obiclean/graph.go b/pkg/obitools/obiclean/graph.go index d173a72..713442f 100644 --- a/pkg/obitools/obiclean/graph.go +++ b/pkg/obitools/obiclean/graph.go @@ -13,6 +13,7 @@ import ( log "github.com/sirupsen/logrus" "git.metabarcoding.org/obitools/obitools4/obitools4/pkg/obialign" + "git.metabarcoding.org/obitools/obitools4/obitools4/pkg/obiutils" "github.com/schollz/progressbar/v3" ) @@ -56,12 +57,15 @@ func makeEdge(father, dist, pos int, from, to byte) Edge { // and writes a CSV file with the first column being the // first nucleotide, the second column being the second nucleotide, and the third column being the // ratio -func EmpiricalDistCsv(filename string, data [][]Ratio) { +func EmpiricalDistCsv(filename string, data [][]Ratio, compressed bool) { file, err := os.Create(filename) + + defer file.Close() + + destfile, err := obiutils.CompressStream(file, true, true) if err != nil { fmt.Println(err) } - defer file.Close() pbopt := make([]progressbar.Option, 0, 5) pbopt = append(pbopt, @@ -74,11 +78,11 @@ func EmpiricalDistCsv(filename string, data [][]Ratio) { bar := progressbar.NewOptions(len(data), pbopt...) - fmt.Fprintln(file, "Sample,Father_id,Father_status,From,To,Weight_from,Weight_to,Count_from,Count_to,Position,length,A,C,G,T") + fmt.Fprintln(destfile, "Sample,Father_id,Father_status,From,To,Weight_from,Weight_to,Count_from,Count_to,Position,length,A,C,G,T") for code, dist := range data { a1, a2 := intToNucPair(code) for _, ratio := range dist { - fmt.Fprintf(file, "%s,%s,%s,%c,%c,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d\n", + fmt.Fprintf(destfile, "%s,%s,%s,%c,%c,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d\n", ratio.Sample, ratio.SeqID, ratio.status, diff --git a/pkg/obitools/obiclean/obiclean.go b/pkg/obitools/obiclean/obiclean.go index 55dda02..8110bab 100644 --- a/pkg/obitools/obiclean/obiclean.go +++ b/pkg/obitools/obiclean/obiclean.go @@ -390,7 +390,7 @@ func CLIOBIClean(itertator obiiter.IBioSequence) obiiter.IBioSequence { if IsSaveRatioTable() { all_ratio := EstimateRatio(samples, MinCountToEvalMutationRate()) - EmpiricalDistCsv(RatioTableFilename(), all_ratio) + EmpiricalDistCsv(RatioTableFilename(), all_ratio, obidefault.CompressOutput()) } iter := annotateOBIClean(source, db)