예제 #1
0
  /** Find all non-empty INFO fields 'infoFieldName' in results */
  protected String findDbInfo(String infoFieldName, QueryResult qr) {
    if (debug) Gpr.debug("Finding DB data for INFO field: " + infoFieldName);
    StringBuilder sb = new StringBuilder();

    for (VariantVcfEntry varVe : qr.results) {
      if (varVe != null) {
        String val = varVe.getVcfEntry().getInfo(infoFieldName);
        if (!VcfEntry.isEmpty(val)) {
          if (debug) Gpr.debug("\tFound: " + val);
          if (sb.length() > 0) sb.append(',');
          sb.append(val);
        }
      }
    }

    return sb.length() <= 0 ? null : sb.toString();
  }
예제 #2
0
  /** Add INFO fields. */
  protected boolean annotateInfo(VcfEntry vcfEntry, Map<String, String> info) {
    if (info == null || info.isEmpty()) return false;

    // Sort keys alphabetically
    ArrayList<String> keys = new ArrayList<String>();
    keys.addAll(info.keySet());
    Collections.sort(keys);

    // Add keys sorted alphabetically
    for (String key : keys) {
      String value = info.get(key);

      // Skip empty fields?
      if (!annotateEmpty && VcfEntry.isEmpty(value)) continue;

      // Add INFO entry
      if (prependInfoFieldName != null) key = prependInfoName(key);
      vcfEntry.addInfo(key, value);
    }

    return true;
  }
예제 #3
0
  /** Fill values for INFO fields requiring 'REF' value */
  protected void findDbInfoRef(Map<String, String> info, Set<VcfEntry> uniqueVcfEntries) {
    if (!useInfoFields || !hasVcfInfoPerAlleleRef) return; // Nothing to do

    for (String infoFieldName : infoFields) {
      // Does this field require 'REF' annotation?
      if (!isVcfInfoPerAlleleRef(infoFieldName)) continue;

      // Try to find 'REF' information in any entry
      String val = null;
      for (VcfEntry dbVcfEntry : uniqueVcfEntries) {
        val = dbVcfEntry.getInfo(infoFieldName, dbVcfEntry.getRef());

        if (VcfEntry.isEmpty(val)) val = null; // Only add non-empty
        else break; // We need only one value
      }

      // Nothing found? Use 'MISSING' value
      if (val == null) val = VcfFileIterator.MISSING;

      // Store value
      info.put(infoFieldName, val);
    }
  }
예제 #4
0
  /** Find the first non-empty INFO field 'infoFieldName' in results Note: ALT must match */
  protected String findDbInfoAlt(String infoFieldName, QueryResult qr) {
    for (VariantVcfEntry varVe : qr.results) {
      if (varVe != null) {
        // IMPORTANT: When a variant is parse, the original 'ALT' entry is stored in
        //            the 'Variant.genotype' whereas 'variant.alt' contains
        //            a 'minimal ALT'. E.g. if we have
        //                vcfEntry.ref = 'AC'
        //                vcfEntry.alt = 'A'
        //            Then
        //                variant.ref = 'C'
        //                variant.alt = ''
        //                variant.genotype = 'A'   <-- This is the 'original' ALT field from
        // vcfEntry
        //            That's why we use 'var.getGenotype()' in the following 'getInfo()' method.
        String vcfAlt = qr.variant.getGenotype();

        String val = varVe.getVcfEntry().getInfo(infoFieldName, vcfAlt);
        if (!VcfEntry.isEmpty(val)) return val;
      }
    }

    return VcfFileIterator.MISSING;
  }