From 2e552eb5a1c7d06add97c085bf442fe0d5f82801 Mon Sep 17 00:00:00 2001 From: hanna Date: Thu, 22 Oct 2009 19:31:15 +0000 Subject: [PATCH] Validates intervals against sequence dictionary header bounds. git-svn-id: file:///humgen/gsa-scr1/gsa-engineering/svn_contents/trunk@1900 348d0f76-0448-11de-a6fe-93d51630548a --- .../sting/utils/GenomeLocParser.java | 20 +++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/java/src/org/broadinstitute/sting/utils/GenomeLocParser.java b/java/src/org/broadinstitute/sting/utils/GenomeLocParser.java index b8705bd0c..0ab26c2b5 100644 --- a/java/src/org/broadinstitute/sting/utils/GenomeLocParser.java +++ b/java/src/org/broadinstitute/sting/utils/GenomeLocParser.java @@ -343,8 +343,9 @@ public class GenomeLocParser { List lines = reader.readLines(); reader.close(); String locStr = Utils.join(";", lines); - logger.debug("locStr: " + locStr); ret = parseGenomeLocs(locStr); + for(GenomeLoc locus: ret) + verifyGenomeLocBounds(locus); return ret; } catch (Exception e2) { logger.error("Attempt to parse interval file in GATK format failed: " + e2.getMessage()); @@ -447,8 +448,9 @@ public class GenomeLocParser { /** * verify the specified genome loc is valid, if it's not, throw an exception + * Will not verify the location against contig bounds. * - * @param toReturn teh genome loc we're about to return + * @param toReturn the genome loc we're about to return * * @return the genome loc if it's valid, otherwise we throw an exception */ @@ -470,6 +472,20 @@ public class GenomeLocParser { } + /** + * Verify the locus against the bounds of the contig. + * @param locus Locus to verify. + */ + private static void verifyGenomeLocBounds(GenomeLoc locus) { + verifyGenomeLoc(locus); + + int contigSize = contigInfo.getSequence(locus.getContigIndex()).getSequenceLength(); + if(locus.getStart() > contigSize) + throw new StingException(String.format("GenomeLoc is invalid: locus start %d is after the end of contig %s",locus.getStart(),locus.getContig())); + if(locus.getStop() > contigSize) + throw new StingException(String.format("GenomeLoc is invalid: locus stop %d is after the end of contig %s",locus.getStop(),locus.getContig())); + } + /** * Move this Genome loc to the next contig, with a start