diff --git a/java/src/org/broadinstitute/sting/utils/GenomeLocParser.java b/java/src/org/broadinstitute/sting/utils/GenomeLocParser.java index 2f8e7f40a..4db6f3611 100644 --- a/java/src/org/broadinstitute/sting/utils/GenomeLocParser.java +++ b/java/src/org/broadinstitute/sting/utils/GenomeLocParser.java @@ -26,6 +26,7 @@ package org.broadinstitute.sting.utils; import java.io.File; +import java.io.IOException; import java.util.ArrayList; import java.util.Iterator; import java.util.List; @@ -314,7 +315,7 @@ public class GenomeLocParser { * 'chr2', 'chr2:1000000' or 'chr2:1,000,000-2,000,000' * * @param file_name - * @param rule also merge abutting intervals + * @return List List of Genome Locs that have been parsed from file */ public static List intervalFileToList(final String file_name) { // try to open file @@ -368,22 +369,15 @@ public class GenomeLocParser { List ret = new ArrayList(); XReadLines reader = new XReadLines(new File(file_name)); for(String line: reader) { - try { ret.add(parseGenomeInterval(line)); - } - catch (Exception e2) { - throw new StingException(String.format("Unable to parse interval: %s in file: %s", line, file_name)); - } } reader.close(); // always return null instead of empty list return ret.isEmpty() ? null : ret; } - catch (Exception e2) { - logger.error("Attempt to parse interval file in GATK format failed: " + e2.getMessage()); - e2.printStackTrace(); - throw new StingException("Unable to parse out interval file in either format", e); + catch (IOException e2) { + throw new StingException("An I/O error occurred while reading the interval file.", e); } } } diff --git a/java/src/org/broadinstitute/sting/utils/interval/IntervalUtils.java b/java/src/org/broadinstitute/sting/utils/interval/IntervalUtils.java index 73139d8ea..01396c4a8 100644 --- a/java/src/org/broadinstitute/sting/utils/interval/IntervalUtils.java +++ b/java/src/org/broadinstitute/sting/utils/interval/IntervalUtils.java @@ -47,8 +47,16 @@ public class IntervalUtils { for (String fileOrInterval : argument.split(";")) { // if it's a file, add items to raw interval list - if (isIntervalFile(fileOrInterval)) - rawIntervals.addAll(GenomeLocParser.intervalFileToList(fileOrInterval)); + if (isIntervalFile(fileOrInterval)) { + try { + rawIntervals.addAll(GenomeLocParser.intervalFileToList(fileOrInterval)); + } + catch (Exception e) { + throw new StingException(String.format("Interval file %s could not be parsed in either format. " + + "The problem is:%n%s", + fileOrInterval, e.getMessage()), e); + } + } // otherwise treat as an interval -> parse and add to raw interval list else { @@ -88,15 +96,21 @@ public class IntervalUtils { public static boolean isIntervalFile(String str) { // should we define list of file extensions as a public array somewhere? // is regex or endsiwth better? + File file = new File(str); if (str.toUpperCase().endsWith(".BED") || str.toUpperCase().endsWith(".LIST") || str.toUpperCase().endsWith(".PICARD") || str.toUpperCase().endsWith(".INTERVAL_LIST") - || str.toUpperCase().endsWith(".INTERVALS")) - return true; + || str.toUpperCase().endsWith(".INTERVALS")) { + if (file.exists()) + return true; + else + throw new StingException(String.format("The interval file %s does not exist.", file.getAbsolutePath())); + } - if(new File(str).exists()) - throw new StingException("Interval argument looks like a filename, but does not have one of " + - "the supported extensions (.bed, .list, .picard, .interval_list, or .intervals). " + - "Please rename your file with the appropriate extension."); + if(file.exists()) + throw new StingException(String.format("The interval file %s does not have one of " + + "the supported extensions (.bed, .list, .picard, .interval_list, or .intervals). " + + "Please rename your file with the appropriate extension. If %s is NOT supposed to be a file, " + + "please move or rename the file at location %s", str, str, file.getAbsolutePath())); else return false; }