reorder some edits

This commit is contained in:
2023-02-02 23:09:16 +01:00
parent 060f7db082
commit 2002299b7f

View File

@ -18,12 +18,18 @@ func DeleteAttributesWorker(toBeDeleted []string) obiseq.SeqWorker {
return f 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 { f := func(s *obiseq.BioSequence) *obiseq.BioSequence {
annot := s.Annotations() annot := s.Annotations()
for key := range annot { for key := range annot {
if _, ok := toBeKept[key]; !ok { if _, ok := d[key]; !ok {
s.DeleteAttribute(key) s.DeleteAttribute(key)
} }
} }
@ -33,6 +39,18 @@ func ToBeKeptAttributesWorker(toBeKept map[string]bool) obiseq.SeqWorker {
return f 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 { func RenameAttributeWorker(toBeRenamed map[string]string) obiseq.SeqWorker {
f := func(s *obiseq.BioSequence) *obiseq.BioSequence { f := func(s *obiseq.BioSequence) *obiseq.BioSequence {
for newName, oldName := range toBeRenamed { for newName, oldName := range toBeRenamed {
@ -69,8 +87,8 @@ func CLIAnnotationWorker() obiseq.SeqWorker {
var annotator obiseq.SeqWorker var annotator obiseq.SeqWorker
annotator = nil annotator = nil
if CLIHasAttributeToBeRenamed() { if CLIHasClearAllFlag() {
w := RenameAttributeWorker(CLIAttributeToBeRenamed()) w := ClearAllAttributesWorker()
annotator = annotator.ChainWorkers(w) annotator = annotator.ChainWorkers(w)
} }
@ -84,6 +102,11 @@ func CLIAnnotationWorker() obiseq.SeqWorker {
annotator = annotator.ChainWorkers(w) annotator = annotator.ChainWorkers(w)
} }
if CLIHasAttributeToBeRenamed() {
w := RenameAttributeWorker(CLIAttributeToBeRenamed())
annotator = annotator.ChainWorkers(w)
}
if CLIHasTaxonAtRank() { if CLIHasTaxonAtRank() {
taxo := obigrep.CLILoadSelectedTaxonomy() taxo := obigrep.CLILoadSelectedTaxonomy()
w := AddTaxonAtRankWorker(taxo, CLITaxonAtRank()...) w := AddTaxonAtRankWorker(taxo, CLITaxonAtRank()...)