Search in sources :

Example 1 with AutoClosingIterator

use of au.edu.wehi.idsv.util.AutoClosingIterator in project gridss by PapenfussLab.

the class AllocateEvidenceTest method should_annotate_reads.

@Test
public void should_annotate_reads() throws IOException {
    final ProcessingContext pc = getCommandlineContext();
    pc.getVariantCallingParameters().minScore = 0;
    pc.getVariantCallingParameters().minSize = 0;
    createInput(RP(0, 1, 10), DP(0, 1, "5M5S", true, 1, 10, "5M", true), DP(0, 2, "5M5S", true, 1, 10, "5M", true));
    SAMEvidenceSource ses = new SAMEvidenceSource(getContext(), input, null, 0);
    ses.ensureMetrics();
    File assemblyFile = new File(testFolder.getRoot(), "assembly.bam");
    AssemblyEvidenceSource aes = new AssemblyEvidenceSource(pc, ImmutableList.of(ses), assemblyFile);
    aes.assembleBreakends(null);
    aes.ensureExtracted();
    VariantCaller caller = new VariantCaller(pc, ImmutableList.of(ses), aes);
    caller.callBreakends(output, MoreExecutors.newDirectExecutorService());
    AllocateEvidence cmd = new AllocateEvidence();
    cmd.INPUT_VCF = output;
    cmd.setContext(pc);
    cmd.setAssemblySource(aes);
    cmd.setSamEvidenceSources(ImmutableList.of(ses));
    cmd.OUTPUT_VCF = new File(testFolder.getRoot(), "annotated.vcf");
    List<VariantContextDirectedBreakpoint> vcfs = Lists.newArrayList(Iterables.filter(getVcf(output, null), VariantContextDirectedBreakpoint.class));
    // both breakends
    assertEquals(2 * 1, vcfs.size());
    assertSymmetrical(vcfs);
    List<VariantContextDirectedBreakpoint> results = Lists.newArrayList(cmd.iterator(new AutoClosingIterator<>(vcfs.iterator()), MoreExecutors.newDirectExecutorService()));
    assertSymmetrical(results);
    assertEquals(vcfs.size(), results.size());
    VariantContextDirectedBreakpoint e = results.get(0);
    assertEquals(2, e.getBreakpointEvidenceCount());
    assertEquals(2, e.getBreakendEvidenceCountSoftClip());
}
Also used : ProcessingContext(au.edu.wehi.idsv.ProcessingContext) AssemblyEvidenceSource(au.edu.wehi.idsv.AssemblyEvidenceSource) AutoClosingIterator(au.edu.wehi.idsv.util.AutoClosingIterator) VariantContextDirectedBreakpoint(au.edu.wehi.idsv.VariantContextDirectedBreakpoint) SAMEvidenceSource(au.edu.wehi.idsv.SAMEvidenceSource) VariantCaller(au.edu.wehi.idsv.VariantCaller) File(java.io.File) IntermediateFilesTest(au.edu.wehi.idsv.IntermediateFilesTest) Test(org.junit.Test)

Example 2 with AutoClosingIterator

use of au.edu.wehi.idsv.util.AutoClosingIterator in project gridss by PapenfussLab.

the class AllocateEvidenceTest method should_apply_filters.

@Test
public void should_apply_filters() throws IOException {
    final ProcessingContext pc = getCommandlineContext();
    pc.getVariantCallingParameters().minScore = 0;
    pc.getVariantCallingParameters().minSize = 0;
    createInput(RP(0, 1, 10), DP(0, 1, "5M5S", true, 1, 10, "5M", true));
    SAMEvidenceSource ses = new SAMEvidenceSource(getContext(), input, null, 0);
    ses.ensureMetrics();
    File assemblyFile = new File(testFolder.getRoot(), "assembly.bam");
    AssemblyEvidenceSource aes = new AssemblyEvidenceSource(pc, ImmutableList.of(ses), assemblyFile);
    aes.assembleBreakends(null);
    aes.ensureExtracted();
    VariantCaller caller = new VariantCaller(pc, ImmutableList.of(ses), aes);
    caller.callBreakends(output, MoreExecutors.newDirectExecutorService());
    AllocateEvidence cmd = new AllocateEvidence();
    cmd.INPUT_VCF = output;
    cmd.setContext(pc);
    cmd.setAssemblySource(aes);
    cmd.setSamEvidenceSources(ImmutableList.of(ses));
    cmd.OUTPUT_VCF = new File(testFolder.getRoot(), "annotated.vcf");
    List<VariantContextDirectedBreakpoint> vcfs = Lists.newArrayList(Iterables.filter(getVcf(output, null), VariantContextDirectedBreakpoint.class));
    // both breakends
    assertEquals(2 * 1, vcfs.size());
    assertSymmetrical(vcfs);
    List<VariantContextDirectedBreakpoint> results = Lists.newArrayList(cmd.iterator(new AutoClosingIterator<>(vcfs.iterator()), MoreExecutors.newDirectExecutorService()));
    assertSymmetrical(results);
    // single read support
    assertEquals(0, results.size());
}
Also used : ProcessingContext(au.edu.wehi.idsv.ProcessingContext) AssemblyEvidenceSource(au.edu.wehi.idsv.AssemblyEvidenceSource) AutoClosingIterator(au.edu.wehi.idsv.util.AutoClosingIterator) VariantContextDirectedBreakpoint(au.edu.wehi.idsv.VariantContextDirectedBreakpoint) SAMEvidenceSource(au.edu.wehi.idsv.SAMEvidenceSource) VariantCaller(au.edu.wehi.idsv.VariantCaller) File(java.io.File) IntermediateFilesTest(au.edu.wehi.idsv.IntermediateFilesTest) Test(org.junit.Test)

