From 414ec6f20ad7db3f1cb7de5f9d4c32461a91feec Mon Sep 17 00:00:00 2001 From: depristo Date: Sat, 17 Jul 2010 22:30:08 +0000 Subject: [PATCH] Removing version argument constructors that shouldn't be used. Temporary allow -- with global variant to indicate this should be removed -- header records without description fields. Real error checking in the headers. git-svn-id: file:///humgen/gsa-scr1/gsa-engineering/svn_contents/trunk@3818 348d0f76-0448-11de-a6fe-93d51630548a --- .../tribble/vcf/VCFCompoundHeaderLine.java | 23 +++++++------ .../tribble/vcf/VCFFilterHeaderLine.java | 5 +++ .../org/broad/tribble/vcf/VCFHeaderLine.java | 34 ++++++------------- .../broad/tribble/vcf/VCFInfoHeaderLine.java | 5 --- 4 files changed, 28 insertions(+), 39 deletions(-) diff --git a/java/src/org/broad/tribble/vcf/VCFCompoundHeaderLine.java b/java/src/org/broad/tribble/vcf/VCFCompoundHeaderLine.java index c78218b91..dff77e24d 100644 --- a/java/src/org/broad/tribble/vcf/VCFCompoundHeaderLine.java +++ b/java/src/org/broad/tribble/vcf/VCFCompoundHeaderLine.java @@ -39,7 +39,6 @@ public abstract class VCFCompoundHeaderLine extends VCFHeaderLine implements VCF SupportedHeaderLineType(boolean flagValues) { allowFlagValues = flagValues; } - } // the field types @@ -79,15 +78,7 @@ public abstract class VCFCompoundHeaderLine extends VCFHeaderLine implements VCF this.type = type; this.description = description; this.lineType = lineType; - } - - protected VCFCompoundHeaderLine(String name, int count, VCFHeaderLineType type, String description, SupportedHeaderLineType lineType, VCFHeaderVersion version) { - super(lineType.toString(), ""); - this.name = name; - this.count = count; - this.type = type; - this.description = description; - this.lineType = lineType; + validate(); } /** @@ -107,8 +98,20 @@ public abstract class VCFCompoundHeaderLine extends VCFHeaderLine implements VCF type = VCFHeaderLineType.valueOf(mapping.get("Type")); if (type == VCFHeaderLineType.Flag && !allowFlagValues()) throw new IllegalArgumentException("Flag is an unsupported type for this kind of field"); + description = mapping.get("Description"); + if ( description == null && ALLOW_UNBOUND_DESCRIPTIONS ) // handle the case where there's no description provided + description = UNBOUND_DESCRIPTION; + this.lineType = lineType; + + validate(); + } + + private void validate() { + if ( name == null || type == null || description == null || lineType == null ) + throw new IllegalArgumentException(String.format("Invalid VCFCompoundHeaderLine: key=%s name=%s type=%s desc=%s lineType=%s", + super.getKey(), name, type, description, lineType )); } /** diff --git a/java/src/org/broad/tribble/vcf/VCFFilterHeaderLine.java b/java/src/org/broad/tribble/vcf/VCFFilterHeaderLine.java index c3981d759..b7869f90d 100755 --- a/java/src/org/broad/tribble/vcf/VCFFilterHeaderLine.java +++ b/java/src/org/broad/tribble/vcf/VCFFilterHeaderLine.java @@ -25,6 +25,9 @@ public class VCFFilterHeaderLine extends VCFHeaderLine implements VCFNamedHeader super("FILTER", ""); this.name = name; this.description = description; + + if ( name == null || description == null ) + throw new IllegalArgumentException(String.format("Invalid VCFCompoundHeaderLine: key=%s name=%s desc=%s", super.getKey(), name, description )); } /** @@ -38,6 +41,8 @@ public class VCFFilterHeaderLine extends VCFHeaderLine implements VCFNamedHeader Map mapping = VCFHeaderLineTranslator.parseLine(version,line, Arrays.asList("ID","Description")); name = mapping.get("ID"); description = mapping.get("Description"); + if ( description == null && ALLOW_UNBOUND_DESCRIPTIONS ) // handle the case where there's no description provided + description = UNBOUND_DESCRIPTION; } protected String toStringEncoding() { diff --git a/java/src/org/broad/tribble/vcf/VCFHeaderLine.java b/java/src/org/broad/tribble/vcf/VCFHeaderLine.java index b9ff7948f..627651892 100644 --- a/java/src/org/broad/tribble/vcf/VCFHeaderLine.java +++ b/java/src/org/broad/tribble/vcf/VCFHeaderLine.java @@ -38,8 +38,9 @@ import java.util.Map; * A class representing a key=value entry in the VCF header */ public class VCFHeaderLine implements Comparable { + protected static boolean ALLOW_UNBOUND_DESCRIPTIONS = true; + protected static String UNBOUND_DESCRIPTION = "Not provided in original VCF header"; - private String stringRep = null; private String mKey = null; private String mValue = null; @@ -51,6 +52,8 @@ public class VCFHeaderLine implements Comparable { * @param value the value for this header line */ public VCFHeaderLine(String key, String value) { + if ( key == null ) + throw new IllegalArgumentException("VCFHeaderLine: key cannot be null: key = " + key); mKey = key; mValue = value; } @@ -64,16 +67,6 @@ public class VCFHeaderLine implements Comparable { return mKey; } - /** - * Set the key - * - * @param key the key for this header line - */ - public void setKey(String key) { - mKey = key; - stringRep = null; - } - /** * Get the value * @@ -83,22 +76,15 @@ public class VCFHeaderLine implements Comparable { return mValue; } - /** - * Set the value - * - * @param value the value for this header line - */ - public void setValue(String value) { - mValue = value; - stringRep = null; - } - public String toString() { - if ( stringRep == null ) - stringRep = toStringEncoding(); - return stringRep; + return toStringEncoding(); } + /** + * Should be overloaded in sub classes to do subclass specific + * + * @return + */ protected String toStringEncoding() { return mKey + "=" + mValue; } diff --git a/java/src/org/broad/tribble/vcf/VCFInfoHeaderLine.java b/java/src/org/broad/tribble/vcf/VCFInfoHeaderLine.java index deeaea001..111338df0 100755 --- a/java/src/org/broad/tribble/vcf/VCFInfoHeaderLine.java +++ b/java/src/org/broad/tribble/vcf/VCFInfoHeaderLine.java @@ -9,11 +9,6 @@ package org.broad.tribble.vcf; * A class representing a key=value entry for INFO fields in the VCF header */ public class VCFInfoHeaderLine extends VCFCompoundHeaderLine { - - public VCFInfoHeaderLine(String name, int count, VCFHeaderLineType type, String description, VCFHeaderVersion version) { - super(name, count, type, description, SupportedHeaderLineType.INFO, version); - } - public VCFInfoHeaderLine(String name, int count, VCFHeaderLineType type, String description) { super(name, count, type, description, SupportedHeaderLineType.INFO); }