10
10
import org .testng .annotations .DataProvider ;
11
11
import org .testng .annotations .Test ;
12
12
13
- import java .io .ByteArrayOutputStream ;
14
13
import java .io .IOException ;
15
14
import java .io .InputStream ;
16
15
import java .nio .ByteBuffer ;
20
19
import java .util .ArrayList ;
21
20
import java .util .List ;
22
21
22
+ import static htsjdk .samtools .cram .CRAMInteropTestUtils .filterEmbeddedNewlines ;
23
+ import static htsjdk .samtools .cram .CRAMInteropTestUtils .getInteropCompressedFilePaths ;
24
+ import static htsjdk .samtools .cram .CRAMInteropTestUtils .getParamsFormatFlags ;
25
+ import static htsjdk .samtools .cram .CRAMInteropTestUtils .getUnCompressedFilePath ;
26
+
23
27
public class RangeInteropTest extends HtsjdkTest {
24
28
public static final String COMPRESSED_RANGE_DIR = "arith" ;
25
29
@@ -30,13 +34,13 @@ public Object[][] getRoundTripTestCases() throws IOException {
30
34
// compressed testfile path, uncompressed testfile path,
31
35
// Range encoder, Range decoder, Range params
32
36
final List <Object []> testCases = new ArrayList <>();
33
- for (Path path : getInteropRangeCompressedFilePaths (COMPRESSED_RANGE_DIR )) {
37
+ for (Path path : getInteropCompressedFilePaths (COMPRESSED_RANGE_DIR )) {
34
38
Object [] objects = new Object []{
35
39
path ,
36
- getRangeUnCompressedFilePath (path ),
40
+ getUnCompressedFilePath (path ),
37
41
new RangeEncode (),
38
42
new RangeDecode (),
39
- getRangeParams ( path )
43
+ new RangeParams ( getParamsFormatFlags ( path ) )
40
44
};
41
45
testCases .add (objects );
42
46
}
@@ -109,68 +113,4 @@ public void testDecodeOnly(
109
113
}
110
114
}
111
115
112
- // the input files have embedded newlines that the test remove before round-tripping...
113
- private final byte [] filterEmbeddedNewlines (final byte [] rawBytes ) throws IOException {
114
- // 1. filters new lines if any.
115
- // 2. "q40+dir" file has an extra column delimited by tab. This column provides READ1 vs READ2 flag.
116
- // This file is also new-line separated. The extra column, '\t' and '\n' are filtered.
117
- try (final ByteArrayOutputStream baos = new ByteArrayOutputStream ()) {
118
- int skip = 0 ;
119
- for (final byte b : rawBytes ) {
120
- if (b == '\t' ){
121
- skip = 1 ;
122
- }
123
- if (b == '\n' ) {
124
- skip = 0 ;
125
- }
126
- if (skip == 0 && b !='\n' ) {
127
- baos .write (b );
128
- }
129
- }
130
- return baos .toByteArray ();
131
- }
132
- }
133
-
134
- // return a list of all encoded test data files in the htscodecs/tests/dat/<compressedDir> directory
135
- private List <Path > getInteropRangeCompressedFilePaths (final String compressedDir ) throws IOException {
136
- final List <Path > paths = new ArrayList <>();
137
- Files .newDirectoryStream (
138
- CRAMInteropTestUtils .getInteropTestDataLocation ().resolve ("dat/" +compressedDir ),
139
- path -> Files .isRegularFile (path ))
140
- .forEach (path -> paths .add (path ));
141
- return paths ;
142
- }
143
-
144
- // Given a compressed test file path, return the corresponding uncompressed file path
145
- public static final Path getRangeUnCompressedFilePath (final Path compressedInteropPath ) {
146
- String uncompressedFileName = getUncompressedFileName (compressedInteropPath .getFileName ().toString ());
147
- // Example compressedInteropPath: ../dat/r4x8/q4.1 => unCompressedFilePath: ../dat/q4
148
- return compressedInteropPath .getParent ().getParent ().resolve (uncompressedFileName );
149
- }
150
-
151
- public static final String getUncompressedFileName (final String compressedFileName ) {
152
- // Returns original filename from compressed file name
153
- int lastDotIndex = compressedFileName .lastIndexOf ("." );
154
- if (lastDotIndex >= 0 ) {
155
- return compressedFileName .substring (0 , lastDotIndex );
156
- } else {
157
- throw new CRAMException ("The format of the compressed File Name is not as expected. " +
158
- "The name of the compressed file should contain a period followed by a number that" +
159
- "indicates the order of compression. Actual compressed file name = " + compressedFileName );
160
- }
161
- }
162
-
163
- public static final RangeParams getRangeParams (final Path compressedInteropPath ){
164
- // Returns RangeParams from compressed file path
165
- final String compressedFileName = compressedInteropPath .getFileName ().toString ();
166
- final int lastDotIndex = compressedFileName .lastIndexOf ("." );
167
- if (lastDotIndex >= 0 && lastDotIndex < compressedFileName .length () - 1 ) {
168
- return new RangeParams (Integer .parseInt (compressedFileName .substring (lastDotIndex + 1 )));
169
- } else {
170
- throw new CRAMException ("The format of the compressed File Name is not as expected. " +
171
- "The name of the compressed file should contain a period followed by a number that" +
172
- "indicates the order of compression. Actual compressed file name = " + compressedFileName );
173
- }
174
- }
175
-
176
116
}
0 commit comments