Search in sources :

Example 6 with SAMEvidenceSource

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

the class AssembleBreakends method doWork.

@Override
public int doWork(ExecutorService threadpool) throws IOException {
    IOUtil.assertFileIsWritable(OUTPUT);
    ProcessingContext pc = getContext();
    List<SAMEvidenceSource> sources = getSamEvidenceSources();
    AssemblyEvidenceSource assembler = new AssemblyEvidenceSource(pc, sources, OUTPUT);
    assembler.assembleBreakends(threadpool);
    return 0;
}
Also used : ProcessingContext(au.edu.wehi.idsv.ProcessingContext) AssemblyEvidenceSource(au.edu.wehi.idsv.AssemblyEvidenceSource) SAMEvidenceSource(au.edu.wehi.idsv.SAMEvidenceSource)

Example 7 with SAMEvidenceSource

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

the class CallVariants method extractEvidence.

private void extractEvidence(ExecutorService threadpool, List<SAMEvidenceSource> samEvidence) throws InterruptedException, ExecutionException {
    log.info("Extracting evidence.");
    for (Future<Void> future : threadpool.invokeAll(Lists.transform(samEvidence, new Function<SAMEvidenceSource, Callable<Void>>() {

        @Override
        public Callable<Void> apply(final SAMEvidenceSource input) {
            return new Callable<Void>() {

                @Override
                public Void call() throws Exception {
                    try {
                        input.ensureMetrics();
                        InsertSizeMetrics ism = input.getMetrics().getInsertSizeMetrics();
                        if (ism != null && ism.PAIR_ORIENTATION != PairOrientation.FR) {
                            String msg = "GRIDSS currently supports only FR read pair orientation. If usage with other read pair orientations is required, please raise an enchancement request at https://github.com/PapenfussLab/gridss/issues";
                            log.error(msg);
                            throw new RuntimeException(msg);
                        }
                        input.ensureExtracted();
                    } catch (Exception e) {
                        log.error(e, "Fatal exception thrown by worker thread.");
                        if (getContext().getConfig().terminateOnFirstError) {
                            System.exit(1);
                        }
                        throw e;
                    }
                    return null;
                }
            };
        }
    }))) {
        // throw exception from worker thread here
        future.get();
    }
    log.info("Evidence extraction complete.");
}
Also used : Function(com.google.common.base.Function) InsertSizeMetrics(picard.analysis.InsertSizeMetrics) SAMEvidenceSource(au.edu.wehi.idsv.SAMEvidenceSource) Callable(java.util.concurrent.Callable) IOException(java.io.IOException) ExecutionException(java.util.concurrent.ExecutionException)

Example 8 with SAMEvidenceSource

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

the class AnnotateReferenceCoverage method iterator.

@Override
public CloseableIterator<VariantContextDirectedBreakpoint> iterator(CloseableIterator<VariantContextDirectedBreakpoint> calls, ExecutorService threadpool) {
    ProcessingContext context = getContext();
    List<SAMEvidenceSource> sources = getSamEvidenceSources();
    AssemblyEvidenceSource asm = getAssemblySource();
    int windowSize = SAMEvidenceSource.maximumWindowSize(context, sources, asm);
    return new SequentialCoverageAnnotator<VariantContextDirectedBreakpoint>(context, sources, calls, 2 * windowSize + WINDOW_SIZE_SAFETY_MARGIN, threadpool);
}
Also used : ProcessingContext(au.edu.wehi.idsv.ProcessingContext) AssemblyEvidenceSource(au.edu.wehi.idsv.AssemblyEvidenceSource) SAMEvidenceSource(au.edu.wehi.idsv.SAMEvidenceSource) SequentialCoverageAnnotator(au.edu.wehi.idsv.SequentialCoverageAnnotator) VariantContextDirectedBreakpoint(au.edu.wehi.idsv.VariantContextDirectedBreakpoint)

Example 9 with SAMEvidenceSource

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

the class AllocateEvidenceTest method should_uniquely_assign.

