Skip to content

Commit a4b2837

Browse files
author
yash-puligundla
committed
Rebase on RANS branch and use common methods from CRAMInteropTestUtils class
1 parent 1f9c2a1 commit a4b2837

File tree

2 files changed

+9
-78
lines changed

2 files changed

+9
-78
lines changed

src/test/java/htsjdk/samtools/cram/CRAMInteropTestUtils.java

+1-10
Original file line numberDiff line numberDiff line change
@@ -33,17 +33,8 @@ public static Path getInteropTestDataLocation() {
3333
return Paths.get(INTEROP_TEST_FILES_PATH);
3434
}
3535

36-
// Given a test file name and the codec, map it to the corresponding compressed file path
37-
public static final Path getCompressedCodecPath(final String codecType, final Path uncompressedInteropPath, int formatFlags) {
38-
39-
// Example uncompressedInteropPath: q4, codecType: r4x16, formatFlags: 193 => compressedFileName: r4x16/q4.193
40-
// the substring after "." in the compressedFileName is the formatFlags or the first byte of the compressed stream
41-
final String compressedFileName = String.format("%s/%s.%s", codecType, uncompressedInteropPath.getFileName(), formatFlags);
42-
return uncompressedInteropPath.getParent().resolve(compressedFileName);
43-
}
44-
4536
// the input files have embedded newlines that the test remove before round-tripping...
46-
public static final byte[] filterEmbeddedNewlines(final byte[] rawBytes) throws IOException {
37+
protected static final byte[] filterEmbeddedNewlines(final byte[] rawBytes) throws IOException {
4738
// 1. filters new lines if any.
4839
// 2. "q40+dir" file has an extra column delimited by tab. This column provides READ1 vs READ2 flag.
4940
// This file is also new-line separated. The extra column, '\t' and '\n' are filtered.

src/test/java/htsjdk/samtools/cram/RangeInteropTest.java

+8-68
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010
import org.testng.annotations.DataProvider;
1111
import org.testng.annotations.Test;
1212

13-
import java.io.ByteArrayOutputStream;
1413
import java.io.IOException;
1514
import java.io.InputStream;
1615
import java.nio.ByteBuffer;
@@ -20,6 +19,11 @@
2019
import java.util.ArrayList;
2120
import java.util.List;
2221

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+
2327
public class RangeInteropTest extends HtsjdkTest {
2428
public static final String COMPRESSED_RANGE_DIR = "arith";
2529

@@ -30,13 +34,13 @@ public Object[][] getRoundTripTestCases() throws IOException {
3034
// compressed testfile path, uncompressed testfile path,
3135
// Range encoder, Range decoder, Range params
3236
final List<Object[]> testCases = new ArrayList<>();
33-
for (Path path : getInteropRangeCompressedFilePaths(COMPRESSED_RANGE_DIR)) {
37+
for (Path path : getInteropCompressedFilePaths(COMPRESSED_RANGE_DIR)) {
3438
Object[] objects = new Object[]{
3539
path,
36-
getRangeUnCompressedFilePath(path),
40+
getUnCompressedFilePath(path),
3741
new RangeEncode(),
3842
new RangeDecode(),
39-
getRangeParams(path)
43+
new RangeParams(getParamsFormatFlags(path))
4044
};
4145
testCases.add(objects);
4246
}
@@ -109,68 +113,4 @@ public void testDecodeOnly(
109113
}
110114
}
111115

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-
176116
}

0 commit comments

Comments
 (0)