Search in sources :

Example 1 with CreateSequenceDictionary

use of picard.sam.CreateSequenceDictionary 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

SAMFileHeader (htsjdk.samtools.SAMFileHeader)1 SAMFileWriter (htsjdk.samtools.SAMFileWriter)1 SAMFileWriterFactory (htsjdk.samtools.SAMFileWriterFactory)1 SAMSequenceDictionary (htsjdk.samtools.SAMSequenceDictionary)1 ReferenceSequenceFile (htsjdk.samtools.reference.ReferenceSequenceFile)1 File (java.io.File)1 IOException (java.io.IOException)1 ExecutionException (java.util.concurrent.ExecutionException)1 ConfigurationException (org.apache.commons.configuration.ConfigurationException)1 CreateSequenceDictionary (picard.sam.CreateSequenceDictionary)1