Fixing the error messages thrown with bad interval arguments. I simplified the exception handling and made the messages more verbose.
Note: the -L argument takes both interval strings and filenames. If you specify an interval string that is also a file, an error will be thrown to move the file: ie. if you have a file "chr1" in the parent directory, GATK will ask you to move/delete it. But, this only happens with interval string arguments, NOT with intervals that are contained in files, which is a majority of the use case. git-svn-id: file:///humgen/gsa-scr1/gsa-engineering/svn_contents/trunk@3602 348d0f76-0448-11de-a6fe-93d51630548a
This commit is contained in:
parent
300a18b85f
commit
9d6a341d15
|
|
@ -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<GenomeLoc> List of Genome Locs that have been parsed from file
|
||||
*/
|
||||
public static List<GenomeLoc> intervalFileToList(final String file_name) {
|
||||
// try to open file
|
||||
|
|
@ -368,22 +369,15 @@ public class GenomeLocParser {
|
|||
List<GenomeLoc> ret = new ArrayList<GenomeLoc>();
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue