Skip to content

Commit

Permalink
Use full path with scheme in beta VCFDecoder
Browse files Browse the repository at this point in the history
* Replace toPath().toString() with toUriString() this should prevent the scheme from being cutoff unintentionally
  • Loading branch information
lbergelson committed Oct 4, 2024
1 parent 4c1c766 commit de2ec4c
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 3 deletions.
4 changes: 2 additions & 2 deletions src/main/java/htsjdk/beta/codecs/variants/vcf/VCFDecoder.java
Original file line number Diff line number Diff line change
Expand Up @@ -206,9 +206,9 @@ private static FeatureReader<VariantContext> getVCFReader(
//TODO: this resolves the index automatically. it should check to make sure the provided index
// matches the one that is automatically resolved, otherwise throw since the request will not be honored
return AbstractFeatureReader.getFeatureReader(
variantsIOPath.toPath().toString(),
variantsIOPath.getURIString(),
indexIOPath.isPresent() ?
indexIOPath.get().toPath().toString() :
indexIOPath.get().getURIString() :
null,
vcfCodec,
indexIOPath.isPresent(),
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
package htsjdk.beta.codecs.variants.vcf;

import com.google.common.jimfs.Configuration;
import com.google.common.jimfs.Jimfs;
import com.google.common.jimfs.SystemJimfsFileSystemProvider;
import htsjdk.HtsjdkTest;
import htsjdk.beta.codecs.variants.vcf.vcfv3_2.VCFCodecV3_2;
import htsjdk.beta.codecs.variants.vcf.vcfv3_3.VCFCodecV3_3;
Expand All @@ -26,6 +29,7 @@
import htsjdk.beta.plugin.variants.VariantsEncoder;
import htsjdk.beta.plugin.variants.VariantsFormats;
import htsjdk.samtools.util.IOUtil;
import htsjdk.tribble.TestUtils;
import htsjdk.variant.variantcontext.VariantContext;
import htsjdk.variant.vcf.VCFHeader;
import org.testng.Assert;
Expand All @@ -36,6 +40,9 @@
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.nio.file.FileSystem;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.Arrays;
import java.util.Collections;
import java.util.function.Function;
Expand All @@ -60,11 +67,26 @@ private Object[][] vcfReadWriteTests() {
};
}

@Test
public void testRoundTripNio() throws IOException {
try(FileSystem fs = Jimfs.newFileSystem("test", Configuration.unix())){
final IOPath outputPath = IOUtils.createTempPath("roundTripVCFThroughPath", ".vcf");
Path tribbleFileInJimfs = TestUtils.getTribbleFileInJimfs(TEST_VCF_WITH_INDEX.getRawInputString(), TEST_VCF_INDEX.getRawInputString(), fs);
HtsPath vcf = new HtsPath(tribbleFileInJimfs.toUri().toString());
checkCodecAndReadWriteVcf( vcf , VCFCodecV4_0.VCF_V40_VERSION , outputPath);
}
}

@Test(dataProvider = "vcfReadWriteTests")
public void testRoundTripVCFThroughPath(final IOPath inputPath, final HtsVersion expectedCodecVersion) {
final IOPath outputPath = IOUtils.createTempPath("roundTripVCFThroughPath", ".vcf");

checkCodecAndReadWriteVcf(inputPath, expectedCodecVersion, outputPath);
}

private void checkCodecAndReadWriteVcf(IOPath inputPath, HtsVersion expectedCodecVersion, IOPath outputPath) {
// some test files require "AllowMissingFields" options for writing
final VariantsEncoderOptions variantsEncoderOptions = new VariantsEncoderOptions().setAllowFieldsMissingFromHeader(true);
final IOPath outputPath = IOUtils.createTempPath("roundTripVCFThroughPath", ".vcf");

try (final VariantsDecoder variantsDecoder = HtsDefaultRegistry.getVariantsResolver().getVariantsDecoder(inputPath);
final VariantsEncoder variantsEncoder = HtsDefaultRegistry.getVariantsResolver().getVariantsEncoder(
Expand Down

0 comments on commit de2ec4c

Please sign in to comment.