Package htsjdk.variant.vcf

Examples of htsjdk.variant.vcf.VCFFileReader


    }

    /** Consumes a VCF and returns a ListMap where each they keys are the IDs of filtered out sites and the values are the set of filters. */
    ListMap<String,String> slurpFilters(final File vcf) {
        final ListMap<String,String> map = new ListMap<String, String>();
        final VCFFileReader in = new VCFFileReader(vcf, false);
        for (final VariantContext ctx : in) {
            if (ctx.isNotFiltered()) continue;
            for (final String filter : ctx.getFilters()) {
                map.add(ctx.getID(), filter);
            }
        }
        in.close();
        return map;
    }
View Full Code Here


        return 0;
    }

    private void collectFileReadersAndHeaders(final List<String> sampleList, SAMSequenceDictionary samSequenceDictionary) {
        for (final File input : INPUT) {
            final VCFFileReader in = new VCFFileReader(input, false);
            final VCFHeader header = in.getFileHeader();
            final SAMSequenceDictionary dict = in.getFileHeader().getSequenceDictionary();
            if (dict == null || dict.isEmpty()) {
                if (null == samSequenceDictionary) {
                    throw new IllegalArgumentException("Sequence dictionary was missing or empty for the VCF: " + input.getAbsolutePath() + " Please add a sequence dictionary to this VCF or specify SEQUENCE_DICTIONARY.");
                }
                header.setSequenceDictionary(samSequenceDictionary);
View Full Code Here

    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.");
        }
      }

      if (sequenceDictionary == null) sequenceDictionary = fileHeader.getSequenceDictionary();

      if (sampleList.isEmpty()) {
        sampleList.addAll(fileHeader.getSampleNamesInOrder());
      } else {
        if ( ! sampleList.equals(fileHeader.getSampleNamesInOrder())) {
          throw new IllegalArgumentException("Input file " + file.getAbsolutePath() + " has sample entries that don't match the other files.");
        }
      }

      headers.add(fileHeader);
      iteratorCollection.add(fileReader.iterator());
    }

    if (CREATE_INDEX && sequenceDictionary == null) {
      throw new PicardException("A sequence dictionary must be available (either through the input file or by setting it explicitly) when creating indexed output.");
    }
View Full Code Here

        final ProgressLogger progress = new ProgressLogger(LOG, 10000);
       
        IOUtil.assertFileIsReadable(INPUT);
        IOUtil.assertFileIsWritable(OUTPUT);

      final VCFFileReader reader = new VCFFileReader(INPUT, REQUIRE_INDEX);
      final VCFHeader header = new VCFHeader(reader.getFileHeader());
      final SAMSequenceDictionary sequenceDictionary = header.getSequenceDictionary();
      if (CREATE_INDEX && sequenceDictionary == null) {
        throw new PicardException("A sequence dictionary must be available in the input file when creating indexed output.");
      }

        final VariantContextWriterBuilder builder = new VariantContextWriterBuilder()
                .setOutputFile(OUTPUT)
                .setReferenceDictionary(sequenceDictionary);
        if (CREATE_INDEX)
            builder.setOption(Options.INDEX_ON_THE_FLY);
        else
            builder.unsetOption(Options.INDEX_ON_THE_FLY);
        final VariantContextWriter writer = builder.build();
        writer.writeHeader(header);
      final CloseableIterator<VariantContext> iterator = reader.iterator();

      while (iterator.hasNext()) {
        final VariantContext context = iterator.next();
            writer.add(context);
            progress.record(context.getChr(), context.getStart());
View Full Code Here

     * if the context is an indel (snp), the next genomic position in the indel
     * (snp) queue is the same. Also make sure that the context is in the order
     * specified by the input files.
     */
    private void validateSnpAndIndelResults(final File output, final Queue<String> indelContigPositions, final Queue<String> snpContigPositions) {
        final VCFFileReader outputReader = new VCFFileReader(output, false);
        final VariantContextComparator outputComparator = outputReader.getFileHeader().getVCFRecordComparator();
        VariantContext last = null;
        final CloseableIterator<VariantContext> iterator = outputReader.iterator();
        while (iterator.hasNext()) {
            final VariantContext outputContext = iterator.next();
            if (outputContext.isIndel()) Assert.assertEquals(getContigPosition(outputContext), indelContigPositions.poll());
            if (outputContext.isSNP()) Assert.assertEquals(getContigPosition(outputContext), snpContigPositions.poll());
            if (last != null) Assert.assertTrue(outputComparator.compare(last, outputContext) <= 0);
View Full Code Here

        runClp(inputs, output, indexing, 0);
        validateResultsForMultipleInputs(output, positionQueues);
  }

    private void validateResultsForMultipleInputs(final File output, final List<Queue<String>> positionQueues) {
        final VCFFileReader outputReader = new VCFFileReader(output, false);
        final VariantContextComparator outputComparator = outputReader.getFileHeader().getVCFRecordComparator();
        VariantContext last = null;
        final CloseableIterator<VariantContext> iterator = outputReader.iterator();
        while (iterator.hasNext()) {
            final VariantContext outputContext = iterator.next();
            final String position = getContigPosition(outputContext);
            for (final Queue<String> positionQueue : positionQueues) {
                if (position.equals(positionQueue.peek())) {
View Full Code Here

            Assert.assertEquals(positionQueue.size(), 0);
        }
    }

    static Queue<String> loadContigPositions(final File inputFile) {
    final VCFFileReader reader = new VCFFileReader(inputFile, false);
    final Queue<String> contigPositions = new LinkedList<String>();
    final CloseableIterator<VariantContext> iterator = reader.iterator();
    while (iterator.hasNext()) contigPositions.add(getContigPosition(iterator.next()));
    iterator.close();
    reader.close();
    return contigPositions;
  }
View Full Code Here

     *
     * @param output VCF file representing the output of SortVCF
     * @param expectedVariantContextCount the total number of variant context entries from all input files that were merged/sorted
     */
    private void validateSortingResults(final File output, final int expectedVariantContextCount) {
        final VCFFileReader outputReader = new VCFFileReader(output, false);
        final VariantContextComparator outputComparator = outputReader.getFileHeader().getVCFRecordComparator();
        VariantContext last = null;
        int variantContextCount = 0;
        final CloseableIterator<VariantContext> iterator = outputReader.iterator();
        while (iterator.hasNext()) {
            final VariantContext outputContext = iterator.next();
            if (last != null) Assert.assertTrue(outputComparator.compare(last, outputContext) <= 0);
            last = outputContext;
            variantContextCount++;
View Full Code Here

        Assert.assertEquals(runPicardCommandLine(args), 0);

    final Queue<String> indelContigPositions = AbstractVcfMergingClpTester.loadContigPositions(indelOutputFile);
    final Queue<String> snpContigPositions = AbstractVcfMergingClpTester.loadContigPositions(snpOutputFile);

    final VCFFileReader reader = new VCFFileReader(input);
        for (final VariantContext inputContext : reader) {
            if (inputContext.isIndel())
                Assert.assertEquals(AbstractVcfMergingClpTester.getContigPosition(inputContext), indelContigPositions.poll());
            if (inputContext.isSNP())
                Assert.assertEquals(AbstractVcfMergingClpTester.getContigPosition(inputContext), snpContigPositions.poll());
View Full Code Here

TOP

Related Classes of htsjdk.variant.vcf.VCFFileReader

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.