Esempio n. 1
0
  /**
   * Add a "key=value" tuple the info field
   *
   * @param key : INFO key name
   * @param value : Can be null if it is a boolean field.
   */
  public void addInfo(String key, String value) {
    if (!isValidInfoKey(key))
      throw new RuntimeException(
          "Illegal INFO key / name. Key: \""
              + key
              + "\" does not match regular expression ^[A-Za-z_][0-9A-Za-z_.]*$");
    if (!isValidInfoValue(value))
      throw new RuntimeException(
          "No white-space, semi-colons, or equals-signs are permitted in INFO field values. Name:\""
              + key
              + "\" Value:\""
              + value
              + "\"");

    // Remove previous 'key' for INFO field?
    removeInfo(key);

    // Is this a 'flag'?
    boolean isFlag = false;
    VcfHeader vcfHeader = vcfFileIterator.getVcfHeader();
    if (vcfHeader != null) {
      VcfHeaderInfo vcfHeaderInfo = vcfFileIterator.getVcfHeader().getVcfInfo(key);
      isFlag = (vcfHeaderInfo != null) && (vcfHeaderInfo.getVcfInfoType() == VcfInfoType.Flag);
    }

    // Add to info hash (if available)
    if (info != null) info.put(key, value);

    // Append value to infoStr
    String addInfoStr = key + (value != null && !isFlag ? "=" + value : ""); // String to append
    if ((infoStr == null) || infoStr.isEmpty()) infoStr = addInfoStr;
    else {
      if (!infoStr.endsWith(SUB_FIELD_SEP))
        infoStr += SUB_FIELD_SEP; // Do we need to add a semicolon?
      infoStr += addInfoStr; // Add info string
    }
  }