Example 3 with AutoClosingIterator

use of au.edu.wehi.idsv.util.AutoClosingIterator in project gridss by PapenfussLab.

the class VcfTransformCommandLineProgram method getAllCalls.

public Iterator<IdsvVariantContext> getAllCalls(File file, CloseableIterator<VariantContextDirectedBreakpoint> breakpointCalls) {
    VCFFileReader vcfReader = new VCFFileReader(file, false);
    CloseableIterator<VariantContext> it = vcfReader.iterator();
    Iterator<IdsvVariantContext> idsvIt = Iterators.transform(it, variant -> IdsvVariantContext.create(getContext(), null, variant));
    Iterator<IdsvVariantContext> nonbpIt = Iterators.filter(idsvIt, variant -> !(variant instanceof VariantContextDirectedBreakpoint));
    // sort back to nominal VCF position
    Iterator<VariantContextDirectedBreakpoint> bpit = new VariantContextWindowedSortingIterator<>(getContext(), SAMEvidenceSource.maximumWindowSize(getContext(), getSamEvidenceSources(), getAssemblySource()), breakpointCalls);
    Iterator<IdsvVariantContext> mergedIt = Iterators.mergeSorted(ImmutableList.of(bpit, nonbpIt), IdsvVariantContext.ByLocationStart);
    return new AutoClosingIterator<>(mergedIt, vcfReader, it);
}
Also used : VCFFileReader(htsjdk.variant.vcf.VCFFileReader) AutoClosingIterator(au.edu.wehi.idsv.util.AutoClosingIterator) VariantContext(htsjdk.variant.variantcontext.VariantContext) IdsvVariantContext(au.edu.wehi.idsv.IdsvVariantContext) IdsvVariantContext(au.edu.wehi.idsv.IdsvVariantContext) VariantContextDirectedBreakpoint(au.edu.wehi.idsv.VariantContextDirectedBreakpoint) VariantContextWindowedSortingIterator(au.edu.wehi.idsv.VariantContextWindowedSortingIterator)

Example 4 with AutoClosingIterator

use of au.edu.wehi.idsv.util.AutoClosingIterator in project gridss by PapenfussLab.

the class GenomicProcessingContext method getSamReaderIterator.

private CloseableIterator<SAMRecord> getSamReaderIterator(SamReader reader, SortOrder expectedOrder, File file) {
    SAMRecordIterator rawIterator = reader.iterator();
    if (expectedOrder != null && expectedOrder != SortOrder.unsorted) {
        rawIterator.assertSorted(expectedOrder);
    }
    // wrap so we're happy to close as many times as we want
    CloseableIterator<SAMRecord> safeIterator = new AutoClosingIterator<SAMRecord>(rawIterator, reader);
    return applyCommonSAMRecordFilters(safeIterator);
}
Also used : SAMRecordIterator(htsjdk.samtools.SAMRecordIterator) SAMRecord(htsjdk.samtools.SAMRecord) AutoClosingIterator(au.edu.wehi.idsv.util.AutoClosingIterator)

Example 5 with AutoClosingIterator

use of au.edu.wehi.idsv.util.AutoClosingIterator in project gridss by PapenfussLab.

the class SAMEvidenceSource method iterator.

