use of org.broadinstitute.hellbender.utils.haplotype.Haplotype in project gatk-protected by broadinstitute.
the class AssemblyResultSetUnitTest method testAddReferenceHaplotype.
@Test
public void testAddReferenceHaplotype() {
final Haplotype ref = new Haplotype("ACGT".getBytes(), true);
ref.setGenomeLocation(genomeLocParser.createGenomeLoc("1", 1, ref.length() + 1));
final AssemblyResultSet subject = new AssemblyResultSet();
Assert.assertTrue(subject.add(ref));
Assert.assertFalse(subject.add(ref));
Assert.assertEquals(subject.getReferenceHaplotype(), ref);
Assert.assertEquals(subject.getHaplotypeCount(), 1);
Assert.assertEquals(subject.getHaplotypeList().size(), 1);
}
use of org.broadinstitute.hellbender.utils.haplotype.Haplotype in project gatk-protected by broadinstitute.
the class AssemblyResultSetUnitTest method testTrimTo.
@Test(dataProvider = "trimmingData")
public void testTrimTo(final Map<Haplotype, AssemblyResult> haplotypesAndResultSets, final AssemblyRegion original) {
final AssemblyResultSet subject = new AssemblyResultSet();
for (final Map.Entry<Haplotype, AssemblyResult> entry : haplotypesAndResultSets.entrySet()) subject.add(entry.getKey(), entry.getValue());
subject.setRegionForGenotyping(original);
final SimpleInterval originalLocation = original.getExtendedSpan();
final int length = originalLocation.size();
final SimpleInterval newLocation = new SimpleInterval(originalLocation.getContig(), originalLocation.getStart() + length / 2, originalLocation.getEnd() - length / 2);
final AssemblyRegion newRegion = original.trim(newLocation);
final Map<Haplotype, Haplotype> originalHaplotypesByTrimmed = new HashMap<>(haplotypesAndResultSets.size());
for (final Haplotype h : haplotypesAndResultSets.keySet()) originalHaplotypesByTrimmed.put(h.trim(newRegion.getExtendedSpan()), h);
final AssemblyResultSet trimmed = subject.trimTo(newRegion);
Assert.assertFalse(subject.wasTrimmed());
Assert.assertTrue(trimmed.wasTrimmed());
for (final Haplotype h : trimmed.getHaplotypeList()) {
Assert.assertEquals(h.getGenomeLocation(), newLocation);
Assert.assertEquals(h.getBases().length, newLocation.size());
}
}
use of org.broadinstitute.hellbender.utils.haplotype.Haplotype in project gatk-protected by broadinstitute.
the class AssemblyResultSetUnitTest method testAddManyHaplotypes.
@Test(dataProvider = "assemblyResults")
public void testAddManyHaplotypes(final List<AssemblyResult> assemblyResults, final List<List<Haplotype>> haplotypes) {
final AssemblyResultSet subject = new AssemblyResultSet();
for (int i = 0; i < haplotypes.size(); i++) {
final int haplotypeCountBefore = subject.getHaplotypeCount();
final List<Haplotype> haplos = haplotypes.get(i);
final AssemblyResult ar = assemblyResults.get(i);
for (final Haplotype h : haplos) {
Assert.assertTrue(subject.add(h, ar));
Assert.assertFalse(subject.add(h, ar));
if (h.isReference())
Assert.assertEquals(subject.getReferenceHaplotype(), h);
}
final int haplotypeCountAfter = subject.getHaplotypeCount();
Assert.assertEquals(haplos.size(), haplotypeCountAfter - haplotypeCountBefore);
Assert.assertTrue(subject.getMaximumKmerSize() >= ar.getKmerSize());
Assert.assertTrue(subject.getMinimumKmerSize() <= ar.getKmerSize());
Assert.assertEquals(subject.getUniqueReadThreadingGraph(ar.getKmerSize()), ar.getThreadingGraph());
}
}
use of org.broadinstitute.hellbender.utils.haplotype.Haplotype in project gatk-protected by broadinstitute.
the class AssemblyRegionTestDataSet method expandAllHaplotypeCombinations.
private List<Haplotype> expandAllHaplotypeCombinations(final String civarString, final String reference) {
final Civar civar = Civar.fromCharSequence(civarString);
final List<Civar> unrolledCivars = civar.optionalizeAll().unroll();
List<Haplotype> result = new ArrayList<>(unrolledCivars.size());
for (final Civar c : unrolledCivars) {
final String baseString = c.applyTo(reference);
final Haplotype haplotype = new Haplotype(baseString.getBytes(), baseString.equals(reference));
haplotype.setGenomeLocation(genomeLocParser.createGenomeLoc("1", 1, reference.length()));
try {
haplotype.setCigar(c.toCigar(reference.length()));
} catch (final RuntimeException ex) {
c.applyTo(reference);
c.toCigar(reference.length());
throw new RuntimeException("" + c + " " + ex.getMessage(), ex);
}
result.add(haplotype);
}
return result;
}
use of org.broadinstitute.hellbender.utils.haplotype.Haplotype in project gatk by broadinstitute.
the class AssemblyBasedCallerUtils method assembleReads.
/**
* High-level function that runs the assembler on the given region's reads,
* returning a data structure with the resulting information needed
* for further HC steps
*/
public static AssemblyResultSet assembleReads(final AssemblyRegion region, final List<VariantContext> givenAlleles, final AssemblyBasedCallerArgumentCollection argumentCollection, final SAMFileHeader header, final SampleList sampleList, final Logger logger, final ReferenceSequenceFile referenceReader, final ReadThreadingAssembler assemblyEngine) {
finalizeRegion(region, argumentCollection.errorCorrectReads, argumentCollection.dontUseSoftClippedBases, (byte) (argumentCollection.minBaseQualityScore - 1), header, sampleList);
if (argumentCollection.debug) {
logger.info("Assembling " + region.getSpan() + " with " + region.size() + " reads: (with overlap region = " + region.getExtendedSpan() + ")");
}
final byte[] fullReferenceWithPadding = region.getAssemblyRegionReference(referenceReader, REFERENCE_PADDING_FOR_ASSEMBLY);
final SimpleInterval paddedReferenceLoc = getPaddedReferenceLoc(region, REFERENCE_PADDING_FOR_ASSEMBLY, referenceReader);
final Haplotype referenceHaplotype = createReferenceHaplotype(region, paddedReferenceLoc, referenceReader);
final ReadErrorCorrector readErrorCorrector = argumentCollection.errorCorrectReads ? new ReadErrorCorrector(argumentCollection.assemblerArgs.kmerLengthForReadErrorCorrection, HaplotypeCallerEngine.MIN_TAIL_QUALITY_WITH_ERROR_CORRECTION, argumentCollection.assemblerArgs.minObservationsForKmerToBeSolid, argumentCollection.debug, fullReferenceWithPadding) : null;
try {
final AssemblyResultSet assemblyResultSet = assemblyEngine.runLocalAssembly(region, referenceHaplotype, fullReferenceWithPadding, paddedReferenceLoc, givenAlleles, readErrorCorrector, header);
assemblyResultSet.debugDump(logger);
return assemblyResultSet;
} catch (final Exception e) {
// Capture any exception that might be thrown, and write out the assembly failure BAM if requested
if (argumentCollection.captureAssemblyFailureBAM) {
try (final SAMFileWriter writer = ReadUtils.createCommonSAMWriter(new File("assemblyFailure.bam"), null, header, false, false, false)) {
for (final GATKRead read : region.getReads()) {
writer.addAlignment(read.convertToSAMRecord(header));
}
}
}
throw e;
}
}
Aggregations