Search in sources :

Example 1 with VCFCodec

use of htsjdk.variant.vcf.VCFCodec in project gatk by broadinstitute.

the class GenomicsDBImport method getReaderFromVCFUri.

/**
     * Creates a feature reader object from a given VCF URI (can also be
     * a local file path) and returns it
     * @param variantPath  URI or file path
     * @return  Feature reader
     */
private AbstractFeatureReader<VariantContext, LineIterator> getReaderFromVCFUri(final String variantPath) {
    final String variantURI = IOUtils.getPath(variantPath).toAbsolutePath().toUri().toString();
    final Function<SeekableByteChannel, SeekableByteChannel> cloudWrapper = (cloudPrefetchBuffer > 0 ? is -> SeekableByteChannelPrefetcher.addPrefetcher(cloudPrefetchBuffer, is) : Function.identity());
    final Function<SeekableByteChannel, SeekableByteChannel> cloudIndexWrapper = (cloudIndexPrefetchBuffer > 0 ? is -> SeekableByteChannelPrefetcher.addPrefetcher(cloudIndexPrefetchBuffer, is) : Function.identity());
    return AbstractFeatureReader.getFeatureReader(variantURI, null, new VCFCodec(), true, cloudWrapper, cloudIndexWrapper);
}
Also used : VCFHeaderLine(htsjdk.variant.vcf.VCFHeaderLine) CommandLineProgramProperties(org.broadinstitute.barclay.argparser.CommandLineProgramProperties) java.util(java.util) LineIterator(htsjdk.tribble.readers.LineIterator) VCFHeader(htsjdk.variant.vcf.VCFHeader) Argument(org.broadinstitute.barclay.argparser.Argument) Advanced(org.broadinstitute.barclay.argparser.Advanced) FeatureReader(htsjdk.tribble.FeatureReader) StandardArgumentDefinitions(org.broadinstitute.hellbender.cmdline.StandardArgumentDefinitions) GATKException(org.broadinstitute.hellbender.exceptions.GATKException) Function(java.util.function.Function) VariantProgramGroup(org.broadinstitute.hellbender.cmdline.programgroups.VariantProgramGroup) AbstractFeatureReader(htsjdk.tribble.AbstractFeatureReader) GenomicsDBCallsetsMapProto(com.intel.genomicsdb.GenomicsDBCallsetsMapProto) VCFCodec(htsjdk.variant.vcf.VCFCodec) Path(java.nio.file.Path) GenomicsDBImporter(com.intel.genomicsdb.GenomicsDBImporter) IOUtils(org.broadinstitute.hellbender.utils.io.IOUtils) Files(java.nio.file.Files) SAMSequenceDictionary(htsjdk.samtools.SAMSequenceDictionary) IOException(java.io.IOException) GenomicsDBImportConfiguration(com.intel.genomicsdb.GenomicsDBImportConfiguration) SimpleInterval(org.broadinstitute.hellbender.utils.SimpleInterval) File(java.io.File) FileNotFoundException(java.io.FileNotFoundException) GATKTool(org.broadinstitute.hellbender.engine.GATKTool) SeekableByteChannel(java.nio.channels.SeekableByteChannel) UserException(org.broadinstitute.hellbender.exceptions.UserException) SeekableByteChannelPrefetcher(org.broadinstitute.hellbender.utils.nio.SeekableByteChannelPrefetcher) VariantContext(htsjdk.variant.variantcontext.VariantContext) VCFUtils(htsjdk.variant.vcf.VCFUtils) Utils(org.broadinstitute.hellbender.utils.Utils) VisibleForTesting(com.google.common.annotations.VisibleForTesting) ChromosomeInterval(com.intel.genomicsdb.ChromosomeInterval) CommandLineException(org.broadinstitute.barclay.argparser.CommandLineException) SeekableByteChannel(java.nio.channels.SeekableByteChannel) VCFCodec(htsjdk.variant.vcf.VCFCodec)

Example 2 with VCFCodec

use of htsjdk.variant.vcf.VCFCodec in project gatk by broadinstitute.

the class GatherVcfs method getReaderFromVCFUri.

