diff --git a/java/src/org/broadinstitute/sting/utils/genotype/vcf/VCFParseException.java b/java/src/org/broadinstitute/sting/utils/genotype/vcf/VCFParseException.java new file mode 100644 index 000000000..2654a43f1 --- /dev/null +++ b/java/src/org/broadinstitute/sting/utils/genotype/vcf/VCFParseException.java @@ -0,0 +1,14 @@ +package org.broadinstitute.sting.utils.genotype.vcf; + +/** + * an exception to funnel all parsing exceptions into; this way we can emit the line we choked on as well + */ +public class VCFParseException extends RuntimeException { + public VCFParseException(String message) { + super(message); + } + + public VCFParseException(String message, Throwable cause) { + super(message, cause); + } +} diff --git a/java/src/org/broadinstitute/sting/utils/genotype/vcf/VCFReader.java b/java/src/org/broadinstitute/sting/utils/genotype/vcf/VCFReader.java index 0ab351ba6..6c26d5705 100644 --- a/java/src/org/broadinstitute/sting/utils/genotype/vcf/VCFReader.java +++ b/java/src/org/broadinstitute/sting/utils/genotype/vcf/VCFReader.java @@ -191,41 +191,44 @@ public class VCFReader implements Iterator, Iterable { * * @param line the line from the file * @param mHeader the VCF header - * * @return the VCFRecord */ public static VCFRecord createRecord(String line, VCFHeader mHeader) { - // things we need to make a VCF record - Map values = new HashMap(); - String tokens[] = line.split("\\s+"); + try { + // things we need to make a VCF record + Map values = new HashMap(); + String tokens[] = line.split("\\s+"); - // check to ensure that the column count of tokens is right - if (tokens.length != mHeader.getColumnCount()) { - throw new RuntimeException("The input file line doesn't contain enough fields, it should have " + mHeader.getColumnCount() + " fields, it has " + tokens.length + ". Line = " + line); - } - - int index = 0; - for (VCFHeader.HEADER_FIELDS field : mHeader.getHeaderFields()) - values.put(field, tokens[index++]); - // if we have genotyping data, we try and extract the genotype fields - if (mHeader.hasGenotypingData()) { - String mFormatString = tokens[index]; - String keyStrings[] = mFormatString.split(":"); - List genotypeRecords = new ArrayList(); - index++; - String[] alt_alleles = values.get(VCFHeader.HEADER_FIELDS.ALT).split(","); - for (String str : mHeader.getGenotypeSamples()) { - genotypeRecords.add(getVCFGenotype(str, keyStrings, tokens[index], alt_alleles, values.get(VCFHeader.HEADER_FIELDS.REF).charAt(0))); - index++; + // check to ensure that the column count of tokens is right + if (tokens.length != mHeader.getColumnCount()) { + throw new RuntimeException("The input file line doesn't contain enough fields, it should have " + mHeader.getColumnCount() + " fields, it has " + tokens.length + ". Line = " + line); } - VCFRecord vrec = new VCFRecord(values, mFormatString, genotypeRecords); - // associate the genotypes with this new record - for ( VCFGenotypeRecord gr : genotypeRecords ) - gr.setVCFRecord(vrec); - return vrec; + int index = 0; + for (VCFHeader.HEADER_FIELDS field : mHeader.getHeaderFields()) + values.put(field, tokens[index++]); + // if we have genotyping data, we try and extract the genotype fields + if (mHeader.hasGenotypingData()) { + String mFormatString = tokens[index]; + String keyStrings[] = mFormatString.split(":"); + List genotypeRecords = new ArrayList(); + index++; + String[] alt_alleles = values.get(VCFHeader.HEADER_FIELDS.ALT).split(","); + for (String str : mHeader.getGenotypeSamples()) { + genotypeRecords.add(getVCFGenotype(str, keyStrings, tokens[index], alt_alleles, values.get(VCFHeader.HEADER_FIELDS.REF).charAt(0))); + index++; + } + VCFRecord vrec = new VCFRecord(values, mFormatString, genotypeRecords); + // associate the genotypes with this new record + for (VCFGenotypeRecord gr : genotypeRecords) + gr.setVCFRecord(vrec); + return vrec; + + } + return new VCFRecord(values); + } catch (Exception e) { + throw new VCFParseException("VCF Reader failed to parsing, on line = " + line, e); } - return new VCFRecord(values); } /**