Skip to content

Commit 1680862

Browse files
committed
sliding output supports fastq now
1 parent a943240 commit 1680862

File tree

4 files changed

+20
-22
lines changed

4 files changed

+20
-22
lines changed

doc/docs/download.md

+2-1
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,8 @@ For Go developer, just one command:
8181
- [SeqKit v0.3.2](https://github.com/shenwei356/seqkit/releases/tag/v0.3.2)
8282
- fix bug of `seqkit split`, error when target file is in a directory.
8383
- improve performance of `seqkit spliding` for big sequences, and output
84-
last part even if it's shorter than window sze.
84+
last part even if it's shorter than window sze,
85+
output of FASTQ is also supported.
8586
- [SeqKit v0.3.1.1](https://github.com/shenwei356/seqkit/releases/tag/v0.3.1.1)
8687
- compile with go1.7rc5, with ***higher performance and smaller size of binary file***
8788
- [SeqKit v0.3.1](https://github.com/shenwei356/seqkit/releases/tag/v0.3.1)

doc/site

+1-1
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
Subproject commit b57dcfbb0fd4a90b2f19ee80d8fc36bd0f8f5690
1+
Subproject commit 782503376f2ab54df795036d02c9dadfab6155f7

seqkit/cmd/sliding.go

+16-19
Original file line numberDiff line numberDiff line change
@@ -21,14 +21,12 @@
2121
package cmd
2222

2323
import (
24-
"bytes"
2524
"fmt"
2625
"io"
2726
"runtime"
2827

2928
"github.com/shenwei356/bio/seq"
3029
"github.com/shenwei356/bio/seqio/fastx"
31-
"github.com/shenwei356/util/byteutil"
3230
"github.com/shenwei356/xopen"
3331
"github.com/spf13/cobra"
3432
)
@@ -69,10 +67,9 @@ var slidingCmd = &cobra.Command{
6967
checkError(err)
7068
defer outfh.Close()
7169

72-
var sequence, s []byte
70+
var sequence, s, qual, q []byte
71+
var r *fastx.Record
7372
var originalLen, l, end, e int
74-
var text []byte
75-
var b *bytes.Buffer
7673
for _, file := range files {
7774
fastxReader, err := fastx.NewReader(alphabet, file, idRegexp)
7875
checkError(err)
@@ -88,6 +85,7 @@ var slidingCmd = &cobra.Command{
8885

8986
originalLen = len(record.Seq.Seq)
9087
sequence = record.Seq.Seq
88+
qual = record.Seq.Qual
9189
l = len(sequence)
9290
end = l - 1
9391
if end < 0 {
@@ -99,26 +97,25 @@ var slidingCmd = &cobra.Command{
9997
e = e - originalLen
10098
s = sequence[i:]
10199
s = append(s, sequence[0:e]...)
100+
if len(qual) > 0 {
101+
q = qual[i:]
102+
q = append(q, qual[0:e]...)
103+
}
102104
} else {
103105
s = sequence[i : i+window]
106+
if len(qual) > 0 {
107+
q = qual[i : i+window]
108+
}
104109
}
105-
outfh.WriteString(fmt.Sprintf(">%s_sliding:%d-%d\n",
106-
record.ID, i+1, e))
107110

108-
// outfh.Write(byteutil.WrapByteSlice(sequence[i:i+window], lineWidth))
109-
if window <= pageSize {
110-
outfh.Write(byteutil.WrapByteSlice(s, lineWidth))
111+
if len(qual) > 0 {
112+
r, _ = fastx.NewRecordWithQualWithoutValidation(record.Seq.Alphabet,
113+
[]byte{}, []byte(fmt.Sprintf("%s_sliding:%d-%d", record.ID, i+1, e)), s, q)
111114
} else {
112-
if bufferedByteSliceWrapper == nil {
113-
bufferedByteSliceWrapper = byteutil.NewBufferedByteSliceWrapper2(1, window, lineWidth)
114-
}
115-
text, b = bufferedByteSliceWrapper.Wrap(s, lineWidth)
116-
outfh.Write(text)
117-
outfh.Flush()
118-
bufferedByteSliceWrapper.Recycle(b)
115+
r, _ = fastx.NewRecordWithoutValidation(record.Seq.Alphabet,
116+
[]byte{}, []byte(fmt.Sprintf("%s_sliding:%d-%d", record.ID, i+1, e)), s)
119117
}
120-
121-
outfh.WriteString("\n")
118+
r.FormatToWriter(outfh, lineWidth)
122119
}
123120
}
124121
}

seqkit/download_all_binaries.sh

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#!/bin/sh
22

33
rm seqkit_*.tar.gz
4-
version="0.3.1.1"
4+
version="0.3.2"
55

66
wget https://github.com/shenwei356/seqkit/releases/download/v$version/seqkit_linux_386.tar.gz
77
wget https://github.com/shenwei356/seqkit/releases/download/v$version/seqkit_linux_amd64.tar.gz

0 commit comments

Comments
 (0)