private static FeatureReader<VariantContext> getReaderFromVCFUri(final Path variantPath, final int cloudPrefetchBuffer) {
    final String variantURI = variantPath.toUri().toString();
    final Function<SeekableByteChannel, SeekableByteChannel> cloudWrapper = (cloudPrefetchBuffer > 0 ? is -> SeekableByteChannelPrefetcher.addPrefetcher(cloudPrefetchBuffer, is) : Function.identity());
    return AbstractFeatureReader.getFeatureReader(variantURI, null, new VCFCodec(), false, cloudWrapper, Function.identity());
}
Also used : CloseableIterator(htsjdk.samtools.util.CloseableIterator) CommandLineProgramProperties(org.broadinstitute.barclay.argparser.CommandLineProgramProperties) java.util(java.util) ProgressLogger(org.broadinstitute.hellbender.utils.runtime.ProgressLogger) IOUtil(htsjdk.samtools.util.IOUtil) VCFHeader(htsjdk.variant.vcf.VCFHeader) Argument(org.broadinstitute.barclay.argparser.Argument) FeatureReader(htsjdk.tribble.FeatureReader) VariantContextWriterBuilder(htsjdk.variant.variantcontext.writer.VariantContextWriterBuilder) StandardArgumentDefinitions(org.broadinstitute.hellbender.cmdline.StandardArgumentDefinitions) Function(java.util.function.Function) VariantProgramGroup(org.broadinstitute.hellbender.cmdline.programgroups.VariantProgramGroup) AbstractFeatureReader(htsjdk.tribble.AbstractFeatureReader) BlockCompressedOutputStream(htsjdk.samtools.util.BlockCompressedOutputStream) RuntimeIOException(htsjdk.samtools.util.RuntimeIOException) CollectionUtil(htsjdk.samtools.util.CollectionUtil) VCFCodec(htsjdk.variant.vcf.VCFCodec) PeekableIterator(htsjdk.samtools.util.PeekableIterator) PicardCommandLineProgram(org.broadinstitute.hellbender.cmdline.PicardCommandLineProgram) Path(java.nio.file.Path) CloserUtil(htsjdk.samtools.util.CloserUtil) BlockCompressedStreamConstants(htsjdk.samtools.util.BlockCompressedStreamConstants) IOUtils(org.broadinstitute.hellbender.utils.io.IOUtils) BlockCompressedInputStream(htsjdk.samtools.util.BlockCompressedInputStream) SAMSequenceDictionary(htsjdk.samtools.SAMSequenceDictionary) Collectors(java.util.stream.Collectors) VariantContextComparator(htsjdk.variant.variantcontext.VariantContextComparator) SeekableByteChannel(java.nio.channels.SeekableByteChannel) Logger(org.apache.logging.log4j.Logger) UserException(org.broadinstitute.hellbender.exceptions.UserException) java.io(java.io) Options(htsjdk.variant.variantcontext.writer.Options) VariantContextWriter(htsjdk.variant.variantcontext.writer.VariantContextWriter) SeekableByteChannelPrefetcher(org.broadinstitute.hellbender.utils.nio.SeekableByteChannelPrefetcher) VariantContext(htsjdk.variant.variantcontext.VariantContext) Utils(org.broadinstitute.hellbender.utils.Utils) VisibleForTesting(com.google.common.annotations.VisibleForTesting) LogManager(org.apache.logging.log4j.LogManager) SeekableByteChannel(java.nio.channels.SeekableByteChannel) VCFCodec(htsjdk.variant.vcf.VCFCodec)

Example 3 with VCFCodec

use of htsjdk.variant.vcf.VCFCodec in project hmftools by hartwigmedical.

the class SvVCFAnnotator method readFromVcf.

private List<VariantContext> readFromVcf(String vcfFilename) {
    List<VariantContext> variants = Lists.newArrayList();
    final StructuralVariantFactory factory = new StructuralVariantFactory(false);
    try (final AbstractFeatureReader<VariantContext, LineIterator> reader = AbstractFeatureReader.getFeatureReader(vcfFilename, new VCFCodec(), false)) {
        while (reader.iterator().hasNext()) variants.add(reader.iterator().next());
    } catch (Exception e) {
    }
    return variants;
}
Also used : VCFCodec(htsjdk.variant.vcf.VCFCodec) VariantContext(htsjdk.variant.variantcontext.VariantContext) StructuralVariantFactory(com.hartwig.hmftools.common.variant.structural.StructuralVariantFactory) LineIterator(htsjdk.tribble.readers.LineIterator) IOException(java.io.IOException)

Example 4 with VCFCodec

use of htsjdk.variant.vcf.VCFCodec in project hmftools by hartwigmedical.

the class BachelorApplication method processSV.

private static Collection<EligibilityReport> processSV(final String patient, final File vcf, final BachelorEligibility eligibility) {
    LOGGER.info("processing sv: {}", vcf.getPath());
    final StructuralVariantFactory factory = new StructuralVariantFactory(true);
    try {
        try (final AbstractFeatureReader<VariantContext, LineIterator> reader = AbstractFeatureReader.getFeatureReader(vcf.getPath(), new VCFCodec(), false)) {
            reader.iterator().forEach(factory::addVariantContext);
        }
    } catch (IOException e) {
        LOGGER.error("error with SV file {}: {}", vcf.getPath(), e.getMessage());
        return Collections.emptyList();
    }
    return eligibility.processStructuralVariants(patient, factory.results());
}
Also used : VCFCodec(htsjdk.variant.vcf.VCFCodec) VariantContext(htsjdk.variant.variantcontext.VariantContext) StructuralVariantFactory(com.hartwig.hmftools.common.variant.structural.StructuralVariantFactory) IOException(java.io.IOException) LineIterator(htsjdk.tribble.readers.LineIterator)

