From 2002299b7ff9a798de28552cd9ef0f513b8213e6 Mon Sep 17 00:00:00 2001 From: Eric Coissac Date: Thu, 2 Feb 2023 23:09:16 +0100 Subject: [PATCH] reorder some edits --- pkg/obitools/obiannotate/obiannotate.go | 31 +++++++++++++++++++++---- 1 file changed, 27 insertions(+), 4 deletions(-) diff --git a/pkg/obitools/obiannotate/obiannotate.go b/pkg/obitools/obiannotate/obiannotate.go index aefab8a..41c5b10 100644 --- a/pkg/obitools/obiannotate/obiannotate.go +++ b/pkg/obitools/obiannotate/obiannotate.go @@ -18,12 +18,18 @@ func DeleteAttributesWorker(toBeDeleted []string) obiseq.SeqWorker { return f } -func ToBeKeptAttributesWorker(toBeKept map[string]bool) obiseq.SeqWorker { +func ToBeKeptAttributesWorker(toBeKept []string) obiseq.SeqWorker { + + d := make(map[string]bool, len(_keepOnly)) + + for _, v := range _keepOnly { + d[v] = true + } f := func(s *obiseq.BioSequence) *obiseq.BioSequence { annot := s.Annotations() for key := range annot { - if _, ok := toBeKept[key]; !ok { + if _, ok := d[key]; !ok { s.DeleteAttribute(key) } } @@ -33,6 +39,18 @@ func ToBeKeptAttributesWorker(toBeKept map[string]bool) obiseq.SeqWorker { return f } +func ClearAllAttributesWorker() obiseq.SeqWorker { + f := func(s *obiseq.BioSequence) *obiseq.BioSequence { + annot := s.Annotations() + for key := range annot { + s.DeleteAttribute(key) + } + return s + } + + return f +} + func RenameAttributeWorker(toBeRenamed map[string]string) obiseq.SeqWorker { f := func(s *obiseq.BioSequence) *obiseq.BioSequence { for newName, oldName := range toBeRenamed { @@ -69,8 +87,8 @@ func CLIAnnotationWorker() obiseq.SeqWorker { var annotator obiseq.SeqWorker annotator = nil - if CLIHasAttributeToBeRenamed() { - w := RenameAttributeWorker(CLIAttributeToBeRenamed()) + if CLIHasClearAllFlag() { + w := ClearAllAttributesWorker() annotator = annotator.ChainWorkers(w) } @@ -84,6 +102,11 @@ func CLIAnnotationWorker() obiseq.SeqWorker { annotator = annotator.ChainWorkers(w) } + if CLIHasAttributeToBeRenamed() { + w := RenameAttributeWorker(CLIAttributeToBeRenamed()) + annotator = annotator.ChainWorkers(w) + } + if CLIHasTaxonAtRank() { taxo := obigrep.CLILoadSelectedTaxonomy() w := AddTaxonAtRankWorker(taxo, CLITaxonAtRank()...)