Exemple #1
0
  /**
   * For each site of interest, annotate based on the requested annotation types
   *
   * @param tracker the meta-data tracker
   * @param ref the reference base
   * @param context the context for the given locus
   * @return 1 if the locus was successfully processed, 0 if otherwise
   */
  public Integer map(RefMetaDataTracker tracker, ReferenceContext ref, AlignmentContext context) {
    if (tracker == null) return 0;

    // get the variant contexts for all the variants at the location
    Collection<VariantContext> VCs =
        tracker.getValues(variantCollection.variants, context.getLocation());
    if (VCs.isEmpty()) return 0;

    Collection<VariantContext> annotatedVCs = VCs;

    // if the reference base is not ambiguous, we can annotate
    Map<String, AlignmentContext> stratifiedContexts;
    if (BaseUtils.simpleBaseToBaseIndex(ref.getBase()) != -1) {
      stratifiedContexts = AlignmentContextUtils.splitContextBySampleName(context.getBasePileup());
      annotatedVCs = new ArrayList<>(VCs.size());
      for (VariantContext vc : VCs)
        annotatedVCs.add(engine.annotateContext(tracker, ref, stratifiedContexts, vc));
    }

    for (VariantContext annotatedVC : annotatedVCs) vcfWriter.add(annotatedVC);

    return 1;
  }
Exemple #2
0
  /** Prepare the output file and the list of available features. */
  public void initialize() {

    if (LIST) {
      AnnotationHelpUtils.listAnnotations();
      System.exit(0);
    }

    // get the list of all sample names from the variant VCF input rod, if applicable
    final List<String> rodName = Arrays.asList(variantCollection.variants.getName());
    final Set<String> samples = SampleUtils.getUniqueSamplesFromRods(getToolkit(), rodName);

    if (USE_ALL_ANNOTATIONS)
      engine = new VariantAnnotatorEngine(annotationsToExclude, this, getToolkit());
    else
      engine =
          new VariantAnnotatorEngine(
              annotationGroupsToUse, annotationsToUse, annotationsToExclude, this, getToolkit());
    engine.initializeExpressions(expressionsToUse);
    engine.setExpressionAlleleConcordance(expressionAlleleConcordance);

    // setup the header fields
    // note that if any of the definitions conflict with our new ones, then we want to overwrite the
    // old ones
    final Set<VCFHeaderLine> hInfo = new HashSet<>();
    hInfo.addAll(engine.getVCFAnnotationDescriptions());
    for (final VCFHeaderLine line : GATKVCFUtils.getHeaderFields(getToolkit(), rodName)) {
      if (isUniqueHeaderLine(line, hInfo)) hInfo.add(line);
    }
    // for the expressions, pull the info header line from the header of the resource rod
    for (final VariantAnnotatorEngine.VAExpression expression : engine.getRequestedExpressions()) {
      // special case the ID field
      if (expression.fieldName.equals("ID")) {
        hInfo.add(
            new VCFInfoHeaderLine(
                expression.fullName,
                1,
                VCFHeaderLineType.String,
                "ID field transferred from external VCF resource"));
        continue;
      }
      VCFInfoHeaderLine targetHeaderLine = null;
      for (final VCFHeaderLine line :
          GATKVCFUtils.getHeaderFields(getToolkit(), Arrays.asList(expression.binding.getName()))) {
        if (line instanceof VCFInfoHeaderLine) {
          final VCFInfoHeaderLine infoline = (VCFInfoHeaderLine) line;
          if (infoline.getID().equals(expression.fieldName)) {
            targetHeaderLine = infoline;
            break;
          }
        }
      }

      if (targetHeaderLine != null) {
        if (targetHeaderLine.getCountType() == VCFHeaderLineCount.INTEGER)
          hInfo.add(
              new VCFInfoHeaderLine(
                  expression.fullName,
                  targetHeaderLine.getCount(),
                  targetHeaderLine.getType(),
                  targetHeaderLine.getDescription()));
        else
          hInfo.add(
              new VCFInfoHeaderLine(
                  expression.fullName,
                  targetHeaderLine.getCountType(),
                  targetHeaderLine.getType(),
                  targetHeaderLine.getDescription()));
      } else {
        hInfo.add(
            new VCFInfoHeaderLine(
                expression.fullName,
                VCFHeaderLineCount.UNBOUNDED,
                VCFHeaderLineType.String,
                "Value transferred from another external VCF resource"));
      }
    }

    engine.makeHeaderInfoMap(hInfo);
    engine.invokeAnnotationInitializationMethods(hInfo);

    VCFHeader vcfHeader = new VCFHeader(hInfo, samples);
    vcfWriter.writeHeader(vcfHeader);
  }