Edits to work with the latest htsjdk release:
* TextCigarCodec.decode() is now static, and the getSingleton() method is gone * MergingSamRecordIterator now wants a Collection<SamReader> rather than Collection<SAMFileReader> in the constructor * SeekableBufferedStream now correctly reads the requested number of bytes, removed workaround in GATKBAMIndex
This commit is contained in:
parent
b73e9d506a
commit
6190d660e0
|
|
@ -269,8 +269,8 @@ public class LDMergerUnitTest extends BaseTest {
|
||||||
|
|
||||||
@Test(dataProvider = "R2MergerData")
|
@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) {
|
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 ref = new Haplotype(refS.getBytes(), true, 0, TextCigarCodec.decode(refS.length() + "M"));
|
||||||
final Haplotype hap = new Haplotype(hapS.getBytes(), false, 0, TextCigarCodec.getSingleton().decode(cigar));
|
final Haplotype hap = new Haplotype(hapS.getBytes(), false, 0, TextCigarCodec.decode(cigar));
|
||||||
final GenomeLoc loc = new UnvalidatingGenomeLoc("1", 0, 1, ref.length());
|
final GenomeLoc loc = new UnvalidatingGenomeLoc("1", 0, 1, ref.length());
|
||||||
|
|
||||||
final List<Haplotype> haplotypes = Arrays.asList(ref, hap);
|
final List<Haplotype> haplotypes = Arrays.asList(ref, hap);
|
||||||
|
|
@ -294,9 +294,9 @@ public class LDMergerUnitTest extends BaseTest {
|
||||||
final String refS = "ACGT";
|
final String refS = "ACGT";
|
||||||
final String hapS = "CCGA";
|
final String hapS = "CCGA";
|
||||||
final String cigar = "4M";
|
final String cigar = "4M";
|
||||||
final Haplotype ref = new Haplotype(refS.getBytes(), true, 0, TextCigarCodec.getSingleton().decode(refS.length() + "M"));
|
final Haplotype ref = new Haplotype(refS.getBytes(), true, 0, TextCigarCodec.decode(refS.length() + "M"));
|
||||||
final Haplotype hap1 = new Haplotype(hapS.getBytes(), false, 0, TextCigarCodec.getSingleton().decode(cigar));
|
final Haplotype hap1 = new Haplotype(hapS.getBytes(), false, 0, TextCigarCodec.decode(cigar));
|
||||||
final Haplotype hap2 = new Haplotype("ACGA".getBytes(), false, 0, TextCigarCodec.getSingleton().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 GenomeLoc loc = new UnvalidatingGenomeLoc("1", 0, 1, ref.length());
|
||||||
|
|
||||||
final List<Haplotype> haplotypes = Arrays.asList(ref, hap1, hap2);
|
final List<Haplotype> haplotypes = Arrays.asList(ref, hap1, hap2);
|
||||||
|
|
@ -321,12 +321,12 @@ public class LDMergerUnitTest extends BaseTest {
|
||||||
final String refS = "ACGT";
|
final String refS = "ACGT";
|
||||||
final String hapS = "TCGA";
|
final String hapS = "TCGA";
|
||||||
final String cigar = "4M";
|
final String cigar = "4M";
|
||||||
final Haplotype ref = new Haplotype(refS.getBytes(), true, 0, TextCigarCodec.getSingleton().decode(refS.length() + "M"));
|
final Haplotype ref = new Haplotype(refS.getBytes(), true, 0, TextCigarCodec.decode(refS.length() + "M"));
|
||||||
final Haplotype hap1 = new Haplotype(hapS.getBytes(), false, 0, TextCigarCodec.getSingleton().decode(cigar));
|
final Haplotype hap1 = new Haplotype(hapS.getBytes(), false, 0, TextCigarCodec.decode(cigar));
|
||||||
|
|
||||||
final GenomeLoc loc = new UnvalidatingGenomeLoc("1", 0, 1, ref.length());
|
final GenomeLoc loc = new UnvalidatingGenomeLoc("1", 0, 1, ref.length());
|
||||||
for (final String hap2S : Arrays.asList("GCGA", "TCGG")) {
|
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<Haplotype> haplotypes = Arrays.asList(ref, hap1, hap2);
|
final List<Haplotype> haplotypes = Arrays.asList(ref, hap1, hap2);
|
||||||
final TreeSet<Integer> vcStarts = EventMap.buildEventMapsForHaplotypes(haplotypes, ref.getBases(), loc, false);
|
final TreeSet<Integer> vcStarts = EventMap.buildEventMapsForHaplotypes(haplotypes, ref.getBases(), loc, false);
|
||||||
|
|
|
||||||
|
|
@ -452,7 +452,7 @@ public class KBestHaplotypeFinderUnitTest extends BaseTest {
|
||||||
Cigar expected = new Cigar();
|
Cigar expected = new Cigar();
|
||||||
expected.add(new CigarElement(padSize, CigarOperator.M));
|
expected.add(new CigarElement(padSize, CigarOperator.M));
|
||||||
if ( ! prefix.equals("") ) expected.add(new CigarElement(prefix.length(), 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));
|
if ( ! end.equals("") ) expected.add(new CigarElement(end.length(), CigarOperator.M));
|
||||||
expected.add(new CigarElement(padSize, CigarOperator.M));
|
expected.add(new CigarElement(padSize, CigarOperator.M));
|
||||||
expected = AlignmentUtils.consolidateCigar(expected);
|
expected = AlignmentUtils.consolidateCigar(expected);
|
||||||
|
|
@ -513,7 +513,7 @@ public class KBestHaplotypeFinderUnitTest extends BaseTest {
|
||||||
public void testLeftAlignCigarSequentiallyAdjacentID() {
|
public void testLeftAlignCigarSequentiallyAdjacentID() {
|
||||||
final String ref = "GTCTCTCTCTCTCTCTCTATATATATATATATATTT";
|
final String ref = "GTCTCTCTCTCTCTCTCTATATATATATATATATTT";
|
||||||
final String hap = "GTCTCTCTCTCTCTCTCTCTCTATATATATATATTT";
|
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);
|
final Cigar result = CigarUtils.leftAlignCigarSequentially(originalCigar, ref.getBytes(), hap.getBytes(), 0, 0);
|
||||||
logger.warn("Result is " + result);
|
logger.warn("Result is " + result);
|
||||||
|
|
|
||||||
|
|
@ -82,7 +82,7 @@ public class HaplotypeBAMWriterUnitTest extends BaseTest {
|
||||||
|
|
||||||
private Haplotype makeHaplotype(final String bases, final String cigar) {
|
private Haplotype makeHaplotype(final String bases, final String cigar) {
|
||||||
final Haplotype hap = new Haplotype(bases.getBytes());
|
final Haplotype hap = new Haplotype(bases.getBytes());
|
||||||
hap.setCigar(TextCigarCodec.getSingleton().decode(cigar));
|
hap.setCigar(TextCigarCodec.decode(cigar));
|
||||||
return hap;
|
return hap;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -160,7 +160,7 @@ public class HaplotypeBAMWriterUnitTest extends BaseTest {
|
||||||
final String badCigar = "31M6D211M";
|
final String badCigar = "31M6D211M";
|
||||||
final String goodCigar = "28M6D214M";
|
final String goodCigar = "28M6D214M";
|
||||||
final Haplotype badHap = new Haplotype(hap.getBytes());
|
final Haplotype badHap = new Haplotype(hap.getBytes());
|
||||||
badHap.setCigar(TextCigarCodec.getSingleton().decode(hapCigar));
|
badHap.setCigar(TextCigarCodec.decode(hapCigar));
|
||||||
badHap.setAlignmentStartHapwrtRef(hapStart);
|
badHap.setAlignmentStartHapwrtRef(hapStart);
|
||||||
|
|
||||||
final int expectedPos = 10130740;
|
final int expectedPos = 10130740;
|
||||||
|
|
@ -179,7 +179,7 @@ public class HaplotypeBAMWriterUnitTest extends BaseTest {
|
||||||
if ( expectedReadCigar == null ) {
|
if ( expectedReadCigar == null ) {
|
||||||
Assert.assertNull(AlignmentUtils.createReadAlignedToRef(read, haplotype, haplotype, refStart, true));
|
Assert.assertNull(AlignmentUtils.createReadAlignedToRef(read, haplotype, haplotype, refStart, true));
|
||||||
} else {
|
} else {
|
||||||
final Cigar expectedCigar = TextCigarCodec.getSingleton().decode(expectedReadCigar);
|
final Cigar expectedCigar = TextCigarCodec.decode(expectedReadCigar);
|
||||||
final GATKSAMRecord alignedRead = AlignmentUtils.createReadAlignedToRef(read, haplotype, haplotype, refStart, true);
|
final GATKSAMRecord alignedRead = AlignmentUtils.createReadAlignedToRef(read, haplotype, haplotype, refStart, true);
|
||||||
|
|
||||||
Assert.assertEquals(alignedRead.getReadName(), originalReadCopy.getReadName());
|
Assert.assertEquals(alignedRead.getReadName(), originalReadCopy.getReadName());
|
||||||
|
|
|
||||||
|
|
@ -363,6 +363,8 @@ public class GATKBAMIndex {
|
||||||
|
|
||||||
private void read(final ByteBuffer buffer) {
|
private void read(final ByteBuffer buffer) {
|
||||||
final int bytesRequested = buffer.limit();
|
final int bytesRequested = buffer.limit();
|
||||||
|
if (bytesRequested == 0)
|
||||||
|
return;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
|
||||||
|
|
@ -379,25 +381,19 @@ public class GATKBAMIndex {
|
||||||
mFile));
|
mFile));
|
||||||
}
|
}
|
||||||
|
|
||||||
int totalBytesRead = 0;
|
int bytesRead = bufferedStream.read(byteArray, 0, bytesRequested);
|
||||||
// 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);
|
|
||||||
|
|
||||||
// We have a rigid expectation here to read in exactly the number of bytes we've limited
|
// 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
|
// our buffer to -- if we encounter EOF (-1), the index
|
||||||
// must be truncated or otherwise corrupt:
|
// must be truncated or otherwise corrupt:
|
||||||
if (bytesRead <= 0) {
|
if (bytesRead <= 0) {
|
||||||
throw new UserException.MalformedFile(mFile, String.format("Premature end-of-file while reading BAM index file %s. " +
|
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 -- " +
|
"It's likely that this file is truncated or corrupt -- " +
|
||||||
"Please try re-indexing the corresponding BAM file.",
|
"Please try re-indexing the corresponding BAM file.",
|
||||||
mFile));
|
mFile));
|
||||||
}
|
|
||||||
totalBytesRead += bytesRead;
|
|
||||||
}
|
}
|
||||||
if(totalBytesRead != bytesRequested)
|
|
||||||
|
if(bytesRead != bytesRequested)
|
||||||
throw new RuntimeException("Read amount different from requested amount. This should not happen.");
|
throw new RuntimeException("Read amount different from requested amount. This should not happen.");
|
||||||
|
|
||||||
buffer.put(byteArray, 0, bytesRequested);
|
buffer.put(byteArray, 0, bytesRequested);
|
||||||
|
|
@ -435,7 +431,7 @@ public class GATKBAMIndex {
|
||||||
long skipped = bufferedStream.skip(count);
|
long skipped = bufferedStream.skip(count);
|
||||||
|
|
||||||
if( skipped != count ) { //if not managed to skip the requested amount
|
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) {
|
catch(IOException ex) {
|
||||||
|
|
|
||||||
|
|
@ -564,7 +564,7 @@ public class SAMDataSource {
|
||||||
*/
|
*/
|
||||||
private GATKSAMIterator getIterator(SAMReaders readers, Shard shard, boolean enableVerification) {
|
private GATKSAMIterator getIterator(SAMReaders readers, Shard shard, boolean enableVerification) {
|
||||||
// Set up merging to dynamically merge together multiple BAMs.
|
// Set up merging to dynamically merge together multiple BAMs.
|
||||||
Map<SAMFileReader,CloseableIterator<SAMRecord>> iteratorMap = new HashMap<SAMFileReader,CloseableIterator<SAMRecord>>();
|
Map<SamReader,CloseableIterator<SAMRecord>> iteratorMap = new HashMap<>();
|
||||||
|
|
||||||
for(SAMReaderID id: getReaderIDs()) {
|
for(SAMReaderID id: getReaderIDs()) {
|
||||||
CloseableIterator<SAMRecord> iterator = null;
|
CloseableIterator<SAMRecord> iterator = null;
|
||||||
|
|
@ -1000,7 +1000,7 @@ public class SAMDataSource {
|
||||||
* @param iteratorMap A map of readers to iterators.
|
* @param iteratorMap A map of readers to iterators.
|
||||||
* @return An iterator which will merge those individual iterators.
|
* @return An iterator which will merge those individual iterators.
|
||||||
*/
|
*/
|
||||||
public MergingSamRecordIterator createMergingIterator(final Map<SAMFileReader,CloseableIterator<SAMRecord>> iteratorMap) {
|
public MergingSamRecordIterator createMergingIterator(final Map<SamReader,CloseableIterator<SAMRecord>> iteratorMap) {
|
||||||
return new MergingSamRecordIterator(headerMerger,iteratorMap,true);
|
return new MergingSamRecordIterator(headerMerger,iteratorMap,true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -28,7 +28,6 @@ package org.broadinstitute.gatk.engine.datasources.reads;
|
||||||
import htsjdk.samtools.seekablestream.SeekableBufferedStream;
|
import htsjdk.samtools.seekablestream.SeekableBufferedStream;
|
||||||
import htsjdk.samtools.seekablestream.SeekableFileStream;
|
import htsjdk.samtools.seekablestream.SeekableFileStream;
|
||||||
import org.broadinstitute.gatk.utils.BaseTest;
|
import org.broadinstitute.gatk.utils.BaseTest;
|
||||||
import org.broadinstitute.gatk.utils.exceptions.GATKException;
|
|
||||||
import org.testng.Assert;
|
import org.testng.Assert;
|
||||||
import org.testng.annotations.DataProvider;
|
import org.testng.annotations.DataProvider;
|
||||||
import org.testng.annotations.Test;
|
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.
|
// 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,
|
// 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.
|
// 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)
|
@Test(dataProvider = "BasicArgumentsIndivisibleAndSmall", enabled = true)
|
||||||
public void testIndivisableSmallReadsFAIL(Integer readLength) throws IOException {
|
public void testIndivisableSmallReadsPASS(Integer readLength) throws IOException {
|
||||||
testReadsLength(readLength);
|
testReadsLength(readLength);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -117,7 +117,7 @@ public class MalformedReadFilterUnitTest extends ReadFilterTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
protected SAMRecord buildSAMRecord(final String cigarString) {
|
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);
|
return this.createRead(nContainingCigar, 1, 0, 10);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -40,7 +40,7 @@ public class ReadFormattingIteratorUnitTest extends BaseTest {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testIteratorConsolidatesCigars() {
|
public void testIteratorConsolidatesCigars() {
|
||||||
final Cigar unconsolidatedCigar = TextCigarCodec.getSingleton().decode("3M0M5M0M");
|
final Cigar unconsolidatedCigar = TextCigarCodec.decode("3M0M5M0M");
|
||||||
final SAMRecord unconsolidatedRead = ArtificialSAMUtils.createArtificialRead(unconsolidatedCigar);
|
final SAMRecord unconsolidatedRead = ArtificialSAMUtils.createArtificialRead(unconsolidatedCigar);
|
||||||
|
|
||||||
final GATKSAMIterator readIterator = GATKSAMIteratorAdapter.adapt(Arrays.asList(unconsolidatedRead).iterator());
|
final GATKSAMIterator readIterator = GATKSAMIteratorAdapter.adapt(Arrays.asList(unconsolidatedRead).iterator());
|
||||||
|
|
|
||||||
|
|
@ -95,7 +95,7 @@ public class SAMReadCodec extends AsciiFeatureCodec<SAMReadFeature> {
|
||||||
final byte[] qualities = StringUtil.stringToBytes(tokens[10]);
|
final byte[] qualities = StringUtil.stringToBytes(tokens[10]);
|
||||||
|
|
||||||
// Infer the alignment end.
|
// Infer the alignment end.
|
||||||
Cigar cigar = TextCigarCodec.getSingleton().decode(cigarString);
|
Cigar cigar = TextCigarCodec.decode(cigarString);
|
||||||
int alignmentEnd = alignmentStart + cigar.getReferenceLength() - 1;
|
int alignmentEnd = alignmentStart + cigar.getReferenceLength() - 1;
|
||||||
|
|
||||||
// Remove printable character conversion from the qualities.
|
// Remove printable character conversion from the qualities.
|
||||||
|
|
|
||||||
|
|
@ -28,7 +28,7 @@ package org.broadinstitute.gatk.utils.sam;
|
||||||
import htsjdk.samtools.MergingSamRecordIterator;
|
import htsjdk.samtools.MergingSamRecordIterator;
|
||||||
import htsjdk.samtools.SamFileHeaderMerger;
|
import htsjdk.samtools.SamFileHeaderMerger;
|
||||||
import htsjdk.samtools.SAMFileHeader;
|
import htsjdk.samtools.SAMFileHeader;
|
||||||
import htsjdk.samtools.SAMFileReader;
|
import htsjdk.samtools.SamReader;
|
||||||
import htsjdk.samtools.SAMRecord;
|
import htsjdk.samtools.SAMRecord;
|
||||||
import org.broadinstitute.gatk.utils.iterators.GATKSAMIterator;
|
import org.broadinstitute.gatk.utils.iterators.GATKSAMIterator;
|
||||||
import org.broadinstitute.gatk.utils.iterators.GATKSAMIteratorAdapter;
|
import org.broadinstitute.gatk.utils.iterators.GATKSAMIteratorAdapter;
|
||||||
|
|
@ -69,13 +69,13 @@ public class ArtificialMultiSampleReadStream implements Iterable<SAMRecord> {
|
||||||
}
|
}
|
||||||
|
|
||||||
private void initialize() {
|
private void initialize() {
|
||||||
Collection<SAMFileReader> perSampleSAMReaders = new ArrayList<SAMFileReader>(perSampleArtificialReadStreams.size());
|
Collection<SamReader> perSampleSAMReaders = new ArrayList<>(perSampleArtificialReadStreams.size());
|
||||||
Collection<SAMFileHeader> headers = new ArrayList<SAMFileHeader>(perSampleArtificialReadStreams.size());
|
Collection<SAMFileHeader> headers = new ArrayList<>(perSampleArtificialReadStreams.size());
|
||||||
|
|
||||||
for ( ArtificialSingleSampleReadStream readStream : perSampleArtificialReadStreams ) {
|
for ( ArtificialSingleSampleReadStream readStream : perSampleArtificialReadStreams ) {
|
||||||
Collection<SAMRecord> thisStreamReads = readStream.makeReads();
|
Collection<SAMRecord> thisStreamReads = readStream.makeReads();
|
||||||
|
|
||||||
SAMFileReader reader = new ArtificialSAMFileReader(readStream.getHeader(),
|
ArtificialSAMFileReader reader = new ArtificialSAMFileReader(readStream.getHeader(),
|
||||||
thisStreamReads.toArray(new SAMRecord[thisStreamReads.size()]));
|
thisStreamReads.toArray(new SAMRecord[thisStreamReads.size()]));
|
||||||
perSampleSAMReaders.add(reader);
|
perSampleSAMReaders.add(reader);
|
||||||
headers.add(reader.getFileHeader());
|
headers.add(reader.getFileHeader());
|
||||||
|
|
|
||||||
|
|
@ -104,7 +104,7 @@ public class CigarUtils {
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Cigar cigarFromString(String cigarString) {
|
public static Cigar cigarFromString(String cigarString) {
|
||||||
return TextCigarCodec.getSingleton().decode(cigarString);
|
return TextCigarCodec.decode(cigarString);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
||||||
|
|
@ -336,7 +336,7 @@ public class FragmentUtilsUnitTest extends BaseTest {
|
||||||
final int readLen = pre + contigLen + post;
|
final int readLen = pre + contigLen + post;
|
||||||
final GATKSAMRecord read = ArtificialSAMUtils.createArtificialRead(header, "read1", 0, 1, readLen);
|
final GATKSAMRecord read = ArtificialSAMUtils.createArtificialRead(header, "read1", 0, 1, readLen);
|
||||||
read.setAlignmentStart(1);
|
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.setBaseQualities(Utils.dupBytes((byte) 30, readLen));
|
||||||
read.setReadBases(Utils.dupBytes((byte)'A', readLen));
|
read.setReadBases(Utils.dupBytes((byte)'A', readLen));
|
||||||
read.setMappingQuality(60);
|
read.setMappingQuality(60);
|
||||||
|
|
|
||||||
|
|
@ -127,7 +127,7 @@ public class EventMapUnitTest extends BaseTest {
|
||||||
*/
|
*/
|
||||||
@Test(dataProvider = "BlockSubstitutionsData")
|
@Test(dataProvider = "BlockSubstitutionsData")
|
||||||
public void testBlockSubstitutionsData(final String refBases, final String haplotypeBases, final String cigar, final VariantContext expectedBlock) {
|
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 GenomeLoc loc = new UnvalidatingGenomeLoc(CHR, 0, 1, refBases.length());
|
||||||
final EventMap ee = new EventMap(hap, refBases.getBytes(), loc, NAME);
|
final EventMap ee = new EventMap(hap, refBases.getBytes(), loc, NAME);
|
||||||
ee.replaceClumpedEventsWithBlockSubstitutions();
|
ee.replaceClumpedEventsWithBlockSubstitutions();
|
||||||
|
|
@ -156,7 +156,7 @@ public class EventMapUnitTest extends BaseTest {
|
||||||
*/
|
*/
|
||||||
@Test(dataProvider = "AdjacentSNPIndelTest")
|
@Test(dataProvider = "AdjacentSNPIndelTest")
|
||||||
public void testAdjacentSNPIndelTest(final String refBases, final String haplotypeBases, final String cigar, final List<List<String>> expectedAlleles) {
|
public void testAdjacentSNPIndelTest(final String refBases, final String haplotypeBases, final String cigar, final List<List<String>> 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 GenomeLoc loc = new UnvalidatingGenomeLoc(CHR, 0, 1, refBases.length());
|
||||||
final EventMap ee = new EventMap(hap, refBases.getBytes(), loc, NAME);
|
final EventMap ee = new EventMap(hap, refBases.getBytes(), loc, NAME);
|
||||||
ee.replaceClumpedEventsWithBlockSubstitutions();
|
ee.replaceClumpedEventsWithBlockSubstitutions();
|
||||||
|
|
|
||||||
|
|
@ -167,7 +167,7 @@ public class HaplotypeUnitTest extends BaseTest {
|
||||||
|
|
||||||
private Haplotype makeHCForCigar(final String bases, final String cigar) {
|
private Haplotype makeHCForCigar(final String bases, final String cigar) {
|
||||||
final Haplotype h = new Haplotype(bases.getBytes());
|
final Haplotype h = new Haplotype(bases.getBytes());
|
||||||
h.setCigar(TextCigarCodec.getSingleton().decode(cigar));
|
h.setCigar(TextCigarCodec.decode(cigar));
|
||||||
return h;
|
return h;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -201,10 +201,10 @@ public class HaplotypeUnitTest extends BaseTest {
|
||||||
|
|
||||||
final int hapStart = 10;
|
final int hapStart = 10;
|
||||||
full.setAlignmentStartHapwrtRef(hapStart);
|
full.setAlignmentStartHapwrtRef(hapStart);
|
||||||
full.setCigar(TextCigarCodec.getSingleton().decode(full.length() + "M"));
|
full.setCigar(TextCigarCodec.decode(full.length() + "M"));
|
||||||
|
|
||||||
trimmed.setAlignmentStartHapwrtRef(hapStart + start);
|
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});
|
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));
|
final Haplotype full = new Haplotype("ACT".getBytes(), new UnvalidatingGenomeLoc("20", 0, 10, 14));
|
||||||
full.setAlignmentStartHapwrtRef(10);
|
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, 11, 12), null});
|
||||||
tests.add(new Object[]{full, new UnvalidatingGenomeLoc("20", 0, 10, 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});
|
tests.add(new Object[]{full, new UnvalidatingGenomeLoc("20", 0, 11, 13), null});
|
||||||
|
|
|
||||||
|
|
@ -98,7 +98,7 @@ public class LocusIteratorByStateBaseTest extends BaseTest {
|
||||||
final private List<CigarElement> elements;
|
final private List<CigarElement> elements;
|
||||||
|
|
||||||
public LIBSTest(final String cigarString) {
|
public LIBSTest(final String cigarString) {
|
||||||
final Cigar cigar = TextCigarCodec.getSingleton().decode(cigarString);
|
final Cigar cigar = TextCigarCodec.decode(cigarString);
|
||||||
this.cigarString = cigarString;
|
this.cigarString = cigarString;
|
||||||
this.elements = cigar.getCigarElements();
|
this.elements = cigar.getCigarElements();
|
||||||
this.readLength = cigar.getReadLength();
|
this.readLength = cigar.getReadLength();
|
||||||
|
|
|
||||||
|
|
@ -168,7 +168,7 @@ public class AlignmentUtilsUnitTest {
|
||||||
|
|
||||||
@Test(enabled = true, dataProvider = "CalcNumDifferentBasesData")
|
@Test(enabled = true, dataProvider = "CalcNumDifferentBasesData")
|
||||||
public void testCalcNumDifferentBases(final String cigarString, final String ref, final String read, final int expectedDifferences) {
|
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);
|
Assert.assertEquals(AlignmentUtils.calcNumDifferentBases(cigar, ref.getBytes(), read.getBytes()), expectedDifferences);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -299,8 +299,8 @@ public class AlignmentUtilsUnitTest {
|
||||||
|
|
||||||
@Test(enabled = !DEBUG, dataProvider = "ConsolidateCigarData")
|
@Test(enabled = !DEBUG, dataProvider = "ConsolidateCigarData")
|
||||||
public void testConsolidateCigarWithData(final String testCigarString, final String expectedCigarString) {
|
public void testConsolidateCigarWithData(final String testCigarString, final String expectedCigarString) {
|
||||||
final Cigar testCigar = TextCigarCodec.getSingleton().decode(testCigarString);
|
final Cigar testCigar = TextCigarCodec.decode(testCigarString);
|
||||||
final Cigar expectedCigar = TextCigarCodec.getSingleton().decode(expectedCigarString);
|
final Cigar expectedCigar = TextCigarCodec.decode(expectedCigarString);
|
||||||
final Cigar actualCigar = AlignmentUtils.consolidateCigar(testCigar);
|
final Cigar actualCigar = AlignmentUtils.consolidateCigar(testCigar);
|
||||||
Assert.assertEquals(actualCigar, expectedCigar);
|
Assert.assertEquals(actualCigar, expectedCigar);
|
||||||
}
|
}
|
||||||
|
|
@ -766,8 +766,8 @@ public class AlignmentUtilsUnitTest {
|
||||||
|
|
||||||
@Test(dataProvider = "TrimCigarData", enabled = ! DEBUG)
|
@Test(dataProvider = "TrimCigarData", enabled = ! DEBUG)
|
||||||
public void testTrimCigar(final String cigarString, final int start, final int length, final String expectedCigarString) {
|
public void testTrimCigar(final String cigarString, final int start, final int length, final String expectedCigarString) {
|
||||||
final Cigar cigar = TextCigarCodec.getSingleton().decode(cigarString);
|
final Cigar cigar = TextCigarCodec.decode(cigarString);
|
||||||
final Cigar expectedCigar = TextCigarCodec.getSingleton().decode(expectedCigarString);
|
final Cigar expectedCigar = TextCigarCodec.decode(expectedCigarString);
|
||||||
final Cigar actualCigar = AlignmentUtils.trimCigarByReference(cigar, start, length);
|
final Cigar actualCigar = AlignmentUtils.trimCigarByReference(cigar, start, length);
|
||||||
Assert.assertEquals(actualCigar, expectedCigar);
|
Assert.assertEquals(actualCigar, expectedCigar);
|
||||||
}
|
}
|
||||||
|
|
@ -801,8 +801,8 @@ public class AlignmentUtilsUnitTest {
|
||||||
|
|
||||||
@Test(dataProvider = "TrimCigarByBasesData", enabled = !DEBUG)
|
@Test(dataProvider = "TrimCigarByBasesData", enabled = !DEBUG)
|
||||||
public void testTrimCigarByBase(final String cigarString, final int start, final int length, final String expectedCigarString) {
|
public void testTrimCigarByBase(final String cigarString, final int start, final int length, final String expectedCigarString) {
|
||||||
final Cigar cigar = TextCigarCodec.getSingleton().decode(cigarString);
|
final Cigar cigar = TextCigarCodec.decode(cigarString);
|
||||||
final Cigar expectedCigar = TextCigarCodec.getSingleton().decode(expectedCigarString);
|
final Cigar expectedCigar = TextCigarCodec.decode(expectedCigarString);
|
||||||
final Cigar actualCigar = AlignmentUtils.trimCigarByBases(cigar, start, length);
|
final Cigar actualCigar = AlignmentUtils.trimCigarByBases(cigar, start, length);
|
||||||
Assert.assertEquals(actualCigar, expectedCigar);
|
Assert.assertEquals(actualCigar, expectedCigar);
|
||||||
}
|
}
|
||||||
|
|
@ -853,9 +853,9 @@ public class AlignmentUtilsUnitTest {
|
||||||
|
|
||||||
@Test(dataProvider = "ApplyCigarToCigarData", enabled = !DEBUG)
|
@Test(dataProvider = "ApplyCigarToCigarData", enabled = !DEBUG)
|
||||||
public void testApplyCigarToCigar(final String firstToSecondString, final String secondToThirdString, final String expectedCigarString) {
|
public void testApplyCigarToCigar(final String firstToSecondString, final String secondToThirdString, final String expectedCigarString) {
|
||||||
final Cigar firstToSecond = TextCigarCodec.getSingleton().decode(firstToSecondString);
|
final Cigar firstToSecond = TextCigarCodec.decode(firstToSecondString);
|
||||||
final Cigar secondToThird = TextCigarCodec.getSingleton().decode(secondToThirdString);
|
final Cigar secondToThird = TextCigarCodec.decode(secondToThirdString);
|
||||||
final Cigar expectedCigar = TextCigarCodec.getSingleton().decode(expectedCigarString);
|
final Cigar expectedCigar = TextCigarCodec.decode(expectedCigarString);
|
||||||
final Cigar actualCigar = AlignmentUtils.applyCigarToCigar(firstToSecond, secondToThird);
|
final Cigar actualCigar = AlignmentUtils.applyCigarToCigar(firstToSecond, secondToThird);
|
||||||
Assert.assertEquals(actualCigar, expectedCigar);
|
Assert.assertEquals(actualCigar, expectedCigar);
|
||||||
}
|
}
|
||||||
|
|
@ -909,7 +909,7 @@ public class AlignmentUtilsUnitTest {
|
||||||
|
|
||||||
@Test(dataProvider = "ReadOffsetFromCigarData", enabled = !DEBUG)
|
@Test(dataProvider = "ReadOffsetFromCigarData", enabled = !DEBUG)
|
||||||
public void testReadOffsetFromCigar(final String cigarString, final int startOnCigar, final int expectedOffset) {
|
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);
|
final int actualOffset = AlignmentUtils.calcFirstBaseMatchingReferenceInCigar(cigar, startOnCigar);
|
||||||
Assert.assertEquals(actualOffset, expectedOffset);
|
Assert.assertEquals(actualOffset, expectedOffset);
|
||||||
}
|
}
|
||||||
|
|
@ -940,9 +940,9 @@ public class AlignmentUtilsUnitTest {
|
||||||
|
|
||||||
@Test(dataProvider = "AddCigarElementsData", enabled = !DEBUG)
|
@Test(dataProvider = "AddCigarElementsData", enabled = !DEBUG)
|
||||||
public void testAddCigarElements(final String cigarString, final int pos, final int start, final int end, final String expectedCigarString) {
|
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 CigarElement elt = cigar.getCigarElement(0);
|
||||||
final Cigar expectedCigar = TextCigarCodec.getSingleton().decode(expectedCigarString);
|
final Cigar expectedCigar = TextCigarCodec.decode(expectedCigarString);
|
||||||
|
|
||||||
final List<CigarElement> elts = new LinkedList<CigarElement>();
|
final List<CigarElement> elts = new LinkedList<CigarElement>();
|
||||||
final int actualEndPos = AlignmentUtils.addCigarElements(elts, pos, start, end, elt);
|
final int actualEndPos = AlignmentUtils.addCigarElements(elts, pos, start, end, elt);
|
||||||
|
|
@ -1000,7 +1000,7 @@ public class AlignmentUtilsUnitTest {
|
||||||
|
|
||||||
@Test(dataProvider = "GetBasesCoveringRefIntervalData", enabled = true)
|
@Test(dataProvider = "GetBasesCoveringRefIntervalData", enabled = true)
|
||||||
public void testGetBasesCoveringRefInterval(final String basesString, final int refStart, final int refEnd, final String cigarString, final String expected) {
|
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 )
|
if ( expected == null )
|
||||||
Assert.assertNull(actualBytes);
|
Assert.assertNull(actualBytes);
|
||||||
else
|
else
|
||||||
|
|
@ -1031,13 +1031,13 @@ public class AlignmentUtilsUnitTest {
|
||||||
|
|
||||||
@Test(dataProvider = "StartsOrEndsWithInsertionOrDeletionData", enabled = true)
|
@Test(dataProvider = "StartsOrEndsWithInsertionOrDeletionData", enabled = true)
|
||||||
public void testStartsOrEndsWithInsertionOrDeletion(final String cigar, final boolean expected) {
|
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)
|
@Test(dataProvider = "StartsOrEndsWithInsertionOrDeletionData", enabled = true)
|
||||||
public void testRemoveTrailingDeletions(final String cigar, final boolean expected) {
|
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);
|
final Cigar newCigar = AlignmentUtils.removeTrailingDeletions(originalCigar);
|
||||||
|
|
||||||
Assert.assertEquals(originalCigar.equals(newCigar), !cigar.endsWith("D"));
|
Assert.assertEquals(originalCigar.equals(newCigar), !cigar.endsWith("D"));
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue