private static SAMRecord copyAndSet(final SAMRecord record, final Consumer<SAMRecord> setParams) { final SAMRecord copy = record.deepCopy(); setParams.accept(copy); return copy; }
private SAMRecord testDeepCopy(SAMRecord sam) { final SAMRecord deepCopy = sam.deepCopy(); Assert.assertTrue(sam.equals(deepCopy)); return deepCopy; }
@Test public void testNullHeaderDeepCopy() { SAMRecord sam = createTestRecordHelper(); sam.setHeader(null); final SAMRecord deepCopy = sam.deepCopy(); Assert.assertTrue(sam.equals(deepCopy)); }
@Test(dataProvider = "deepCopyTestData") public void testDeepCopyGetCigarString(SAMRecord sam) { sam.setCigarString(sam.getCigarString()); final SAMRecord deepCopy = sam.deepCopy(); Assert.assertTrue(sam.equals(deepCopy)); }
@Test(dataProvider = "deepCopyTestData") public void testDeepCopyCigar(SAMRecord sam) { sam.setCigar(sam.getCigar()); final SAMRecord deepCopy = sam.deepCopy(); Assert.assertTrue(sam.equals(deepCopy)); }
@Test(dataProvider = "deepCopyTestData") public void testDeepFloatAttributes( final SAMRecord sam ) throws Exception { SAMRecord deepCopy = testDeepCopy(sam); final float floats[] = { -2.4f, -1.2f, 0, 2.3f, 4.6f }; sam.setAttribute("FL", floats); deepCopy = sam.deepCopy(); Assert.assertEquals(sam, deepCopy); // validate reference inequality and content equality final float samFloats[] = sam.getFloatArrayAttribute("FL"); final float copyFloats[] = deepCopy.getFloatArrayAttribute("FL"); Assert.assertFalse(copyFloats == floats); Assert.assertFalse(copyFloats == samFloats); Assert.assertTrue(Arrays.equals(copyFloats, samFloats)); // validate mutation independence final float testFloat = -1.0f; Assert.assertTrue(samFloats[2] != testFloat); // ensure initial test condition Assert.assertTrue(samFloats[2] != testFloat); // ensure initial test condition samFloats[2] = testFloat; // mutate original Assert.assertTrue(samFloats[2] == testFloat); Assert.assertTrue(copyFloats[2] != testFloat); sam.setAttribute("FL", samFloats); Assert.assertTrue(sam.getFloatArrayAttribute("FL")[2] != deepCopy.getFloatArrayAttribute("FL")[2]); }
@Test(dataProvider = "ambiguityCodeVerification") public void ambiguityCodeVerificationTest(String name) throws IOException { doComplianceTest(name, (version, expected, actual) -> { if (expected.getReadString().equals(actual.getReadString())) { Assert.assertEquals(expected, actual); } else { // tolerate BAM and CRAM conversion of read bases to upper case IUPAC codes by // creating a deep copy of the expected reads and normalizing (upper case IUPAC) // the bases; then proceeding with the full compare with the actual SAMRecord expectedNormalized = actual.deepCopy(); final byte[] expectedBases = expectedNormalized.getReadBases(); SequenceUtil.toBamReadBasesInPlace(expectedBases); Assert.assertEquals(actual, expectedNormalized); } } ); }
originalCRAMRecords.forEach(origRec -> copiedCRAMRecords.add(origRec.deepCopy()));
@Override public String getRemoteEvidenceID() { SAMRecord remote = this.getSAMRecord().deepCopy(); remote.setReferenceName(remoteAlignment.rname); remote.setAlignmentStart(remoteAlignment.pos); remote.setReadUnmappedFlag(false); remote.setReadNegativeStrandFlag(remoteAlignment.isNegativeStrand); remote.setCigar(remoteAlignment.cigar); remote.setAttribute(SAMTag.SA.name(), new ChimericAlignment(this.getSAMRecord()).toString()); SplitReadEvidence remoteEvidence = SplitReadEvidence.create(source, remote).get(0); return source.getContext().getEvidenceIDGenerator().getEvidenceID(remoteEvidence); } @Override
record.getReadName(), ComputeSamTags.class.getName())); record = record.deepCopy(); SAMRecordUtil.hardClipToN(record);
} else if (origEditDist > alignment.numMismatches) { SAMRecord orig = read.deepCopy();