mirror of
https://github.com/metabarcoding/obitools4.git
synced 2025-06-29 16:20:46 +00:00
Patch a small bug on json write
This commit is contained in:
@ -19,6 +19,8 @@ func TaxonomyClassifier(taxonomicRank string,
|
||||
taxonomy *obitax.Taxonomy,
|
||||
abortOnMissing bool) *BioSequenceClassifier {
|
||||
|
||||
taxonomy = taxonomy.OrDefault(true)
|
||||
|
||||
keys := make(map[*obitax.TaxNode]int)
|
||||
codes := make([]*obitax.TaxNode, 1)
|
||||
codes[0] = nil
|
||||
|
@ -12,6 +12,8 @@ func (sequence *BioSequence) TaxonomicDistribution(taxonomy *obitax.Taxonomy) ma
|
||||
taxids := sequence.StatsOn(MakeStatsOnDescription("taxid"), "na")
|
||||
taxons := make(map[*obitax.TaxNode]int, len(taxids))
|
||||
|
||||
taxonomy = taxonomy.OrDefault(true)
|
||||
|
||||
for taxid, v := range taxids {
|
||||
t := taxonomy.Taxon(taxid)
|
||||
if t == nil {
|
||||
@ -27,6 +29,9 @@ func (sequence *BioSequence) TaxonomicDistribution(taxonomy *obitax.Taxonomy) ma
|
||||
}
|
||||
|
||||
func (sequence *BioSequence) LCA(taxonomy *obitax.Taxonomy, threshold float64) (*obitax.Taxon, float64, int) {
|
||||
|
||||
taxonomy = taxonomy.OrDefault(true)
|
||||
|
||||
taxons := sequence.TaxonomicDistribution(taxonomy)
|
||||
paths := make(map[*obitax.TaxNode]*obitax.TaxonSlice, len(taxons))
|
||||
answer := (*obitax.TaxNode)(nil)
|
||||
@ -34,11 +39,11 @@ func (sequence *BioSequence) LCA(taxonomy *obitax.Taxonomy, threshold float64) (
|
||||
granTotal := 0
|
||||
|
||||
for t, w := range taxons {
|
||||
p := (&obitax.Taxon{Taxonomy: taxonomy,
|
||||
Node: t,
|
||||
}).Path()
|
||||
taxon := &obitax.Taxon{Taxonomy: taxonomy, Node: t}
|
||||
p := taxon.Path()
|
||||
|
||||
if p == nil {
|
||||
log.Panicf("Sequence %s: taxonomic path cannot be retreived from Taxid %d : %v", sequence.Id(), t.String(taxonomy.Code()))
|
||||
log.Panicf("Sequence %s: taxonomic path cannot be retreived from Taxid : %s", sequence.Id(), taxon.String())
|
||||
}
|
||||
|
||||
p.Reverse(true)
|
||||
@ -103,6 +108,8 @@ func (sequence *BioSequence) LCA(taxonomy *obitax.Taxonomy, threshold float64) (
|
||||
|
||||
func AddLCAWorker(taxonomy *obitax.Taxonomy, slot_name string, threshold float64) SeqWorker {
|
||||
|
||||
taxonomy = taxonomy.OrDefault(true)
|
||||
|
||||
if !strings.HasSuffix(slot_name, "taxid") {
|
||||
slot_name = slot_name + "_taxid"
|
||||
}
|
||||
|
@ -9,6 +9,7 @@ import (
|
||||
)
|
||||
|
||||
func (s *BioSequence) Taxon(taxonomy *obitax.Taxonomy) *obitax.Taxon {
|
||||
|
||||
taxid := s.Taxid()
|
||||
if taxid == "NA" {
|
||||
return nil
|
||||
@ -21,16 +22,39 @@ func (s *BioSequence) Taxon(taxonomy *obitax.Taxonomy) *obitax.Taxon {
|
||||
// Parameters:
|
||||
//
|
||||
// taxid - the taxid to set.
|
||||
func (s *BioSequence) SetTaxid(taxid string) {
|
||||
func (s *BioSequence) SetTaxid(taxid string, rank ...string) {
|
||||
if taxid == "" {
|
||||
taxid = "NA"
|
||||
} else {
|
||||
taxonomy := obitax.DefaultTaxonomy()
|
||||
taxon := (*obitax.Taxon)(nil)
|
||||
|
||||
if taxonomy != nil {
|
||||
taxon = taxonomy.Taxon(taxid)
|
||||
}
|
||||
|
||||
if taxon != nil {
|
||||
taxid = taxon.String()
|
||||
}
|
||||
}
|
||||
|
||||
if len(rank) > 0 {
|
||||
r := rank[0]
|
||||
s.SetAttribute(r+"_taxid", taxid)
|
||||
} else {
|
||||
s.SetAttribute("taxid", taxid)
|
||||
}
|
||||
s.SetAttribute("taxid", taxid)
|
||||
}
|
||||
|
||||
func (s *BioSequence) SetTaxon(taxon *obitax.Taxon) {
|
||||
func (s *BioSequence) SetTaxon(taxon *obitax.Taxon, rank ...string) {
|
||||
taxid := taxon.String()
|
||||
s.SetTaxid(taxid)
|
||||
|
||||
if len(rank) > 0 {
|
||||
r := rank[0]
|
||||
s.SetAttribute(r+"_taxid", taxid)
|
||||
} else {
|
||||
s.SetAttribute("taxid", taxid)
|
||||
}
|
||||
}
|
||||
|
||||
// Taxid returns the taxonomic ID associated with the BioSequence.
|
||||
|
Reference in New Issue
Block a user