21
21
package cmd
22
22
23
23
import (
24
- "bytes"
25
24
"fmt"
26
25
"io"
27
26
"runtime"
28
27
29
28
"github.com/shenwei356/bio/seq"
30
29
"github.com/shenwei356/bio/seqio/fastx"
31
- "github.com/shenwei356/util/byteutil"
32
30
"github.com/shenwei356/xopen"
33
31
"github.com/spf13/cobra"
34
32
)
@@ -69,10 +67,9 @@ var slidingCmd = &cobra.Command{
69
67
checkError (err )
70
68
defer outfh .Close ()
71
69
72
- var sequence , s []byte
70
+ var sequence , s , qual , q []byte
71
+ var r * fastx.Record
73
72
var originalLen , l , end , e int
74
- var text []byte
75
- var b * bytes.Buffer
76
73
for _ , file := range files {
77
74
fastxReader , err := fastx .NewReader (alphabet , file , idRegexp )
78
75
checkError (err )
@@ -88,6 +85,7 @@ var slidingCmd = &cobra.Command{
88
85
89
86
originalLen = len (record .Seq .Seq )
90
87
sequence = record .Seq .Seq
88
+ qual = record .Seq .Qual
91
89
l = len (sequence )
92
90
end = l - 1
93
91
if end < 0 {
@@ -99,26 +97,25 @@ var slidingCmd = &cobra.Command{
99
97
e = e - originalLen
100
98
s = sequence [i :]
101
99
s = append (s , sequence [0 :e ]... )
100
+ if len (qual ) > 0 {
101
+ q = qual [i :]
102
+ q = append (q , qual [0 :e ]... )
103
+ }
102
104
} else {
103
105
s = sequence [i : i + window ]
106
+ if len (qual ) > 0 {
107
+ q = qual [i : i + window ]
108
+ }
104
109
}
105
- outfh .WriteString (fmt .Sprintf (">%s_sliding:%d-%d\n " ,
106
- record .ID , i + 1 , e ))
107
110
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 )
111
114
} 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 )
119
117
}
120
-
121
- outfh .WriteString ("\n " )
118
+ r .FormatToWriter (outfh , lineWidth )
122
119
}
123
120
}
124
121
}
0 commit comments