Package htsjdk.variant.variantcontext

Examples of htsjdk.variant.variantcontext.VariantContext


            int count = 0, nRecordsAtPos = 1;
            String prevName = "";
            Iterator<VariantContext> it = reader.iterator();
            while ( it.hasNext() ) {
                VariantContext vc = it.next();
                String name = vc.getChr() + ":" + vc.getStart();
                if ( name.equals(prevName) ) {
                    name += "_" + ++nRecordsAtPos;
                } else {
                    prevName = name;
                }
                DiffNode vcRoot = DiffNode.empty(name, root);

                // add fields
                vcRoot.add("CHROM", vc.getChr());
                vcRoot.add("POS", vc.getStart());
                vcRoot.add("ID", vc.getID());
                vcRoot.add("REF", vc.getReference());
                vcRoot.add("ALT", vc.getAlternateAlleles());
                vcRoot.add("QUAL", vc.hasLog10PError() ? vc.getLog10PError() * -10 : VCFConstants.MISSING_VALUE_v4);
                vcRoot.add("FILTER", ! vc.filtersWereApplied() // needs null to differentiate between PASS and .
                        ? VCFConstants.MISSING_VALUE_v4
                        : ( vc.getFilters().isEmpty() ? VCFConstants.PASSES_FILTERS_v4 : vc.getFilters()) );

                // add info fields
                for (Map.Entry<String, Object> attribute : vc.getAttributes().entrySet()) {
                    if ( ! attribute.getKey().startsWith("_") )
                        vcRoot.add(attribute.getKey(), attribute.getValue());
                }

                for (Genotype g : vc.getGenotypes() ) {
                    DiffNode gRoot = DiffNode.empty(g.getSampleName(), vcRoot);
                    gRoot.add("GT", g.getGenotypeString());
                    if ( g.hasGQ() ) gRoot.add("GQ", g.getGQ() );
                    if ( g.hasDP() ) gRoot.add("DP", g.getDP() );
                    if ( g.hasAD() ) gRoot.add("AD", Utils.join(",", g.getAD()));
View Full Code Here


        Assert.assertEquals(header.getGenotypeSamples().size(), 1, "Wrong number of samples in output vcf header");
        Assert.assertEquals(header.getGenotypeSamples().get(0), newSampleName, "Wrong sample name in output vcf header");

        int recordCount = 0;
        while ( iter.hasNext() && recordCount < 10 ) {
            final VariantContext vcfRecord = iter.next();
            Assert.assertEquals(vcfRecord.getSampleNames().size(), 1, "Wrong number of samples in output vcf record");
            Assert.assertEquals(vcfRecord.getSampleNames().iterator().next(), newSampleName, "Wrong sample name in output vcf record");
            recordCount++;
        }
    }
View Full Code Here

                Iterator<VariantContext> it = reader.iterator();
                if(!it.hasNext()){
                    System.err.println(String.format("File %s is empty. This file will be ignored",file.getAbsolutePath()));
                    continue;
                }
                VariantContext vc = it.next();
                int firstPosition = vc.getStart();
                reader.close();
                priorityQueue.add(new Pair<>(firstPosition,file));
            }

        }

        FileOutputStream outputStream = new FileOutputStream(outputFile);
        EnumSet<Options> options = EnumSet.of(Options.INDEX_ON_THE_FLY);
        final IndexCreator idxCreator = GATKVCFUtils.getIndexCreator(variant_index_type, variant_index_parameter, outputFile, ref.getSequenceDictionary());
        final VariantContextWriter outputWriter = VariantContextWriterFactory.create(outputFile, outputStream, ref.getSequenceDictionary(), idxCreator, options);

        boolean firstFile = true;
        int count = 0;
        while(!priorityQueue.isEmpty() ){
            count++;
            File file = priorityQueue.remove().getSecond();
            if (!file.exists()) {
                throw new UserException(String.format("File %s doesn't exist",file.getAbsolutePath()));
            }
            FeatureReader<VariantContext> reader = getFeatureReader(fileType, file);

            if(count%10 ==0)
                System.out.print(count);
            else
                System.out.print(".");
            if (firstFile){
                VCFHeader header = (VCFHeader)reader.getHeader();
                outputWriter.writeHeader(header);
                firstFile = false;
            }

            Iterator<VariantContext> it = reader.iterator();

            while (it.hasNext()){
                VariantContext vc = it.next();
                outputWriter.add(vc);
            }

            reader.close();
View Full Code Here

                            if ( rightNotClump != -1 ) allVCS.add(GATKVariantContextUtils.makeFromAlleles(NAME, CHR, rightNotClump, SNP_ALLELES));

                            int clumpStart = 50;
                            final List<VariantContext> vcs = new LinkedList<VariantContext>();
                            for ( final List<String> myAlleles : alleles ) {
                                final VariantContext vc = GATKVariantContextUtils.makeFromAlleles(NAME, CHR, clumpStart, myAlleles);
                                clumpStart = vc.getEnd() + 3;
                                vcs.add(vc);
                            }

                            tests.add(new Object[]{new EventMap(new LinkedList<VariantContext>(allVCS)), Collections.emptyList()});
                            allVCS.addAll(vcs);
View Full Code Here

    /**
     * Example testng test using MyDataProvider
     */
    @Test(dataProvider = "MyDataProvider", enabled = true)
    public void testGetNeighborhood(final EventMap eventMap, final List<VariantContext> expectedNeighbors) {
        final VariantContext leftOfNeighors = expectedNeighbors.isEmpty() ? null : expectedNeighbors.get(0);

        for ( final VariantContext vc : eventMap.getVariantContexts() ) {
            final List<VariantContext> n = eventMap.getNeighborhood(vc, 5);
            if ( leftOfNeighors == vc )
                Assert.assertEquals(n, expectedNeighbors);
View Full Code Here

        final Haplotype hap = new Haplotype(haplotypeBases.getBytes(), false, 0, TextCigarCodec.getSingleton().decode(cigar));
        final GenomeLoc loc = new UnvalidatingGenomeLoc(CHR, 0, 1, refBases.length());
        final EventMap ee = new EventMap(hap, refBases.getBytes(), loc, NAME);
        ee.replaceClumpedEventsWithBlockSubstitutions();
        Assert.assertEquals(ee.getNumberOfEvents(), 1);
        final VariantContext actual = ee.getVariantContexts().iterator().next();
        Assert.assertTrue(GATKVariantContextUtils.equalSites(actual, expectedBlock), "Failed with " + actual);
    }
View Full Code Here

        final EventMap ee = new EventMap(hap, refBases.getBytes(), loc, NAME);
        ee.replaceClumpedEventsWithBlockSubstitutions();
        Assert.assertEquals(ee.getNumberOfEvents(), expectedAlleles.size());
        final List<VariantContext> actuals = new ArrayList<VariantContext>(ee.getVariantContexts());
        for ( int i = 0; i < ee.getNumberOfEvents(); i++ ) {
            final VariantContext actual = actuals.get(i);
            Assert.assertEquals(actual.getReference().getDisplayString(), expectedAlleles.get(i).get(0));
            Assert.assertEquals(actual.getAlternateAllele(0).getDisplayString(), expectedAlleles.get(i).get(1));
        }
    }
View Full Code Here

    /**
     * Example testng test using MyDataProvider
     */
    @Test(dataProvider = "MakeBlockData", enabled = true)
    public void testGetNeighborhood(final List<String> firstAlleles, final List<String> secondAlleles, final List<String> expectedAlleles) {
        final VariantContext vc1 = GATKVariantContextUtils.makeFromAlleles("x", "20", 10, firstAlleles);
        final VariantContext vc2 = GATKVariantContextUtils.makeFromAlleles("x", "20", 10, secondAlleles);
        final VariantContext expected = GATKVariantContextUtils.makeFromAlleles("x", "20", 10, expectedAlleles);

        final EventMap eventMap = new EventMap(Collections.<VariantContext>emptyList());
        final VariantContext block = eventMap.makeBlock(vc1, vc2);

        Assert.assertEquals(block.getStart(), expected.getStart());
        Assert.assertEquals(block.getAlleles(), expected.getAlleles());
    }
View Full Code Here

     * Test code that creates VariantContexts
     */
    @Test()
    public void testWithVariantContext() throws Exception {
        final List<Allele> alleles = Arrays.asList(Allele.create("A", true), Allele.create("C"));
        final VariantContext vc = new VariantContextBuilder("test", "1", 10, 10, alleles).make();
        Assert.assertTrue(vc.getAlleles().size() >= 0);
        // TODO -- add some tests that use VariantContext
    }
View Full Code Here

        final Allele h1refAllele = Allele.create(ref, true);
        final Allele h1altAllele = Allele.create(alt, false);
        final ArrayList<Allele> alleles = new ArrayList<Allele>();
        alleles.add(h1refAllele);
        alleles.add(h1altAllele);
        final VariantContext vc = new VariantContextBuilder().alleles(alleles).loc("1", loc, loc + h1refAllele.getBases().length - 1).make();
        h.setAlignmentStartHapwrtRef(0);
        h.setCigar(cigar);
        final Haplotype h1 = h.insertAllele(vc.getReference(), vc.getAlternateAllele(0), loc, vc.getStart());
        final Haplotype h1expected = new Haplotype(newHap.getBytes());
        Assert.assertEquals(h1, h1expected);
    }
View Full Code Here

TOP

Related Classes of htsjdk.variant.variantcontext.VariantContext

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.