/**
   * For each variant in the file, determine the phasing for the child and replace the child's
   * genotype with the trio's genotype
   *
   * @param tracker the reference meta-data tracker
   * @param ref the reference context
   * @param context the alignment context
   * @return null
   */
  @Override
  public Integer map(RefMetaDataTracker tracker, ReferenceContext ref, AlignmentContext context) {
    if (tracker != null) {
      for (VariantContext vc :
          tracker.getValues(variantCollection.variants, context.getLocation())) {
        vc = vc.subContextFromSamples(samples);
        if (!vc.isPolymorphicInSamples()) continue;

        double log10pSomatic = calcLog10pSomatic(vc);

        // write in the somatic status probability
        Map<String, Object> attrs = new HashMap<String, Object>(); // vc.getAttributes());
        if (!minimalVCF) attrs.putAll(vc.getAttributes());
        attrs.put(SOMATIC_LOD_TAG_NAME, log10pSomatic);
        if (log10pSomatic > somaticMinLOD) {
          attrs.put(VCFConstants.SOMATIC_KEY, true);
          attrs.put(SOMATIC_NONREF_TAG_NAME, calculateTumorNNR(vc));
          attrs.put(SOMATIC_AC_TAG_NAME, calculateTumorAC(vc));
        }
        final VariantContextBuilder builder = new VariantContextBuilder(vc).attributes(attrs);
        VariantContextUtils.calculateChromosomeCounts(builder, false);
        VariantContext newvc = builder.make();

        vcfWriter.add(newvc);
      }

      return null;
    }

    return null;
  }
Пример #2
0
  private Collection<VariantContext> getVariantContexts(
      RefMetaDataTracker tracker, ReferenceContext ref) {

    List<Feature> features = tracker.getValues(variants, ref.getLocus());
    List<VariantContext> VCs = new ArrayList<VariantContext>(features.size());

    for (Feature record : features) {
      if (VariantContextAdaptors.canBeConvertedToVariantContext(record)) {
        // we need to special case the HapMap format because indels aren't handled correctly
        if (record instanceof RawHapMapFeature) {

          // is it an indel?
          RawHapMapFeature hapmap = (RawHapMapFeature) record;
          if (hapmap.getAlleles()[0].equals(RawHapMapFeature.NULL_ALLELE_STRING)
              || hapmap.getAlleles()[1].equals(RawHapMapFeature.NULL_ALLELE_STRING)) {
            // get the dbsnp object corresponding to this record (needed to help us distinguish
            // between insertions and deletions)
            VariantContext dbsnpVC = getDbsnp(hapmap.getName());
            if (dbsnpVC == null || dbsnpVC.isMixed()) continue;

            Map<String, Allele> alleleMap = new HashMap<String, Allele>(2);
            alleleMap.put(
                RawHapMapFeature.DELETION,
                Allele.create(ref.getBase(), dbsnpVC.isSimpleInsertion()));
            alleleMap.put(
                RawHapMapFeature.INSERTION,
                Allele.create(
                    (char) ref.getBase() + ((RawHapMapFeature) record).getAlleles()[1],
                    !dbsnpVC.isSimpleInsertion()));
            hapmap.setActualAlleles(alleleMap);

            // also, use the correct positioning for insertions
            hapmap.updatePosition(dbsnpVC.getStart());

            if (hapmap.getStart() < ref.getWindow().getStart()) {
              logger.warn(
                  "Hapmap record at "
                      + ref.getLocus()
                      + " represents an indel too large to be converted; skipping...");
              continue;
            }
          }
        }

        // ok, we might actually be able to turn this record in a variant context
        VariantContext vc =
            VariantContextAdaptors.toVariantContext(variants.getName(), record, ref);

        if (vc != null) // sometimes the track has odd stuff in it that can't be converted
        VCs.add(vc);
      }
    }

    return VCs;
  }
Пример #3
0
 /**
  * Adds all intervals that overlap the current reference locus to the intervalMap
  *
  * @param refLocus the current reference locus
  */
 private void addNewOverlappingIntervals(final GenomeLoc refLocus) {
   GenomeLoc interval = intervalListIterator.peek();
   while (interval != null && !interval.isPast(refLocus)) {
     intervalMap.put(interval, createIntervalStatistic(interval));
     intervalListIterator.next();
     interval = intervalListIterator.peek();
   }
 }
Пример #4
0
  /**
   * Takes the interval, finds it in the stash, prints it to the VCF
   *
   * @param stats The statistics of the interval
   * @param refAllele the reference allele
   */
  private void outputStatsToVCF(final IntervalStratification stats, final Allele refAllele) {
    GenomeLoc interval = stats.getInterval();

    final List<Allele> alleles = new ArrayList<>();
    final Map<String, Object> attributes = new HashMap<>();
    final ArrayList<Genotype> genotypes = new ArrayList<>();

    for (String sample : samples) {
      final GenotypeBuilder gb = new GenotypeBuilder(sample);

      SampleStratification sampleStat = stats.getSampleStatistics(sample);
      gb.attribute(
          GATKVCFConstants.AVG_INTERVAL_DP_BY_SAMPLE_KEY,
          sampleStat.averageCoverage(interval.size()));
      gb.attribute(GATKVCFConstants.LOW_COVERAGE_LOCI, sampleStat.getNLowCoveredLoci());
      gb.attribute(GATKVCFConstants.ZERO_COVERAGE_LOCI, sampleStat.getNUncoveredLoci());
      gb.filters(statusToStrings(stats.getSampleStatistics(sample).callableStatuses(), false));

      genotypes.add(gb.make());
    }
    alleles.add(refAllele);
    alleles.add(SYMBOLIC_ALLELE);
    VariantContextBuilder vcb =
        new VariantContextBuilder(
            "DiagnoseTargets",
            interval.getContig(),
            interval.getStart(),
            interval.getStop(),
            alleles);

    vcb = vcb.log10PError(VariantContext.NO_LOG10_PERROR);
    vcb.filters(new LinkedHashSet<>(statusToStrings(stats.callableStatuses(), true)));

    attributes.put(VCFConstants.END_KEY, interval.getStop());
    attributes.put(GATKVCFConstants.AVG_INTERVAL_DP_KEY, stats.averageCoverage(interval.size()));
    attributes.put(GATKVCFConstants.INTERVAL_GC_CONTENT_KEY, stats.gcContent());

    vcb = vcb.attributes(attributes);
    vcb = vcb.genotypes(genotypes);

    vcfWriter.add(vcb.make());
  }
Пример #5
0
 private void addAnnotation(Map<String, Object> annotations, String keyName, String keyValue) {
   // Only add annotations for keys associated with non-empty values:
   if (keyValue != null && keyValue.trim().length() > 0) {
     annotations.put(keyName, keyValue);
   }
 }