diff --git a/go.mod b/go.mod index 5c62e94..afcb2e0 100644 --- a/go.mod +++ b/go.mod @@ -25,6 +25,7 @@ require ( require ( github.com/Clever/csvlint v0.3.0 // indirect + github.com/TuftsBCB/io v0.0.0-20140121014543-22b94e9b23f9 // indirect github.com/buger/jsonparser v1.1.1 // indirect github.com/chzyer/readline v0.0.0-20180603132655-2972be24d48e // indirect github.com/davecgh/go-spew v1.1.1 // indirect diff --git a/go.sum b/go.sum index 7c68023..9bac5f4 100644 --- a/go.sum +++ b/go.sum @@ -6,6 +6,8 @@ github.com/PaesslerAG/gval v1.2.2 h1:Y7iBzhgE09IGTt5QgGQ2IdaYYYOU134YGHBThD+wm9E github.com/PaesslerAG/gval v1.2.2/go.mod h1:XRFLwvmkTEdYziLdaCeCa5ImcGVrfQbeNUbVR+C6xac= github.com/PaesslerAG/jsonpath v0.1.0 h1:gADYeifvlqK3R3i2cR5B4DGgxLXIPb3TRTH1mGi0jPI= github.com/PaesslerAG/jsonpath v0.1.0/go.mod h1:4BzmtoM/PI8fPO4aQGIusjGxGir2BzcV0grWtFzq1Y8= +github.com/TuftsBCB/io v0.0.0-20140121014543-22b94e9b23f9 h1:Zc1/GNsUpgZR9qm1EmRSKrnOHA7CCd0bIzGdq0cREN0= +github.com/TuftsBCB/io v0.0.0-20140121014543-22b94e9b23f9/go.mod h1:PZyV4WA3NpqtezSY0h6E6NARAmdDm0qwrydveOyR5Gc= github.com/barkimedes/go-deepcopy v0.0.0-20220514131651-17c30cfc62df h1:GSoSVRLoBaFpOOds6QyY1L8AX7uoY+Ln3BHc22W40X0= github.com/barkimedes/go-deepcopy v0.0.0-20220514131651-17c30cfc62df/go.mod h1:hiVxq5OP2bUGBRNS3Z/bt/reCLFNbdcST6gISi1fiOM= github.com/buger/jsonparser v1.1.1 h1:2PnMjfWD7wBILjqQbt530v576A/cAbQvEW9gGIpYMUs= diff --git a/pkg/obioptions/version.go b/pkg/obioptions/version.go index b41764f..1c22e99 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 = "b9bee5f" +var _Commit = "ceca339" var _Version = "Release 4.2.0" // Version returns the version of the obitools package. diff --git a/pkg/obitax/csvtaxdump_write.go b/pkg/obitax/csvtaxdump_write.go index 9f4c3a6..c2c6a1a 100644 --- a/pkg/obitax/csvtaxdump_write.go +++ b/pkg/obitax/csvtaxdump_write.go @@ -1 +1,38 @@ package obitax + +import ( + "strings" + + "github.com/TuftsBCB/io/newick" +) + +func (taxonomy *Taxonomy) Newick() string { + if taxonomy == nil { + return "" + } + + iterator := taxonomy.AsTaxonSet().Sort().Iterator() + + nodes := make(map[*string]*newick.Tree, taxonomy.Len()) + trees := make([]*newick.Tree, 0) + + for iterator.Next() { + taxon := iterator.Get() + tree := &newick.Tree{Label: taxon.String()} + nodes[taxon.Node.id] = tree + if parent, ok := nodes[taxon.Parent().Node.id]; ok { + parent.Children = append(parent.Children, *tree) + } else { + trees = append(trees, tree) + } + } + + rep := strings.Builder{} + + for _, tree := range trees { + rep.WriteString(tree.String()) + rep.WriteString("\n") + } + + return rep.String() +} diff --git a/pkg/obitax/newick_write.go b/pkg/obitax/newick_write.go new file mode 100644 index 0000000..9f4c3a6 --- /dev/null +++ b/pkg/obitax/newick_write.go @@ -0,0 +1 @@ +package obitax diff --git a/pkg/obitools/obiconvert/options.go b/pkg/obitools/obiconvert/options.go index 22684df..832f6b9 100644 --- a/pkg/obitools/obiconvert/options.go +++ b/pkg/obitools/obiconvert/options.go @@ -163,10 +163,6 @@ func CLIOutputFormat() string { } } -func CLICompressed() bool { - return __compressed__ -} - func CLISkipEmpty() bool { return __skip_empty__ } diff --git a/pkg/obitools/obiconvert/sequence_writer.go b/pkg/obitools/obiconvert/sequence_writer.go index 8c12a7f..01f964b 100644 --- a/pkg/obitools/obiconvert/sequence_writer.go +++ b/pkg/obitools/obiconvert/sequence_writer.go @@ -58,7 +58,7 @@ func CLIWriteBioSequences(iterator obiiter.IBioSequence, opts = append(opts, obiformats.OptionsParallelWorkers(nworkers)) opts = append(opts, obiformats.OptionsBatchSize(obidefault.BatchSize())) - opts = append(opts, obiformats.OptionsCompressed(CLICompressed())) + opts = append(opts, obiformats.OptionsCompressed(obidefault.CompressOutput())) var err error diff --git a/pkg/obitools/obidistribute/distribute.go b/pkg/obitools/obidistribute/distribute.go index 4757a28..6d23c53 100644 --- a/pkg/obitools/obidistribute/distribute.go +++ b/pkg/obitools/obidistribute/distribute.go @@ -33,7 +33,7 @@ func CLIDistributeSequence(sequences obiiter.IBioSequence) { opts = append(opts, obiformats.OptionsParallelWorkers(nworkers), obiformats.OptionsBatchSize(obidefault.BatchSize()), obiformats.OptionsAppendFile(CLIAppendSequences()), - obiformats.OptionsCompressed(obiconvert.CLICompressed())) + obiformats.OptionsCompressed(obidefault.CompressOutput())) var formater obiformats.SequenceBatchWriterToFile