diff --git a/protected/gatk-tools-protected/src/test/java/org/broadinstitute/gatk/tools/walkers/haplotypecaller/LDMergerUnitTest.java b/protected/gatk-tools-protected/src/test/java/org/broadinstitute/gatk/tools/walkers/haplotypecaller/LDMergerUnitTest.java index 68c6bea73..826666d43 100644 --- a/protected/gatk-tools-protected/src/test/java/org/broadinstitute/gatk/tools/walkers/haplotypecaller/LDMergerUnitTest.java +++ b/protected/gatk-tools-protected/src/test/java/org/broadinstitute/gatk/tools/walkers/haplotypecaller/LDMergerUnitTest.java @@ -269,8 +269,8 @@ public class LDMergerUnitTest extends BaseTest { @Test(dataProvider = "R2MergerData") public void testR2Merger(final String refS, final String hapS, int nEvents, final String cigar, final String expectedMergedRef, final String expectedMergedAlt, final double r2, final boolean expectMerge) { - final Haplotype ref = new Haplotype(refS.getBytes(), true, 0, TextCigarCodec.getSingleton().decode(refS.length() + "M")); - final Haplotype hap = new Haplotype(hapS.getBytes(), false, 0, TextCigarCodec.getSingleton().decode(cigar)); + final Haplotype ref = new Haplotype(refS.getBytes(), true, 0, TextCigarCodec.decode(refS.length() + "M")); + final Haplotype hap = new Haplotype(hapS.getBytes(), false, 0, TextCigarCodec.decode(cigar)); final GenomeLoc loc = new UnvalidatingGenomeLoc("1", 0, 1, ref.length()); final List haplotypes = Arrays.asList(ref, hap); @@ -294,9 +294,9 @@ public class LDMergerUnitTest extends BaseTest { final String refS = "ACGT"; final String hapS = "CCGA"; final String cigar = "4M"; - final Haplotype ref = new Haplotype(refS.getBytes(), true, 0, TextCigarCodec.getSingleton().decode(refS.length() + "M")); - final Haplotype hap1 = new Haplotype(hapS.getBytes(), false, 0, TextCigarCodec.getSingleton().decode(cigar)); - final Haplotype hap2 = new Haplotype("ACGA".getBytes(), false, 0, TextCigarCodec.getSingleton().decode(cigar)); + final Haplotype ref = new Haplotype(refS.getBytes(), true, 0, TextCigarCodec.decode(refS.length() + "M")); + final Haplotype hap1 = new Haplotype(hapS.getBytes(), false, 0, TextCigarCodec.decode(cigar)); + final Haplotype hap2 = new Haplotype("ACGA".getBytes(), false, 0, TextCigarCodec.decode(cigar)); final GenomeLoc loc = new UnvalidatingGenomeLoc("1", 0, 1, ref.length()); final List haplotypes = Arrays.asList(ref, hap1, hap2); @@ -321,12 +321,12 @@ public class LDMergerUnitTest extends BaseTest { final String refS = "ACGT"; final String hapS = "TCGA"; final String cigar = "4M"; - final Haplotype ref = new Haplotype(refS.getBytes(), true, 0, TextCigarCodec.getSingleton().decode(refS.length() + "M")); - final Haplotype hap1 = new Haplotype(hapS.getBytes(), false, 0, TextCigarCodec.getSingleton().decode(cigar)); + final Haplotype ref = new Haplotype(refS.getBytes(), true, 0, TextCigarCodec.decode(refS.length() + "M")); + final Haplotype hap1 = new Haplotype(hapS.getBytes(), false, 0, TextCigarCodec.decode(cigar)); final GenomeLoc loc = new UnvalidatingGenomeLoc("1", 0, 1, ref.length()); for (final String hap2S : Arrays.asList("GCGA", "TCGG")) { - final Haplotype hap2 = new Haplotype(hap2S.getBytes(), false, 0, TextCigarCodec.getSingleton().decode(cigar)); + final Haplotype hap2 = new Haplotype(hap2S.getBytes(), false, 0, TextCigarCodec.decode(cigar)); final List haplotypes = Arrays.asList(ref, hap1, hap2); final TreeSet vcStarts = EventMap.buildEventMapsForHaplotypes(haplotypes, ref.getBases(), loc, false); diff --git a/protected/gatk-tools-protected/src/test/java/org/broadinstitute/gatk/tools/walkers/haplotypecaller/graphs/KBestHaplotypeFinderUnitTest.java b/protected/gatk-tools-protected/src/test/java/org/broadinstitute/gatk/tools/walkers/haplotypecaller/graphs/KBestHaplotypeFinderUnitTest.java index b1bc1e22c..33d091953 100644 --- a/protected/gatk-tools-protected/src/test/java/org/broadinstitute/gatk/tools/walkers/haplotypecaller/graphs/KBestHaplotypeFinderUnitTest.java +++ b/protected/gatk-tools-protected/src/test/java/org/broadinstitute/gatk/tools/walkers/haplotypecaller/graphs/KBestHaplotypeFinderUnitTest.java @@ -452,7 +452,7 @@ public class KBestHaplotypeFinderUnitTest extends BaseTest { Cigar expected = new Cigar(); expected.add(new CigarElement(padSize, CigarOperator.M)); if ( ! prefix.equals("") ) expected.add(new CigarElement(prefix.length(), CigarOperator.M)); - for ( final CigarElement elt : TextCigarCodec.getSingleton().decode(midCigar).getCigarElements() ) expected.add(elt); + for ( final CigarElement elt : TextCigarCodec.decode(midCigar).getCigarElements() ) expected.add(elt); if ( ! end.equals("") ) expected.add(new CigarElement(end.length(), CigarOperator.M)); expected.add(new CigarElement(padSize, CigarOperator.M)); expected = AlignmentUtils.consolidateCigar(expected); @@ -513,7 +513,7 @@ public class KBestHaplotypeFinderUnitTest extends BaseTest { public void testLeftAlignCigarSequentiallyAdjacentID() { final String ref = "GTCTCTCTCTCTCTCTCTATATATATATATATATTT"; final String hap = "GTCTCTCTCTCTCTCTCTCTCTATATATATATATTT"; - final Cigar originalCigar = TextCigarCodec.getSingleton().decode("18M4I12M4D2M"); + final Cigar originalCigar = TextCigarCodec.decode("18M4I12M4D2M"); final Cigar result = CigarUtils.leftAlignCigarSequentially(originalCigar, ref.getBytes(), hap.getBytes(), 0, 0); logger.warn("Result is " + result); diff --git a/protected/gatk-tools-protected/src/test/java/org/broadinstitute/gatk/utils/haplotypeBAMWriter/HaplotypeBAMWriterUnitTest.java b/protected/gatk-tools-protected/src/test/java/org/broadinstitute/gatk/utils/haplotypeBAMWriter/HaplotypeBAMWriterUnitTest.java index b09efb939..e2f703e01 100644 --- a/protected/gatk-tools-protected/src/test/java/org/broadinstitute/gatk/utils/haplotypeBAMWriter/HaplotypeBAMWriterUnitTest.java +++ b/protected/gatk-tools-protected/src/test/java/org/broadinstitute/gatk/utils/haplotypeBAMWriter/HaplotypeBAMWriterUnitTest.java @@ -82,7 +82,7 @@ public class HaplotypeBAMWriterUnitTest extends BaseTest { private Haplotype makeHaplotype(final String bases, final String cigar) { final Haplotype hap = new Haplotype(bases.getBytes()); - hap.setCigar(TextCigarCodec.getSingleton().decode(cigar)); + hap.setCigar(TextCigarCodec.decode(cigar)); return hap; } @@ -160,7 +160,7 @@ public class HaplotypeBAMWriterUnitTest extends BaseTest { final String badCigar = "31M6D211M"; final String goodCigar = "28M6D214M"; final Haplotype badHap = new Haplotype(hap.getBytes()); - badHap.setCigar(TextCigarCodec.getSingleton().decode(hapCigar)); + badHap.setCigar(TextCigarCodec.decode(hapCigar)); badHap.setAlignmentStartHapwrtRef(hapStart); final int expectedPos = 10130740; @@ -179,7 +179,7 @@ public class HaplotypeBAMWriterUnitTest extends BaseTest { if ( expectedReadCigar == null ) { Assert.assertNull(AlignmentUtils.createReadAlignedToRef(read, haplotype, haplotype, refStart, true)); } else { - final Cigar expectedCigar = TextCigarCodec.getSingleton().decode(expectedReadCigar); + final Cigar expectedCigar = TextCigarCodec.decode(expectedReadCigar); final GATKSAMRecord alignedRead = AlignmentUtils.createReadAlignedToRef(read, haplotype, haplotype, refStart, true); Assert.assertEquals(alignedRead.getReadName(), originalReadCopy.getReadName()); diff --git a/public/gatk-engine/src/main/java/org/broadinstitute/gatk/engine/datasources/reads/GATKBAMIndex.java b/public/gatk-engine/src/main/java/org/broadinstitute/gatk/engine/datasources/reads/GATKBAMIndex.java index 17afd5894..3b94e438a 100644 --- a/public/gatk-engine/src/main/java/org/broadinstitute/gatk/engine/datasources/reads/GATKBAMIndex.java +++ b/public/gatk-engine/src/main/java/org/broadinstitute/gatk/engine/datasources/reads/GATKBAMIndex.java @@ -363,6 +363,8 @@ public class GATKBAMIndex { private void read(final ByteBuffer buffer) { final int bytesRequested = buffer.limit(); + if (bytesRequested == 0) + return; try { @@ -379,25 +381,19 @@ public class GATKBAMIndex { mFile)); } - int totalBytesRead = 0; - // This while loop must terminate since we demand that we read at least one byte from the file at each iteration - while (totalBytesRead < bytesRequested) { - // bufferedStream.read may return less than the requested amount of byte despite - // not reaching the end of the file, hence the loop. - int bytesRead = bufferedStream.read(byteArray, totalBytesRead, bytesRequested-totalBytesRead); + int bytesRead = bufferedStream.read(byteArray, 0, bytesRequested); - // We have a rigid expectation here to read in exactly the number of bytes we've limited - // our buffer to -- if we encounter EOF (-1), the index - // must be truncated or otherwise corrupt: - if (bytesRead <= 0) { - throw new UserException.MalformedFile(mFile, String.format("Premature end-of-file while reading BAM index file %s. " + - "It's likely that this file is truncated or corrupt -- " + - "Please try re-indexing the corresponding BAM file.", - mFile)); - } - totalBytesRead += bytesRead; + // We have a rigid expectation here to read in exactly the number of bytes we've limited + // our buffer to -- if we encounter EOF (-1), the index + // must be truncated or otherwise corrupt: + if (bytesRead <= 0) { + throw new UserException.MalformedFile(mFile, String.format("Premature end-of-file while reading BAM index file %s. " + + "It's likely that this file is truncated or corrupt -- " + + "Please try re-indexing the corresponding BAM file.", + mFile)); } - if(totalBytesRead != bytesRequested) + + if(bytesRead != bytesRequested) throw new RuntimeException("Read amount different from requested amount. This should not happen."); buffer.put(byteArray, 0, bytesRequested); @@ -435,7 +431,7 @@ public class GATKBAMIndex { long skipped = bufferedStream.skip(count); if( skipped != count ) { //if not managed to skip the requested amount - throw new ReviewedGATKException("Index: unable to reposition file channel of index file " + mFile); + throw new ReviewedGATKException("Index: unable to reposition file channel of index file " + mFile); } } catch(IOException ex) { diff --git a/public/gatk-engine/src/main/java/org/broadinstitute/gatk/engine/datasources/reads/SAMDataSource.java b/public/gatk-engine/src/main/java/org/broadinstitute/gatk/engine/datasources/reads/SAMDataSource.java index 4c4759b26..9933a6152 100644 --- a/public/gatk-engine/src/main/java/org/broadinstitute/gatk/engine/datasources/reads/SAMDataSource.java +++ b/public/gatk-engine/src/main/java/org/broadinstitute/gatk/engine/datasources/reads/SAMDataSource.java @@ -564,7 +564,7 @@ public class SAMDataSource { */ private GATKSAMIterator getIterator(SAMReaders readers, Shard shard, boolean enableVerification) { // Set up merging to dynamically merge together multiple BAMs. - Map> iteratorMap = new HashMap>(); + Map> iteratorMap = new HashMap<>(); for(SAMReaderID id: getReaderIDs()) { CloseableIterator iterator = null; @@ -1000,7 +1000,7 @@ public class SAMDataSource { * @param iteratorMap A map of readers to iterators. * @return An iterator which will merge those individual iterators. */ - public MergingSamRecordIterator createMergingIterator(final Map> iteratorMap) { + public MergingSamRecordIterator createMergingIterator(final Map> iteratorMap) { return new MergingSamRecordIterator(headerMerger,iteratorMap,true); } diff --git a/public/gatk-engine/src/test/java/org/broadinstitute/gatk/engine/datasources/reads/SeekableBufferedStreamUnitTest.java b/public/gatk-engine/src/test/java/org/broadinstitute/gatk/engine/datasources/reads/SeekableBufferedStreamUnitTest.java index c24a21a63..c67cadb8d 100644 --- a/public/gatk-engine/src/test/java/org/broadinstitute/gatk/engine/datasources/reads/SeekableBufferedStreamUnitTest.java +++ b/public/gatk-engine/src/test/java/org/broadinstitute/gatk/engine/datasources/reads/SeekableBufferedStreamUnitTest.java @@ -28,7 +28,6 @@ package org.broadinstitute.gatk.engine.datasources.reads; import htsjdk.samtools.seekablestream.SeekableBufferedStream; import htsjdk.samtools.seekablestream.SeekableFileStream; import org.broadinstitute.gatk.utils.BaseTest; -import org.broadinstitute.gatk.utils.exceptions.GATKException; import org.testng.Assert; import org.testng.annotations.DataProvider; import org.testng.annotations.Test; @@ -77,9 +76,13 @@ public class SeekableBufferedStreamUnitTest extends BaseTest { // These tests fail because SeekableBuffered stream may return _less_ than the amount you are asking for. // make sure that you wrap reads with while-loops. If these test start failing (meaning that the reads work properly, // the layer of protection built into GATKBamIndex can be removed. + // + // pdexheimer, Jan 2015 - SeekableBufferedStream no longer returns less than the expected amount. + // Renaming testIndivisableSmallReadsFAIL to testIndivisableSmallReadsPASS and removing the expected exception + // If this bug regresses, the while loop will need to be re-introduced into GATKBamIndex.read() - @Test(dataProvider = "BasicArgumentsIndivisibleAndSmall", enabled = true, expectedExceptions = java.lang.AssertionError.class) - public void testIndivisableSmallReadsFAIL(Integer readLength) throws IOException { + @Test(dataProvider = "BasicArgumentsIndivisibleAndSmall", enabled = true) + public void testIndivisableSmallReadsPASS(Integer readLength) throws IOException { testReadsLength(readLength); } diff --git a/public/gatk-engine/src/test/java/org/broadinstitute/gatk/engine/filters/MalformedReadFilterUnitTest.java b/public/gatk-engine/src/test/java/org/broadinstitute/gatk/engine/filters/MalformedReadFilterUnitTest.java index 20566f510..405610011 100644 --- a/public/gatk-engine/src/test/java/org/broadinstitute/gatk/engine/filters/MalformedReadFilterUnitTest.java +++ b/public/gatk-engine/src/test/java/org/broadinstitute/gatk/engine/filters/MalformedReadFilterUnitTest.java @@ -117,7 +117,7 @@ public class MalformedReadFilterUnitTest extends ReadFilterTest { } protected SAMRecord buildSAMRecord(final String cigarString) { - final Cigar nContainingCigar = TextCigarCodec.getSingleton().decode(cigarString); + final Cigar nContainingCigar = TextCigarCodec.decode(cigarString); return this.createRead(nContainingCigar, 1, 0, 10); } diff --git a/public/gatk-engine/src/test/java/org/broadinstitute/gatk/engine/iterators/ReadFormattingIteratorUnitTest.java b/public/gatk-engine/src/test/java/org/broadinstitute/gatk/engine/iterators/ReadFormattingIteratorUnitTest.java index d6f4be97a..c12bb1551 100644 --- a/public/gatk-engine/src/test/java/org/broadinstitute/gatk/engine/iterators/ReadFormattingIteratorUnitTest.java +++ b/public/gatk-engine/src/test/java/org/broadinstitute/gatk/engine/iterators/ReadFormattingIteratorUnitTest.java @@ -40,7 +40,7 @@ public class ReadFormattingIteratorUnitTest extends BaseTest { @Test public void testIteratorConsolidatesCigars() { - final Cigar unconsolidatedCigar = TextCigarCodec.getSingleton().decode("3M0M5M0M"); + final Cigar unconsolidatedCigar = TextCigarCodec.decode("3M0M5M0M"); final SAMRecord unconsolidatedRead = ArtificialSAMUtils.createArtificialRead(unconsolidatedCigar); final GATKSAMIterator readIterator = GATKSAMIteratorAdapter.adapt(Arrays.asList(unconsolidatedRead).iterator()); diff --git a/public/gatk-utils/src/main/java/org/broadinstitute/gatk/utils/codecs/samread/SAMReadCodec.java b/public/gatk-utils/src/main/java/org/broadinstitute/gatk/utils/codecs/samread/SAMReadCodec.java index d83ce6d8d..d0e69db9f 100644 --- a/public/gatk-utils/src/main/java/org/broadinstitute/gatk/utils/codecs/samread/SAMReadCodec.java +++ b/public/gatk-utils/src/main/java/org/broadinstitute/gatk/utils/codecs/samread/SAMReadCodec.java @@ -95,7 +95,7 @@ public class SAMReadCodec extends AsciiFeatureCodec { final byte[] qualities = StringUtil.stringToBytes(tokens[10]); // Infer the alignment end. - Cigar cigar = TextCigarCodec.getSingleton().decode(cigarString); + Cigar cigar = TextCigarCodec.decode(cigarString); int alignmentEnd = alignmentStart + cigar.getReferenceLength() - 1; // Remove printable character conversion from the qualities. diff --git a/public/gatk-utils/src/main/java/org/broadinstitute/gatk/utils/sam/ArtificialMultiSampleReadStream.java b/public/gatk-utils/src/main/java/org/broadinstitute/gatk/utils/sam/ArtificialMultiSampleReadStream.java index a468dc06b..010759ecf 100644 --- a/public/gatk-utils/src/main/java/org/broadinstitute/gatk/utils/sam/ArtificialMultiSampleReadStream.java +++ b/public/gatk-utils/src/main/java/org/broadinstitute/gatk/utils/sam/ArtificialMultiSampleReadStream.java @@ -28,7 +28,7 @@ package org.broadinstitute.gatk.utils.sam; import htsjdk.samtools.MergingSamRecordIterator; import htsjdk.samtools.SamFileHeaderMerger; import htsjdk.samtools.SAMFileHeader; -import htsjdk.samtools.SAMFileReader; +import htsjdk.samtools.SamReader; import htsjdk.samtools.SAMRecord; import org.broadinstitute.gatk.utils.iterators.GATKSAMIterator; import org.broadinstitute.gatk.utils.iterators.GATKSAMIteratorAdapter; @@ -69,13 +69,13 @@ public class ArtificialMultiSampleReadStream implements Iterable { } private void initialize() { - Collection perSampleSAMReaders = new ArrayList(perSampleArtificialReadStreams.size()); - Collection headers = new ArrayList(perSampleArtificialReadStreams.size()); + Collection perSampleSAMReaders = new ArrayList<>(perSampleArtificialReadStreams.size()); + Collection headers = new ArrayList<>(perSampleArtificialReadStreams.size()); for ( ArtificialSingleSampleReadStream readStream : perSampleArtificialReadStreams ) { Collection thisStreamReads = readStream.makeReads(); - SAMFileReader reader = new ArtificialSAMFileReader(readStream.getHeader(), + ArtificialSAMFileReader reader = new ArtificialSAMFileReader(readStream.getHeader(), thisStreamReads.toArray(new SAMRecord[thisStreamReads.size()])); perSampleSAMReaders.add(reader); headers.add(reader.getFileHeader()); diff --git a/public/gatk-utils/src/main/java/org/broadinstitute/gatk/utils/sam/CigarUtils.java b/public/gatk-utils/src/main/java/org/broadinstitute/gatk/utils/sam/CigarUtils.java index cd492fec9..06e0653f5 100644 --- a/public/gatk-utils/src/main/java/org/broadinstitute/gatk/utils/sam/CigarUtils.java +++ b/public/gatk-utils/src/main/java/org/broadinstitute/gatk/utils/sam/CigarUtils.java @@ -104,7 +104,7 @@ public class CigarUtils { } public static Cigar cigarFromString(String cigarString) { - return TextCigarCodec.getSingleton().decode(cigarString); + return TextCigarCodec.decode(cigarString); } /** diff --git a/public/gatk-utils/src/test/java/org/broadinstitute/gatk/utils/fragments/FragmentUtilsUnitTest.java b/public/gatk-utils/src/test/java/org/broadinstitute/gatk/utils/fragments/FragmentUtilsUnitTest.java index f9f9ba441..4984d0a71 100644 --- a/public/gatk-utils/src/test/java/org/broadinstitute/gatk/utils/fragments/FragmentUtilsUnitTest.java +++ b/public/gatk-utils/src/test/java/org/broadinstitute/gatk/utils/fragments/FragmentUtilsUnitTest.java @@ -336,7 +336,7 @@ public class FragmentUtilsUnitTest extends BaseTest { final int readLen = pre + contigLen + post; final GATKSAMRecord read = ArtificialSAMUtils.createArtificialRead(header, "read1", 0, 1, readLen); read.setAlignmentStart(1); - read.setCigar(TextCigarCodec.getSingleton().decode(pre + "S" + contigLen + "M" + post + "S")); + read.setCigar(TextCigarCodec.decode(pre + "S" + contigLen + "M" + post + "S")); read.setBaseQualities(Utils.dupBytes((byte) 30, readLen)); read.setReadBases(Utils.dupBytes((byte)'A', readLen)); read.setMappingQuality(60); diff --git a/public/gatk-utils/src/test/java/org/broadinstitute/gatk/utils/haplotype/EventMapUnitTest.java b/public/gatk-utils/src/test/java/org/broadinstitute/gatk/utils/haplotype/EventMapUnitTest.java index 6baf6ef4d..c4ff9b587 100644 --- a/public/gatk-utils/src/test/java/org/broadinstitute/gatk/utils/haplotype/EventMapUnitTest.java +++ b/public/gatk-utils/src/test/java/org/broadinstitute/gatk/utils/haplotype/EventMapUnitTest.java @@ -127,7 +127,7 @@ public class EventMapUnitTest extends BaseTest { */ @Test(dataProvider = "BlockSubstitutionsData") public void testBlockSubstitutionsData(final String refBases, final String haplotypeBases, final String cigar, final VariantContext expectedBlock) { - final Haplotype hap = new Haplotype(haplotypeBases.getBytes(), false, 0, TextCigarCodec.getSingleton().decode(cigar)); + final Haplotype hap = new Haplotype(haplotypeBases.getBytes(), false, 0, TextCigarCodec.decode(cigar)); final GenomeLoc loc = new UnvalidatingGenomeLoc(CHR, 0, 1, refBases.length()); final EventMap ee = new EventMap(hap, refBases.getBytes(), loc, NAME); ee.replaceClumpedEventsWithBlockSubstitutions(); @@ -156,7 +156,7 @@ public class EventMapUnitTest extends BaseTest { */ @Test(dataProvider = "AdjacentSNPIndelTest") public void testAdjacentSNPIndelTest(final String refBases, final String haplotypeBases, final String cigar, final List> expectedAlleles) { - final Haplotype hap = new Haplotype(haplotypeBases.getBytes(), false, 0, TextCigarCodec.getSingleton().decode(cigar)); + final Haplotype hap = new Haplotype(haplotypeBases.getBytes(), false, 0, TextCigarCodec.decode(cigar)); final GenomeLoc loc = new UnvalidatingGenomeLoc(CHR, 0, 1, refBases.length()); final EventMap ee = new EventMap(hap, refBases.getBytes(), loc, NAME); ee.replaceClumpedEventsWithBlockSubstitutions(); diff --git a/public/gatk-utils/src/test/java/org/broadinstitute/gatk/utils/haplotype/HaplotypeUnitTest.java b/public/gatk-utils/src/test/java/org/broadinstitute/gatk/utils/haplotype/HaplotypeUnitTest.java index b0087dc05..e71413d12 100644 --- a/public/gatk-utils/src/test/java/org/broadinstitute/gatk/utils/haplotype/HaplotypeUnitTest.java +++ b/public/gatk-utils/src/test/java/org/broadinstitute/gatk/utils/haplotype/HaplotypeUnitTest.java @@ -167,7 +167,7 @@ public class HaplotypeUnitTest extends BaseTest { private Haplotype makeHCForCigar(final String bases, final String cigar) { final Haplotype h = new Haplotype(bases.getBytes()); - h.setCigar(TextCigarCodec.getSingleton().decode(cigar)); + h.setCigar(TextCigarCodec.decode(cigar)); return h; } @@ -201,10 +201,10 @@ public class HaplotypeUnitTest extends BaseTest { final int hapStart = 10; full.setAlignmentStartHapwrtRef(hapStart); - full.setCigar(TextCigarCodec.getSingleton().decode(full.length() + "M")); + full.setCigar(TextCigarCodec.decode(full.length() + "M")); trimmed.setAlignmentStartHapwrtRef(hapStart + start); - trimmed.setCigar(TextCigarCodec.getSingleton().decode(trimmed.length() + "M")); + trimmed.setCigar(TextCigarCodec.decode(trimmed.length() + "M")); tests.add(new Object[]{full, trimmedLoc, trimmed}); } @@ -212,7 +212,7 @@ public class HaplotypeUnitTest extends BaseTest { final Haplotype full = new Haplotype("ACT".getBytes(), new UnvalidatingGenomeLoc("20", 0, 10, 14)); full.setAlignmentStartHapwrtRef(10); - full.setCigar(TextCigarCodec.getSingleton().decode("1M2D2M")); + full.setCigar(TextCigarCodec.decode("1M2D2M")); tests.add(new Object[]{full, new UnvalidatingGenomeLoc("20", 0, 11, 12), null}); tests.add(new Object[]{full, new UnvalidatingGenomeLoc("20", 0, 10, 12), null}); tests.add(new Object[]{full, new UnvalidatingGenomeLoc("20", 0, 11, 13), null}); diff --git a/public/gatk-utils/src/test/java/org/broadinstitute/gatk/utils/locusiterator/LocusIteratorByStateBaseTest.java b/public/gatk-utils/src/test/java/org/broadinstitute/gatk/utils/locusiterator/LocusIteratorByStateBaseTest.java index 073d69cde..8f5d8f7b2 100644 --- a/public/gatk-utils/src/test/java/org/broadinstitute/gatk/utils/locusiterator/LocusIteratorByStateBaseTest.java +++ b/public/gatk-utils/src/test/java/org/broadinstitute/gatk/utils/locusiterator/LocusIteratorByStateBaseTest.java @@ -98,7 +98,7 @@ public class LocusIteratorByStateBaseTest extends BaseTest { final private List elements; public LIBSTest(final String cigarString) { - final Cigar cigar = TextCigarCodec.getSingleton().decode(cigarString); + final Cigar cigar = TextCigarCodec.decode(cigarString); this.cigarString = cigarString; this.elements = cigar.getCigarElements(); this.readLength = cigar.getReadLength(); diff --git a/public/gatk-utils/src/test/java/org/broadinstitute/gatk/utils/sam/AlignmentUtilsUnitTest.java b/public/gatk-utils/src/test/java/org/broadinstitute/gatk/utils/sam/AlignmentUtilsUnitTest.java index 3334efddc..d0d6eb442 100644 --- a/public/gatk-utils/src/test/java/org/broadinstitute/gatk/utils/sam/AlignmentUtilsUnitTest.java +++ b/public/gatk-utils/src/test/java/org/broadinstitute/gatk/utils/sam/AlignmentUtilsUnitTest.java @@ -168,7 +168,7 @@ public class AlignmentUtilsUnitTest { @Test(enabled = true, dataProvider = "CalcNumDifferentBasesData") public void testCalcNumDifferentBases(final String cigarString, final String ref, final String read, final int expectedDifferences) { - final Cigar cigar = TextCigarCodec.getSingleton().decode(cigarString); + final Cigar cigar = TextCigarCodec.decode(cigarString); Assert.assertEquals(AlignmentUtils.calcNumDifferentBases(cigar, ref.getBytes(), read.getBytes()), expectedDifferences); } @@ -299,8 +299,8 @@ public class AlignmentUtilsUnitTest { @Test(enabled = !DEBUG, dataProvider = "ConsolidateCigarData") public void testConsolidateCigarWithData(final String testCigarString, final String expectedCigarString) { - final Cigar testCigar = TextCigarCodec.getSingleton().decode(testCigarString); - final Cigar expectedCigar = TextCigarCodec.getSingleton().decode(expectedCigarString); + final Cigar testCigar = TextCigarCodec.decode(testCigarString); + final Cigar expectedCigar = TextCigarCodec.decode(expectedCigarString); final Cigar actualCigar = AlignmentUtils.consolidateCigar(testCigar); Assert.assertEquals(actualCigar, expectedCigar); } @@ -766,8 +766,8 @@ public class AlignmentUtilsUnitTest { @Test(dataProvider = "TrimCigarData", enabled = ! DEBUG) public void testTrimCigar(final String cigarString, final int start, final int length, final String expectedCigarString) { - final Cigar cigar = TextCigarCodec.getSingleton().decode(cigarString); - final Cigar expectedCigar = TextCigarCodec.getSingleton().decode(expectedCigarString); + final Cigar cigar = TextCigarCodec.decode(cigarString); + final Cigar expectedCigar = TextCigarCodec.decode(expectedCigarString); final Cigar actualCigar = AlignmentUtils.trimCigarByReference(cigar, start, length); Assert.assertEquals(actualCigar, expectedCigar); } @@ -801,8 +801,8 @@ public class AlignmentUtilsUnitTest { @Test(dataProvider = "TrimCigarByBasesData", enabled = !DEBUG) public void testTrimCigarByBase(final String cigarString, final int start, final int length, final String expectedCigarString) { - final Cigar cigar = TextCigarCodec.getSingleton().decode(cigarString); - final Cigar expectedCigar = TextCigarCodec.getSingleton().decode(expectedCigarString); + final Cigar cigar = TextCigarCodec.decode(cigarString); + final Cigar expectedCigar = TextCigarCodec.decode(expectedCigarString); final Cigar actualCigar = AlignmentUtils.trimCigarByBases(cigar, start, length); Assert.assertEquals(actualCigar, expectedCigar); } @@ -853,9 +853,9 @@ public class AlignmentUtilsUnitTest { @Test(dataProvider = "ApplyCigarToCigarData", enabled = !DEBUG) public void testApplyCigarToCigar(final String firstToSecondString, final String secondToThirdString, final String expectedCigarString) { - final Cigar firstToSecond = TextCigarCodec.getSingleton().decode(firstToSecondString); - final Cigar secondToThird = TextCigarCodec.getSingleton().decode(secondToThirdString); - final Cigar expectedCigar = TextCigarCodec.getSingleton().decode(expectedCigarString); + final Cigar firstToSecond = TextCigarCodec.decode(firstToSecondString); + final Cigar secondToThird = TextCigarCodec.decode(secondToThirdString); + final Cigar expectedCigar = TextCigarCodec.decode(expectedCigarString); final Cigar actualCigar = AlignmentUtils.applyCigarToCigar(firstToSecond, secondToThird); Assert.assertEquals(actualCigar, expectedCigar); } @@ -909,7 +909,7 @@ public class AlignmentUtilsUnitTest { @Test(dataProvider = "ReadOffsetFromCigarData", enabled = !DEBUG) public void testReadOffsetFromCigar(final String cigarString, final int startOnCigar, final int expectedOffset) { - final Cigar cigar = TextCigarCodec.getSingleton().decode(cigarString); + final Cigar cigar = TextCigarCodec.decode(cigarString); final int actualOffset = AlignmentUtils.calcFirstBaseMatchingReferenceInCigar(cigar, startOnCigar); Assert.assertEquals(actualOffset, expectedOffset); } @@ -940,9 +940,9 @@ public class AlignmentUtilsUnitTest { @Test(dataProvider = "AddCigarElementsData", enabled = !DEBUG) public void testAddCigarElements(final String cigarString, final int pos, final int start, final int end, final String expectedCigarString) { - final Cigar cigar = TextCigarCodec.getSingleton().decode(cigarString); + final Cigar cigar = TextCigarCodec.decode(cigarString); final CigarElement elt = cigar.getCigarElement(0); - final Cigar expectedCigar = TextCigarCodec.getSingleton().decode(expectedCigarString); + final Cigar expectedCigar = TextCigarCodec.decode(expectedCigarString); final List elts = new LinkedList(); final int actualEndPos = AlignmentUtils.addCigarElements(elts, pos, start, end, elt); @@ -1000,7 +1000,7 @@ public class AlignmentUtilsUnitTest { @Test(dataProvider = "GetBasesCoveringRefIntervalData", enabled = true) public void testGetBasesCoveringRefInterval(final String basesString, final int refStart, final int refEnd, final String cigarString, final String expected) { - final byte[] actualBytes = AlignmentUtils.getBasesCoveringRefInterval(refStart, refEnd, basesString.getBytes(), 0, TextCigarCodec.getSingleton().decode(cigarString)); + final byte[] actualBytes = AlignmentUtils.getBasesCoveringRefInterval(refStart, refEnd, basesString.getBytes(), 0, TextCigarCodec.decode(cigarString)); if ( expected == null ) Assert.assertNull(actualBytes); else @@ -1031,13 +1031,13 @@ public class AlignmentUtilsUnitTest { @Test(dataProvider = "StartsOrEndsWithInsertionOrDeletionData", enabled = true) public void testStartsOrEndsWithInsertionOrDeletion(final String cigar, final boolean expected) { - Assert.assertEquals(AlignmentUtils.startsOrEndsWithInsertionOrDeletion(TextCigarCodec.getSingleton().decode(cigar)), expected); + Assert.assertEquals(AlignmentUtils.startsOrEndsWithInsertionOrDeletion(TextCigarCodec.decode(cigar)), expected); } @Test(dataProvider = "StartsOrEndsWithInsertionOrDeletionData", enabled = true) public void testRemoveTrailingDeletions(final String cigar, final boolean expected) { - final Cigar originalCigar = TextCigarCodec.getSingleton().decode(cigar); + final Cigar originalCigar = TextCigarCodec.decode(cigar); final Cigar newCigar = AlignmentUtils.removeTrailingDeletions(originalCigar); Assert.assertEquals(originalCigar.equals(newCigar), !cigar.endsWith("D"));