From ff25b656e15c8e694d796676b8af8414e73f69f9 Mon Sep 17 00:00:00 2001 From: Laura Gauthier Date: Fri, 4 Apr 2014 15:38:50 -0400 Subject: [PATCH] Added check to make sure file passed in with sample IDs is valid (used in SelectVariants) -- throws UserException. Corresponding test checks for UserException. --- .../sting/utils/SampleUtils.java | 3 +- .../sting/utils/SampleUtilsUnitTest.java | 53 +++++++++++++++++++ 2 files changed, 55 insertions(+), 1 deletion(-) create mode 100644 public/gatk-framework/src/test/java/org/broadinstitute/sting/utils/SampleUtilsUnitTest.java diff --git a/public/gatk-framework/src/main/java/org/broadinstitute/sting/utils/SampleUtils.java b/public/gatk-framework/src/main/java/org/broadinstitute/sting/utils/SampleUtils.java index b1de89dd8..b52154c2b 100644 --- a/public/gatk-framework/src/main/java/org/broadinstitute/sting/utils/SampleUtils.java +++ b/public/gatk-framework/src/main/java/org/broadinstitute/sting/utils/SampleUtils.java @@ -28,6 +28,7 @@ package org.broadinstitute.sting.utils; import net.sf.samtools.SAMFileHeader; import net.sf.samtools.SAMReadGroupRecord; import org.broadinstitute.sting.gatk.GenomeAnalysisEngine; +import org.broadinstitute.sting.utils.exceptions.UserException; import org.broadinstitute.sting.utils.variant.GATKVCFUtils; import org.broadinstitute.sting.utils.variant.GATKVariantContextUtils; import org.broadinstitute.sting.utils.collections.Pair; @@ -280,7 +281,7 @@ public class SampleUtils { samplesFromFiles.add(line); } } catch (FileNotFoundException e) { - // ignore exception + throw new UserException.CouldNotReadInputFile(file, e); } } } diff --git a/public/gatk-framework/src/test/java/org/broadinstitute/sting/utils/SampleUtilsUnitTest.java b/public/gatk-framework/src/test/java/org/broadinstitute/sting/utils/SampleUtilsUnitTest.java new file mode 100644 index 000000000..2377d221c --- /dev/null +++ b/public/gatk-framework/src/test/java/org/broadinstitute/sting/utils/SampleUtilsUnitTest.java @@ -0,0 +1,53 @@ +/* +* Copyright (c) 2012 The Broad Institute +* +* Permission is hereby granted, free of charge, to any person +* obtaining a copy of this software and associated documentation +* files (the "Software"), to deal in the Software without +* restriction, including without limitation the rights to use, +* copy, modify, merge, publish, distribute, sublicense, and/or sell +* copies of the Software, and to permit persons to whom the +* Software is furnished to do so, subject to the following +* conditions: +* +* The above copyright notice and this permission notice shall be +* included in all copies or substantial portions of the Software. +* +* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES +* OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT +* HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, +* WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING +* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR +* THE USE OR OTHER DEALINGS IN THE SOFTWARE. +*/ + + +package org.broadinstitute.sting.utils; + +import org.apache.commons.io.FileUtils; +import org.broadinstitute.sting.utils.exceptions.UserException; +import org.broadinstitute.sting.utils.io.IOUtils; +import org.testng.Assert; +import org.broadinstitute.sting.BaseTest; +import org.testng.annotations.DataProvider; +import org.testng.annotations.Test; + +import java.io.File; +import java.util.*; + +/** + * Testing framework for sample utilities class. + * + * @author gauthier + */ + +public class SampleUtilsUnitTest extends BaseTest { + @Test(expectedExceptions=UserException.class) + public void testBadSampleFiles() throws Exception { + Set sampleFiles = new HashSet(0); + sampleFiles.add(new File("fileNotHere.samples")); + Collection samplesFromFile = SampleUtils.getSamplesFromFiles(sampleFiles); + } +}