Search in sources :

Example 1 with SAMFileGATKReadWriter

use of org.broadinstitute.hellbender.utils.read.SAMFileGATKReadWriter in project gatk by broadinstitute.

the class SplitReads method createWriters.

/**
     * Creates SAMFileWriter instances for the reader splitters based on the input file.
     * @param splitters Reader splitters.
     * @return A map of file name keys to SAMFileWriter.
     */
private Map<String, SAMFileGATKReadWriter> createWriters(final List<ReaderSplitter<?>> splitters) {
    final Map<String, SAMFileGATKReadWriter> outs = new LinkedHashMap<>();
    final SAMFileWriterFactory samFileWriterFactory = new SAMFileWriterFactory();
    final SAMFileHeader samFileHeaderIn = getHeaderForReads();
    // Build up a list of key options at each level.
    final List<List<?>> splitKeys = splitters.stream().map(splitter -> splitter.getSplitsBy(samFileHeaderIn)).collect(Collectors.toList());
    // For every combination of keys, add a SAMFileWriter.
    addKey(splitKeys, 0, "", key -> {
        outs.put(key, prepareSAMFileWriter(samFileWriterFactory, samFileHeaderIn, key));
    });
    return outs;
}
Also used : DocumentedFeature(org.broadinstitute.barclay.help.DocumentedFeature) LibraryNameSplitter(org.broadinstitute.hellbender.tools.readersplitters.LibraryNameSplitter) CommandLineProgramProperties(org.broadinstitute.barclay.argparser.CommandLineProgramProperties) IOUtil(htsjdk.samtools.util.IOUtil) Argument(org.broadinstitute.barclay.argparser.Argument) StandardArgumentDefinitions(org.broadinstitute.hellbender.cmdline.StandardArgumentDefinitions) SampleNameSplitter(org.broadinstitute.hellbender.tools.readersplitters.SampleNameSplitter) GATKRead(org.broadinstitute.hellbender.utils.read.GATKRead) SAMFileHeader(htsjdk.samtools.SAMFileHeader) GATKException(org.broadinstitute.hellbender.exceptions.GATKException) ArrayList(java.util.ArrayList) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map) ReadWalker(org.broadinstitute.hellbender.engine.ReadWalker) ReadProgramGroup(org.broadinstitute.hellbender.cmdline.programgroups.ReadProgramGroup) ReferenceContext(org.broadinstitute.hellbender.engine.ReferenceContext) FeatureContext(org.broadinstitute.hellbender.engine.FeatureContext) ReadGroupIdSplitter(org.broadinstitute.hellbender.tools.readersplitters.ReadGroupIdSplitter) SAMFileWriterFactory(htsjdk.samtools.SAMFileWriterFactory) ReaderSplitter(org.broadinstitute.hellbender.tools.readersplitters.ReaderSplitter) Collectors(java.util.stream.Collectors) File(java.io.File) Consumer(java.util.function.Consumer) List(java.util.List) UserException(org.broadinstitute.hellbender.exceptions.UserException) SAMFileGATKReadWriter(org.broadinstitute.hellbender.utils.read.SAMFileGATKReadWriter) FilenameUtils(org.apache.commons.io.FilenameUtils) SAMFileWriterFactory(htsjdk.samtools.SAMFileWriterFactory) SAMFileGATKReadWriter(org.broadinstitute.hellbender.utils.read.SAMFileGATKReadWriter) ArrayList(java.util.ArrayList) List(java.util.List) SAMFileHeader(htsjdk.samtools.SAMFileHeader) LinkedHashMap(java.util.LinkedHashMap)

Example 2 with SAMFileGATKReadWriter

use of org.broadinstitute.hellbender.utils.read.SAMFileGATKReadWriter in project gatk by broadinstitute.

the class ReadsDataSourceUnitTest method getFileWithAddedContig.

// Copy the reads in the inputFile to the output file, adding an extra contig to the sequence dictionary
// and a read referencing that contig
private File getFileWithAddedContig(final Path inputPath, final String extraContig, final String outputName, final String extension) {
    final File outputFile = BaseTest.createTempFile(outputName, extension);
    try (ReadsDataSource readsSource = new ReadsDataSource(inputPath)) {
        SAMFileHeader header = readsSource.getHeader();
        SAMSequenceRecord fakeSequenceRec = new SAMSequenceRecord(extraContig, 100);
        header.addSequence(fakeSequenceRec);
        try (final SAMFileGATKReadWriter gatkReadWriter = new SAMFileGATKReadWriter(ReadUtils.createCommonSAMWriter(outputFile, null, header, true, true, false))) {
            for (final GATKRead read : readsSource) {
                gatkReadWriter.addRead(read);
            }
            // use the contig name in the read name to make it easy to see where this read came from
            SAMRecord samRec = new SAMRecord(header);
            samRec.setReadName(extraContig + "_READ");
            samRec.setReferenceName(extraContig);
            samRec.setAlignmentStart(5);
            samRec.setReadBases(new byte[] { 'a', 'c', 'g', 't' });
            gatkReadWriter.addRead(new SAMRecordToGATKReadAdapter(samRec));
        }
    }
    return outputFile;
}
Also used : GATKRead(org.broadinstitute.hellbender.utils.read.GATKRead) SAMRecordToGATKReadAdapter(org.broadinstitute.hellbender.utils.read.SAMRecordToGATKReadAdapter) SAMFileGATKReadWriter(org.broadinstitute.hellbender.utils.read.SAMFileGATKReadWriter) File(java.io.File)

Aggregations

File (java.io.File)2 GATKRead (org.broadinstitute.hellbender.utils.read.GATKRead)2 SAMFileGATKReadWriter (org.broadinstitute.hellbender.utils.read.SAMFileGATKReadWriter)2 SAMFileHeader (htsjdk.samtools.SAMFileHeader)1 SAMFileWriterFactory (htsjdk.samtools.SAMFileWriterFactory)1 IOUtil (htsjdk.samtools.util.IOUtil)1 ArrayList (java.util.ArrayList)1 LinkedHashMap (java.util.LinkedHashMap)1 List (java.util.List)1 Map (java.util.Map)1 Consumer (java.util.function.Consumer)1 Collectors (java.util.stream.Collectors)1 FilenameUtils (org.apache.commons.io.FilenameUtils)1 Argument (org.broadinstitute.barclay.argparser.Argument)1 CommandLineProgramProperties (org.broadinstitute.barclay.argparser.CommandLineProgramProperties)1 DocumentedFeature (org.broadinstitute.barclay.help.DocumentedFeature)1 StandardArgumentDefinitions (org.broadinstitute.hellbender.cmdline.StandardArgumentDefinitions)1 ReadProgramGroup (org.broadinstitute.hellbender.cmdline.programgroups.ReadProgramGroup)1 FeatureContext (org.broadinstitute.hellbender.engine.FeatureContext)1 ReadWalker (org.broadinstitute.hellbender.engine.ReadWalker)1