@Test
public void should_uniquely_assign() throws IOException, InterruptedException, ExecutionException {
    final int fragSize = 4;
    final int testSize = 64;
    final List<SAMRecord> in = new ArrayList<SAMRecord>();
    final ProcessingContext pc = getCommandlineContext();
    pc.getVariantCallingParameters().writeFiltered = true;
    pc.getVariantCallingParameters().minScore = 0;
    StubSAMEvidenceSource ses = new StubSAMEvidenceSource(pc, input, 0, 0, fragSize);
    for (int i = 1; i < testSize; i++) {
        for (int j = 1; j < testSize; j++) {
            SAMRecord[] dp = withReadName(String.format("read-%d-%d", i, j), DP(0, i, "1M", true, 1, j, "1M", false));
            ses.evidence.add(NonReferenceReadPair.create(dp[0], dp[1], ses));
            ses.evidence.add(NonReferenceReadPair.create(dp[1], dp[0], ses));
            in.add(dp[0]);
            in.add(dp[1]);
        }
    }
    StubAssemblyEvidenceSource aes = new StubAssemblyEvidenceSource(pc);
    aes.fragSize = fragSize;
    Collections.sort(ses.evidence, DirectedEvidenceOrder.ByNatural);
    createInput(in);
    VariantCaller vc = new VariantCaller(pc, ImmutableList.<SAMEvidenceSource>of(ses), aes);
    ExecutorService threadpool = Executors.newSingleThreadExecutor();
    vc.callBreakends(output, threadpool);
    threadpool.shutdown();
    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");
    cmd.ASSEMBLY = new File(testFolder.getRoot(), "assembly.bam");
    // to shut up the command-line parsing
    createBAM(cmd.ASSEMBLY, SortOrder.coordinate, Collections.emptyList());
    cmd.doWork(null);
    // List<IdsvVariantContext> annotated = getVcf(new File(testFolder.getRoot(), "out.vcf"), null);
    List<IdsvVariantContext> rawcalls = getVcf(output, null);
    List<IdsvVariantContext> calls = getVcf(cmd.OUTPUT_VCF, null);
    assertSymmetrical(rawcalls.stream().map(x -> (VariantContextDirectedBreakpoint) x).collect(Collectors.toList()));
    assertSymmetrical(calls.stream().map(x -> (VariantContextDirectedBreakpoint) x).collect(Collectors.toList()));
    // with no filtering, annotation should not change call set
    double expectedEvidence = 0;
    for (DirectedEvidence e : ses.evidence) {
        DiscordantReadPair bp = (DiscordantReadPair) e;
        expectedEvidence += bp.getBreakpointQual();
    }
    double annotatedEvidence = 0;
    for (IdsvVariantContext e : calls) {
        annotatedEvidence += e.getPhredScaledQual();
    }
    double rawEvidence = rawcalls.stream().mapToDouble(e -> e.getPhredScaledQual()).sum();
    // unique assignment must result in the evidence total being, at most, the same
    assertTrue(annotatedEvidence <= rawEvidence);
    // each piece of evidence should be assigned to a single breakpoint so totals should match
    int rpCalls = calls.stream().mapToInt(v -> ((VariantContextDirectedBreakpoint) v).getBreakpointEvidenceCount()).sum();
    assertEquals(ses.evidence.size(), rpCalls);
    // floating point truncation on VCF is severe!
    assertEquals(expectedEvidence, annotatedEvidence, 20);
}
Also used : AssemblyEvidenceSource(au.edu.wehi.idsv.AssemblyEvidenceSource) DirectedEvidenceOrder(au.edu.wehi.idsv.DirectedEvidenceOrder) Iterables(com.google.common.collect.Iterables) MoreExecutors(com.google.common.util.concurrent.MoreExecutors) SAMEvidenceSource(au.edu.wehi.idsv.SAMEvidenceSource) ArrayList(java.util.ArrayList) SortOrder(htsjdk.samtools.SAMFileHeader.SortOrder) VariantContextDirectedBreakpoint(au.edu.wehi.idsv.VariantContextDirectedBreakpoint) Lists(com.google.common.collect.Lists) AutoClosingIterator(au.edu.wehi.idsv.util.AutoClosingIterator) ImmutableList(com.google.common.collect.ImmutableList) ProcessingContext(au.edu.wehi.idsv.ProcessingContext) ExecutorService(java.util.concurrent.ExecutorService) VariantCaller(au.edu.wehi.idsv.VariantCaller) IntermediateFilesTest(au.edu.wehi.idsv.IntermediateFilesTest) NonReferenceReadPair(au.edu.wehi.idsv.NonReferenceReadPair) Assert.assertTrue(org.junit.Assert.assertTrue) Set(java.util.Set) IOException(java.io.IOException) Test(org.junit.Test) Collectors(java.util.stream.Collectors) DirectedEvidence(au.edu.wehi.idsv.DirectedEvidence) File(java.io.File) Executors(java.util.concurrent.Executors) SAMRecord(htsjdk.samtools.SAMRecord) ExecutionException(java.util.concurrent.ExecutionException) DiscordantReadPair(au.edu.wehi.idsv.DiscordantReadPair) List(java.util.List) IdsvVariantContext(au.edu.wehi.idsv.IdsvVariantContext) Collections(java.util.Collections) Assert.assertEquals(org.junit.Assert.assertEquals) ProcessingContext(au.edu.wehi.idsv.ProcessingContext) ArrayList(java.util.ArrayList) IdsvVariantContext(au.edu.wehi.idsv.IdsvVariantContext) VariantContextDirectedBreakpoint(au.edu.wehi.idsv.VariantContextDirectedBreakpoint) VariantContextDirectedBreakpoint(au.edu.wehi.idsv.VariantContextDirectedBreakpoint) DirectedEvidence(au.edu.wehi.idsv.DirectedEvidence) SAMRecord(htsjdk.samtools.SAMRecord) ExecutorService(java.util.concurrent.ExecutorService) VariantCaller(au.edu.wehi.idsv.VariantCaller) DiscordantReadPair(au.edu.wehi.idsv.DiscordantReadPair) File(java.io.File) IntermediateFilesTest(au.edu.wehi.idsv.IntermediateFilesTest) Test(org.junit.Test)