public CloseableIterator<DirectedEvidence> iterator(final QueryInterval[] intervals) {
    SamReader reader = getReader();
    // expand query bounds as the alignment for a discordant read pair could fall before or after the breakend interval we are extracting
    SAMRecordIterator it = tryOpenReader(reader, QueryIntervalUtil.padIntervals(getContext().getDictionary(), intervals, getMaxConcordantFragmentSize() + 1));
    Iterator<DirectedEvidence> eit = asEvidence(it);
    eit = Iterators.filter(eit, e -> QueryIntervalUtil.overlaps(intervals, e.getBreakendSummary()));
    return new AutoClosingIterator<>(eit, reader, it);
}
Also used : TextCigarCodec(htsjdk.samtools.TextCigarCodec) Cigar(htsjdk.samtools.Cigar) CloseableIterator(htsjdk.samtools.util.CloseableIterator) Iterables(com.google.common.collect.Iterables) SAMRecordUtil(au.edu.wehi.idsv.sam.SAMRecordUtil) BufferedIterator(au.edu.wehi.idsv.util.BufferedIterator) AsyncBufferedIterator(au.edu.wehi.idsv.util.AsyncBufferedIterator) Iterators(com.google.common.collect.Iterators) ComputeSamTags(gridss.ComputeSamTags) SoftClipsToSplitReads(gridss.SoftClipsToSplitReads) SortOrder(htsjdk.samtools.SAMFileHeader.SortOrder) GridssConfiguration(au.edu.wehi.idsv.configuration.GridssConfiguration) SAMTag(htsjdk.samtools.SAMTag) CollectGridssMetrics(gridss.analysis.CollectGridssMetrics) Lists(com.google.common.collect.Lists) AutoClosingIterator(au.edu.wehi.idsv.util.AutoClosingIterator) ImmutableList(com.google.common.collect.ImmutableList) FileHelper(au.edu.wehi.idsv.util.FileHelper) StructuralVariantReadMetrics(gridss.analysis.StructuralVariantReadMetrics) ChimericAlignment(au.edu.wehi.idsv.sam.ChimericAlignment) CommandLineProgramHelper(gridss.cmdline.CommandLineProgramHelper) PairOrientation(htsjdk.samtools.SamPairUtil.PairOrientation) Iterator(java.util.Iterator) IdsvSamFileMetrics(au.edu.wehi.idsv.metrics.IdsvSamFileMetrics) SAMRecordIterator(htsjdk.samtools.SAMRecordIterator) SAMSequenceDictionary(htsjdk.samtools.SAMSequenceDictionary) IOException(java.io.IOException) SoftClipConfiguration(au.edu.wehi.idsv.configuration.SoftClipConfiguration) OrderAssertingIterator(au.edu.wehi.idsv.validation.OrderAssertingIterator) SamReader(htsjdk.samtools.SamReader) MetricsFile(htsjdk.samtools.metrics.MetricsFile) Collectors(java.util.stream.Collectors) File(java.io.File) IntervalBed(au.edu.wehi.idsv.bed.IntervalBed) AutoClosingMergedIterator(au.edu.wehi.idsv.util.AutoClosingMergedIterator) SAMRecord(htsjdk.samtools.SAMRecord) CommandLineProgram(picard.cmdline.CommandLineProgram) List(java.util.List) ExtractSVReads(gridss.ExtractSVReads) Log(htsjdk.samtools.util.Log) QueryInterval(htsjdk.samtools.QueryInterval) ReferenceCommandLineProgram(gridss.cmdline.ReferenceCommandLineProgram) SAMFileUtil(au.edu.wehi.idsv.sam.SAMFileUtil) CigarUtil(au.edu.wehi.idsv.sam.CigarUtil) SamReaderFactory(htsjdk.samtools.SamReaderFactory) SamReader(htsjdk.samtools.SamReader) SAMRecordIterator(htsjdk.samtools.SAMRecordIterator) AutoClosingIterator(au.edu.wehi.idsv.util.AutoClosingIterator)

Aggregations

AutoClosingIterator (au.edu.wehi.idsv.util.AutoClosingIterator)9 VariantContextDirectedBreakpoint (au.edu.wehi.idsv.VariantContextDirectedBreakpoint)6 File (java.io.File)5 AssemblyEvidenceSource (au.edu.wehi.idsv.AssemblyEvidenceSource)4 IntermediateFilesTest (au.edu.wehi.idsv.IntermediateFilesTest)4 ProcessingContext (au.edu.wehi.idsv.ProcessingContext)4 SAMEvidenceSource (au.edu.wehi.idsv.SAMEvidenceSource)4 VariantCaller (au.edu.wehi.idsv.VariantCaller)4 Test (org.junit.Test)4 SAMRecordIterator (htsjdk.samtools.SAMRecordIterator)3 IdsvVariantContext (au.edu.wehi.idsv.IdsvVariantContext)2 SAMRecord (htsjdk.samtools.SAMRecord)2 SamReader (htsjdk.samtools.SamReader)2 VariantContextWindowedSortingIterator (au.edu.wehi.idsv.VariantContextWindowedSortingIterator)1 IntervalBed (au.edu.wehi.idsv.bed.IntervalBed)1 GridssConfiguration (au.edu.wehi.idsv.configuration.GridssConfiguration)1 SoftClipConfiguration (au.edu.wehi.idsv.configuration.SoftClipConfiguration)1 IdsvSamFileMetrics (au.edu.wehi.idsv.metrics.IdsvSamFileMetrics)1 ChimericAlignment (au.edu.wehi.idsv.sam.ChimericAlignment)1 CigarUtil (au.edu.wehi.idsv.sam.CigarUtil)1