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;
}
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;
}
Aggregations