diff --git a/src/main/java/org/broadinstitute/hellbender/engine/FeatureManager.java b/src/main/java/org/broadinstitute/hellbender/engine/FeatureManager.java index 3104d492818..8bcdda19e34 100644 --- a/src/main/java/org/broadinstitute/hellbender/engine/FeatureManager.java +++ b/src/main/java/org/broadinstitute/hellbender/engine/FeatureManager.java @@ -493,8 +493,8 @@ private FeatureDataSource lookupDataSource( final Feature * @param file file to check * @return True if the file exists and contains Features (ie., we have a FeatureCodec that can decode it), otherwise false */ - public static boolean isFeatureFile( final File file ) { - return file.exists() && ! getCandidateCodecsForFile(file.toPath()).isEmpty(); + public static boolean isFeatureFile( final Path file ) { + return Files.exists(file) && ! getCandidateCodecsForFile(file).isEmpty(); } /** diff --git a/src/main/java/org/broadinstitute/hellbender/utils/IntervalUtils.java b/src/main/java/org/broadinstitute/hellbender/utils/IntervalUtils.java index c1c8cb4443b..30647c0d745 100644 --- a/src/main/java/org/broadinstitute/hellbender/utils/IntervalUtils.java +++ b/src/main/java/org/broadinstitute/hellbender/utils/IntervalUtils.java @@ -270,7 +270,7 @@ public static List parseIntervalArguments(final GenomeLocParser parse "interval or an interval file instead."); } // If it's a Feature-containing file, convert it to a list of intervals - else if ( FeatureManager.isFeatureFile(new File(arg)) ) { + else if ( FeatureManager.isFeatureFile(IOUtils.getPath(arg)) ) { rawIntervals.addAll(featureFileToIntervals(parser, arg)); } // If it's an interval file, add its contents to the raw interval list @@ -307,12 +307,11 @@ else if ( new File(arg).exists() ) { * Converts a Feature-containing file to a list of intervals * * @param parser GenomeLocParser for creating intervals - * @param featureFileName file containing Features to convert to intervals + * @param featureFile file containing Features to convert to intervals * @return a List of intervals corresponding to the locations of the Features in the provided file * @throws UserException.CouldNotReadInputFile if the provided file is not in a supported Feature file format */ - public static List featureFileToIntervals( final GenomeLocParser parser, final String featureFileName ) { - final File featureFile = new File(featureFileName); + public static List featureFileToIntervals( final GenomeLocParser parser, final String featureFile ) { try ( final FeatureDataSource dataSource = new FeatureDataSource<>(featureFile) ) { final List featureIntervals = new ArrayList<>(); diff --git a/src/test/java/org/broadinstitute/hellbender/engine/FeatureManagerUnitTest.java b/src/test/java/org/broadinstitute/hellbender/engine/FeatureManagerUnitTest.java index 91e79b9bcb6..fd510bc0ab4 100644 --- a/src/test/java/org/broadinstitute/hellbender/engine/FeatureManagerUnitTest.java +++ b/src/test/java/org/broadinstitute/hellbender/engine/FeatureManagerUnitTest.java @@ -89,7 +89,7 @@ public Object[][] getIsFeatureFileTestData() { @Test(dataProvider = "IsFeatureFileTestData") public void testIsFeatureFile( final File file, final boolean expectedIsFeatureFile ) { - Assert.assertEquals(FeatureManager.isFeatureFile(file), expectedIsFeatureFile, "isFeatureFile() returned incorrect result for file " + file.getAbsolutePath()); + Assert.assertEquals(FeatureManager.isFeatureFile(file.toPath()), expectedIsFeatureFile, "isFeatureFile() returned incorrect result for file " + file.getAbsolutePath()); } @CommandLineProgramProperties(summary = "", oneLineSummary = "", programGroup = TestProgramGroup.class) diff --git a/src/test/java/org/broadinstitute/hellbender/utils/IntervalUtilsUnitTest.java b/src/test/java/org/broadinstitute/hellbender/utils/IntervalUtilsUnitTest.java index 42310ead834..e78c1c574dc 100644 --- a/src/test/java/org/broadinstitute/hellbender/utils/IntervalUtilsUnitTest.java +++ b/src/test/java/org/broadinstitute/hellbender/utils/IntervalUtilsUnitTest.java @@ -3,6 +3,8 @@ import com.google.common.collect.ImmutableMap; import com.google.common.collect.Lists; import com.google.common.collect.Sets; +import com.google.common.jimfs.Configuration; +import com.google.common.jimfs.Jimfs; import htsjdk.samtools.QueryInterval; import htsjdk.samtools.SAMFileHeader; import htsjdk.samtools.SAMSequenceDictionary; @@ -28,6 +30,9 @@ import java.io.File; import java.io.FileWriter; import java.io.IOException; +import java.nio.file.FileSystem; +import java.nio.file.Files; +import java.nio.file.Path; import java.util.*; import java.util.stream.Collectors; import java.util.stream.Stream; @@ -1245,10 +1250,21 @@ public Object[][] loadIntervalsFromFeatureFileData() { @Test(dataProvider = "loadIntervalsFromFeatureFileData") public void testLoadIntervalsFromFeatureFile( final File featureFile, final List expectedIntervals ) { - final GenomeLocSortedSet actualIntervals = IntervalUtils.loadIntervals(Arrays.asList(featureFile.getAbsolutePath()), IntervalSetRule.UNION, IntervalMergingRule.ALL, 0, hg19GenomeLocParser); + final GenomeLocSortedSet actualIntervals = IntervalUtils.loadIntervals(Collections.singletonList(featureFile.getAbsolutePath()), IntervalSetRule.UNION, IntervalMergingRule.ALL, 0, hg19GenomeLocParser); Assert.assertEquals(actualIntervals, expectedIntervals, "Wrong intervals loaded from Feature file " + featureFile.getAbsolutePath()); } + @Test(dataProvider = "loadIntervalsFromFeatureFileData") + public void testLoadIntervalsFromFeatureFileInJimfs( final File featureFile, final List expectedIntervals ) throws IOException { + try(final FileSystem fs = Jimfs.newFileSystem(Configuration.unix())){ + final Path jimfsRootPath = fs.getRootDirectories().iterator().next(); + final Path jimfsCopy = Files.copy(featureFile.toPath(), jimfsRootPath.resolve(featureFile.getName())); + final String jimfsPathString = jimfsCopy.toAbsolutePath().toUri().toString(); + final GenomeLocSortedSet actualIntervals = IntervalUtils.loadIntervals(Collections.singletonList(jimfsPathString), IntervalSetRule.UNION, IntervalMergingRule.ALL, 0, hg19GenomeLocParser); + Assert.assertEquals(actualIntervals, expectedIntervals, "Wrong intervals loaded from Feature file " + jimfsPathString); + } + } + // Note: because the file does not exist and all characters are allowed in contig names, // we will not know that this is supposed to be interpreted as a file. // So we'll blow up with MalformedGenomeLoc and not anything related to files