Add the --with-taxon-at-rank option code to obiannotate

This commit is contained in:
2023-02-02 16:36:32 +01:00
parent 886c5118e3
commit 5639a09fb9
4 changed files with 45 additions and 9 deletions

View File

@ -33,7 +33,7 @@ func (taxon *TaxNode) TaxonAtRank(rank string) *TaxNode {
}
}
if taxon == taxon.pparent {
if taxon == taxon.pparent && taxon.rank != rank {
taxon = nil
}

View File

@ -12,26 +12,37 @@ import (
// If the taxon at the given rank doesn't exist for the taxonomy annotation
// of the sequence, nothing happens.
func (taxonomy *Taxonomy) SetTaxonAtRank(sequence *obiseq.BioSequence, rank string) *TaxNode {
var taxonAtRank *TaxNode
taxid := sequence.Taxid()
taxon, err := taxonomy.Taxon(taxid)
taxonAtRank := taxon.TaxonAtRank(rank)
if err == nil && taxonAtRank != nil {
sequence.SetAttribute(rank, taxonAtRank.taxid)
sequence.SetAttribute(rank+"_name", taxonAtRank.scientificname)
taxonAtRank = nil
if err == nil {
taxonAtRank = taxon.TaxonAtRank(rank)
if taxonAtRank != nil {
// log.Printf("Taxid: %d Rank: %s --> proposed : %d (%s)", taxid, rank, taxonAtRank.taxid, *(taxonAtRank.scientificname))
sequence.SetAttribute(rank, taxonAtRank.taxid)
sequence.SetAttribute(rank+"_name", *taxonAtRank.scientificname)
} else {
sequence.SetAttribute(rank, -1)
sequence.SetAttribute(rank+"_name", "NA")
}
}
return taxonAtRank
}
// Setting the species of a sequence.
func (taxonomy *Taxonomy) SetSpecies(sequence *obiseq.BioSequence) *TaxNode {
return taxonomy.SetTaxonAtRank(sequence, "species")
}
// Setting the genus of a sequence.
func (taxonomy *Taxonomy) SetGenus(sequence *obiseq.BioSequence) *TaxNode {
return taxonomy.SetTaxonAtRank(sequence, "genus")
}
// Setting the family of a sequence.
func (taxonomy *Taxonomy) SetFamily(sequence *obiseq.BioSequence) *TaxNode {
return taxonomy.SetTaxonAtRank(sequence, "family")
}