Skip to content

Commit

Permalink
fix #4
Browse files Browse the repository at this point in the history
  • Loading branch information
shenwei356 committed Jul 19, 2017
1 parent 27a453d commit fd659d5
Show file tree
Hide file tree
Showing 7 changed files with 188 additions and 19 deletions.
24 changes: 24 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,11 @@
- `reformat` reformat lineage (supporting STDIN)
- `name2taxid` query taxid by taxon scientific name (supporting STDIN)

Misc

- `version` print version information and check for update
- `genautocomplete` generate shell autocompletion script

## Installation

Go to [Download Page](http://bioinf.shenwei.me/taxonkit/download) for more download options and changelogs.
Expand Down Expand Up @@ -58,6 +63,25 @@ And then:

go get -u github.com/shenwei356/taxonkit/taxonkit

## Bash-completion

Note: The current version supports Bash only.
This should work for *nix systems with Bash installed.

Howto:

1. run: `taxonkit genautocomplete`

2. create and edit `~/.bash_completion` file if you don't have it.

nano ~/.bash_completion

add the following:

for bcfile in ~/.bash_completion.d/* ; do
. $bcfile
done

## Contact

Email me for any problem when using taxonkit. shenwei356(at)gmail.com
Expand Down
47 changes: 36 additions & 11 deletions doc/docs/download.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,23 +6,25 @@

## Current Version

[TaxonKit v0.2.0](https://github.com/shenwei356/taxonkit/releases/tag/v0.2.0)
[![Github Releases (by Release)](https://img.shields.io/github/downloads/shenwei356/taxonkit/v0.2.0/total.svg)](https://github.com/shenwei356/taxonkit/releases/tag/v0.2.0)
[TaxonKit v0.2.1](https://github.com/shenwei356/taxonkit/releases/tag/v0.2.1)
[![Github Releases (by Release)](https://img.shields.io/github/downloads/shenwei356/taxonkit/v0.2.1/total.svg)](https://github.com/shenwei356/taxonkit/releases/tag/v0.2.1)

- add command `name2taxid` to query taxid by taxon scientific name.
- `lineage`, `reformat`: ***changed flags and default operations***,
check the [usage](http://bioinf.shenwei.me/taxonkit/usage/).
- `taxonkit list`: fix bug of no output for leaf nodes of the taxonomic tree.
[#4](https://github.com/shenwei356/taxonkit/issues/4)
- add new command `genautocomplete` to generate **shell autocompletion** script!

Links:

***Tip: run `taxonkit version` to check update !!!***

OS |Arch |File, (mirror为中国用户下载镜像链接) |Download Count
:------|:---------|:----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|:-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Linux |32-bit |[taxonkit_linux_386.tar.gz](https://github.com/shenwei356/taxonkit/releases/download/v0.2.0/taxonkit_linux_386.tar.gz), ([mirror](http://app.shenwei.me/data/taxonkit/taxonkit_linux_386.tar.gz)) |[![Github Releases (by Asset)](https://img.shields.io/github/downloads/shenwei356/taxonkit/latest/taxonkit_linux_386.tar.gz.svg?maxAge=3600)](https://github.com/shenwei356/taxonkit/releases/download/v0.2.0/taxonkit_linux_386.tar.gz)
Linux |**64-bit**|[**taxonkit_linux_amd64.tar.gz**](https://github.com/shenwei356/taxonkit/releases/download/v0.2.0/taxonkit_linux_amd64.tar.gz), ([mirror](http://app.shenwei.me/data/taxonkit/taxonkit_linux_amd64.tar.gz)) |[![Github Releases (by Asset)](https://img.shields.io/github/downloads/shenwei356/taxonkit/latest/taxonkit_linux_amd64.tar.gz.svg?maxAge=3600)](https://github.com/shenwei356/taxonkit/releases/download/v0.2.0/taxonkit_linux_amd64.tar.gz)
OS X |32-bit |[taxonkit_darwin_386.tar.gz](https://github.com/shenwei356/taxonkit/releases/download/v0.2.0/taxonkit_darwin_386.tar.gz), ([mirror](http://app.shenwei.me/data/taxonkit/taxonkit_darwin_386.tar.gz)) |[![Github Releases (by Asset)](https://img.shields.io/github/downloads/shenwei356/taxonkit/latest/taxonkit_darwin_386.tar.gz.svg?maxAge=3600)](https://github.com/shenwei356/taxonkit/releases/download/v0.2.0/taxonkit_darwin_386.tar.gz)
OS X |**64-bit**|[**taxonkit_darwin_amd64.tar.gz**](https://github.com/shenwei356/taxonkit/releases/download/v0.2.0/taxonkit_darwin_amd64.tar.gz), ([mirror](http://app.shenwei.me/data/taxonkit/taxonkit_darwin_amd64.tar.gz)) |[![Github Releases (by Asset)](https://img.shields.io/github/downloads/shenwei356/taxonkit/latest/taxonkit_darwin_amd64.tar.gz.svg?maxAge=3600)](https://github.com/shenwei356/taxonkit/releases/download/v0.2.0/taxonkit_darwin_amd64.tar.gz)
Windows|32-bit |[taxonkit_windows_386.exe.tar.gz](https://github.com/shenwei356/taxonkit/releases/download/v0.2.0/taxonkit_windows_386.exe.tar.gz), ([mirror](http://app.shenwei.me/data/taxonkit/taxonkit_windows_386.exe.tar.gz)) |[![Github Releases (by Asset)](https://img.shields.io/github/downloads/shenwei356/taxonkit/latest/taxonkit_windows_386.exe.tar.gz.svg?maxAge=3600)](https://github.com/shenwei356/taxonkit/releases/download/v0.2.0/taxonkit_windows_386.exe.tar.gz)
Windows|**64-bit**|[**taxonkit_windows_amd64.exe.tar.gz**](https://github.com/shenwei356/taxonkit/releases/download/v0.2.0/taxonkit_windows_amd64.exe.tar.gz), ([mirror](http://app.shenwei.me/data/taxonkit/taxonkit_windows_amd64.exe.tar.gz))|[![Github Releases (by Asset)](https://img.shields.io/github/downloads/shenwei356/taxonkit/latest/taxonkit_windows_amd64.exe.tar.gz.svg?maxAge=3600)](https://github.com/shenwei356/taxonkit/releases/download/v0.2.0/taxonkit_windows_amd64.exe.tar.gz)
Linux |32-bit |[taxonkit_linux_386.tar.gz](https://github.com/shenwei356/taxonkit/releases/download/v0.2.1/taxonkit_linux_386.tar.gz), ([mirror](http://app.shenwei.me/data/taxonkit/taxonkit_linux_386.tar.gz)) |[![Github Releases (by Asset)](https://img.shields.io/github/downloads/shenwei356/taxonkit/latest/taxonkit_linux_386.tar.gz.svg?maxAge=3600)](https://github.com/shenwei356/taxonkit/releases/download/v0.2.1/taxonkit_linux_386.tar.gz)
Linux |**64-bit**|[**taxonkit_linux_amd64.tar.gz**](https://github.com/shenwei356/taxonkit/releases/download/v0.2.1/taxonkit_linux_amd64.tar.gz), ([mirror](http://app.shenwei.me/data/taxonkit/taxonkit_linux_amd64.tar.gz)) |[![Github Releases (by Asset)](https://img.shields.io/github/downloads/shenwei356/taxonkit/latest/taxonkit_linux_amd64.tar.gz.svg?maxAge=3600)](https://github.com/shenwei356/taxonkit/releases/download/v0.2.1/taxonkit_linux_amd64.tar.gz)
OS X |32-bit |[taxonkit_darwin_386.tar.gz](https://github.com/shenwei356/taxonkit/releases/download/v0.2.1/taxonkit_darwin_386.tar.gz), ([mirror](http://app.shenwei.me/data/taxonkit/taxonkit_darwin_386.tar.gz)) |[![Github Releases (by Asset)](https://img.shields.io/github/downloads/shenwei356/taxonkit/latest/taxonkit_darwin_386.tar.gz.svg?maxAge=3600)](https://github.com/shenwei356/taxonkit/releases/download/v0.2.1/taxonkit_darwin_386.tar.gz)
OS X |**64-bit**|[**taxonkit_darwin_amd64.tar.gz**](https://github.com/shenwei356/taxonkit/releases/download/v0.2.1/taxonkit_darwin_amd64.tar.gz), ([mirror](http://app.shenwei.me/data/taxonkit/taxonkit_darwin_amd64.tar.gz)) |[![Github Releases (by Asset)](https://img.shields.io/github/downloads/shenwei356/taxonkit/latest/taxonkit_darwin_amd64.tar.gz.svg?maxAge=3600)](https://github.com/shenwei356/taxonkit/releases/download/v0.2.1/taxonkit_darwin_amd64.tar.gz)
Windows|32-bit |[taxonkit_windows_386.exe.tar.gz](https://github.com/shenwei356/taxonkit/releases/download/v0.2.1/taxonkit_windows_386.exe.tar.gz), ([mirror](http://app.shenwei.me/data/taxonkit/taxonkit_windows_386.exe.tar.gz)) |[![Github Releases (by Asset)](https://img.shields.io/github/downloads/shenwei356/taxonkit/latest/taxonkit_windows_386.exe.tar.gz.svg?maxAge=3600)](https://github.com/shenwei356/taxonkit/releases/download/v0.2.1/taxonkit_windows_386.exe.tar.gz)
Windows|**64-bit**|[**taxonkit_windows_amd64.exe.tar.gz**](https://github.com/shenwei356/taxonkit/releases/download/v0.2.1/taxonkit_windows_amd64.exe.tar.gz), ([mirror](http://app.shenwei.me/data/taxonkit/taxonkit_windows_amd64.exe.tar.gz))|[![Github Releases (by Asset)](https://img.shields.io/github/downloads/shenwei356/taxonkit/latest/taxonkit_windows_amd64.exe.tar.gz.svg?maxAge=3600)](https://github.com/shenwei356/taxonkit/releases/download/v0.2.1/taxonkit_windows_amd64.exe.tar.gz)


## Installation
Expand Down Expand Up @@ -61,9 +63,32 @@ And then:

go get -u github.com/shenwei356/taxonkit/taxonkit

## Bash-completion

Note: The current version supports Bash only.
This should work for *nix systems with Bash installed.

Howto:

1. run: `taxonkit genautocomplete`

2. create and edit `~/.bash_completion` file if you don't have it.

nano ~/.bash_completion

add the following:

for bcfile in ~/.bash_completion.d/* ; do
. $bcfile
done

## Previous Versions

- [TaxonKit v0.2.0](https://github.com/shenwei356/taxonkit/releases/tag/v0.2.0)
[![Github Releases (by Release)](https://img.shields.io/github/downloads/shenwei356/taxonkit/v0.2.0/total.svg)](https://github.com/shenwei356/taxonkit/releases/tag/v0.2.0)
- add command `name2taxid` to query taxid by taxon scientific name.
- `lineage`, `reformat`: ***changed flags and default operations***,
check the [usage](http://bioinf.shenwei.me/taxonkit/usage/).
- [TaxonKit v0.1.8](https://github.com/shenwei356/taxonkit/releases/tag/v0.1.8)
[![Github Releases (by Release)](https://img.shields.io/github/downloads/shenwei356/taxonkit/v0.1.8/total.svg)](https://github.com/shenwei356/taxonkit/releases/tag/v0.1.8)
- `taxonkit lineage`, add an extra column of lineage in Taxid.
Expand Down
49 changes: 42 additions & 7 deletions doc/docs/usage.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ Usage
```
TaxonKit - Cross-platform and Efficient NCBI Taxonomy Toolkit
Version: 0.2.0
Version: 0.2.1
Author: Wei Shen <shenwei356@gmail.com>
Expand All @@ -34,14 +34,16 @@ Usage:
taxonkit [command]
Available Commands:
help Help about any command
lineage query lineage of given taxids
list list taxon tree of given taxids
name2taxid query taxid by taxon scientific name
reformat reformat lineage
version print version information and check for update
genautocomplete generate shell autocompletion script
help Help about any command
lineage query lineage of given taxids
list list taxon tree of given taxids
name2taxid query taxid by taxon scientific name
reformat reformat lineage
version print version information and check for update
Flags:
-h, --help help for taxonkit
--names-file string names.dmp file (default "/home/shenwei/.taxonkit/names.dmp")
--nodes-file string nodes.dmp file (default "/home/shenwei/.taxonkit/nodes.dmp")
-o, --out-file string out file ("-" for stdout, suffix .gz for gzipped out) (default "-")
Expand Down Expand Up @@ -407,6 +409,39 @@ Example data
Homo sapiens 9606 cellular organisms;Eukaryota;Opisthokonta;Metazoa;Eumetazoa;Bilateria;Deuterostomia;Chordata;Craniata;Vertebrata;Gnathostomata;Teleostomi;Euteleostomi;Sarcopterygii;Dipnotetrapodomorpha;Tetrapoda;Amniota;Mammalia;Theria;Eutheria;Boreoeutheria;Euarchontoglires;Primates;Haplorrhini;Simiiformes;Catarrhini;Hominoidea;Hominidae;Homininae;Homo;Homo sapiens 131567;2759;33154;33208;6072;33213;33511;7711;89593;7742;7776;117570;117571;8287;1338369;32523;32524;40674;32525;9347;1437010;314146;9443;376913;314293;9526;314295;9604;207598;9605;9606
...

## genautocomplete

Usage

```
generate shell autocompletion script
Note: The current version supports Bash only.
This should work for *nix systems with Bash installed.
Howto:
1. run: taxonkit genautocomplete
2. create and edit ~/.bash_completion file if you don't have it.
nano ~/.bash_completion
add the following:
for bcfile in ~/.bash_completion.d/* ; do
. $bcfile
done
Usage:
taxonkit genautocomplete [flags]
Flags:
--file string autocompletion file (default "/home/shenwei/.bash_completion.d/taxonkit.sh")
-h, --help help for genautocomplete
--type string autocompletion type (currently only bash supported) (default "bash")
```

<div id="disqus_thread"></div>
<script>
Expand Down
83 changes: 83 additions & 0 deletions taxonkit/cmd/genautocomplete.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
// Copyright © 2016 Wei Shen <shenwei356@gmail.com>
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.

package cmd

import (
"fmt"
"os"
"path/filepath"

homedir "github.com/mitchellh/go-homedir"
"github.com/shenwei356/util/pathutil"
"github.com/spf13/cobra"
)

// genautocompleteCmd represents the fq2fa command
var genautocompleteCmd = &cobra.Command{
Use: "genautocomplete",
Short: "generate shell autocompletion script",
Long: `generate shell autocompletion script
Note: The current version supports Bash only.
This should work for *nix systems with Bash installed.
Howto:
1. run: taxonkit genautocomplete
2. create and edit ~/.bash_completion file if you don't have it.
nano ~/.bash_completion
add the following:
for bcfile in ~/.bash_completion.d/* ; do
. $bcfile
done
`,
Run: func(cmd *cobra.Command, args []string) {
autocompleteTarget := getFlagString(cmd, "file")
autocompleteType := getFlagString(cmd, "type")

if autocompleteType != "bash" {
checkError(fmt.Errorf("only Bash is supported for now"))
}

dir := filepath.Dir(autocompleteTarget)
ok, err := pathutil.DirExists(dir)
checkError(err)
if !ok {
os.MkdirAll(dir, 0744)
}
checkError(cmd.Root().GenBashCompletionFile(autocompleteTarget))

log.Infof("bash completion file for taxonkit saved to %s", autocompleteTarget)
},
}

func init() {
RootCmd.AddCommand(genautocompleteCmd)
defaultCompletionFile, err := homedir.Expand("~/.bash_completion.d/taxonkit.sh")
checkError(err)
genautocompleteCmd.Flags().StringP("file", "", defaultCompletionFile, "autocompletion file")
genautocompleteCmd.Flags().StringP("type", "", "bash", "autocompletion type (currently only bash supported)")
}
2 changes: 1 addition & 1 deletion taxonkit/cmd/helper.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ import (
)

// VERSION of csvtk
const VERSION = "0.2.0"
const VERSION = "0.2.1"

// Config is the struct containing all global flags
type Config struct {
Expand Down
1 change: 1 addition & 0 deletions taxonkit/cmd/list.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ var listCmd = &cobra.Command{
tree[parent] = make(map[int32]bool)
}
tree[parent][child] = false
tree[child] = make(map[int32]bool)
if printRank {
ranks[child] = info.rank
}
Expand Down
1 change: 1 addition & 0 deletions taxonkit/taxids.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
9606
9913
349741
239935
11932
Expand Down

0 comments on commit fd659d5

Please sign in to comment.