Skip to content

Commit

Permalink
add new flag --compress-level to set compression level. #320 . suppor…
Browse files Browse the repository at this point in the history
…t bzip2 #361
  • Loading branch information
shenwei356 committed Mar 14, 2023
1 parent d1e0ea2 commit 4081f4d
Show file tree
Hide file tree
Showing 8 changed files with 100 additions and 28 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
- [SeqKit v2.4.0](https://github.com/shenwei356/seqkit/releases/tag/v2.4.0) - 2022-09-22
[![Github Releases (by Release)](https://img.shields.io/github/downloads/shenwei356/seqkit/v2.4.0/total.svg)](https://github.com/shenwei356/seqkit/releases/tag/v2.4.0)
- `seqkit`:
- support `bzip2` format. [#361](https://github.com/shenwei356/seqkit/issues/361)
- support setting compression level for `gzip`, `zstd`, and `bzip2` format via `--compress-level`. [#320](https://github.com/shenwei356/seqkit/issues/320)
- the global flag `--infile-list` accepts stdin "-" now.
- `seqkit locate`:
- **do not remove embeded regions when searching with regular expressions**. [#368](https://github.com/shenwei356/seqkit/issues/368)
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ and
- **Easy to use**
- Ultrafast (see [technical-details](http://bioinf.shenwei.me/seqkit/usage/#technical-details-and-guides-for-use) and [benchmark](http://bioinf.shenwei.me/seqkit/benchmark))
- Seamlessly parsing both FASTA and FASTQ formats
- Supporting (`gzip`/`xz`/`zstd` compressed) STDIN/STDOUT and input/output file, easily integrated in pipe
- Supporting (`gzip`/`xz`/`zstd`/`bzip2` compressed) STDIN/STDOUT and input/output file, easily integrated in pipe
- Reproducible results (configurable rand seed in `sample` and `shuffle`)
- Supporting custom sequence ID via regular expression
- Supporting [Bash/Zsh completion](http://bioinf.shenwei.me/seqkit/download/#shell-completion)
Expand Down
17 changes: 14 additions & 3 deletions doc/docs/usage.md
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ reproduced in different environments with same random seed.
``` text
SeqKit -- a cross-platform and ultrafast toolkit for FASTA/Q file manipulation
Version: 2.3.0
Version: 2.4.0
Author: Wei Shen <[email protected]>
Expand All @@ -172,6 +172,16 @@ larger than files generated by GNU gzip.
Seqkit writes gzip files very fast, much faster than the multi-threaded pigz,
therefore there's no need to pipe the result to gzip/pigz.
Seqkit also supports reading and writing xz (.xz) and zstd (.zst) formats since v2.2.0.
Bzip2 format is supported since v2.4.0.
Compression level:
format range default comment
gzip 1-9 5 https://github.com/klauspost/pgzip sets 5 as the default value.
xz NA NA https://github.com/ulikunitz/xz does not support.
zstd 1-4 2 roughly equals to zstd 1, 3, 7, 11, respectively.
bzip 1-9 6 https://github.com/dsnet/compress
Usage:
seqkit [command]
Expand Down Expand Up @@ -202,7 +212,7 @@ Available Commands:
sample sample sequences by number or proportion
sana sanitize broken single line FASTQ files
scat real time recursive concatenation and streaming of fastx files
seq transform sequences (extract ID, filter by length, remove gaps...)
seq transform sequences (extract ID, filter by length, remove gaps, reverse complement...)
shuffle shuffle sequences
sliding extract subsequences in sliding windows
sort sort sequences by id/name/sequence/length
Expand All @@ -218,11 +228,12 @@ Available Commands:
Flags:
--alphabet-guess-seq-length int length of sequence prefix of the first FASTA record based on which seqkit guesses the sequence type (0 for whole seq) (default 10000)
--compress-level int compression level for gzip, zstd, xz and bzip2. type "seqkit -h" for the range and default value for each format (default -1)
-h, --help help for seqkit
--id-ncbi FASTA head is NCBI-style, e.g. >gi|110645304|ref|NC_002516.2| Pseud...
--id-regexp string regular expression for parsing ID (default "^(\\S+)\\s?")
--infile-list string file of input files list (one file per line), if given, they are appended to files from cli arguments
-w, --line-width int line width when outputing FASTA format (0 for no wrap) (default 60)
-w, --line-width int line width when outputting FASTA format (0 for no wrap) (default 60)
-o, --out-file string out file ("-" for stdout, suffix .gz for gzipped out) (default "-")
--quiet be quiet and do not show extra information
-t, --seq-type string sequence type (dna|rna|protein|unlimit|auto) (for auto, it automatically detect by the first sequence) (default "auto")
Expand Down
11 changes: 5 additions & 6 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ require (
github.com/dustin/go-humanize v1.0.0
github.com/fsnotify/fsnotify v1.5.4
github.com/iafan/cwalk v0.0.0-20210125030640-586a8832a711
github.com/klauspost/compress v1.15.12
github.com/klauspost/compress v1.16.3
github.com/klauspost/pgzip v1.2.5
github.com/logrusorgru/aurora v2.0.3+incompatible
github.com/mattn/go-colorable v0.1.13
Expand All @@ -23,7 +23,7 @@ require (
github.com/shenwei356/bwt v0.6.1
github.com/shenwei356/go-logging v0.0.0-20171012171522-c6b9702d88ba
github.com/shenwei356/util v0.5.1
github.com/shenwei356/xopen v0.2.2
github.com/shenwei356/xopen v0.3.1
github.com/smallfish/simpleyaml v0.1.0
github.com/spf13/cobra v1.5.0
github.com/tatsushid/go-prettytable v0.0.0-20141013043238-ed2d14c29939
Expand All @@ -36,7 +36,7 @@ replace github.com/miekg/dns v1.0.14 => github.com/miekg/dns v1.1.46
require (
git.sr.ht/~sbinet/gg v0.3.1 // indirect
github.com/ajstarks/svgo v0.0.0-20211024235047-1546f124cd8b // indirect
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/dsnet/compress v0.0.1 // indirect
github.com/edsrzf/mmap-go v1.1.0 // indirect
github.com/go-fonts/liberation v0.2.0 // indirect
github.com/go-latex/latex v0.0.0-20210823091927-c0d11ff05a81 // indirect
Expand All @@ -49,11 +49,10 @@ require (
github.com/shenwei356/natsort v0.0.0-20220117010048-580176ad49fb // indirect
github.com/spf13/pflag v1.0.5 // indirect
golang.org/x/crypto v0.0.0-20220919173607-35f4265a4bc0 // indirect
golang.org/x/image v0.5.0 // indirect
golang.org/x/image v0.0.0-20220902085622-e7cb96979f69 // indirect
golang.org/x/sys v0.0.0-20220919091848-fb04ddd9f9c8 // indirect
golang.org/x/term v0.0.0-20220919170432-7a66f970e087 // indirect
golang.org/x/text v0.7.0 // indirect
golang.org/x/text v0.3.7 // indirect
gonum.org/v1/plot v0.12.0 // indirect
gopkg.in/yaml.v2 v2.4.0 // indirect
gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b // indirect
)
25 changes: 13 additions & 12 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,11 @@ github.com/cpuguy83/go-md2man/v2 v2.0.2/go.mod h1:tgQtvFlXSQOSOSIRvRPT7W67SCa46t
github.com/cznic/mathutil v0.0.0-20181122101859-297441e03548 h1:iwZdTE0PVqJCos1vaoKsclOGD3ADKpshg3SRtYBbwso=
github.com/cznic/sortutil v0.0.0-20181122101858-f5f958428db8 h1:LpMLYGyy67BoAFGda1NeOBQwqlv7nUXpm+rIVHGxZZ4=
github.com/cznic/sortutil v0.0.0-20181122101858-f5f958428db8/go.mod h1:q2w6Bg5jeox1B+QkJ6Wp/+Vn0G/bo3f1uY7Fn3vivIQ=
github.com/davecgh/go-spew v1.1.0 h1:ZDRjVQ15GmhC3fiQ8ni8+OwkZQO4DARzQgrnXU1Liz8=
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/dsnet/compress v0.0.1 h1:PlZu0n3Tuv04TzpfPbrnI0HW/YwodEXDS+oPKahKF0Q=
github.com/dsnet/compress v0.0.1/go.mod h1:Aw8dCMJ7RioblQeTqt88akK31OvO8Dhf5JflhBbQEHo=
github.com/dsnet/golib v0.0.0-20171103203638-1ea166775780/go.mod h1:Lj+Z9rebOhdfkVLjJ8T6VcRQv3SXugXy999NBtR9aFY=
github.com/dustin/go-humanize v1.0.0 h1:VSnTsYCnlFHaM2/igO1h6X3HA71jcobQuxemgkq4zYo=
github.com/dustin/go-humanize v1.0.0/go.mod h1:HtrtbFcZ19U5GC7JDqmcUSB87Iq5E25KnS6fMYU6eOk=
github.com/edsrzf/mmap-go v1.1.0 h1:6EUwBLQ/Mcr1EYLE4Tn1VdW1A4ckqCQWZBw8Hr0kjpQ=
Expand Down Expand Up @@ -71,8 +73,10 @@ github.com/jung-kurt/gofpdf v1.0.0/go.mod h1:7Id9E/uU8ce6rXgefFLlgrJj/GYY22cpxn+
github.com/jung-kurt/gofpdf v1.0.3-0.20190309125859-24315acbbda5/go.mod h1:7Id9E/uU8ce6rXgefFLlgrJj/GYY22cpxn+r32jIOes=
github.com/jung-kurt/gofpdf v1.16.2/go.mod h1:1hl7y57EsiPAkLbOwzpzqgx1A30nQCk/YmFV8S2vmK0=
github.com/kisielk/gotool v1.0.0/go.mod h1:XhKaO+MFFWcvkIS/tQcRk01m1F5IRFswLeQ+oQHNcck=
github.com/klauspost/compress v1.15.12 h1:YClS/PImqYbn+UILDnqxQCZ3RehC9N318SU3kElDUEM=
github.com/klauspost/compress v1.15.12/go.mod h1:QPwzmACJjUTFsnSHH934V6woptycfrDDJnH7hvFVbGM=
github.com/klauspost/compress v1.4.1/go.mod h1:RyIbtBH6LamlWaDj8nUwkbUhJ87Yi3uG0guNDohfE1A=
github.com/klauspost/compress v1.16.3 h1:XuJt9zzcnaz6a16/OU53ZjWp/v7/42WcR5t2a0PcNQY=
github.com/klauspost/compress v1.16.3/go.mod h1:ntbaceVETuRiXiv4DpjP66DpAtAGkEQskQzEyD//IeE=
github.com/klauspost/cpuid v1.2.0/go.mod h1:Pj4uuM528wm8OyEC2QMXAi2YiTZ96dNQPGgoMS4s3ek=
github.com/klauspost/pgzip v1.2.5 h1:qnWYvvKqedOF2ulHpMG72XQol4ILEJ8k2wwRl/Km8oE=
github.com/klauspost/pgzip v1.2.5/go.mod h1:Ch1tH69qFZu15pkjo5kYi6mth2Zzwzt50oCQKQE9RUs=
github.com/kortschak/utter v0.0.0-20190412033250-50fe362e6560/go.mod h1:oDr41C7kH9wvAikWyFhr6UFr8R7nelpmCF5XR5rL7I8=
Expand Down Expand Up @@ -122,8 +126,8 @@ github.com/shenwei356/natsort v0.0.0-20220117010048-580176ad49fb h1:pb0RhpaADsFr
github.com/shenwei356/natsort v0.0.0-20220117010048-580176ad49fb/go.mod h1:SiiGiRFyRtV7S9RamOrmQR5gpGIRhWJM1w0EtmuQ1io=
github.com/shenwei356/util v0.5.1 h1:m3SjmJvIkEr7hQ1LyGGy5cgfQFSFOww2wmpZ0/hIiIM=
github.com/shenwei356/util v0.5.1/go.mod h1:3tRAOfreWdgl/Zh1gE008h2lWocf5/YAxVSjgLKvd4k=
github.com/shenwei356/xopen v0.2.2 h1:g1v3YjiIky9k6oN4qmnU1bDciAHnSrmOn2sMTE5pChY=
github.com/shenwei356/xopen v0.2.2/go.mod h1:6EQUa6I7Zsl2GQKqcL9qGLrTzVE+oZyly+uhzovQYSk=
github.com/shenwei356/xopen v0.3.1 h1:3pju0hVeRRnlpXC7s3aE/RVOhFB1S3qRJGN+eV85r3s=
github.com/shenwei356/xopen v0.3.1/go.mod h1:6EQUa6I7Zsl2GQKqcL9qGLrTzVE+oZyly+uhzovQYSk=
github.com/smallfish/simpleyaml v0.1.0 h1:5uAZdLAiHxS9cmzkOxg7lH0dILXKTD7uRZbAhyHmyU0=
github.com/smallfish/simpleyaml v0.1.0/go.mod h1:gU3WdNn44dQVAbVHD2SrSqKKCvmzFApWD2UURhgEj1M=
github.com/spf13/cobra v1.5.0 h1:X+jTBEBqF0bHN+9cSMgmfuvv2VHJ9ezmFNf9Y/XstYU=
Expand Down Expand Up @@ -175,9 +179,8 @@ golang.org/x/image v0.0.0-20210607152325-775e3b0c77b9/go.mod h1:023OzeP/+EPmXeap
golang.org/x/image v0.0.0-20210628002857-a66eb6448b8d/go.mod h1:023OzeP/+EPmXeapQh35lcL3II3LrY8Ic+EFFKVhULM=
golang.org/x/image v0.0.0-20211028202545-6944b10bf410/go.mod h1:023OzeP/+EPmXeapQh35lcL3II3LrY8Ic+EFFKVhULM=
golang.org/x/image v0.0.0-20220302094943-723b81ca9867/go.mod h1:023OzeP/+EPmXeapQh35lcL3II3LrY8Ic+EFFKVhULM=
golang.org/x/image v0.0.0-20220902085622-e7cb96979f69 h1:Lj6HJGCSn5AjxRAH2+r35Mir4icalbqku+CLUtjnvXY=
golang.org/x/image v0.0.0-20220902085622-e7cb96979f69/go.mod h1:doUCurBvlfPMKfmIpRIywoHmhN3VyhnoFDbvIEWF4hY=
golang.org/x/image v0.5.0 h1:5JMiNunQeQw++mMOz48/ISeNu3Iweh/JaZU8ZLqHRrI=
golang.org/x/image v0.5.0/go.mod h1:FVC7BI/5Ym8R25iw5OLsgshdUBbT1h5jZTpA+mvAdZ4=
golang.org/x/mobile v0.0.0-20190312151609-d3739f865fa6/go.mod h1:z+o9i4GpDbdi3rU15maQ/Ox0txvL9dWGYEHz965HBQE=
golang.org/x/mobile v0.0.0-20190719004257-d2bd2a29d028/go.mod h1:E/iHnbuqvinMTCcRqshq8CkpyQDoeVncDDYHnLhea+o=
golang.org/x/mobile v0.0.0-20201217150744-e6ae53a27f4f/go.mod h1:skQtrUTUwhdJvXM/2KKJzY8pDgNr9I/FOMqDVRPBUS4=
Expand Down Expand Up @@ -223,9 +226,8 @@ golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
golang.org/x/text v0.3.5/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
golang.org/x/text v0.3.6/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
golang.org/x/text v0.3.7 h1:olpwvP2KacW1ZWvsR7uQhoyTYvKAupfQrRGBFM352Gk=
golang.org/x/text v0.3.7/go.mod h1:u+2+/6zg+i71rQMx5EYifcz6MCKuco9NR6JIITiCfzQ=
golang.org/x/text v0.7.0 h1:4BRB4x83lYWy72KwLD/qYDuTu7q9PjSagHvijDw7cLo=
golang.org/x/text v0.7.0/go.mod h1:mrYo+phRRbMaCq/xk9113O4dZlRixOauAjOtrjsXDZ8=
golang.org/x/tools v0.0.0-20180525024113-a5b4c53f6e8b/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
golang.org/x/tools v0.0.0-20190206041539-40960b6deb8e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
Expand Down Expand Up @@ -259,9 +261,8 @@ gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15/go.mod h1:Co6ibVJAznAaIkqp8
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c h1:Hei/4ADfdWqJk1ZMxUNpqntNwaWcugrBjAiHlqqRiVk=
gopkg.in/yaml.v2 v2.4.0 h1:D8xgwECY7CYvx+Y2n4sBz93Jn9JRvxdiyyo8CTfuKaY=
gopkg.in/yaml.v2 v2.4.0/go.mod h1:RDklbk79AGWmwhnvt/jBztapEOGDOx6ZbXqjP6csGnQ=
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c h1:dUUwHk2QECo/6vqA44rthZ8ie2QXMNeKRTHCNY2nXvo=
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b h1:h8qDotaEPuJATrMmW04NCwg7v22aHH28wwpauUhK9Oo=
gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
honnef.co/go/tools v0.1.3/go.mod h1:NgwopIslSNH47DimFoV78dnkksY2EFtX0ajyb3K/las=
modernc.org/cc v1.0.0/go.mod h1:1Sk4//wdnYJiUIxnW8ddKpaOJCF37yAdqYnkxUpaYxw=
modernc.org/golex v1.0.0/go.mod h1:b/QX9oBD/LhixY6NDh+IdGv17hgB+51fET1i2kPSmvk=
Expand Down
35 changes: 34 additions & 1 deletion seqkit/cmd/helper.go
Original file line number Diff line number Diff line change
Expand Up @@ -238,23 +238,56 @@ type Config struct {
Quiet bool
AlphabetGuessSeqLength int
ValidateSeqLength int
CompressionLevel int
}

func getConfigs(cmd *cobra.Command) Config {
threads := getFlagPositiveInt(cmd, "threads")
if threads >= 1000 {
checkError(fmt.Errorf("are your seriously? %d threads? It will exhaust your RAM", threads))
}
outfile := getFlagString(cmd, "out-file")

level := getFlagInt(cmd, "compress-level")

f := strings.ToLower(outfile)
var ranges [3]int
var format string
checkCompressLevel := true
if strings.HasSuffix(f, ".gz") {
format = "gzip"
ranges = [3]int{1, 9, 5}
} else if strings.HasSuffix(f, ".xz") {
checkCompressLevel = false
} else if strings.HasSuffix(f, ".zst") {
format = "zstd"
ranges = [3]int{1, 4, 2}
} else if strings.HasSuffix(f, ".bz2") {
format = "bzip2"
ranges = [3]int{1, 9, 6}
} else {
checkCompressLevel = false
}
if checkCompressLevel {
if level == -1 {
level = ranges[2]
}
if level < ranges[0] || level > ranges[1] {
checkError(fmt.Errorf("compression level out of range for %s format (%d-%d): %d", format, ranges[0], ranges[1], level))
}
}
xopen.Level = level

return Config{
Alphabet: getAlphabet(cmd, "seq-type"),
Threads: threads,
LineWidth: getFlagNonNegativeInt(cmd, "line-width"),
IDRegexp: getIDRegexp(cmd, "id-regexp"),
IDNCBI: getFlagBool(cmd, "id-ncbi"),
OutFile: getFlagString(cmd, "out-file"),
OutFile: outfile,
Quiet: getFlagBool(cmd, "quiet"),
AlphabetGuessSeqLength: getFlagAlphabetGuessSeqLength(cmd, "alphabet-guess-seq-length"),
CompressionLevel: level,
}

}
Expand Down
9 changes: 9 additions & 0 deletions seqkit/cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,14 @@ Seqkit writes gzip files very fast, much faster than the multi-threaded pigz,
therefore there's no need to pipe the result to gzip/pigz.
Seqkit also supports reading and writing xz (.xz) and zstd (.zst) formats since v2.2.0.
Bzip2 format is supported since v2.4.0.
Compression level:
format range default comment
gzip 1-9 5 https://github.com/klauspost/pgzip sets 5 as the default value.
xz NA NA https://github.com/ulikunitz/xz does not support.
zstd 1-4 2 roughly equals to zstd 1, 3, 7, 11, respectively.
bzip 1-9 6 https://github.com/dsnet/compress
`, VERSION),
}
Expand Down Expand Up @@ -90,6 +98,7 @@ func init() {
RootCmd.PersistentFlags().BoolP("quiet", "", false, "be quiet and do not show extra information")
RootCmd.PersistentFlags().IntP("alphabet-guess-seq-length", "", 10000, "length of sequence prefix of the first FASTA record based on which seqkit guesses the sequence type (0 for whole seq)")
RootCmd.PersistentFlags().StringP("infile-list", "", "", "file of input files list (one file per line), if given, they are appended to files from cli arguments")
RootCmd.PersistentFlags().IntP("compress-level", "", -1, `compression level for gzip, zstd, xz and bzip2. type "seqkit -h" for the range and default value for each format`)

RootCmd.CompletionOptions.DisableDefaultCmd = true
RootCmd.SetHelpCommand(&cobra.Command{Hidden: true})
Expand Down
27 changes: 22 additions & 5 deletions seqkit/cmd/seq.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ import (

// "runtime/debug"

"github.com/dsnet/compress/bzip2"
gzip "github.com/klauspost/pgzip"
"github.com/shenwei356/bio/seq"
"github.com/shenwei356/bio/seqio/fastx"
Expand Down Expand Up @@ -157,21 +158,27 @@ var seqCmd = &cobra.Command{
color = false
}

gzippedOutfile := strings.HasSuffix(strings.ToLower(outFile), ".gz")
xzOutfile := strings.HasSuffix(strings.ToLower(outFile), ".xz")
zstdOutfile := strings.HasSuffix(strings.ToLower(outFile), ".zst")
outFileLower := strings.ToLower(outFile)
gzippedOutfile := strings.HasSuffix(outFileLower, ".gz")
xzOutfile := strings.HasSuffix(outFileLower, ".xz")
zstdOutfile := strings.HasSuffix(outFileLower, ".zst")
bzip2Outfile := strings.HasSuffix(outFileLower, ".bz2")

var fh io.Writer
var outbw *bufio.Writer
var gw *gzip.Writer
var xw *xz.Writer
var zw *zstd.Encoder
var bz2 *bzip2.Writer

if color {
fh = seqCol.WrapWriter(outfh)
outbw = bufio.NewWriterSize(fh, bufSize)
} else if gzippedOutfile {
gw = gzip.NewWriter(outfh)
gw, err = gzip.NewWriterLevel(outfh, config.CompressionLevel)
if err != nil {
checkError(err)
}
outbw = bufio.NewWriterSize(gw, bufSize)
} else if xzOutfile {
xw, err = xz.NewWriter(outfh)
Expand All @@ -180,11 +187,17 @@ var seqCmd = &cobra.Command{
}
outbw = bufio.NewWriterSize(xw, bufSize)
} else if zstdOutfile {
zw, err = zstd.NewWriter(outfh)
zw, err = zstd.NewWriter(outfh, zstd.WithEncoderLevel(zstd.EncoderLevel(config.CompressionLevel)))
if err != nil {
checkError(err)
}
outbw = bufio.NewWriterSize(zw, bufSize)
} else if bzip2Outfile {
bz2, err = bzip2.NewWriter(outfh, &bzip2.WriterConfig{Level: config.CompressionLevel})
if err != nil {
checkError(err)
}
outbw = bufio.NewWriterSize(bz2, bufSize)
} else {
fh = outfh
outbw = bufio.NewWriterSize(fh, bufSize)
Expand All @@ -206,6 +219,10 @@ var seqCmd = &cobra.Command{
checkError(zw.Close())
}

if bzip2Outfile {
checkError(bz2.Close())
}

checkError(outfh.Close())
}()

Expand Down

0 comments on commit 4081f4d

Please sign in to comment.