Example 5 with VCFCodec

use of htsjdk.variant.vcf.VCFCodec in project ASCIIGenome by dariober.

the class IntervalFeatureTest method canFormatVCFLine.

@Test
public void canFormatVCFLine() throws InvalidGenomicCoordsException, InvalidColourException, IOException, InvalidConfigException {
    List<Double> rulerMap = new ArrayList<Double>();
    for (int i = 1; i < 100; i++) {
        rulerMap.add((double) i);
    }
    // Prepare header
    VCFFileReader reader = new VCFFileReader(new File("test_data/CHD.exon.2010_03.sites.vcf.gz"));
    VCFHeader vcfHeader = reader.getFileHeader();
    reader.close();
    VCFCodec vcfCodec = new VCFCodec();
    vcfCodec.setVCFHeader(vcfHeader, Utils.getVCFHeaderVersion(vcfHeader));
    String vcfLine = "1 10 . C G 23 PASS AA=.;AC=.;AN=.DP=.".replaceAll(" ", "\t");
    IntervalFeature ift = new IntervalFeature(vcfLine, TrackFormat.VCF, vcfCodec);
    ift.mapToScreen(rulerMap);
    assertEquals(1, ift.getIdeogram(true, true).size());
    assertEquals('G', ift.getIdeogram(true, true).get(0).getText());
    // Just check there is a formatting char
    assertTrue(ift.getIdeogram(true, true).get(0).format(false).contains("["));
    // Deletion
    vcfLine = "1 10 . CTTG C 23 PASS AA=.;AC=.;AN=.DP=.".replaceAll(" ", "\t");
    ift = new IntervalFeature(vcfLine, TrackFormat.VCF, vcfCodec);
    ift.mapToScreen(rulerMap);
    assertEquals('D', ift.getIdeogram(true, true).get(0).getText());
    assertEquals(3, ift.getIdeogram(true, true).size());
    // Insertion
    vcfLine = "1 10 . C CTTG 23 PASS AA=.;AC=.;AN=.DP=.".replaceAll(" ", "\t");
    ift = new IntervalFeature(vcfLine, TrackFormat.VCF, vcfCodec);
    ift.mapToScreen(rulerMap);
    assertEquals("I", ift.getIdeogram(true, true).get(0).format(true));
    assertEquals(3, ift.getIdeogram(true, true).size());
    // Multiple alleles
    vcfLine = "1 10 . C CTTG,A 23 PASS AA=.;AC=.;AN=.DP=.".replaceAll(" ", "\t");
    ift = new IntervalFeature(vcfLine, TrackFormat.VCF, vcfCodec);
    ift.mapToScreen(rulerMap);
    assertEquals("|", ift.getIdeogram(true, true).get(0).format(true));
}
Also used : VCFCodec(htsjdk.variant.vcf.VCFCodec) ArrayList(java.util.ArrayList) VCFFileReader(htsjdk.variant.vcf.VCFFileReader) VCFHeader(htsjdk.variant.vcf.VCFHeader) File(java.io.File) Test(org.junit.Test)

Aggregations

VCFCodec (htsjdk.variant.vcf.VCFCodec)21 LineIterator (htsjdk.tribble.readers.LineIterator)12 VariantContext (htsjdk.variant.variantcontext.VariantContext)12 VCFHeader (htsjdk.variant.vcf.VCFHeader)11 File (java.io.File)11 IOException (java.io.IOException)8 ArrayList (java.util.ArrayList)6 VCFFileReader (htsjdk.variant.vcf.VCFFileReader)5 PositionalBufferedStream (htsjdk.tribble.readers.PositionalBufferedStream)4 SAMSequenceDictionary (htsjdk.samtools.SAMSequenceDictionary)3 Index (htsjdk.tribble.index.Index)3 VisibleForTesting (com.google.common.annotations.VisibleForTesting)2 StructuralVariantFactory (com.hartwig.hmftools.common.variant.structural.StructuralVariantFactory)2 GenomicsDBFeatureReader (com.intel.genomicsdb.GenomicsDBFeatureReader)2 BlockCompressedInputStream (htsjdk.samtools.util.BlockCompressedInputStream)2 BlockCompressedOutputStream (htsjdk.samtools.util.BlockCompressedOutputStream)2 CloseableIterator (htsjdk.samtools.util.CloseableIterator)2 AbstractFeatureReader (htsjdk.tribble.AbstractFeatureReader)2 FeatureReader (htsjdk.tribble.FeatureReader)2 BCF2Codec (htsjdk.variant.bcf2.BCF2Codec)2