/** * Create a ReadDestination that writes to a BAM file */ public ToBAM(final GATKSAMFileWriter stingSAMWriter, final SAMFileHeader header, final String readGroupID) { super(header, readGroupID); if ( stingSAMWriter == null ) throw new IllegalArgumentException("writer cannot be null"); bamWriter = stingSAMWriter; stingSAMWriter.setPresorted(false); stingSAMWriter.writeHeader(getHeader()); }
private void emit(final SAMRecord read) { if ( writer != null ) writer.addAlignment(read); }
outputBam.setPresorted(presorted.contains(clippingRepresentation));
/** * Creates a program record for the program, adds it to the list of program records (@PG tags) in the bam file and sets * up the writer with the header and presorted status. * * @param writer BAM file writer * @param toolkit the engine * @param preSorted whether or not the writer can assume reads are going to be added are already sorted * @param walker the walker object (so we can extract the command line) * @param PROGRAM_RECORD_NAME the name for the PG tag */ public static void setupWriter(GATKSAMFileWriter writer, GenomeAnalysisEngine toolkit, SAMFileHeader originalHeader, boolean preSorted, Object walker, String PROGRAM_RECORD_NAME) { SAMFileHeader header = setupWriter(toolkit, originalHeader, walker, PROGRAM_RECORD_NAME); writer.writeHeader(header); writer.setPresorted(preSorted); }
public ClippingData reduce(ReadClipperWithData clipper, ClippingData data) { if ( clipper == null ) return data; GATKSAMRecord clippedRead = clipper.clipRead(clippingRepresentation); if (outputBam != null) { outputBam.addAlignment(clippedRead); } else { out.println(clippedRead.format()); } data.nTotalReads++; data.nTotalBases += clipper.getRead().getReadLength(); if (clipper.wasClipped()) { data.nClippedReads++; data.addData(clipper.getData()); } return data; }
private void setupWriter(SAMFileHeader header) { if ( !NO_PG_TAG ) { final SAMProgramRecord programRecord = createProgramRecord(); List<SAMProgramRecord> oldRecords = header.getProgramRecords(); List<SAMProgramRecord> newRecords = new ArrayList<SAMProgramRecord>(oldRecords.size()+1); for ( SAMProgramRecord record : oldRecords ) { if ( !record.getId().startsWith(PROGRAM_RECORD_NAME) || KEEP_ALL_PG_RECORDS ) newRecords.add(record); } newRecords.add(programRecord); header.setProgramRecords(newRecords); } writer.writeHeader(header); writer.setPresorted(true); }
/** * Creates and writes an artificial read given the appropriate data * * @param readBases the bases * @param contig the contig * @param start the read start * @param cigar the cigar string * @param sample the sample name (used to get the right read group) * @param isNegStrand should this read be on the negative strand? */ private void writeRead(final byte[] readBases, final String contig, final int start, final String cigar, final String sample, final boolean isNegStrand) { final GATKSAMRecord read = new GATKSAMRecord(header); read.setBaseQualities(readQuals); read.setReadBases(readBases); read.setReadName("" + readNameCounter++); read.setCigarString(cigar); read.setReadPairedFlag(false); read.setAlignmentStart(start); read.setMappingQuality(60); read.setReferenceName(contig); read.setReadNegativeStrandFlag(isNegStrand); read.setAttribute("RG", sampleRG(sample).getReadGroupId()); readWriter.addAlignment(read); }
NWaySAMFileWriter.setupWriter(out, toolkit, outputHeader, preSorted, this, PROGRAM_RECORD_NAME); } else { out.writeHeader(outputHeader); out.setPresorted(preSorted);
@Override public void initialize() { // All for the no_pg_tag. Should this be in the engine and not in the walker? final GenomeAnalysisEngine toolkit = getToolkit(); final SAMFileHeader outputHeader = toolkit.getSAMFileHeader().clone(); final String PROGRAM_RECORD_NAME = "GATK PrintReads"; final boolean preSorted = true; if (toolkit.getArguments().BQSR_RECAL_FILE != null && !NO_PG_TAG ) { NWaySAMFileWriter.setupWriter(out, toolkit, outputHeader, preSorted, this, PROGRAM_RECORD_NAME); } else { out.writeHeader(outputHeader); out.setPresorted(preSorted); } }
@Override public void initialize() { // initialize sample -> read group map final List<SAMReadGroupRecord> sampleRGs = new ArrayList<SAMReadGroupRecord>(); for ( final String sample : SampleUtils.getUniqueSamplesFromRods(getToolkit(), Arrays.asList(variantCollection.variants.getName())) ) { final SAMReadGroupRecord rg = createRG(sample); sampleRGs.add(rg); sample2RG.put(sample, rg); } // initialize BAM headers header = new SAMFileHeader(); header.setSequenceDictionary(getToolkit().getReferenceDataSource().getReference().getSequenceDictionary()); header.setSortOrder(SAMFileHeader.SortOrder.coordinate); header.setReadGroups(sampleRGs); final SAMProgramRecord programRecord = new SAMProgramRecord(PROGRAM_RECORD_NAME); if ( !NO_PG_TAG ) { programRecord.setProgramVersion(CommandLineProgram.getVersionNumber()); programRecord.setCommandLine(getToolkit().createApproximateCommandLineArgumentString(getToolkit(), this)); } header.setProgramRecords(Arrays.asList(programRecord)); readWriter.setPresorted(false); readWriter.writeHeader(header); halfReadLength = readLength / 2; errorRate = QualityUtils.qualToErrorProb((byte)phredErrorRate); readQuals = new byte[readLength]; Arrays.fill(readQuals, (byte)phredErrorRate); if ( samplingMode == ReadSamplingMode.POISSON ) poissonRandom = new Poisson(readDepth, new MersenneTwister((int)RANDOM_SEED)); }