Exemple #1
0
  @Override
  public void initialize(
      AnnotatorCompatible walker, GenomeAnalysisEngine toolkit, Set<VCFHeaderLine> headerLines) {
    // Make sure that we actually have a valid SnpEff rod binding (just in case the user specified
    // -A SnpEff
    // without providing a SnpEff rod via --snpEffFile):
    if (!isValidRodBinding(walker.getSnpEffRodBinding())) {
      canAnnotate = false;
      return;
    }

    RodBinding<VariantContext> snpEffRodBinding = walker.getSnpEffRodBinding();

    // Make sure that the SnpEff version number and command-line header lines are present in the VCF
    // header of
    // the SnpEff rod, and that the file was generated by a supported version of SnpEff:
    VCFHeader snpEffVCFHeader =
        GATKVCFUtils.getVCFHeadersFromRods(toolkit, Arrays.asList(snpEffRodBinding.getName()))
            .get(snpEffRodBinding.getName());
    VCFHeaderLine snpEffVersionLine =
        snpEffVCFHeader.getOtherHeaderLine(SNPEFF_VCF_HEADER_VERSION_LINE_KEY);
    VCFHeaderLine snpEffCommandLine =
        snpEffVCFHeader.getOtherHeaderLine(SNPEFF_VCF_HEADER_COMMAND_LINE_KEY);

    if (!isValidSnpEffVersionAndCommandLine(snpEffVersionLine, snpEffCommandLine)) {
      canAnnotate = false;
      return;
    }

    // If everything looks ok, add the SnpEff version number and command-line header lines to the
    // header of the VCF output file, changing the key names so that our output file won't be
    // mistaken in the future for a SnpEff output file:
    headerLines.add(
        new VCFHeaderLine(OUTPUT_VCF_HEADER_VERSION_LINE_KEY, snpEffVersionLine.getValue()));
    headerLines.add(
        new VCFHeaderLine(OUTPUT_VCF_HEADER_COMMAND_LINE_KEY, snpEffCommandLine.getValue()));

    // Can only be called from VariantAnnotator
    if (!(walker instanceof VariantAnnotator)) {
      if (walker != null)
        logger.warn(
            "Annotation will not be calculated, must be called from VariantAnnotator, not "
                + walker.getClass().getName());
      else logger.warn("Annotation will not be calculated, must be called from VariantAnnotator");
      canAnnotate = false;
      return;
    }
  }
  public void writeHeader(VCFHeader header) {
    mHeader = doNotWriteGenotypes ? new VCFHeader(header.getMetaData()) : header;

    try {
      // the file format field needs to be written first
      mWriter.write(
          VCFHeader.METADATA_INDICATOR
              + VCFHeaderVersion.VCF4_1.getFormatString()
              + "="
              + VCFHeaderVersion.VCF4_1.getVersionString()
              + "\n");

      for (VCFHeaderLine line : mHeader.getMetaData()) {
        if (VCFHeaderVersion.isFormatString(line.getKey())) continue;

        // are the records filtered (so we know what to put in the FILTER column of passing records)
        // ?
        if (line instanceof VCFFilterHeaderLine) filtersWereAppliedToContext = true;

        mWriter.write(VCFHeader.METADATA_INDICATOR);
        mWriter.write(line.toString());
        mWriter.write("\n");
      }

      // write out the column line
      mWriter.write(VCFHeader.HEADER_INDICATOR);
      for (VCFHeader.HEADER_FIELDS field : mHeader.getHeaderFields()) {
        mWriter.write(field.toString());
        mWriter.write(VCFConstants.FIELD_SEPARATOR);
      }

      if (mHeader.hasGenotypingData()) {
        mWriter.write("FORMAT");
        for (String sample : mHeader.getGenotypeSamples()) {
          mWriter.write(VCFConstants.FIELD_SEPARATOR);
          mWriter.write(sample);
        }
      }

      mWriter.write("\n");
      mWriter.flush(); // necessary so that writing to an output stream will work
    } catch (IOException e) {
      throw new TribbleException("IOException writing the VCF header to " + locationString(), e);
    }
  }
Exemple #3
0
  private boolean isValidSnpEffVersionAndCommandLine(
      final VCFHeaderLine snpEffVersionLine, final VCFHeaderLine snpEffCommandLine) {
    if (snpEffVersionLine == null
        || snpEffVersionLine.getValue() == null
        || snpEffVersionLine.getValue().trim().length() == 0) {
      logger.warn(
          String.format(
              "Could not find a %s entry in the VCF header for the SnpEff input file, "
                  + "and so could not verify that the file was generated by a supported version of SnpEff (%s)",
              SNPEFF_VCF_HEADER_VERSION_LINE_KEY, supportedSnpEffVersionsString()));
      return false;
    }

    if (snpEffCommandLine == null
        || snpEffCommandLine.getValue() == null
        || snpEffCommandLine.getValue().trim().length() == 0) {
      logger.warn(
          String.format(
              "Could not find a %s entry in the VCF header for the SnpEff input file, "
                  + "which should be added by all supported versions of SnpEff (%s)",
              SNPEFF_VCF_HEADER_COMMAND_LINE_KEY, supportedSnpEffVersionsString()));
      return false;
    }

    String snpEffVersionString = snpEffVersionLine.getValue().replaceAll("\"", "").split(" ")[0];

    if (!isSupportedSnpEffVersion(snpEffVersionString, snpEffCommandLine.getValue())) {
      logger.warn(
          String.format(
              "The version of SnpEff used to generate the SnpEff input file (%s) "
                  + "is not currently supported by the GATK, and was not run in GATK "
                  + "compatibility mode. Supported versions are: %s",
              snpEffVersionString, supportedSnpEffVersionsString()));
      return false;
    }

    return true;
  }