Search in sources :

Example 16 with ReferenceSequenceFile

use of htsjdk.samtools.reference.ReferenceSequenceFile in project gatk by broadinstitute.

the class HaplotypeCaller method onTraversalStart.

@Override
public void onTraversalStart() {
    final ReferenceSequenceFile referenceReader = getReferenceReader(referenceArguments);
    hcEngine = new HaplotypeCallerEngine(hcArgs, getHeaderForReads(), referenceReader);
    // The HC engine will make the right kind (VCF or GVCF) of writer for us
    final SAMSequenceDictionary sequenceDictionary = getHeaderForReads().getSequenceDictionary();
    vcfWriter = hcEngine.makeVCFWriter(outputVCF, sequenceDictionary);
    hcEngine.writeHeader(vcfWriter, sequenceDictionary, getDefaultToolVCFHeaderLines());
}
Also used : ReferenceSequenceFile(htsjdk.samtools.reference.ReferenceSequenceFile) SAMSequenceDictionary(htsjdk.samtools.SAMSequenceDictionary)

Example 17 with ReferenceSequenceFile

use of htsjdk.samtools.reference.ReferenceSequenceFile in project gatk-protected by broadinstitute.

the class HaplotypeCaller method onTraversalStart.

@Override
public void onTraversalStart() {
    final ReferenceSequenceFile referenceReader = getReferenceReader(referenceArguments);
    hcEngine = new HaplotypeCallerEngine(hcArgs, getHeaderForReads(), referenceReader);
    // The HC engine will make the right kind (VCF or GVCF) of writer for us
    final SAMSequenceDictionary sequenceDictionary = getHeaderForReads().getSequenceDictionary();
    vcfWriter = hcEngine.makeVCFWriter(outputVCF, sequenceDictionary);
    hcEngine.writeHeader(vcfWriter, sequenceDictionary, getDefaultToolVCFHeaderLines());
}
Also used : ReferenceSequenceFile(htsjdk.samtools.reference.ReferenceSequenceFile) SAMSequenceDictionary(htsjdk.samtools.SAMSequenceDictionary)

Example 18 with ReferenceSequenceFile

use of htsjdk.samtools.reference.ReferenceSequenceFile in project gridss by PapenfussLab.

the class GenomicProcessingContext method ensureSeqeunceDictionary.

/**
 * Ensures that a sequence dictionary exists for the given reference
 * @param referenceFile reference genome fasta
 */
protected void ensureSeqeunceDictionary(File referenceFile) {
    try {
        ReferenceSequenceFile rsf = new FastaSequenceFile(referenceFile, false);
        Path path = referenceFile.toPath().toAbsolutePath();
        if (rsf.getSequenceDictionary() == null) {
            log.info("Attempting to create sequence dictionary for " + referenceFile);
            Path dictPath = path.resolveSibling(path.getFileName().toString() + htsjdk.samtools.util.IOUtil.DICT_FILE_EXTENSION);
            picard.sam.CreateSequenceDictionary csd = new picard.sam.CreateSequenceDictionary();
            if (program != null) {
                CommandLineProgramHelper.copyInputs(program, csd);
            }
            csd.instanceMain(new String[] { "OUTPUT=" + dictPath.toFile(), "REFERENCE_SEQUENCE=" + referenceFile.getAbsolutePath() });
        }
        rsf.close();
    } catch (Exception e) {
        log.error("Sequence dictionary creation failed. Please create using picard CreateSequenceDictionary.", e);
    }
}
Also used : Path(java.nio.file.Path) FastaSequenceFile(htsjdk.samtools.reference.FastaSequenceFile) IndexedFastaSequenceFile(htsjdk.samtools.reference.IndexedFastaSequenceFile) ReferenceSequenceFile(htsjdk.samtools.reference.ReferenceSequenceFile) TwoBitBufferedReferenceSequenceFile(au.edu.wehi.idsv.picard.TwoBitBufferedReferenceSequenceFile) IOException(java.io.IOException) FileNotFoundException(java.io.FileNotFoundException)

Example 19 with ReferenceSequenceFile

use of htsjdk.samtools.reference.ReferenceSequenceFile in project gridss by PapenfussLab.

the class MultipleSamFileCommandLineProgram method ensureIndexed.

