Generate the ratio file as compressed if -Z option enabled.

This commit is contained in:
Eric Coissac
2025-02-27 09:06:07 +01:00
parent 6245d7f684
commit 791d253edc
3 changed files with 10 additions and 6 deletions

View File

@ -8,7 +8,7 @@ import (
// corresponds to the last commit, and not the one when the file will be // corresponds to the last commit, and not the one when the file will be
// commited // commited
var _Commit = "db284f1" var _Commit = "6245d7f"
var _Version = "Release 4.2.0" var _Version = "Release 4.2.0"
// Version returns the version of the obitools package. // Version returns the version of the obitools package.

View File

@ -13,6 +13,7 @@ import (
log "github.com/sirupsen/logrus" log "github.com/sirupsen/logrus"
"git.metabarcoding.org/obitools/obitools4/obitools4/pkg/obialign" "git.metabarcoding.org/obitools/obitools4/obitools4/pkg/obialign"
"git.metabarcoding.org/obitools/obitools4/obitools4/pkg/obiutils"
"github.com/schollz/progressbar/v3" "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 // 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 // first nucleotide, the second column being the second nucleotide, and the third column being the
// ratio // ratio
func EmpiricalDistCsv(filename string, data [][]Ratio) { func EmpiricalDistCsv(filename string, data [][]Ratio, compressed bool) {
file, err := os.Create(filename) file, err := os.Create(filename)
defer file.Close()
destfile, err := obiutils.CompressStream(file, true, true)
if err != nil { if err != nil {
fmt.Println(err) fmt.Println(err)
} }
defer file.Close()
pbopt := make([]progressbar.Option, 0, 5) pbopt := make([]progressbar.Option, 0, 5)
pbopt = append(pbopt, pbopt = append(pbopt,
@ -74,11 +78,11 @@ func EmpiricalDistCsv(filename string, data [][]Ratio) {
bar := progressbar.NewOptions(len(data), pbopt...) 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 { for code, dist := range data {
a1, a2 := intToNucPair(code) a1, a2 := intToNucPair(code)
for _, ratio := range dist { 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.Sample,
ratio.SeqID, ratio.SeqID,
ratio.status, ratio.status,

View File

@ -390,7 +390,7 @@ func CLIOBIClean(itertator obiiter.IBioSequence) obiiter.IBioSequence {
if IsSaveRatioTable() { if IsSaveRatioTable() {
all_ratio := EstimateRatio(samples, MinCountToEvalMutationRate()) all_ratio := EstimateRatio(samples, MinCountToEvalMutationRate())
EmpiricalDistCsv(RatioTableFilename(), all_ratio) EmpiricalDistCsv(RatioTableFilename(), all_ratio, obidefault.CompressOutput())
} }
iter := annotateOBIClean(source, db) iter := annotateOBIClean(source, db)