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());
}
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());
}
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);
}
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);
}
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);
}
Aggregations