use of htsjdk.samtools.SAMFileHeader in project gatk by broadinstitute.
the class ReadUtilsUnitTest method testGetSamplesFromHeaderNoSamples.
@Test
public void testGetSamplesFromHeaderNoSamples() {
final SAMFileHeader header = ArtificialReadUtils.createArtificialSamHeader(5, 1, 100);
header.setReadGroups(Arrays.asList(new SAMReadGroupRecord("ReadGroup1")));
Assert.assertEquals(header.getReadGroups().size(), 1);
Assert.assertNull(header.getReadGroups().get(0).getSample());
Assert.assertTrue(ReadUtils.getSamplesFromHeader(header).isEmpty(), "Non-empty Set returned from ReadUtils.getSamplesFromHeader() for a header with no samples");
}
use of htsjdk.samtools.SAMFileHeader in project gatk by broadinstitute.
the class ReadUtilsUnitTest method testReadWithNsRefAfterDeletion.
@Test
public void testReadWithNsRefAfterDeletion() throws FileNotFoundException {
final IndexedFastaSequenceFile seq = new CachingIndexedFastaSequenceFile(new File(exampleReference));
final SAMFileHeader header = ArtificialReadUtils.createArtificialSamHeader(seq.getSequenceDictionary());
final int readLength = 76;
final GATKRead read = ArtificialReadUtils.createArtificialRead(header, "myRead", 0, 8975, readLength);
read.setBases(Utils.dupBytes((byte) 'A', readLength));
read.setBaseQualities(Utils.dupBytes((byte) 30, readLength));
read.setCigar("3M414N1D73M");
final int result = ReadUtils.getReadCoordinateForReferenceCoordinateUpToEndOfRead(read, 9393, ReadUtils.ClippingTail.LEFT_TAIL);
Assert.assertEquals(result, 3);
}
use of htsjdk.samtools.SAMFileHeader in project gatk by broadinstitute.
the class ReadUtilsUnitTest method testGetSamplesFromHeader.
@Test
public void testGetSamplesFromHeader() {
final SAMFileHeader header = ArtificialReadUtils.createArtificialSamHeader(5, 1, 100);
final List<SAMReadGroupRecord> readGroups = new ArrayList<>();
for (int i = 1; i <= 5; ++i) {
SAMReadGroupRecord readGroup = new SAMReadGroupRecord("ReadGroup" + i);
readGroup.setSample("Sample" + i);
readGroups.add(readGroup);
}
header.setReadGroups(readGroups);
final Set<String> samples = ReadUtils.getSamplesFromHeader(header);
Assert.assertEquals(samples.size(), 5, "Wrong number of samples returned from ReadUtils.getSamplesFromHeader()");
for (int i = 1; i <= 5; ++i) {
Assert.assertTrue(samples.contains("Sample" + i), "Missing Sample" + i + " in samples returned from ReadUtils.getSamplesFromHeader()");
}
}
use of htsjdk.samtools.SAMFileHeader in project gatk by broadinstitute.
the class CycleCovariateUnitTest method testMoreThanMaxCycleFails.
@Test(expectedExceptions = { UserException.class })
public void testMoreThanMaxCycleFails() {
final SAMFileHeader header = ArtificialReadUtils.createArtificialSamHeaderWithReadGroup(illuminaReadGroup);
int readLength = RAC.MAXIMUM_CYCLE_VALUE + 1;
GATKRead read = ArtificialReadUtils.createRandomRead(readLength);
read.setIsPaired(true);
read.setReadGroup(illuminaReadGroup.getReadGroupId());
ReadCovariates readCovariates = new ReadCovariates(read.getLength(), 1, new CovariateKeyCache());
covariate.recordValues(read, header, readCovariates, true);
}
use of htsjdk.samtools.SAMFileHeader in project gatk by broadinstitute.
the class ReadCovariatesUnitTest method testCovariateGeneration.
@Test
public void testCovariateGeneration() {
final RecalibrationArgumentCollection RAC = new RecalibrationArgumentCollection();
final String[] readGroups = { "RG1", "RG2", "RGbla" };
ReadGroupCovariate rgCov = new ReadGroupCovariate(RAC, Arrays.asList(readGroups));
QualityScoreCovariate qsCov = new QualityScoreCovariate(RAC);
ContextCovariate coCov = new ContextCovariate(RAC);
CycleCovariate cyCov = new CycleCovariate(RAC);
StandardCovariateList covariates = new StandardCovariateList(RAC, Arrays.asList(readGroups));
final int NUM_READS = 100;
final Random rnd = Utils.getRandomGenerator();
final CovariateKeyCache keyCache = new CovariateKeyCache();
for (int idx = 0; idx < NUM_READS; idx++) {
for (final String readGroupID : readGroups) {
final SAMReadGroupRecord readGroupRecord = new SAMReadGroupRecord(readGroupID);
readGroupRecord.setPlatform("illumina");
final SAMFileHeader header = ArtificialReadUtils.createArtificialSamHeaderWithReadGroup(readGroupRecord);
// random read length, at least 10 bp long
final int length = 10 + rnd.nextInt(100);
final GATKRead read = ArtificialReadUtils.createRandomRead(header, length, false);
read.setIsReverseStrand(rnd.nextBoolean());
read.setReadGroup(readGroupID);
final byte[] mQuals = read.getBaseQualities();
final byte[] iQuals = ReadUtils.getBaseInsertionQualities(read);
final byte[] dQuals = ReadUtils.getBaseDeletionQualities(read);
ReadCovariates rc = RecalUtils.computeCovariates(read, header, covariates, true, keyCache);
// check that the length is correct
Assert.assertEquals(rc.getMismatchesKeySet().length, length);
Assert.assertEquals(rc.getInsertionsKeySet().length, length);
Assert.assertEquals(rc.getDeletionsKeySet().length, length);
for (int i = 0; i < length; i++) {
// check that read group is always the same
Assert.assertEquals(rgCov.formatKey(rc.getMismatchesKeySet(i)[0]), readGroupID);
Assert.assertEquals(rgCov.formatKey(rc.getInsertionsKeySet(i)[0]), readGroupID);
Assert.assertEquals(rgCov.formatKey(rc.getDeletionsKeySet(i)[0]), readGroupID);
// check quality score
Assert.assertEquals(qsCov.formatKey(rc.getMismatchesKeySet(i)[1]), String.valueOf(mQuals[i]));
Assert.assertEquals(qsCov.formatKey(rc.getInsertionsKeySet(i)[1]), String.valueOf(iQuals[i]));
Assert.assertEquals(qsCov.formatKey(rc.getDeletionsKeySet(i)[1]), String.valueOf(dQuals[i]));
// check context
Assert.assertEquals(coCov.formatKey(rc.getMismatchesKeySet(i)[2]), ContextCovariateUnitTest.expectedContext(read, i, RAC.MISMATCHES_CONTEXT_SIZE, RAC.LOW_QUAL_TAIL), "read: " + idx + " readGroup:" + readGroupID + " context mismatch key at position:" + i);
Assert.assertEquals(coCov.formatKey(rc.getInsertionsKeySet(i)[2]), ContextCovariateUnitTest.expectedContext(read, i, RAC.INDELS_CONTEXT_SIZE, RAC.LOW_QUAL_TAIL), "read: " + idx + " readGroup:" + readGroupID + " context insertion key at position:" + i);
Assert.assertEquals(coCov.formatKey(rc.getDeletionsKeySet(i)[2]), ContextCovariateUnitTest.expectedContext(read, i, RAC.INDELS_CONTEXT_SIZE, RAC.LOW_QUAL_TAIL), "read: " + idx + " readGroup:" + readGroupID + " context deletion key at position:" + i);
// check cycle
final int expectedCycleMismatch = CycleCovariateUnitTest.expectedCycle(read, i, false, RAC.MAXIMUM_CYCLE_VALUE);
final int expectedCycleIndel = CycleCovariateUnitTest.expectedCycle(read, i, true, RAC.MAXIMUM_CYCLE_VALUE);
Assert.assertEquals(cyCov.formatKey(rc.getMismatchesKeySet(i)[3]), String.valueOf(expectedCycleMismatch), "read: " + idx + " cycle mismatch key at position:" + i);
Assert.assertEquals(cyCov.formatKey(rc.getInsertionsKeySet(i)[3]), String.valueOf(expectedCycleIndel), "read: " + idx + " cycle insertion key at position:" + i);
Assert.assertEquals(cyCov.formatKey(rc.getDeletionsKeySet(i)[3]), String.valueOf(expectedCycleIndel), "read: " + idx + " cycle deletion key at position:" + i);
}
}
}
}
Aggregations