Skip to content

Commit

Permalink
reformat: add a new placeholder "{K}" for rank "kingdom". #64
Browse files Browse the repository at this point in the history
  • Loading branch information
shenwei356 committed Aug 25, 2022
1 parent e3d6cff commit a73772d
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 0 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
- [TaxonKit v0.12.1](https://github.com/shenwei356/taxonkit/releases/tag/v0.12.1)
[![Github Releases (by Release)](https://img.shields.io/github/downloads/shenwei356/taxonkit/v0.12.1/total.svg)](https://github.com/shenwei356/taxonkit/releases/tag/v0.12.1)
- `taxonkit reformat`: add a new placeholder `{K}` for rank `kingdom`. [#64](https://github.com/shenwei356/taxonkit/issues/64)
- `taxonkit create-taxdump`:
- fix merged.dmp and delnodes.dmp. [gtdb-taxdump/issues/2](https://github.com/shenwei356/gtdb-taxdump/issues/2)
- fix bug of handling non-GTDB data when using `-A/--field-accession` and no rank names given.
Expand Down
4 changes: 4 additions & 0 deletions taxonkit/cmd/reformat.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ Ambiguous names:
Output format can be formated by flag --format, available placeholders:
{k}: superkingdom
{K}: kingdom
{p}: phylum
{c}: class
{o}: order
Expand Down Expand Up @@ -114,6 +115,7 @@ Output format can contains some escape charactors like "\t".

addPrefix := getFlagBool(cmd, "add-prefix")
prefixK := getFlagString(cmd, "prefix-k")
prefixK2 := getFlagString(cmd, "prefix-K")
prefixP := getFlagString(cmd, "prefix-p")
prefixC := getFlagString(cmd, "prefix-c")
prefixO := getFlagString(cmd, "prefix-o")
Expand All @@ -128,6 +130,7 @@ Output format can contains some escape charactors like "\t".

prefixes := map[string]string{
"k": prefixK,
"K": prefixK2,
"p": prefixP,
"c": prefixC,
"o": prefixO,
Expand Down Expand Up @@ -516,6 +519,7 @@ func init() {

flineageCmd.Flags().BoolP("add-prefix", "P", false, `add prefixes for all ranks, single prefix for a rank is defined by flag --prefix-X`)
flineageCmd.Flags().StringP("prefix-k", "", "k__", `prefix for superkingdom, used along with flag -P/--add-prefix`)
flineageCmd.Flags().StringP("prefix-K", "", "K__", `prefix for kingdom, used along with flag -P/--add-prefix`)
flineageCmd.Flags().StringP("prefix-p", "", "p__", `prefix for phylum, used along with flag -P/--add-prefix`)
flineageCmd.Flags().StringP("prefix-c", "", "c__", `prefix for class, used along with flag -P/--add-prefix`)
flineageCmd.Flags().StringP("prefix-o", "", "o__", `prefix for order, used along with flag -P/--add-prefix`)
Expand Down
6 changes: 6 additions & 0 deletions taxonkit/cmd/util-rank.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import "regexp"
var rankList = []string{
"",
"superkingdom",
"kingdom",
"phylum",
"class",
"order",
Expand All @@ -39,6 +40,7 @@ var rankList = []string{
var srankList = []string{
"",
"k",
"K",
"p",
"c",
"o",
Expand All @@ -52,6 +54,7 @@ var srankList = []string{

var rank2symbol = map[string]string{
"superkingdom": "k",
"kingdom": "K",
"phylum": "p",
"class": "c",
"order": "o",
Expand All @@ -65,6 +68,7 @@ var rank2symbol = map[string]string{

var symbol2rank = map[string]string{
"k": "superkingdom",
"K": "kingdom",
"p": "phylum",
"c": "class",
"o": "order",
Expand All @@ -77,6 +81,7 @@ var symbol2rank = map[string]string{
}
var symbol2weight = map[string]float32{
"k": 1,
"K": 1.5,
"p": 2,
"c": 3,
"o": 4,
Expand All @@ -92,6 +97,7 @@ var reRankPlaceHolder = regexp.MustCompile(`\{(\w)\}`)

var reRankPlaceHolders = map[string]*regexp.Regexp{
"k": regexp.MustCompile(`\{k\}`),
"K": regexp.MustCompile(`\{K\}`),
"p": regexp.MustCompile(`\{p\}`),
"c": regexp.MustCompile(`\{c\}`),
"o": regexp.MustCompile(`\{o\}`),
Expand Down

0 comments on commit a73772d

Please sign in to comment.