Skip to content

Commit

Permalink
Fix calls to deprecated htsjdk APIs
Browse files Browse the repository at this point in the history
  • Loading branch information
tomwhite authored and heuermh committed Sep 30, 2019
1 parent 65cfd22 commit 202e1f0
Show file tree
Hide file tree
Showing 19 changed files with 46 additions and 43 deletions.
4 changes: 2 additions & 2 deletions src/main/java/org/disq_bio/disq/BaiWriteOption.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
*/
package org.disq_bio.disq;

import htsjdk.samtools.BAMIndex;
import htsjdk.samtools.util.FileExtensions;

/** An option for for enabling or disabling writing BAI files. Disabled by default. */
public enum BaiWriteOption implements WriteOption {
Expand All @@ -44,6 +44,6 @@ public static BaiWriteOption fromBoolean(boolean writeBai) {

/** @return the extension for BAI files. */
public static String getIndexExtension() {
return BAMIndex.BAMIndexSuffix;
return FileExtensions.BAI_INDEX;
}
}
4 changes: 2 additions & 2 deletions src/main/java/org/disq_bio/disq/CraiWriteOption.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
*/
package org.disq_bio.disq;

import htsjdk.samtools.cram.CRAIIndex;
import htsjdk.samtools.util.FileExtensions;

/** An option for for enabling or disabling writing CRAI files. Disabled by default. */
public enum CraiWriteOption implements WriteOption {
Expand All @@ -44,6 +44,6 @@ public static CraiWriteOption fromBoolean(boolean writeCrai) {

/** @return the extension for CRAI files. */
public static String getIndexExtension() {
return CRAIIndex.CRAI_INDEX_SUFFIX;
return FileExtensions.CRAM_INDEX;
}
}
4 changes: 2 additions & 2 deletions src/main/java/org/disq_bio/disq/SbiWriteOption.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
*/
package org.disq_bio.disq;

import htsjdk.samtools.SBIIndex;
import htsjdk.samtools.util.FileExtensions;

/** An option for for enabling or disabling writing SBI files. Disabled by default. */
public enum SbiWriteOption implements WriteOption {
Expand All @@ -44,6 +44,6 @@ public static SbiWriteOption fromBoolean(boolean writeSbi) {

/** @return the extension for SBI files. */
public static String getIndexExtension() {
return SBIIndex.FILE_EXTENSION;
return FileExtensions.SBI;
}
}
4 changes: 2 additions & 2 deletions src/main/java/org/disq_bio/disq/TabixIndexWriteOption.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
*/
package org.disq_bio.disq;

import htsjdk.tribble.util.TabixUtils;
import htsjdk.samtools.util.FileExtensions;

/** An option for for enabling or disabling writing tabix files. Disabled by default. */
public enum TabixIndexWriteOption implements WriteOption {
Expand All @@ -44,6 +44,6 @@ public static TabixIndexWriteOption fromBoolean(boolean writeTabix) {

/** @return the extension for tabix files. */
public static String getIndexExtension() {
return TabixUtils.STANDARD_INDEX_EXTENSION;
return FileExtensions.TABIX_INDEX;
}
}
4 changes: 2 additions & 2 deletions src/main/java/org/disq_bio/disq/impl/file/BaiMerger.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@
package org.disq_bio.disq.impl.file;

import htsjdk.samtools.AbstractBAMFileIndex;
import htsjdk.samtools.BAMIndex;
import htsjdk.samtools.BAMIndexMerger;
import htsjdk.samtools.IndexMerger;
import htsjdk.samtools.SAMFileHeader;
Expand All @@ -36,6 +35,7 @@
import java.io.IOException;
import java.io.OutputStream;
import org.apache.hadoop.conf.Configuration;
import org.disq_bio.disq.BaiWriteOption;

/** Merges BAM index files for (headerless) parts of a BAM file into a single index file. */
public class BaiMerger extends IndexFileMerger<AbstractBAMFileIndex, SAMFileHeader> {
Expand All @@ -45,7 +45,7 @@ public BaiMerger(FileSystemWrapper fileSystemWrapper) {

@Override
protected String getIndexExtension() {
return BAMIndex.BAMIndexSuffix;
return BaiWriteOption.getIndexExtension();
}

@Override
Expand Down
3 changes: 2 additions & 1 deletion src/main/java/org/disq_bio/disq/impl/file/CraiMerger.java
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
import java.io.IOException;
import java.io.OutputStream;
import org.apache.hadoop.conf.Configuration;
import org.disq_bio.disq.CraiWriteOption;

/** Merges CRAM index files for (headerless) parts of a CRAM file into a single index file. */
public class CraiMerger extends IndexFileMerger<CRAIIndex, SAMFileHeader> {
Expand All @@ -43,7 +44,7 @@ public CraiMerger(FileSystemWrapper fileSystemWrapper) {

@Override
protected String getIndexExtension() {
return CRAIIndex.CRAI_INDEX_SUFFIX;
return CraiWriteOption.getIndexExtension();
}

@Override
Expand Down
3 changes: 2 additions & 1 deletion src/main/java/org/disq_bio/disq/impl/file/SbiMerger.java
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
import java.io.IOException;
import java.io.OutputStream;
import org.apache.hadoop.conf.Configuration;
import org.disq_bio.disq.SbiWriteOption;

public class SbiMerger extends IndexFileMerger<SBIIndex, SAMFileHeader> {

Expand All @@ -42,7 +43,7 @@ public SbiMerger(FileSystemWrapper fileSystemWrapper) {

@Override
protected String getIndexExtension() {
return SBIIndex.FILE_EXTENSION;
return SbiWriteOption.getIndexExtension();
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
import htsjdk.samtools.SBIIndex;
import htsjdk.samtools.seekablestream.SeekableStream;
import htsjdk.samtools.util.BlockCompressedFilePointerUtil;
import htsjdk.samtools.util.FileExtensions;
import java.io.IOException;
import java.io.OutputStream;
import java.io.Serializable;
Expand Down Expand Up @@ -79,7 +80,7 @@ public BamRecordGuesserChecker(boolean useNio) {
}

SBIIndex getSBIIndex(Configuration conf, String bamFile) throws IOException {
String sbiFile = bamFile + SBIIndex.FILE_EXTENSION;
String sbiFile = bamFile + FileExtensions.SBI;
if (!fileSystemWrapper.exists(conf, sbiFile)) {
// create SBI file
try (SeekableStream in = fileSystemWrapper.open(conf, bamFile);
Expand Down
6 changes: 2 additions & 4 deletions src/main/java/org/disq_bio/disq/impl/formats/bam/BamSink.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,8 @@
package org.disq_bio.disq.impl.formats.bam;

import htsjdk.samtools.BAMFileWriter;
import htsjdk.samtools.BAMIndex;
import htsjdk.samtools.SAMFileHeader;
import htsjdk.samtools.SAMRecord;
import htsjdk.samtools.SBIIndex;
import htsjdk.samtools.util.BlockCompressedStreamConstants;
import java.io.IOException;
import java.io.OutputStream;
Expand Down Expand Up @@ -122,7 +120,7 @@ public void save(
.mergeParts(
conf,
tempPartsDirectory,
path + SBIIndex.FILE_EXTENSION,
path + SbiWriteOption.getIndexExtension(),
header,
partLengths,
fileLength);
Expand All @@ -132,7 +130,7 @@ public void save(
.mergeParts(
conf,
tempPartsDirectory,
path + BAMIndex.BAMIndexSuffix,
path + BaiWriteOption.getIndexExtension(),
header,
partLengths,
fileLength);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
import htsjdk.samtools.seekablestream.SeekableStream;
import htsjdk.samtools.util.BlockCompressedFilePointerUtil;
import htsjdk.samtools.util.CloseableIterator;
import htsjdk.samtools.util.FileExtensions;
import htsjdk.samtools.util.Locatable;
import java.io.IOException;
import java.io.Serializable;
Expand Down Expand Up @@ -95,7 +96,7 @@ protected JavaRDD<PathChunk> getPathChunks(
String referenceSourcePath)
throws IOException {

String sbiPath = path + SBIIndex.FILE_EXTENSION;
String sbiPath = path + FileExtensions.SBI;
if (fileSystemWrapper.exists(jsc.hadoopConfiguration(), sbiPath)) {
logger.debug("Using SBI file {} for finding splits", sbiPath);
try (SeekableStream sbiStream = fileSystemWrapper.open(jsc.hadoopConfiguration(), sbiPath)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,15 +26,13 @@
package org.disq_bio.disq.impl.formats.bam;

import htsjdk.samtools.BAMFileSpan;
import htsjdk.samtools.BAMIndex;
import htsjdk.samtools.BAMIndexer2;
import htsjdk.samtools.BAMRecordCodec;
import htsjdk.samtools.Chunk;
import htsjdk.samtools.SAMFileHeader;
import htsjdk.samtools.SAMFileSource;
import htsjdk.samtools.SAMRecord;
import htsjdk.samtools.SAMRecordHelper;
import htsjdk.samtools.SBIIndex;
import htsjdk.samtools.SBIIndexWriter;
import htsjdk.samtools.util.BinaryCodec;
import htsjdk.samtools.util.BlockCompressedOutputStream;
Expand All @@ -45,7 +43,9 @@
import org.apache.hadoop.mapreduce.RecordWriter;
import org.apache.hadoop.mapreduce.TaskAttemptContext;
import org.apache.hadoop.mapreduce.lib.output.FileOutputFormat;
import org.disq_bio.disq.BaiWriteOption;
import org.disq_bio.disq.HtsjdkReadsRdd;
import org.disq_bio.disq.SbiWriteOption;
import org.disq_bio.disq.impl.formats.bgzf.TerminatorlessBlockCompressedOutputStream;

/**
Expand Down Expand Up @@ -176,13 +176,15 @@ public RecordWriter<Void, SAMRecord> getRecordWriter(TaskAttemptContext taskAtte
Path sbiFile;
if (writeSbiFile) {
// ensure sbi files are hidden so they don't interfere with merging of part files
sbiFile = new Path(file.getParent(), "." + file.getName() + SBIIndex.FILE_EXTENSION);
sbiFile =
new Path(file.getParent(), "." + file.getName() + SbiWriteOption.getIndexExtension());
} else {
sbiFile = null;
}
Path baiFile;
if (writeBaiFile) {
baiFile = new Path(file.getParent(), "." + file.getName() + BAMIndex.BAMIndexSuffix);
baiFile =
new Path(file.getParent(), "." + file.getName() + BaiWriteOption.getIndexExtension());
} else {
baiFile = null;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@
import htsjdk.samtools.CRAMContainerStreamWriter;
import htsjdk.samtools.SAMFileHeader;
import htsjdk.samtools.SAMRecord;
import htsjdk.samtools.cram.CRAIIndex;
import htsjdk.samtools.cram.ref.CRAMReferenceSource;
import java.io.IOException;
import java.io.OutputStream;
Expand All @@ -38,6 +37,7 @@
import org.apache.hadoop.mapreduce.RecordWriter;
import org.apache.hadoop.mapreduce.TaskAttemptContext;
import org.apache.hadoop.mapreduce.lib.output.FileOutputFormat;
import org.disq_bio.disq.CraiWriteOption;
import org.disq_bio.disq.HtsjdkReadsRdd;
import org.disq_bio.disq.impl.file.FileSystemWrapper;
import org.disq_bio.disq.impl.file.HadoopFileSystemWrapper;
Expand Down Expand Up @@ -73,7 +73,8 @@ public RecordWriter<Void, SAMRecord> getRecordWriter(TaskAttemptContext taskAtte
Path craiFile;
if (writeCraiFile) {
// ensure CRAI files are hidden so they don't interfere with merging of part files
craiFile = new Path(file.getParent(), "." + file.getName() + CRAIIndex.CRAI_INDEX_SUFFIX);
craiFile =
new Path(file.getParent(), "." + file.getName() + CraiWriteOption.getIndexExtension());
} else {
craiFile = null;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
import htsjdk.samtools.reference.ReferenceSequenceFile;
import htsjdk.samtools.reference.ReferenceSequenceFileFactory;
import htsjdk.samtools.seekablestream.SeekableStream;
import htsjdk.samtools.util.FileExtensions;
import htsjdk.samtools.util.GZIIndex;
import htsjdk.samtools.util.IOUtil;
import java.io.IOException;
Expand All @@ -40,16 +41,14 @@

/** A utility class for creating a {@link CRAMReferenceSource}. */
public class CramReferenceSourceBuilder {
private static final String FASTA_INDEX_EXTENSION = ".fai";

public static CRAMReferenceSource build(
FileSystemWrapper fileSystemWrapper, Configuration conf, String referenceSourcePath)
throws IOException {
SeekableStream refIn = fileSystemWrapper.open(conf, referenceSourcePath);
String indexPath = referenceSourcePath + FASTA_INDEX_EXTENSION;
String indexPath = referenceSourcePath + FileExtensions.FASTA_INDEX;
ReferenceSequenceFile refSeqFile;
if (IOUtil.hasBlockCompressedExtension(referenceSourcePath)) {
String gziIndexPath = referenceSourcePath + GZIIndex.DEFAULT_EXTENSION;
String gziIndexPath = referenceSourcePath + FileExtensions.GZI;
try (SeekableStream indexIn = fileSystemWrapper.open(conf, indexPath);
SeekableStream gziIndexIn = fileSystemWrapper.open(conf, gziIndexPath)) {
FastaSequenceIndex index = new FastaSequenceIndex(indexIn);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@
import htsjdk.samtools.CRAMContainerStreamWriter;
import htsjdk.samtools.SAMFileHeader;
import htsjdk.samtools.SAMRecord;
import htsjdk.samtools.cram.CRAIIndex;
import htsjdk.samtools.cram.build.CramIO;
import htsjdk.samtools.cram.common.CramVersions;
import htsjdk.samtools.cram.ref.CRAMReferenceSource;
Expand Down Expand Up @@ -121,7 +120,7 @@ public void save(
.mergeParts(
conf,
tempPartsDirectory,
path + CRAIIndex.CRAI_INDEX_SUFFIX,
path + CraiWriteOption.getIndexExtension(),
header,
partLengths,
fileLength);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,9 @@
*/
package org.disq_bio.disq.impl.formats.vcf;

import htsjdk.samtools.SamStreams;
import htsjdk.samtools.seekablestream.SeekableStream;
import htsjdk.samtools.util.BlockCompressedInputStream;
import htsjdk.samtools.util.IOUtil;
import htsjdk.samtools.util.Locatable;
import htsjdk.samtools.util.OverlapDetector;
import htsjdk.tribble.FeatureCodecHeader;
Expand Down Expand Up @@ -108,7 +108,7 @@ private static InputStream bufferAndDecompressIfNecessary(final InputStream in)
BufferedInputStream bis = new BufferedInputStream(in);
// despite the name, SamStreams.isGzippedSAMFile looks for any gzipped stream (including block
// compressed)
return SamStreams.isGzippedSAMFile(bis) ? new GZIPInputStream(bis) : bis;
return IOUtil.isGZIPInputStream(bis) ? new GZIPInputStream(bis) : bis;
}

public <T extends Locatable> JavaRDD<VariantContext> getVariants(
Expand Down
4 changes: 2 additions & 2 deletions src/test/java/org/disq_bio/disq/BaseTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
*/
package org.disq_bio.disq;

import htsjdk.samtools.SBIIndex;
import htsjdk.samtools.util.FileExtensions;
import java.io.IOException;
import java.net.URI;
import java.net.URISyntaxException;
Expand Down Expand Up @@ -143,7 +143,7 @@ protected List<String> listPartFiles(String dir) throws IOException {

protected List<String> listSBIIndexFiles(String dir) throws IOException {
return Files.list(Paths.get(URI.create(dir)))
.filter(path -> path.getFileName().toString().endsWith(SBIIndex.FILE_EXTENSION))
.filter(path -> path.getFileName().toString().endsWith(FileExtensions.SBI))
.map(path -> path.toUri().toString())
.collect(Collectors.toList());
}
Expand Down
5 changes: 3 additions & 2 deletions src/test/java/org/disq_bio/disq/HtsjdkReadsRddTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
import htsjdk.samtools.SBIIndex;
import htsjdk.samtools.seekablestream.SeekablePathStream;
import htsjdk.samtools.seekablestream.SeekableStream;
import htsjdk.samtools.util.FileExtensions;
import htsjdk.samtools.util.Interval;
import htsjdk.samtools.util.Locatable;
import java.io.ByteArrayInputStream;
Expand Down Expand Up @@ -180,7 +181,7 @@ public void testWriteSBIIndex(String inputFile, int splitSize, boolean useNio) t
createTempPath(SamFormat.fromFormatWriteOption(ReadsFormatWriteOption.BAM).getExtension());
htsjdkReadsRddStorage.write(htsjdkReadsRdd, outputPath, SbiWriteOption.ENABLE);

Path sbiFile = Paths.get(URI.create(outputPath + SBIIndex.FILE_EXTENSION));
Path sbiFile = Paths.get(URI.create(outputPath + FileExtensions.SBI));
Assert.assertTrue(Files.exists(sbiFile));
SBIIndex actualSbiIndex = SBIIndex.load(sbiFile);

Expand Down Expand Up @@ -501,7 +502,7 @@ public void testSBIIndexWrittenWhenNotCoordinateSorted() throws Exception {
createTempPath(SamFormat.fromFormatWriteOption(ReadsFormatWriteOption.BAM).getExtension());
htsjdkReadsRddStorage.write(htsjdkReadsRdd, outputPath, SbiWriteOption.ENABLE);

Assert.assertTrue(Files.exists(Paths.get(URI.create(outputPath + SBIIndex.FILE_EXTENSION))));
Assert.assertTrue(Files.exists(Paths.get(URI.create(outputPath + FileExtensions.SBI))));
}

@Test
Expand Down
6 changes: 3 additions & 3 deletions src/test/java/org/disq_bio/disq/TbiMergingTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,10 @@
package org.disq_bio.disq;

import htsjdk.samtools.TbiEqualityChecker;
import htsjdk.samtools.util.FileExtensions;
import htsjdk.samtools.util.RuntimeIOException;
import htsjdk.tribble.index.IndexFactory;
import htsjdk.tribble.index.tabix.TabixIndex;
import htsjdk.tribble.util.TabixUtils;
import htsjdk.variant.vcf.VCFCodec;
import java.io.File;
import java.io.IOException;
Expand Down Expand Up @@ -84,8 +84,8 @@ public void test(String inputFile) throws Exception {

File outputVcf = new File(URI.create(outputPath));
File outputTbi =
new File(outputVcf.getParent(), outputVcf.getName() + TabixUtils.STANDARD_INDEX_EXTENSION);
String outputTbiHtsjdkPath = createTempPath(TabixUtils.STANDARD_INDEX_EXTENSION);
new File(outputVcf.getParent(), outputVcf.getName() + FileExtensions.TABIX_INDEX);
String outputTbiHtsjdkPath = createTempPath(FileExtensions.TABIX_INDEX);
File outputTbiHtsjdk = indexVcf(outputVcf, new File(URI.create(outputTbiHtsjdkPath)));

// Don't check for strict equality (byte identical), since the TBI files
Expand Down
Loading

0 comments on commit 202e1f0

Please sign in to comment.