Пример #1
0
  /** Check that all fields to add are available */
  public void checkFieldsToAdd() throws IOException {
    // Check that all fields have a descriptor (used in VCF header)
    if (verbose) {
      for (String filedName : dbNsfp.getFieldNames())
        if (fieldsDescription.get(filedName) == null)
          System.err.println(
              "WARNING: Field (column) '"
                  + filedName
                  + "' does not have an approriate field descriptor.");
    }

    // Check that all "field to add" are in the database
    for (String fieldKey : fieldsToAdd.keySet())
      if (!dbNsfp.hasField(fieldKey))
        fatalError("dbNsfp does not have field '" + fieldKey + "' (file '" + dbFileName + "')");
  }
Пример #2
0
  /** Initialize annotation process */
  @Override
  public boolean annotateInit(VcfFileIterator vcfFile) {
    this.vcfFile = vcfFile;

    // Get database name from config file?
    // Note this can happen when invoked a VcfAnnotator (e.g. form ClinEff)
    if (dbFileName == null && config != null) {
      String configKey = CONFIG_DBNSFP_DB_FILE;
      String coordinates = config.getString(Config.KEY_COORDINATES);
      if (coordinates != null) configKey += "." + coordinates;
      dbFileName = config.getString(configKey);
    }

    // Check and open dbNsfp
    dbNsfp = new DbNsfp(dbFileName);
    dbNsfp.setDebug(debug);
    dbNsfp.setVerbose(verbose);
    dbNsfp.open();

    // Initialize fields to annotate
    annotateInitFields();

    return true;
  }
Пример #3
0
  /** Annotate a VCF entry */
  public boolean annotate(Variant variant, Map<String, String> info) {
    if (verbose) Gpr.showMark(++countVariants, SHOW_EVERY);

    // Find in database
    Collection<DbNsfpEntry> dbEntries = dbNsfp.query(variant);
    if (dbEntries == null || dbEntries.isEmpty()) return false;

    // Add all INFO fields that refer to this allele
    boolean annotated = false;
    for (String fieldKey : fieldsToAdd.keySet()) {
      // Are there any values to annotate?
      String infoValue = getVcfInfo(dbEntries, fieldKey);

      // Missing or empty?
      if (annotateEmpty) {
        if (infoValue.isEmpty()) infoValue = ".";
      } else if (isDbNsfpValueEmpty(infoValue)) {
        infoValue = null;
      }

      // Add annotations
      if (infoValue != null) {
        String oldInfo = info.get(fieldKey);
        if (oldInfo == null) oldInfo = "";

        info.put(fieldKey, oldInfo + (oldInfo.isEmpty() ? "" : ",") + infoValue);
        annotated = true;
      }
    }

    // Show progress
    if (annotated) {
      countAnnotated++;
      if (debug) Gpr.debug("Annotated: " + variant.toStr());
    }

    return annotated;
  }
Пример #4
0
  /** Initialize fields to annotate */
  void annotateInitFields() {
    // ---
    // Fields to use
    // ---
    VcfInfoType types[] = dbNsfp.getTypes();
    String fieldNames[] = dbNsfp.getFieldNamesSorted();
    if (verbose) Timer.showStdErr("Database fields:");
    for (int i = 0; i < fieldNames.length; i++) {
      String type = (types[i] != null ? types[i].toString() : "String");
      fieldsType.put(fieldNames[i], type);
      fieldsDescription.put(fieldNames[i], "Field '" + fieldNames[i] + "' from dbNSFP");
      if (verbose) System.err.println("\t'" + fieldNames[i] + "'");
    }

    currentDbEntry = null;

    if (inverseFieldSelection) {
      // Inverted selection: Start with ALL fields and then remove the ones selected

      // Add all fields
      Set<String> fields = new HashSet<String>();
      fields.addAll(fieldsDescription.keySet());

      // Remove selected fields
      if (fieldsNamesToAdd != null) {
        for (String fn : fieldsNamesToAdd.split(",")) fields.remove(fn);
      }

      // Sort
      ArrayList<String> fieldsSort = new ArrayList<String>();
      fieldsSort.addAll(fields);
      Collections.sort(fieldsSort);

      // Fields to be added
      for (String fn : fieldsSort) fieldsToAdd.put(fn, fieldsDescription.get(fn));

    } else {
      // No fields specified? Use default list of fields to add
      if (fieldsNamesToAdd == null) fieldsNamesToAdd = DEFAULT_FIELDS_NAMES_TO_ADD;

      // Add them to the list
      for (String fn : fieldsNamesToAdd.split(",")) {
        if (fieldsDescription.get(fn) == null) {
          // Field not found
          if (fieldsNamesToAdd == DEFAULT_FIELDS_NAMES_TO_ADD) {
            // Was it one of the default fields? => Ignore
            if (verbose)
              Timer.showStdErr("Warning: Default field name '" + fn + "' not found, ignoring");
          } else usage("Error: Field name '" + fn + "' not found");
        } else fieldsToAdd.put(fn, fieldsDescription.get(fn)); // Add field
      }
    }

    // Show selected fields
    if (verbose) {
      ArrayList<String> fieldsSort = new ArrayList<String>();
      fieldsSort.addAll(fieldsToAdd.keySet());
      Collections.sort(fieldsSort);

      Timer.showStdErr("Fields to add:");
      for (String fn : fieldsSort) System.err.println("\t\t\t" + fn);
    }
  }
Пример #5
0
 @Override
 public boolean annotateFinish() {
   if (dbNsfp != null) dbNsfp.close();
   return true;
 }