Example 10 with SAMEvidenceSource

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

the class AllocateEvidenceTest method should_filter_if_insufficient_reads.

@Test
public void should_filter_if_insufficient_reads() throws IOException {
    final ProcessingContext pc = getCommandlineContext();
    pc.getVariantCallingParameters().minScore = 0;
    pc.getVariantCallingParameters().minSize = 0;
    pc.getVariantCallingParameters().minReads = 3;
    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));
    List<VariantContextDirectedBreakpoint> results = Lists.newArrayList(cmd.iterator(new AutoClosingIterator<>(vcfs.iterator()), MoreExecutors.newDirectExecutorService()));
    assertEquals(2, vcfs.size());
    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)

Aggregations

SAMEvidenceSource (au.edu.wehi.idsv.SAMEvidenceSource)12 ProcessingContext (au.edu.wehi.idsv.ProcessingContext)9 AssemblyEvidenceSource (au.edu.wehi.idsv.AssemblyEvidenceSource)8 Test (org.junit.Test)8 IntermediateFilesTest (au.edu.wehi.idsv.IntermediateFilesTest)6 VariantContextDirectedBreakpoint (au.edu.wehi.idsv.VariantContextDirectedBreakpoint)6 File (java.io.File)6 VariantCaller (au.edu.wehi.idsv.VariantCaller)5 AutoClosingIterator (au.edu.wehi.idsv.util.AutoClosingIterator)5 DirectedEvidence (au.edu.wehi.idsv.DirectedEvidence)3 ArrayList (java.util.ArrayList)3 DiscordantReadPair (au.edu.wehi.idsv.DiscordantReadPair)2 SAMRecord (htsjdk.samtools.SAMRecord)2 IOException (java.io.IOException)2 ExecutionException (java.util.concurrent.ExecutionException)2 DirectedEvidenceOrder (au.edu.wehi.idsv.DirectedEvidenceOrder)1 IdsvVariantContext (au.edu.wehi.idsv.IdsvVariantContext)1 NonReferenceReadPair (au.edu.wehi.idsv.NonReferenceReadPair)1 SequentialCoverageAnnotator (au.edu.wehi.idsv.SequentialCoverageAnnotator)1 SoftClipEvidence (au.edu.wehi.idsv.SoftClipEvidence)1