/** * Hallucinates sample objects for all the samples in the SAM file and stores them */ public SampleDBBuilder addSamplesFromSAMHeader(final SAMFileHeader header) { addSamplesFromSampleNames(ReadUtils.getSAMFileSamples(header)); return this; }
public static GATKSAMRecord createRandomRead(int length) { return createRandomRead(length, true); }
private void emitReadLists() { // pre-merge lists to sort them in preparation for constrained SAMFileWriter readsNotToClean.addAll(readsToClean.getReads()); ReadUtils.sortReadsByCoordinate(readsNotToClean); manager.addReads(readsNotToClean, readsActuallyCleaned); readsToClean.clear(); readsNotToClean.clear(); readsActuallyCleaned.clear(); }
public void addAlignment(GATKSAMRecord read) { output.println("@" + read.getReadName()); if (read.getReadNegativeStrandFlag()) { output.println(ReadUtils.getBasesReverseComplement(read)); output.println("+"); output.println(ReadUtils.convertReadQualToString(invertQuals(read.getBaseQualities()))); } else { output.println(ReadUtils.convertReadBasesToString(read)); output.println("+"); output.println(ReadUtils.convertReadQualToString(read)); } }
/** * Checks if a read contains adaptor sequences. If it does, hard clips them out. * * Note: To see how a read is checked for adaptor sequence see {@link ReadUtils::getAdaptorBoundary} * * @return a new read without adaptor sequence */ private GATKSAMRecord hardClipAdaptorSequence () { final int adaptorBoundary = ReadUtils.getAdaptorBoundary(read); if (adaptorBoundary == ReadUtils.CANNOT_COMPUTE_ADAPTOR_BOUNDARY || !ReadUtils.isInsideRead(read, adaptorBoundary)) return read; return read.getReadNegativeStrandFlag() ? hardClipByReferenceCoordinatesLeftTail(adaptorBoundary) : hardClipByReferenceCoordinatesRightTail(adaptorBoundary); } public static GATKSAMRecord hardClipAdaptorSequence (GATKSAMRecord read) {
@Test (enabled = true) public void testGetMaxReadLength() { for( final int minLength : Arrays.asList( 5, 30, 50 ) ) { for( final int maxLength : Arrays.asList( 50, 75, 100 ) ) { final List<GATKSAMRecord> reads = new ArrayList<>(); for( int readLength = minLength; readLength <= maxLength; readLength++ ) { reads.add( ReadUtils.createRandomRead( readLength ) ); } Assert.assertEquals(ReadUtils.getMaxReadLength(reads), maxLength, "max length does not match"); } } final List<GATKSAMRecord> reads = new LinkedList<>(); Assert.assertEquals(ReadUtils.getMaxReadLength(reads), 0, "Empty list should have max length of zero"); }
clippedRead= ReadClipper.hardClipLowQualEnds( myRead, MIN_TAIL_QUALITY ); if ( dontUseSoftClippedBases || ! ReadUtils.hasWellDefinedFragmentSize(clippedRead) ) { final List<GATKSAMRecord> downsampledReads = DownsamplingUtils.levelCoverageByPosition(ReadUtils.sortReadsByCoordinate(readsToUse), maxReadsInRegionPerSample, minReadsPerAlignmentStart);
public BAQCalculationResult calcBAQFromHMM(final SAMRecord read, final ReferenceSequenceFile refReader) { // start is alignment start - band width / 2 - size of first I element, if there is one. Stop is similar int offset = getBandWidth() / 2; long readStart = includeClippedBases ? read.getUnclippedStart() : read.getAlignmentStart(); long start = Math.max(readStart - offset - ReadUtils.getFirstInsertionOffset(read), 1); long stop = (includeClippedBases ? read.getUnclippedEnd() : read.getAlignmentEnd()) + offset + ReadUtils.getLastInsertionOffset(read); if ( stop > refReader.getSequenceDictionary().getSequence(read.getReferenceName()).getSequenceLength() ) { return null; } else { // now that we have the start and stop, get the reference sequence covering it ReferenceSequence refSeq = refReader.getSubsequenceAt(read.getReferenceName(), start, stop); return calcBAQFromHMM(read, refSeq.getBases(), (int)(start - readStart)); } }
public boolean filterOut(SAMRecord rec) { return (ReadUtils.is454Read((GATKSAMRecord)rec)); } }
private boolean doNotTryToClean(GATKSAMRecord read) { return read.getReadUnmappedFlag() || read.getNotPrimaryAlignmentFlag() || read.getReadFailsVendorQualityCheckFlag() || read.getMappingQuality() == 0 || read.getAlignmentStart() == SAMRecord.NO_ALIGNMENT_START || ConstrainedMateFixingManager.iSizeTooBigToMove(read, MAX_ISIZE_FOR_MOVEMENT) || ReadUtils.is454Read(read) || ReadUtils.isIonRead(read); // TODO -- it would be nice if we could use indels from 454/Ion reads as alternate consenses }
/** * Returns the reverse complement of the read bases * * @param read the read * @return the reverse complement of the read bases */ public static String getBasesReverseComplement(GATKSAMRecord read) { return getBasesReverseComplement(read.getReadBases()); }
@Test(dataProvider = "HasWellDefinedFragmentSizeData") public void testHasWellDefinedFragmentSize(final String name, final GATKSAMRecord read, final boolean expected) { Assert.assertEquals(ReadUtils.hasWellDefinedFragmentSize(read), expected); }
@Override public int getAdaptor(final GATKSAMRecord record) { return ReadUtils.getAdaptorBoundary(record); } }});
/** * Given a read, outputs the base qualities in a string format * * @param read the read * @return a string representation of the base qualities */ public static String convertReadQualToString(GATKSAMRecord read) { return convertReadQualToString(read.getBaseQualities()); }
clippedRead= ReadClipper.hardClipLowQualEnds( myRead, MIN_TAIL_QUALITY ); if ( dontUseSoftClippedBases || ! ReadUtils.hasWellDefinedFragmentSize(clippedRead) ) { final List<GATKSAMRecord> downsampledReads = DownsamplingUtils.levelCoverageByPosition(ReadUtils.sortReadsByCoordinate(readsToUse), maxReadsInRegionPerSample, minReadsPerAlignmentStart);
long startLocationInRefForHaplotypes = Math.max(readStart + numStartSoftClippedBases - trailingBases - ReadUtils.getFirstInsertionOffset(read) - absEventLength, 0); long stopLocationInRefForHaplotypes = readEnd - numEndSoftClippedBases + trailingBases + ReadUtils.getLastInsertionOffset(read) + absEventLength;
int i=0; for (GATKSAMRecord read : pileup.getReads()) { if(ReadUtils.is454Read(read)) { continue;
@Test (enabled = true) public void testGetBasesReverseComplement() { int iterations = 1000; Random random = Utils.getRandomGenerator(); while(iterations-- > 0) { final int l = random.nextInt(1000); GATKSAMRecord read = GATKSAMRecord.createRandomRead(l); byte [] original = read.getReadBases(); byte [] reconverted = new byte[l]; String revComp = ReadUtils.getBasesReverseComplement(read); for (int i=0; i<l; i++) { reconverted[l-1-i] = BaseUtils.getComplement((byte) revComp.charAt(i)); } Assert.assertEquals(reconverted, original); } }
if ( ! hasWellDefinedFragmentSize(read) ) { return CANNOT_COMPUTE_ADAPTOR_BOUNDARY; } else if ( read.getReadNegativeStrandFlag() ) {
/** * A caching version of ReadUtils.getAdaptorBoundary() * * see #ReadUtils.getAdaptorBoundary(SAMRecord) for more information about the meaning of this function * * WARNING -- this function caches a value depending on the inferred insert size and alignment starts * and stops of this read and its mate. Changing these values in any way will invalidate the cached value. * However, we do not monitor those setter functions, so modifying a GATKSAMRecord in any way may * result in stale cached values. * * @return the result of calling ReadUtils.getAdaptorBoundary on this read */ @Ensures("result == ReadUtils.getAdaptorBoundary(this)") public int getAdaptorBoundary() { if ( adapterBoundary == null ) adapterBoundary = ReadUtils.getAdaptorBoundary(this); return adapterBoundary; } }