+ * Decodes colon, semicolon, equals sign, percent sign, comma to their decoded
+ * form. The VCF specification (para 1.2) requires these to be encoded where not
+ * used with their special meaning in the VCF syntax. Note that general URL
+ * decoding should not be applied, since this would incorrectly decode (for
+ * example) a '+' sign.
+ *
+ * @param value
+ * @return
+ */
+ protected static String decodeSpecialCharacters(String value)
+ {
+ /*
+ * avoid regex compilation if it is not needed!
+ */
+ if (!value.contains(ENCODED_COLON) && !value.contains(ENCODED_SEMICOLON)
+ && !value.contains(ENCODED_EQUALS)
+ && !value.contains(ENCODED_PERCENT)
+ && !value.contains(ENCODED_COMMA))
+ {
+ return value;
+ }
+
+ value = value.replace(ENCODED_COLON, ":")
+ .replace(ENCODED_SEMICOLON, ";").replace(ENCODED_EQUALS, "=")
+ .replace(ENCODED_PERCENT, "%").replace(ENCODED_COMMA, ",");
+ return value;
+ }
+
+ /**
+ * Answers true for '.', null, or an empty value, or if the INFO type is String.
+ * If the INFO type is Integer or Float, answers false if the value is not in
+ * valid format.
+ *
+ * @param variant
+ * @param infoId
+ * @param value
+ * @return
+ */
+ protected boolean isValid(VariantContext variant, String infoId,
+ String value)
+ {
+ if (value == null || value.isEmpty() || NO_VALUE.equals(value))
+ {
+ return true;
+ }
+ VCFInfoHeaderLine infoHeader = header.getInfoHeaderLine(infoId);
+ if (infoHeader == null)
+ {
+ Cache.log.error("Field " + infoId + " has no INFO header");
+ return false;
+ }
+ VCFHeaderLineType infoType = infoHeader.getType();
+ try
+ {
+ if (infoType == VCFHeaderLineType.Integer)
+ {
+ Integer.parseInt(value);
+ }
+ else if (infoType == VCFHeaderLineType.Float)
+ {
+ Float.parseFloat(value);
+ }
+ } catch (NumberFormatException e)
+ {
+ logInvalidValue(variant, infoId, value);
+ return false;
+ }
+ return true;
+ }
+
+ /**
+ * Logs an error message for malformed data; duplicate messages (same id and
+ * value) are not logged
+ *
+ * @param variant
+ * @param infoId
+ * @param value
+ */
+ private void logInvalidValue(VariantContext variant, String infoId,
+ String value)
+ {
+ if (badData == null)
+ {
+ badData = new HashSet<>();
+ }
+ String token = infoId + ":" + value;
+ if (!badData.contains(token))
+ {
+ badData.add(token);
+ Cache.log.error(String.format("Invalid VCF data at %s:%d %s=%s",
+ variant.getContig(), variant.getStart(), infoId, value));
+ }
+ }
+
+ /**