当前位置: 首页>>代码示例>>Java>>正文


Java VCFFileReader.iterator方法代码示例

本文整理汇总了Java中htsjdk.variant.vcf.VCFFileReader.iterator方法的典型用法代码示例。如果您正苦于以下问题:Java VCFFileReader.iterator方法的具体用法?Java VCFFileReader.iterator怎么用?Java VCFFileReader.iterator使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在htsjdk.variant.vcf.VCFFileReader的用法示例。


在下文中一共展示了VCFFileReader.iterator方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: validateSortingResults

import htsjdk.variant.vcf.VCFFileReader; //导入方法依赖的package包/类
/**
 * Checks the ordering and total number of variant context entries in the specified output VCF file.
 * Does NOT check explicitly that the VC genomic positions match exactly those from the inputs. We assume this behavior from other tests.
 *
 * @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++;
    }
    iterator.close();
    Assert.assertEquals(variantContextCount, expectedVariantContextCount);
}
 
开发者ID:broadinstitute,项目名称:picard,代码行数:23,代码来源:SortVcfsTest.java

示例2: validateSnpAndIndelResults

import htsjdk.variant.vcf.VCFFileReader; //导入方法依赖的package包/类
/**
 * Make sure that the order of the output file is identical to the order
 * of the input files by iterating through the output, making sure that,
 * 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);
        last = outputContext;
    }
    iterator.close();

    // We should have polled everything off the indel (snp) queues
    Assert.assertEquals(indelContigPositions.size(), 0);
    Assert.assertEquals(snpContigPositions.size(), 0);
}
 
开发者ID:broadinstitute,项目名称:picard,代码行数:26,代码来源:AbstractVcfMergingClpTester.java

示例3: testJavaScript

import htsjdk.variant.vcf.VCFFileReader; //导入方法依赖的package包/类
@Test(dataProvider = "goodInputVcfs")
public void testJavaScript(final File input) throws Exception {
    final File out = VcfTestUtils.createTemporaryIndexedVcfFile("filterVcfTestJS.", ".vcf");
    final FilterVcf filterer = new FilterVcf();
    filterer.INPUT = input;
    filterer.OUTPUT = out;
    filterer.JAVASCRIPT_FILE = quickJavascriptFilter("variant.getStart()%5 != 0");

    final int retval = filterer.doWork();
    Assert.assertEquals(retval, 0);

    //count the number of reads
    final int expectedNumber = 4;
    int count = 0;
    VCFFileReader in = new VCFFileReader(filterer.OUTPUT, false);
    CloseableIterator<VariantContext> iter = in.iterator();
    while (iter.hasNext()) {
        final VariantContext ctx = iter.next();
        count += (ctx.isFiltered() ? 1 : 0);
    }
    iter.close();
    in.close();
    Assert.assertEquals(count, expectedNumber);
}
 
开发者ID:broadinstitute,项目名称:picard,代码行数:25,代码来源:TestFilterVcf.java

示例4: forEachVariantData

import htsjdk.variant.vcf.VCFFileReader; //导入方法依赖的package包/类
public Stream<VariantData> forEachVariantData(final String vcfFile) throws IOException
{
final File file = new File(vcfFile);
IOUtil.assertFileIsReadable(file);
final VCFFileReader r= new VCFFileReader(file, false);
final VCFHeader header = r.getFileHeader();
this.init(header);
final VcfTools vcfTools = new VcfTools(header);
final CloseableIterator<VariantContext> iter = r.iterator();
final Iterable<VariantContext> iterable = () -> iter;
return StreamSupport.stream(iterable.spliterator(),false).onClose(()->{
	CloserUtil.close(iter);
	CloserUtil.close(r);
	}).map(V->new VariantData(V){
		@Override public  VCFHeader getVcfHeader() {
			return header;
			}
		@Override public  VcfTools getVcfTools(){
			return vcfTools;
			}
	});
}
 
开发者ID:lindenb,项目名称:jvarkit,代码行数:23,代码来源:KnimeVariantHelper.java

示例5: stream

import htsjdk.variant.vcf.VCFFileReader; //导入方法依赖的package包/类
public Stream<VariantContext> stream()
{
close();
if(this.disposed) throw new IllegalStateException("buffer was disposed");
if(this.header==null) {
	throw new IllegalStateException("header was not set");	
	}
if(this.tmpFile==null) 
	{
	return this.buffer.stream();
	}
else
	{
	final VCFFileReader reader= new VCFFileReader(this.tmpFile,false);
	final CloseableIterator<VariantContext> iter = reader.iterator();
	return  StreamSupport.stream(new IterableAdapter<VariantContext>(iter).spliterator(), false).onClose(
			()->{CloserUtil.close(iter);CloserUtil.close(reader);}
			);
	}
}
 
开发者ID:lindenb,项目名称:jvarkit,代码行数:21,代码来源:VCFBuffer.java

示例6: testCountSitesForOneChunkedContig

import htsjdk.variant.vcf.VCFFileReader; //导入方法依赖的package包/类
public void testCountSitesForOneChunkedContig() throws IOException {

		String configFolder = "test-data/configs/hapmap-chr1";
		String inputFolder = "test-data/data/simulated-chip-1chr-imputation";

		// create workflow context
		WorkflowTestContext context = buildContext(inputFolder, "hapmap2");

		String out = context.getOutput("chunksDir");

		// create step instance
		FastQualityControlMock qcStats = new FastQualityControlMock(configFolder);

		// run and test
		assertTrue(run(context, qcStats));

		File[] files = new File(out).listFiles();
		Arrays.sort(files);

		// baseline from a earlier job execution
		int[] array = { 4588, 968, 3002, 5781, 5116, 4750, 5699, 5174, 6334, 3188, 5106, 5832, 5318 };
		int pos = 0;

		for (File file : files) {
			int count = 0;
			if (file.getName().endsWith(".gz")) {
				VCFFileReader vcfReader = new VCFFileReader(file, false);
				CloseableIterator<VariantContext> it = vcfReader.iterator();
				while (it.hasNext()) {
					it.next();
					count++;
				}
				assertEquals(array[pos], count);
				vcfReader.close();
				pos++;
			}

		}
		FileUtil.deleteDirectory(new File(out));
	}
 
开发者ID:genepi,项目名称:imputationserver,代码行数:41,代码来源:FastQualityControlTest.java

示例7: testCountSamplesInCreatedChunk

import htsjdk.variant.vcf.VCFFileReader; //导入方法依赖的package包/类
public void testCountSamplesInCreatedChunk() throws IOException {

		String configFolder = "test-data/configs/hapmap-chr1";
		String inputFolder = "test-data/data/simulated-chip-1chr-imputation";

		// create workflow context
		WorkflowTestContext context = buildContext(inputFolder, "hapmap2");

		// get output directory
		String out = context.getOutput("chunksDir");

		// create step instance
		FastQualityControlMock qcStats = new FastQualityControlMock(configFolder);

		// run and test
		assertTrue(run(context, qcStats));
		for (File file : new File(out).listFiles()) {
			if (file.getName().endsWith("chunk_1_80000001_100000000.vcf.gz")) {
				VCFFileReader vcfReader = new VCFFileReader(file, false);
				CloseableIterator<VariantContext> it = vcfReader.iterator();
				if (it.hasNext()) {
					VariantContext a = it.next();
					assertEquals(255, a.getNSamples());
				}
				vcfReader.close();
			}

		}

		FileUtil.deleteDirectory(new File(out));
	}
 
开发者ID:genepi,项目名称:imputationserver,代码行数:32,代码来源:FastQualityControlTest.java

示例8: vcfTester

import htsjdk.variant.vcf.VCFFileReader; //导入方法依赖的package包/类
public void vcfTester(String inVcf){
	// Credit: https://www.biostars.org/p/262943/
	VCFFileReader r=new VCFFileReader(new File(inVcf));
	CloseableIterator<VariantContext> t=r.iterator();
	while(t.hasNext()){
	    t.next();
	}
	t.close();
	r.close();
}
 
开发者ID:dariober,项目名称:ASCIIGenome,代码行数:11,代码来源:MakeTabixFileTest.java

示例9: doWork

import htsjdk.variant.vcf.VCFFileReader; //导入方法依赖的package包/类
@Override
protected int doWork() {
    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.getContig(), context.getStart());
    }

 CloserUtil.close(iterator);
 CloserUtil.close(reader);
    writer.close();

    return 0;
}
 
开发者ID:broadinstitute,项目名称:picard,代码行数:38,代码来源:VcfFormatConverter.java

示例10: getQueryIntervalsMap

import htsjdk.variant.vcf.VCFFileReader; //导入方法依赖的package包/类
private SortedMap<QueryInterval, List<Allele>> getQueryIntervalsMap(final File vcf) {

        final Map<String, Integer> contigIndexMap = new HashMap<>();
        final VCFFileReader vcfReader = new VCFFileReader(vcf, false);

        // We want to look at unfiltered SNP sites for which the sample is genotyped as a het
        // with high quality.
        final CompoundFilter compoundFilter = new CompoundFilter(true);
        compoundFilter.add(new SnpFilter());
        compoundFilter.add(new PassingVariantFilter());
        compoundFilter.add(new GenotypeQualityFilter(MINIMUM_GQ, SAMPLE));
        compoundFilter.add(new HeterozygosityFilter(true, SAMPLE));

        final Iterator<VariantContext> hetIterator = new FilteringVariantContextIterator(vcfReader.iterator(), compoundFilter);

        for (final VCFContigHeaderLine vcfContig : vcfReader.getFileHeader().getContigLines()) {
            contigIndexMap.put(vcfContig.getID(), vcfContig.getContigIndex());
        }

        // return a TreeMap since the keys are comparable, and this will use their order in the iteration
        final SortedMap<QueryInterval, List<Allele>> map = new TreeMap<>();

        while (hetIterator.hasNext()) {
            final VariantContext vc = hetIterator.next();
            map.put(new QueryInterval(contigIndexMap.get(vc.getContig()), vc.getStart(), vc.getEnd()), vc.getGenotype(SAMPLE).getAlleles());
        }

        vcfReader.close();

        return map;
    }
 
开发者ID:broadinstitute,项目名称:picard,代码行数:32,代码来源:CollectIndependentReplicateMetrics.java

示例11: loadContigPositions

import htsjdk.variant.vcf.VCFFileReader; //导入方法依赖的package包/类
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;
}
 
开发者ID:broadinstitute,项目名称:picard,代码行数:10,代码来源:AbstractVcfMergingClpTester.java

示例12: testHaplotypeMapWriteToVcf

import htsjdk.variant.vcf.VCFFileReader; //导入方法依赖的package包/类
@Test(dataProvider = "haplotypeMapForWriting")
public void testHaplotypeMapWriteToVcf(final HaplotypeMap haplotypeMap) throws Exception {
    final File temp = File.createTempFile("haplotypeMap", ".vcf");
    temp.deleteOnExit();
    haplotypeMap.writeAsVcf(temp, TEST_FASTA);

    final VCFFileReader reader = new VCFFileReader(temp);

    Assert.assertEquals(reader.getFileHeader().getNGenotypeSamples(), 1, "VCF should have exactly one sample");
    Assert.assertEquals(reader.getFileHeader().getSampleNamesInOrder().get(0), HaplotypeMap.HET_GENOTYPE_FOR_PHASING, "VCF sole sample should be " + HaplotypeMap.HET_GENOTYPE_FOR_PHASING);

    final Iterator<VariantContext> iter = reader.iterator();
    final VariantContext first = iter.next();
    Assert.assertEquals(first.getContig(), "chr1", "Wrong chromosome on first snp: " + first);
    Assert.assertEquals(first.getID(), "snp1", "Wrong name on first snp: " + first);
    Assert.assertEquals(first.getGenotype(0).getExtendedAttribute(VCFConstants.PHASE_SET_KEY), Integer.toString(first.getStart()), "anchor snp should have PS equal to its position " + first);
    Assert.assertEquals(first.getAttributeAsDouble(VCFConstants.ALLELE_FREQUENCY_KEY, 0D), 1 - 0.15); // because it's swapped w.r.t the reference

    final VariantContext second = iter.next();
    Assert.assertEquals(second.getContig(), "chr1", "Wrong chromosome on second snp: " + second);
    Assert.assertEquals(second.getID(), "snp2", "Wrong name on second snp: " + second);
    Assert.assertEquals(second.getGenotype(0).getExtendedAttribute(VCFConstants.PHASE_SET_KEY), Integer.toString(first.getStart()), "Phase set is incorrect on second snp: " + second);
    Assert.assertEquals(second.getAttributeAsDouble(VCFConstants.ALLELE_FREQUENCY_KEY, 0D), 0.16);

    final VariantContext third = iter.next();
    Assert.assertEquals(third.getContig(), "chr2", "Wrong chromosome on third snp: " + third);
    Assert.assertEquals(third.getID(), "snp3", "Wrong name on third snp: " + third);
    Assert.assertFalse (third.getGenotype(0).hasAnyAttribute(VCFConstants.PHASE_SET_KEY), "Third snp should not have a phaseset" + third);
    Assert.assertEquals(third.getAttributeAsDouble(VCFConstants.ALLELE_FREQUENCY_KEY, 0D), 0.2);
}
 
开发者ID:broadinstitute,项目名称:picard,代码行数:31,代码来源:HaplotypeMapTest.java

示例13: testChangingInfoFields

import htsjdk.variant.vcf.VCFFileReader; //导入方法依赖的package包/类
@Test
public void testChangingInfoFields() {
    final String filename = "testLiftoverFailingVariants.vcf";
    final File liftOutputFile = new File(OUTPUT_DATA_PATH, "lift-delete-me.vcf");
    final File rejectOutputFile = new File(OUTPUT_DATA_PATH, "reject-delete-me.vcf");
    final File input = new File(TEST_DATA_PATH, filename);

    liftOutputFile.deleteOnExit();
    rejectOutputFile.deleteOnExit();

    final String[] args = new String[]{
            "INPUT=" + input.getAbsolutePath(),
            "OUTPUT=" + liftOutputFile.getAbsolutePath(),
            "REJECT=" + rejectOutputFile.getAbsolutePath(),
            "CHAIN=" + CHAIN_FILE,
            "REFERENCE_SEQUENCE=" + REFERENCE_FILE,
            "CREATE_INDEX=false"
    };
    Assert.assertEquals(runPicardCommandLine(args), 0);

    final VCFFileReader liftReader = new VCFFileReader(liftOutputFile, false);
    final CloseableIterator<VariantContext> iterator = liftReader.iterator();
    while (iterator.hasNext()) {
        final VariantContext vc = iterator.next();
        Assert.assertTrue(vc.hasAttribute("AF"));

        Assert.assertEquals(vc.hasAttribute(LiftoverUtils.SWAPPED_ALLELES), vc.hasAttribute("FLIPPED_AF"), vc.toString());
        Assert.assertEquals(!vc.hasAttribute(LiftoverUtils.SWAPPED_ALLELES), vc.hasAttribute("MAX_AF") && vc.getAttribute("MAX_AF") != null, vc.toString());

        if (vc.hasAttribute(LiftoverUtils.SWAPPED_ALLELES)) {
            final double af = vc.getAttributeAsDouble("AF", -1.0);
            final double flippedAf = vc.getAttributeAsDouble("FLIPPED_AF", -2.0);

            Assert.assertTrue(TestNGUtil.compareDoubleWithAccuracy(af, flippedAf, 0.01),
                    "Error while comparing AF. expected " + flippedAf + " but found " + af);

        }
    }
}
 
开发者ID:broadinstitute,项目名称:picard,代码行数:40,代码来源:LiftoverVcfTest.java

示例14: countEntries

import htsjdk.variant.vcf.VCFFileReader; //导入方法依赖的package包/类
@Test
public void countEntries() throws Exception {
    VCFFileReader vcfFileReader =
        new VCFFileReader(new File("src/test/resources/" + filename), false);
    Iterator<VariantContext> variantIterator;
    if (interval == null) {
        variantIterator = vcfFileReader.iterator();
    } else {
        variantIterator = vcfFileReader.query(interval.getContig(),
            interval.getStart(), interval.getEnd());
    }
    int expectedCount = Iterators.size(variantIterator);

    int counter = 0;
    for (RecordReader<LongWritable, VariantContextWritable> reader : readers) {
        while (reader.nextKeyValue()) {
            writable = reader.getCurrentValue();
            assertNotNull(writable);
            VariantContext vc = writable.get();
            assertNotNull(vc);
            String value = vc.toString();
            assertNotNull(value);
            counter++;
        }
    }
    assertEquals(expectedCount, counter);
}
 
开发者ID:HadoopGenomics,项目名称:Hadoop-BAM,代码行数:28,代码来源:TestVCFInputFormat.java

示例15: loadVcf

import htsjdk.variant.vcf.VCFFileReader; //导入方法依赖的package包/类
/** Private helper method to read through the VCF and create one or more bit sets. */
private static void loadVcf(final File dbSnpFile,
                            final SAMSequenceDictionary sequenceDictionary,
                            final Map<DbSnpBitSetUtil, Set<DbSnpVariantType>> bitSetsToVariantTypes) {

    final VCFFileReader variantReader = new VCFFileReader(dbSnpFile);
    final CloseableIterator<VariantContext> variantIterator = variantReader.iterator();

    while (variantIterator.hasNext()) {
        final VariantContext kv = variantIterator.next();

        for (final Map.Entry<DbSnpBitSetUtil, Set<DbSnpVariantType>> tuple : bitSetsToVariantTypes.entrySet()) {
            final DbSnpBitSetUtil bitset            = tuple.getKey();
            final Set<DbSnpVariantType> variantsToMatch  = tuple.getValue();

            BitSet bits = bitset.sequenceToBitSet.get(kv.getContig());
            if (bits == null) {
                final int nBits;
                if (sequenceDictionary == null) nBits = kv.getEnd() + 1;
                else nBits = sequenceDictionary.getSequence(kv.getContig()).getSequenceLength() + 1;
                bits = new BitSet(nBits);
                bitset.sequenceToBitSet.put(kv.getContig(), bits);
            }
            if (variantsToMatch.isEmpty() ||
                    (kv.isSNP() && variantsToMatch.contains(DbSnpVariantType.SNP)) ||
                    (kv.isIndel() && variantsToMatch.contains(DbSnpVariantType.insertion)) ||
                    (kv.isIndel() && variantsToMatch.contains(DbSnpVariantType.deletion))) {

                for (int i = kv.getStart(); i <= kv.getEnd(); i++)  bits.set(i, true);
            }
        }
    }

    CloserUtil.close(variantIterator);
    CloserUtil.close(variantReader);
}
 
开发者ID:broadinstitute,项目名称:gatk,代码行数:37,代码来源:DbSnpBitSetUtil.java


注:本文中的htsjdk.variant.vcf.VCFFileReader.iterator方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。