/** * Creates a new GATKSAMRecord with the source read's header, read group and mate information, but * with the following fields set to user-supplied values: - Read Bases - Base Qualities - Base * Insertion Qualities - Base Deletion Qualities * * <p>Cigar string is empty (not-null) * * <p>Use this method if you want to create a new GATKSAMRecord based on another GATKSAMRecord, * but with modified bases and qualities * * @param read a read to copy the header from * @param readBases an array containing the new bases you wish use in place of the originals * @param baseQualities an array containing the new base qualities you wish use in place of the * originals * @param baseInsertionQualities an array containing the new base insertion qaulities * @param baseDeletionQualities an array containing the new base deletion qualities * @return a read with modified bases and qualities, safe for the GATK */ public static GATKSAMRecord createQualityModifiedRead( final GATKSAMRecord read, final byte[] readBases, final byte[] baseQualities, final byte[] baseInsertionQualities, final byte[] baseDeletionQualities) { if (baseQualities.length != readBases.length || baseInsertionQualities.length != readBases.length || baseDeletionQualities.length != readBases.length) throw new IllegalArgumentException( "Read bases and read quality arrays aren't the same size: Bases:" + readBases.length + " vs Base Q's:" + baseQualities.length + " vs Insert Q's:" + baseInsertionQualities.length + " vs Delete Q's:" + baseDeletionQualities.length); final GATKSAMRecord processedRead = GATKSAMRecord.emptyRead(read); processedRead.setReadBases(readBases); processedRead.setBaseQualities(baseQualities, EventType.BASE_SUBSTITUTION); processedRead.setBaseQualities(baseInsertionQualities, EventType.BASE_INSERTION); processedRead.setBaseQualities(baseDeletionQualities, EventType.BASE_DELETION); return processedRead; }
/** * Creates an empty GATKSAMRecord with the read's header, read group and mate information, but * empty (not-null) fields: - Cigar String - Read Bases - Base Qualities * * <p>Use this method if you want to create a new empty GATKSAMRecord based on another * GATKSAMRecord * * @param read a read to copy the header from * @return a read with no bases but safe for the GATK */ public static GATKSAMRecord emptyRead(GATKSAMRecord read) { final GATKSAMRecord emptyRead = new GATKSAMRecord(read.getHeader()); emptyRead.setReferenceIndex(read.getReferenceIndex()); emptyRead.setAlignmentStart(0); emptyRead.setMappingQuality(0); // setting read indexing bin last emptyRead.setFlags(read.getFlags()); emptyRead.setMateReferenceIndex(read.getMateReferenceIndex()); emptyRead.setMateAlignmentStart(read.getMateAlignmentStart()); emptyRead.setInferredInsertSize(read.getInferredInsertSize()); emptyRead.setCigarString(""); emptyRead.setReadBases(new byte[0]); emptyRead.setBaseQualities(new byte[0]); SAMReadGroupRecord samRG = read.getReadGroup(); emptyRead.clearAttributes(); if (samRG != null) { GATKSAMReadGroupRecord rg = new GATKSAMReadGroupRecord(samRG); emptyRead.setReadGroup(rg); } GATKBin.setReadIndexingBin(emptyRead, 0); return emptyRead; }
@Test(enabled = true) public void testReadWithNsRefAfterDeletion() throws FileNotFoundException { final IndexedFastaSequenceFile seq = new CachingIndexedFastaSequenceFile(new File(b37KGReference)); final SAMFileHeader header = ArtificialSAMUtils.createArtificialSamHeader(seq.getSequenceDictionary()); final int readLength = 76; final GATKSAMRecord read = ArtificialSAMUtils.createArtificialRead(header, "myRead", 0, 8975, readLength); read.setReadBases(Utils.dupBytes((byte) 'A', readLength)); read.setBaseQualities(Utils.dupBytes((byte) 30, readLength)); read.setCigarString("3M414N1D73M"); final int result = ReadUtils.getReadCoordinateForReferenceCoordinateUpToEndOfRead( read, 9393, ReadUtils.ClippingTail.LEFT_TAIL); Assert.assertEquals(result, 3); }