Skip to content

Commit

Permalink
better output for bits presentation of encoded k-mers
Browse files Browse the repository at this point in the history
  • Loading branch information
shenwei356 committed Jan 21, 2019
1 parent 4361491 commit b34a062
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 2 deletions.
2 changes: 2 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
- v0.6.2
- `unikmer encode`: better output for bits presentation of encoded k-mers (`-a/--all`)
- v0.6.1
- `unikmer dump`:
- new option `-K/--canonical` to keep the canonical k-mers.
Expand Down
12 changes: 12 additions & 0 deletions kmer.go
Original file line number Diff line number Diff line change
Expand Up @@ -223,6 +223,9 @@ func RevComp(code uint64, k int) (c uint64) {
// bit2base is for mapping bit to base.
var bit2base = [4]byte{'A', 'C', 'G', 'T'}

// bit2str is for output bits string
var bit2str = [4]string{"00", "01", "10", "11"}

// Decode converts the code to original seq
func Decode(code uint64, k int) []byte {
if k <= 0 || k > 32 {
Expand Down Expand Up @@ -311,3 +314,12 @@ func (kcode KmerCode) Bytes() []byte {
func (kcode KmerCode) String() string {
return string(Decode(kcode.Code, kcode.K))
}

// BitsString returns code to string
func (kcode KmerCode) BitsString() string {
var buf bytes.Buffer
for _, b := range Decode(kcode.Code, kcode.K) {
buf.WriteString(bit2str[base2bit[b]])
}
return buf.String()
}
2 changes: 1 addition & 1 deletion unikmer/cmd/encode.go
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ var encodeCmd = &cobra.Command{
}

if all {
outfh.WriteString(fmt.Sprintf("%s\t%s\t%d\t%b\n", line, kcode.String(), kcode.Code, kcode.Code))
outfh.WriteString(fmt.Sprintf("%s\t%s\t%d\t%s\n", line, kcode.String(), kcode.Code, kcode.BitsString()))
} else {
outfh.WriteString(fmt.Sprintf("%d\n", kcode.Code))
}
Expand Down
2 changes: 1 addition & 1 deletion unikmer/cmd/version.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ import (
)

// VERSION is the version
var VERSION = "0.6.1"
var VERSION = "0.6.2"

// versionCmd represents the version command
var versionCmd = &cobra.Command{
Expand Down

0 comments on commit b34a062

Please sign in to comment.