/**
   * Update the attributes of the attributes map given the VariantContext to reflect the proper
   * chromosome-based VCF tags
   *
   * @param vc the VariantContext
   * @param attributes the attributes map to populate; must not be null; may contain old values
   * @param removeStaleValues should we remove stale values from the mapping?
   * @return the attributes map provided as input, returned for programming convenience
   */
  public static Map<String, Object> calculateChromosomeCounts(
      VariantContext vc, Map<String, Object> attributes, boolean removeStaleValues) {
    final int AN = vc.getCalledChrCount();

    // if everyone is a no-call, remove the old attributes if requested
    if (AN == 0 && removeStaleValues) {
      if (attributes.containsKey(VCFConstants.ALLELE_COUNT_KEY))
        attributes.remove(VCFConstants.ALLELE_COUNT_KEY);
      if (attributes.containsKey(VCFConstants.ALLELE_FREQUENCY_KEY))
        attributes.remove(VCFConstants.ALLELE_FREQUENCY_KEY);
      if (attributes.containsKey(VCFConstants.ALLELE_NUMBER_KEY))
        attributes.remove(VCFConstants.ALLELE_NUMBER_KEY);
      return attributes;
    }

    if (vc.hasGenotypes()) {
      attributes.put(VCFConstants.ALLELE_NUMBER_KEY, AN);

      // if there are alternate alleles, record the relevant tags
      if (vc.getAlternateAlleles().size() > 0) {
        final ArrayList<String> alleleFreqs = new ArrayList<String>();
        final ArrayList<Integer> alleleCounts = new ArrayList<Integer>();
        for (Allele allele : vc.getAlternateAlleles()) {
          int altChromosomes = vc.getCalledChrCount(allele);
          alleleCounts.add(altChromosomes);
          if (AN == 0) {
            alleleFreqs.add("0.0");
          } else {
            // todo -- this is a performance problem
            final String freq =
                String.format(
                    makePrecisionFormatStringFromDenominatorValue((double) AN),
                    ((double) altChromosomes / (double) AN));
            alleleFreqs.add(freq);
          }
        }

        attributes.put(
            VCFConstants.ALLELE_COUNT_KEY,
            alleleCounts.size() == 1 ? alleleCounts.get(0) : alleleCounts);
        attributes.put(
            VCFConstants.ALLELE_FREQUENCY_KEY,
            alleleFreqs.size() == 1 ? alleleFreqs.get(0) : alleleFreqs);
      } else {
        attributes.put(VCFConstants.ALLELE_COUNT_KEY, 0);
        attributes.put(VCFConstants.ALLELE_FREQUENCY_KEY, 0.0);
      }
    }

    return attributes;
  }
 public static double computeHardyWeinbergPvalue(VariantContext vc) {
   if (vc.getCalledChrCount() == 0) return 0.0;
   return HardyWeinbergCalculation.hwCalculate(
       vc.getHomRefCount(), vc.getHetCount(), vc.getHomVarCount());
 }