Skip to content

Commit

Permalink
do not skipping visited subtrees when some of give taxids are descend…
Browse files Browse the repository at this point in the history
…ants of others. fix #68
  • Loading branch information
shenwei356 committed Oct 14, 2022
1 parent cd74253 commit 8ec6026
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 11 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
- [TaxonKit v0.13.1](https://github.com/shenwei356/taxonkit/releases/tag/v0.13.1)
[![Github Releases (by Release)](https://img.shields.io/github/downloads/shenwei356/taxonkit/v0.13.1/total.svg)](https://github.com/shenwei356/taxonkit/releases/tag/v0.13.1)
- `taxonkit list`:
- do not skipping visited subtrees when some of give taxids are descendants of others. [#68](https://github.com/shenwei356/taxonkit/issues/68)
- [TaxonKit v0.13.0](https://github.com/shenwei356/taxonkit/releases/tag/v0.13.0)
[![Github Releases (by Release)](https://img.shields.io/github/downloads/shenwei356/taxonkit/v0.13.0/total.svg)](https://github.com/shenwei356/taxonkit/releases/tag/v0.13.0)
- `taxonkit reformat`:
Expand Down
6 changes: 5 additions & 1 deletion doc/docs/usage.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ All-in-one command:
```text
TaxonKit - A Practical and Efficient NCBI Taxonomy Toolkit
Version: 0.13.0
Version: 0.13.1
Author: Wei Shen <shenwei356@gmail.com>
Expand Down Expand Up @@ -94,6 +94,10 @@ Usage
```text
List taxonomic subtrees of given TaxIds
Attentions:
1. When multiple taxids are given, the output may contain duplicated records
if some taxids are descendants of others.
Examples:
$ taxonkit list --ids 9606 -n -r --indent " "
Expand Down
30 changes: 20 additions & 10 deletions taxonkit/cmd/list.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,10 @@ var listCmd = &cobra.Command{
Short: "List taxonomic subtrees of given TaxIds",
Long: `List taxonomic subtrees of given TaxIds
Attentions:
1. When multiple taxids are given, the output may contain duplicated records
if some taxids are descendants of others.
Examples:
$ taxonkit list --ids 9606 -n -r --indent " "
Expand Down Expand Up @@ -75,7 +79,8 @@ Examples:
var names map[uint32]string
var delnodes map[uint32]struct{}
var merged map[uint32]uint32
var tree map[uint32]map[uint32]bool // different from that in lineage.go
// var tree map[uint32]map[uint32]bool // different from that in lineage.go
var tree map[uint32]map[uint32]interface{} // different from that in lineage.go
var ranks map[uint32]string

var wg sync.WaitGroup
Expand All @@ -88,7 +93,8 @@ Examples:

wg.Add(1)
go func() {
tree = make(map[uint32]map[uint32]bool, mapInitialSize)
// tree = make(map[uint32]map[uint32]bool, mapInitialSize)
tree = make(map[uint32]map[uint32]interface{}, mapInitialSize)
ranks = make(map[uint32]string, mapInitialSize)

fh, err := xopen.Ropen(config.NodesFile)
Expand Down Expand Up @@ -121,13 +127,16 @@ Examples:

if child > 1 {
if _, ok = tree[parent]; !ok {
tree[parent] = make(map[uint32]bool)
// tree[parent] = make(map[uint32]bool)
tree[parent] = make(map[uint32]interface{})
}
tree[parent][child] = false
// tree[parent][child] = false
tree[parent][child] = struct{}{}
}

if _, ok = tree[child]; !ok {
tree[child] = make(map[uint32]bool)
// tree[child] = make(map[uint32]bool)
tree[child] = make(map[uint32]interface{})
}
if printRank {
ranks[child] = rank
Expand Down Expand Up @@ -229,7 +238,8 @@ func init() {
}

func traverseTree(
tree map[uint32]map[uint32]bool,
// tree map[uint32]map[uint32]bool,
tree map[uint32]map[uint32]interface{},
parent uint32,
outfh *xopen.Writer,
indent string,
Expand Down Expand Up @@ -257,9 +267,9 @@ func traverseTree(
var child uint32
for i, c := range children {
child = uint32(c)
if tree[parent][child] {
continue
}
// if tree[parent][child] {
// continue
// }

outfh.WriteString(strings.Repeat(indent, level))

Expand Down Expand Up @@ -291,7 +301,7 @@ func traverseTree(
outfh.Flush()
}

tree[parent][child] = true
// tree[parent][child] = true

traverseTree(tree, child, outfh, indent, level+1, names, printName,
ranks, printRank, jsonFormat, config)
Expand Down

0 comments on commit 8ec6026

Please sign in to comment.