public static void ensureIndexed(File fa) throws IOException {
    try (ReferenceSequenceFile reference = ReferenceSequenceFileFactory.getReferenceSequenceFile(fa)) {
        if (!reference.isIndexed()) {
            String msg = String.format("Unable to find index for %1$s. Please run 'samtools faidx %1$s' or picard tools BuildBamIndex to generate an index file.", fa);
            log.error(msg);
            throw new IOException(msg);
        } else {
            log.debug(fa, " is indexed.");
        }
    }
}
Also used : ReferenceSequenceFile(htsjdk.samtools.reference.ReferenceSequenceFile) IOException(java.io.IOException)

Example 20 with ReferenceSequenceFile

use of htsjdk.samtools.reference.ReferenceSequenceFile in project gridss by PapenfussLab.

the class MultipleSamFileCommandLineProgram method ensureSequenceDictionary.

public static void ensureSequenceDictionary(File fa) throws IOException {
    File output = new File(fa.getAbsolutePath() + ".dict");
    try (ReferenceSequenceFile reference = ReferenceSequenceFileFactory.getReferenceSequenceFile(fa)) {
        SAMSequenceDictionary dictionary = reference.getSequenceDictionary();
        if (dictionary == null) {
            log.info("Attempting to generate missing sequence dictionary for ", fa);
            try {
                final SAMSequenceDictionary sequences = new CreateSequenceDictionary().makeSequenceDictionary(fa);
                final SAMFileHeader samHeader = new SAMFileHeader();
                samHeader.setSequenceDictionary(sequences);
                try (SAMFileWriter samWriter = new SAMFileWriterFactory().makeSAMWriter(samHeader, false, output)) {
                }
            } catch (Exception e) {
                log.error("Missing sequence dictionary for ", fa, " and creation of sequencing dictionary failed.", "Please run the Picard tools CreateSequenceDictionary utility to create", output);
                throw e;
            }
            log.info("Created sequence dictionary ", output);
        } else {
            log.debug("Found sequence dictionary for ", fa);
        }
    }
}
Also used : CreateSequenceDictionary(picard.sam.CreateSequenceDictionary) SAMFileWriter(htsjdk.samtools.SAMFileWriter) SAMFileWriterFactory(htsjdk.samtools.SAMFileWriterFactory) ReferenceSequenceFile(htsjdk.samtools.reference.ReferenceSequenceFile) SAMFileHeader(htsjdk.samtools.SAMFileHeader) ReferenceSequenceFile(htsjdk.samtools.reference.ReferenceSequenceFile) File(java.io.File) SAMSequenceDictionary(htsjdk.samtools.SAMSequenceDictionary) IOException(java.io.IOException) ExecutionException(java.util.concurrent.ExecutionException) ConfigurationException(org.apache.commons.configuration.ConfigurationException)

Aggregations

ReferenceSequenceFile (htsjdk.samtools.reference.ReferenceSequenceFile)20 File (java.io.File)9 SAMFileHeader (htsjdk.samtools.SAMFileHeader)5 SAMFileWriter (htsjdk.samtools.SAMFileWriter)5 SAMSequenceDictionary (htsjdk.samtools.SAMSequenceDictionary)5 ReferenceSequence (htsjdk.samtools.reference.ReferenceSequence)5 FileNotFoundException (java.io.FileNotFoundException)5 IOException (java.io.IOException)4 UserException (org.broadinstitute.hellbender.exceptions.UserException)4 CachingIndexedFastaSequenceFile (org.broadinstitute.hellbender.utils.fasta.CachingIndexedFastaSequenceFile)4 SamReader (htsjdk.samtools.SamReader)3 SimpleInterval (org.broadinstitute.hellbender.utils.SimpleInterval)3 SAMFileWriterFactory (htsjdk.samtools.SAMFileWriterFactory)2 SAMRecord (htsjdk.samtools.SAMRecord)2 IndexedFastaSequenceFile (htsjdk.samtools.reference.IndexedFastaSequenceFile)2 Haplotype (org.broadinstitute.hellbender.utils.haplotype.Haplotype)2 GATKRead (org.broadinstitute.hellbender.utils.read.GATKRead)2 ReferenceBases (org.broadinstitute.hellbender.utils.reference.ReferenceBases)2 BeforeClass (org.testng.annotations.BeforeClass)2 TwoBitBufferedReferenceSequenceFile (au.edu.wehi.idsv.picard.TwoBitBufferedReferenceSequenceFile)1