Package htsjdk.variant.variantcontext

Examples of htsjdk.variant.variantcontext.VariantContextComparator


    /** Validates that all headers contain the same set of genotyped samples and that files are in order by position of first record. */
    private static void assertSameSamplesAndValidOrdering(final List<File> inputFiles) {
        final VCFHeader header = new VCFFileReader(inputFiles.get(0), false).getFileHeader();
        final SAMSequenceDictionary dict = header.getSequenceDictionary();
        final VariantContextComparator comparator = new VariantContextComparator(header.getSequenceDictionary());
        final List<String> samples = header.getGenotypeSamples();

        File lastFile = null;
        VariantContext lastContext = null;

        for (final File f : inputFiles) {
            final VCFFileReader in = new VCFFileReader(f, false);
            dict.assertSameDictionary(in.getFileHeader().getSequenceDictionary());
            final List<String> theseSamples = in.getFileHeader().getGenotypeSamples();

            if (!samples.equals(theseSamples)) {
                final SortedSet<String> s1 = new TreeSet<String>(samples);
                final SortedSet<String> s2 = new TreeSet<String>(theseSamples);
                s1.removeAll(theseSamples);
                s2.removeAll(samples);

                throw new IllegalArgumentException("VCFs do not have identical sample lists." +
                        " Samples unique to first file: " + s1 + ". Samples unique to " + f.getAbsolutePath() + ": " + s2 + ".");
            }

            final CloseableIterator<VariantContext> variantIterator = in.iterator();
            if (variantIterator.hasNext()) {
                final VariantContext currentContext = variantIterator.next();
                if (lastContext != null) {
                    if (comparator.compare(lastContext, currentContext) >= 0) {
                        throw new IllegalArgumentException("First record in file " + f.getAbsolutePath() + " is not after first record in " +
                                "previous file " + lastFile.getAbsolutePath());
                    }
                }

View Full Code Here


        final ProgressLogger progress = new ProgressLogger(log, 10000);
        VariantContext lastContext = null;
        File lastFile = null;
        VCFHeader firstHeader = null;
        VariantContextComparator comparator = null;

        for (final File f : inputFiles) {
            log.debug("Gathering from file: ", f.getAbsolutePath());
            final VCFFileReader variantReader = new VCFFileReader(f, false);
            final PeekableIterator<VariantContext> variantIterator = new PeekableIterator<VariantContext>(variantReader.iterator());
            final VCFHeader header = variantReader.getFileHeader();

            if (firstHeader == null) {
                firstHeader = header;
                out.writeHeader(firstHeader);
                comparator = new VariantContextComparator(firstHeader.getContigLines());
            }

            if (lastContext != null && variantIterator.hasNext()) {
                final VariantContext vc = variantIterator.peek();
                if (comparator.compare(vc, lastContext) <= 0) {
                    throw new IllegalStateException("First variant in file " + f.getAbsolutePath() + " is at " + vc.getSource() +
                            " but last variant in earlier file " + lastFile.getAbsolutePath() + " is at " + lastContext.getSource());
                }
            }
View Full Code Here

                                 final SAMSequenceDictionary dict) {
        this.truthIterator = new PeekableIterator<VariantContext>(truthIterator);
        this.truthSample = truthSample;
        this.callIterator = new PeekableIterator<VariantContext>(callIterator);
        this.callSample = callSample;
        this.comparator = new VariantContextComparator(dict);
    }
View Full Code Here

    final ProgressLogger progress = new ProgressLogger(log, 10000);
    final List<String> sampleList = new ArrayList<String>();
    final Collection<CloseableIterator<VariantContext>> iteratorCollection = new ArrayList<CloseableIterator<VariantContext>>(INPUT.size());
    final Collection<VCFHeader> headers = new HashSet<VCFHeader>(INPUT.size());

    VariantContextComparator variantContextComparator = null;
    SAMSequenceDictionary sequenceDictionary = null;

    if (SEQUENCE_DICTIONARY != null) sequenceDictionary = SAMFileReader.getSequenceDictionary(SEQUENCE_DICTIONARY);

    for (final File file : INPUT) {
      IOUtil.assertFileIsReadable(file);
      final VCFFileReader fileReader = new VCFFileReader(file, false);
      final VCFHeader fileHeader = fileReader.getFileHeader();

      if (variantContextComparator == null) {
        variantContextComparator = fileHeader.getVCFRecordComparator();
      } else {
        if ( ! variantContextComparator.isCompatible(fileHeader.getContigLines())) {
          throw new IllegalArgumentException(
              "The contig entries in input file " + file.getAbsolutePath() + " are not compatible with the others.");
        }
      }
View Full Code Here

  @Test
  public void testIdentical() {
    final VariantContext contextOne = buildVariantContext("source", "one", 100);
    final List<String> contigs = getOrderedContigList(contextOne);
    Assert.assertEquals(0, new VariantContextComparator(contigs).compare(contextOne, contextOne));
  }
View Full Code Here

  @Test
  public void testPositions() {
    final VariantContext contextOne = buildVariantContext("source", "one", 100);
    final VariantContext contextTwo = buildVariantContext("source", "one", 150);
    final List<String> contigs = getOrderedContigList(contextOne, contextTwo);
    Assert.assertTrue(new VariantContextComparator(contigs).compare(contextOne, contextTwo) < 0);
    Assert.assertTrue(new VariantContextComparator(contigs).compare(contextTwo, contextOne) > 0);
  }
View Full Code Here

  @Test
  public void testContigs() {
    final VariantContext contextOne = buildVariantContext("source", "one", 100);
    final VariantContext contextTwo = buildVariantContext("source", "two", 100);
    final List<String> contigs = getOrderedContigList(contextOne, contextTwo);
    Assert.assertTrue(new VariantContextComparator(contigs).compare(contextOne, contextTwo) < 0);
    Assert.assertTrue(new VariantContextComparator(contigs).compare(contextTwo, contextOne) > 0);
  }
View Full Code Here

  @Test
  public void testCombinationOne() {
    final VariantContext contextOne = buildVariantContext("source", "one", 100);
    final VariantContext contextTwo = buildVariantContext("source", "two", 150);
    final List<String> contigs = getOrderedContigList(contextOne, contextTwo);
    Assert.assertTrue(new VariantContextComparator(contigs).compare(contextOne, contextTwo) < 0);
    Assert.assertTrue(new VariantContextComparator(contigs).compare(contextTwo, contextOne) > 0);
  }
View Full Code Here

  @Test
  public void testCombinationTwo() {
    final VariantContext contextOne = buildVariantContext("source", "one", 150);
    final VariantContext contextTwo = buildVariantContext("source", "two", 100);
    final List<String> contigs = getOrderedContigList(contextOne, contextTwo);
    Assert.assertTrue(new VariantContextComparator(contigs).compare(contextOne, contextTwo) < 0);
    Assert.assertTrue(new VariantContextComparator(contigs).compare(contextTwo, contextOne) > 0);
  }
View Full Code Here

    final List<String> contigs = new ArrayList<String>(3);
    contigs.add("one");
    contigs.add("two");
    contigs.add("one");

    new VariantContextComparator(contigs);
  }
View Full Code Here

TOP

Related Classes of htsjdk.variant.variantcontext.VariantContextComparator

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.