From 7b7128196af84b0ce2cde39d3bf9b04c83dbc4a4 Mon Sep 17 00:00:00 2001 From: Eric Coissac Date: Sun, 27 Aug 2023 15:52:28 +0200 Subject: [PATCH] small refactoring including doc Former-commit-id: 6d6b527d89d77aa571831f7500f841840e280536 --- pkg/obiseq/class.go | 4 ++-- pkg/obitax/lca.go | 4 ++-- pkg/obitools/obiclean/obiclean.go | 8 ++++---- pkg/obiutils/array.go | 9 +++++++++ 4 files changed, 17 insertions(+), 8 deletions(-) diff --git a/pkg/obiseq/class.go b/pkg/obiseq/class.go index c2a6ae4..21c722b 100644 --- a/pkg/obiseq/class.go +++ b/pkg/obiseq/class.go @@ -71,7 +71,7 @@ func AnnotationClassifier(key string, na string) *BioSequenceClassifier { locke.RLock() defer locke.RUnlock() if k >= maxcode { - log.Fatalf("value %d not register") + log.Fatalf("value %d not register", k) } return decode[k] } @@ -154,7 +154,7 @@ func DualAnnotationClassifier(key1, key2 string, na string) *BioSequenceClassifi locke.RLock() defer locke.RUnlock() if k >= maxcode { - log.Fatalf("value %d not register") + log.Fatalf("value %d not register", k) } return decode[k] } diff --git a/pkg/obitax/lca.go b/pkg/obitax/lca.go index 725700b..b3a6292 100644 --- a/pkg/obitax/lca.go +++ b/pkg/obitax/lca.go @@ -43,7 +43,7 @@ func (taxonomy *Taxonomy) TaxonomicDistribution(sequence *obiseq.BioSequence) ma t, et := taxonomy.Taxon(taxid) if et != nil { - log.Panic("Taxid %d not defined in taxonomy : %v", k, et) + log.Panicf("Taxid %d not defined in taxonomy : %v", k, et) } taxons[t] = v } @@ -60,7 +60,7 @@ func (taxonomy *Taxonomy) LCA(sequence *obiseq.BioSequence, threshold float64) ( for t, w := range taxons { p, ep := t.Path() if ep != nil { - log.Panic("Taxonomic path cannot be retreived from Taxid %d : %v", t.Taxid(), ep) + log.Panicf("Taxonomic path cannot be retreived from Taxid %d : %v", t.Taxid(), ep) } obiutils.Reverse(*p, true) diff --git a/pkg/obitools/obiclean/obiclean.go b/pkg/obitools/obiclean/obiclean.go index 65be6b3..f3cb685 100644 --- a/pkg/obitools/obiclean/obiclean.go +++ b/pkg/obitools/obiclean/obiclean.go @@ -106,7 +106,7 @@ func IsHead(sequence *obiseq.BioSequence) bool { case bool: ishead = iishead default: - log.Panic("obiclean_head attribute of sequence %s must be a boolean not : %v", sequence.Id(), iishead) + log.Panicf("obiclean_head attribute of sequence %s must be a boolean not : %v", sequence.Id(), iishead) } } @@ -122,7 +122,7 @@ func HeadCount(sequence *obiseq.BioSequence) int { if ok { value, err = obiutils.InterfaceToInt(value) if err != nil { - log.Panic("obiclean_headcount attribute of sequence %s must be an integer value not : %v", sequence.Id(), ivalue) + log.Panicf("obiclean_headcount attribute of sequence %s must be an integer value not : %v", sequence.Id(), ivalue) } } @@ -138,7 +138,7 @@ func InternalCount(sequence *obiseq.BioSequence) int { if ok { value, err = obiutils.InterfaceToInt(value) if err != nil { - log.Panic("obiclean_internalcount attribute of sequence %s must be an integer value not : %v", sequence.Id(), ivalue) + log.Panicf("obiclean_internalcount attribute of sequence %s must be an integer value not : %v", sequence.Id(), ivalue) } } @@ -154,7 +154,7 @@ func SingletonCount(sequence *obiseq.BioSequence) int { if ok { value, err = obiutils.InterfaceToInt(value) if err != nil { - log.Panic("obiclean_samplecount attribute of sequence %s must be an integer value not : %v", sequence.Id(), ivalue) + log.Panicf("obiclean_samplecount attribute of sequence %s must be an integer value not : %v", sequence.Id(), ivalue) } } diff --git a/pkg/obiutils/array.go b/pkg/obiutils/array.go index cc20f80..b616f31 100644 --- a/pkg/obiutils/array.go +++ b/pkg/obiutils/array.go @@ -33,6 +33,15 @@ func Make2DArray[T any](rows, cols int) Matrix[T] { return matrix } +// Make2DNumericArray generates a 2D numeric array with the specified number of rows and columns. +// +// Parameters: +// - rows: the number of rows in the array. +// - cols: the number of columns in the array. +// - zeroed: a boolean indicating whether the array should be initialized with zeros. +// +// Returns: +// - matrix: a 2D numeric array with the specified dimensions. func Make2DNumericArray[T Numeric](rows, cols int, zeroed bool) Matrix[T] { matrix := make(Matrix[T], rows) data := make([]T, cols*rows)