/**
   * Assert that two variant contexts are actually equal
   *
   * @param actual
   * @param expected
   */
  public static void assertEquals(final VariantContext actual, final VariantContext expected) {
    Assert.assertNotNull(actual, "VariantContext expected not null");
    Assert.assertEquals(actual.getChr(), expected.getChr(), "chr");
    Assert.assertEquals(actual.getStart(), expected.getStart(), "start");
    Assert.assertEquals(actual.getEnd(), expected.getEnd(), "end");
    Assert.assertEquals(actual.getID(), expected.getID(), "id");
    Assert.assertEquals(
        actual.getAlleles(), expected.getAlleles(), "alleles for " + expected + " vs " + actual);

    assertAttributesEquals(actual.getAttributes(), expected.getAttributes());
    Assert.assertEquals(
        actual.filtersWereApplied(), expected.filtersWereApplied(), "filtersWereApplied");
    Assert.assertEquals(actual.isFiltered(), expected.isFiltered(), "isFiltered");
    VariantBaseTest.assertEqualsSet(actual.getFilters(), expected.getFilters(), "filters");
    VariantBaseTest.assertEqualsDoubleSmart(
        actual.getPhredScaledQual(), expected.getPhredScaledQual());

    Assert.assertEquals(actual.hasGenotypes(), expected.hasGenotypes(), "hasGenotypes");
    if (expected.hasGenotypes()) {
      VariantBaseTest.assertEqualsSet(
          actual.getSampleNames(), expected.getSampleNames(), "sample names set");
      Assert.assertEquals(
          actual.getSampleNamesOrderedByName(),
          expected.getSampleNamesOrderedByName(),
          "sample names");
      final Set<String> samples = expected.getSampleNames();
      for (final String sample : samples) {
        assertEquals(actual.getGenotype(sample), expected.getGenotype(sample));
      }
    }
  }
 public VariantContextTestData(final VCFHeader header, final List<VariantContext> vcs) {
   final Set<String> samples = new HashSet<String>();
   for (final VariantContext vc : vcs)
     if (vc.hasGenotypes()) samples.addAll(vc.getSampleNames());
   this.header =
       samples.isEmpty() ? header : new VCFHeader(header.getMetaDataInSortedOrder(), samples);
   this.vcs = vcs;
 }
Пример #3
0
  private void writeRecord(VariantContext vc, RefMetaDataTracker tracker, GenomeLoc loc) {
    if (!wroteHeader) {
      wroteHeader = true;

      // setup the header fields
      Set<VCFHeaderLine> hInfo = new HashSet<VCFHeaderLine>();
      hInfo.addAll(GATKVCFUtils.getHeaderFields(getToolkit(), Arrays.asList(variants.getName())));
      hInfo.add(VCFStandardHeaderLines.getFormatLine(VCFConstants.GENOTYPE_KEY));

      allowedGenotypeFormatStrings.add(VCFConstants.GENOTYPE_KEY);
      for (VCFHeaderLine field : hInfo) {
        if (field instanceof VCFFormatHeaderLine) {
          allowedGenotypeFormatStrings.add(((VCFFormatHeaderLine) field).getID());
        }
      }

      samples = new LinkedHashSet<String>();
      if (sampleName != null) {
        samples.add(sampleName);
      } else {
        // try VCF first
        samples =
            SampleUtils.getSampleListWithVCFHeader(getToolkit(), Arrays.asList(variants.getName()));

        if (samples.isEmpty()) {
          List<Feature> features = tracker.getValues(variants, loc);
          if (features.size() == 0)
            throw new IllegalStateException(
                "No rod data is present, but we just created a VariantContext");

          Feature f = features.get(0);
          if (f instanceof RawHapMapFeature)
            samples.addAll(Arrays.asList(((RawHapMapFeature) f).getSampleIDs()));
          else samples.addAll(vc.getSampleNames());
        }
      }

      vcfwriter.writeHeader(new VCFHeader(hInfo, samples));
    }

    vc = GATKVariantContextUtils.purgeUnallowedGenotypeAttributes(vc, allowedGenotypeFormatStrings);
    vcfwriter.add(vc);
  }